use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldShipLoadingController method determineLoadAndUnload.
/**
* Tells the WorldServerShipManager which ships to load/unload/load in background.
*/
void determineLoadAndUnload() {
for (ShipData data : QueryableShipData.get(shipManager.getWorld())) {
ShipTransform transform = data.getShipTransform();
Vec3d shipPos = transform.getShipPositionVec3d();
if (shipManager.getPhysObjectFromUUID(data.getUuid()) == null) {
if (existsPlayerWithinDistanceXZ(shipManager.getWorld(), shipPos, VSConfig.SHIP_LOADING_SETTINGS.loadDistance)) {
shipManager.queueShipLoad(data.getUuid());
} else {
if (VSConfig.SHIP_LOADING_SETTINGS.permanentlyLoaded || existsPlayerWithinDistanceXZ(shipManager.getWorld(), shipPos, VSConfig.SHIP_LOADING_SETTINGS.loadBackgroundDistance)) {
shipManager.queueShipLoadBackground(data.getUuid());
}
}
} else {
if (!VSConfig.SHIP_LOADING_SETTINGS.permanentlyLoaded && !existsPlayerWithinDistanceXZ(shipManager.getWorld(), shipPos, VSConfig.SHIP_LOADING_SETTINGS.unloadDistance)) {
shipManager.queueShipUnload(data.getUuid());
}
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class TileEntityBoatChair method getTorqueInGlobal.
@Nullable
public Vector3dc getTorqueInGlobal(PhysicsCalculations physicsCalculations) {
// Don't add force if theres no pilot
if (getPilotEntity() == null) {
return null;
}
final PhysicsObject physicsObject = physicsCalculations.getParent();
final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
final Vector3dc idealAngularVelocity = shipTransform.transformDirectionNew(new Vector3d(targetAngularVelocity), TransformType.SUBSPACE_TO_GLOBAL);
final Vector3dc currentAngularVelocity = physicsCalculations.getAngularVelocity();
final Vector3dc velocityDifference = idealAngularVelocity.sub(currentAngularVelocity, new Vector3d());
final Vector3d resultingTorque = physicsCalculations.getPhysMOITensor().transform(velocityDifference, new Vector3d());
resultingTorque.mul(physicsCalculations.getPhysicsTimeDeltaPerPhysTick());
resultingTorque.mul(ANGULAR_EMA_FILTER_CONSTANT);
// Only effect y axis
resultingTorque.x = 0;
resultingTorque.z = 0;
// Add a stabilization torque
final Vector3dc shipUp = shipTransform.transformDirectionNew(new Vector3d(0, 1, 0), TransformType.SUBSPACE_TO_GLOBAL);
final Vector3dc idealUp = new Vector3d(0, 1, 0);
final double angleBetween = shipUp.angle(idealUp);
if (angleBetween > .01) {
final Vector3dc stabilizationRotationAxisNormalized = shipUp.cross(idealUp, new Vector3d()).normalize();
final Vector3d stabilizationTorque = physicsCalculations.getPhysMOITensor().transform(stabilizationRotationAxisNormalized.mul(angleBetween, new Vector3d()));
stabilizationTorque.mul(physicsCalculations.getPhysicsTimeDeltaPerPhysTick());
stabilizationTorque.mul(STABILIZATION_TORQUE_CONSTANT);
resultingTorque.add(stabilizationTorque);
}
return resultingTorque;
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method destroyShip.
void destroyShip() {
// Then tell the game to stop tracking/loading the chunks
List<EntityPlayerMP> watchersCopy = new ArrayList<>(getWatchingPlayers());
for (ChunkPos chunkPos : getChunkClaim()) {
SPacketUnloadChunk unloadPacket = new SPacketUnloadChunk(chunkPos.x, chunkPos.z);
for (EntityPlayerMP wachingPlayer : watchersCopy) {
wachingPlayer.connection.sendPacket(unloadPacket);
}
// NOTICE: This method isnt being called to avoid the
// watchingPlayers.remove(player) call, which is a waste of CPU time
// onPlayerUntracking(wachingPlayer);
}
getWatchingPlayers().clear();
// Finally, copy all the blocks from the ship to the world
if (!getBlockPositions().isEmpty()) {
if (deconstructState.copyBlocks) {
MutableBlockPos newPos = new MutableBlockPos();
ShipTransform currentTransform = getShipTransformationManager().getCurrentTickTransform();
Vector3dc position = new Vector3d(currentTransform.getPosX(), currentTransform.getPosY(), currentTransform.getPosZ());
BlockPos centerDifference = new BlockPos(Math.round(getCenterCoord().x() - position.x()), Math.round(getCenterCoord().y() - position.y()), Math.round(getCenterCoord().z() - position.z()));
for (BlockPos oldPos : this.getBlockPositions()) {
newPos.setPos(oldPos.getX() - centerDifference.getX(), oldPos.getY() - centerDifference.getY(), oldPos.getZ() - centerDifference.getZ());
MoveBlocks.copyBlockToPos(getWorld(), oldPos, newPos, null);
}
// Then relight the chunks we just copied the blocks to
{
Set<Long> chunksRelit = new HashSet<>();
for (BlockPos changedPos : this.getBlockPositions()) {
int changedChunkX = (changedPos.getX() - centerDifference.getX()) >> 4;
int changedChunkZ = (changedPos.getZ() - centerDifference.getZ()) >> 4;
long changedChunkPos = ChunkPos.asLong(changedChunkX, changedChunkZ);
if (chunksRelit.contains(changedChunkPos)) {
continue;
}
final Chunk chunk = world.getChunk(changedChunkX, changedChunkZ);
chunk.generateSkylightMap();
chunk.checkLight();
chunk.markDirty();
chunksRelit.add(changedChunkPos);
}
}
}
// Just delete the tile entities in ship to prevent any dupe bugs.
for (BlockPos oldPos : this.getBlockPositions()) {
getWorld().removeTileEntity(oldPos);
}
}
// Delete all the old ship chunks
getClaimedChunkCache().deleteShipChunksFromWorld();
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method onTick.
void onTick() {
if (!world.isRemote) {
cachedSurroundingChunks.updateChunkCache();
final boolean forceToUseShipDataTransformLocalCopy = forceToUseShipDataTransform;
forceToUseShipDataTransform = false;
if (forceToUseShipDataTransformLocalCopy) {
final ShipTransform forcedTransform = shipData.getShipTransform();
// This is BAD! Race condition! But I don't think this will cause any problems (I hope).
getShipTransformationManager().setPrevPhysicsTransform(forcedTransform);
getShipTransformationManager().setCurrentPhysicsTransform(forcedTransform);
getShipTransformationManager().setPrevTickTransform(forcedTransform);
getShipTransformationManager().setCurrentTickTransform(forcedTransform);
}
ticksSinceShipTeleport++;
ShipTransform physicsTransform = getShipTransformationManager().getCurrentPhysicsTransform();
getShipTransformationManager().updateAllTransforms(physicsTransform, false, true);
// Copy the current and prev transforms into ShipData
getShipData().setShipTransform(getShipTransformationManager().getCurrentTickTransform());
getShipData().setPrevTickShipTransform(getShipTransformationManager().getPrevTickTransform());
} else {
transformInterpolator.tickTransformInterpolator();
ShipTransform newTransform = transformInterpolator.getCurrentTickTransform();
AxisAlignedBB newAABB = transformInterpolator.getCurrentAABB();
shipData.setPrevTickShipTransform(shipData.getShipTransform());
shipData.setShipTransform(newTransform);
shipData.setShipBB(newAABB);
shipTransformationManager.updateAllTransforms(newTransform, false, false);
}
this.ticksExisted++;
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipPilot method getBlockForceInShipSpace.
public Vector3dc getBlockForceInShipSpace(PhysicsObject physicsObject, double secondsToApply) {
final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
final Vector3dc idealLinearVelocity = shipTransform.transformDirectionNew(new Vector3d(targetLinearVelocity), TransformType.SUBSPACE_TO_GLOBAL);
final Vector3dc currentLinearVelocity = physicsObject.getPhysicsCalculations().getLinearVelocity();
final Vector3dc velocityDifference = idealLinearVelocity.sub(currentLinearVelocity, new Vector3d());
final Vector3d resultingBlockForce = new Vector3d(velocityDifference);
resultingBlockForce.mul(physicsObject.getInertiaData().getGameTickMass());
resultingBlockForce.mul(secondsToApply);
resultingBlockForce.mul(LINEAR_EMA_FILTER_CONSTANT);
// Do not affect y axis
resultingBlockForce.y = 0;
return resultingBlockForce;
}
Aggregations