use of org.valkyrienskies.mod.common.network.ShipTransformUpdateMessage in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class VSWorldPhysicsLoop method physicsTick.
private void physicsTick(double delta) {
// Update the immutable ship list.
immutableShipsList = ((IHasShipManager) hostWorld).getManager().getAllLoadedThreadSafe();
// Run tasks queued to run on physics thread
recurringTasks.forEach(t -> t.runTask(delta));
taskQueue.forEach(Runnable::run);
taskQueue.clear();
// Make a sublist of physics objects to process physics on.
List<PhysicsObject> physicsEntitiesToDoPhysics = new ArrayList<>();
for (PhysicsObject physicsObject : immutableShipsList) {
if (physicsObject.isPhysicsReady() && physicsObject.isPhysicsEnabled() && physicsObject.getCachedSurroundingChunks() != null) {
physicsEntitiesToDoPhysics.add(physicsObject);
}
}
// Finally, actually process the physics tick
tickThePhysicsAndCollision(physicsEntitiesToDoPhysics, delta);
// Send ship position update packets around 20 times a second
final long currentTimeMillis = System.currentTimeMillis();
final double secondsSinceLastPacket = (currentTimeMillis - lastPacketSendTime) / 1000.0;
// Use .04 to guarantee we're always sending at least 20 packets per second
if (secondsSinceLastPacket > .04) {
// Update the last update time
lastPacketSendTime = currentTimeMillis;
try {
// At the end, send the transform update packets
final ShipTransformUpdateMessage shipTransformUpdateMessage = new ShipTransformUpdateMessage();
final int dimensionID = hostWorld.provider.getDimension();
shipTransformUpdateMessage.setDimensionID(dimensionID);
for (final PhysicsObject physicsObject : immutableShipsList) {
final UUID shipUUID = physicsObject.getUuid();
final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
final AxisAlignedBB shipBB = physicsObject.getPhysicsTransformAABB();
shipTransformUpdateMessage.addData(shipUUID, shipTransform, shipBB);
}
ValkyrienSkiesMod.physWrapperTransformUpdateNetwork.sendToDimension(shipTransformUpdateMessage, shipTransformUpdateMessage.getDimensionID());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations