use of org.valkyrienskies.mod.common.collision.WaterForcesTask in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class VSWorldPhysicsLoop method tickThePhysicsAndCollision.
/**
* Ticks physics and collision for the List of PhysicsWrapperEntity passed in.
*/
private void tickThePhysicsAndCollision(List<PhysicsObject> shipsWithPhysics, double timeStep) {
final List<ShipCollisionTask> collisionTasks = new ArrayList<>(shipsWithPhysics.size() * 2);
final List<WaterForcesTask> waterForcesTasks = new ArrayList<>();
for (PhysicsObject wrapper : shipsWithPhysics) {
// Update the physics simulation
try {
wrapper.getPhysicsCalculations().rawPhysTickPreCol(timeStep);
// Do water collision and buoyancy
wrapper.getPhysicsCalculations().getWorldWaterCollider().tickUpdatingTheCollisionCache();
// Add water forces tasks to be processed in parallel
waterForcesTasks.addAll(wrapper.getPhysicsCalculations().getWorldWaterCollider().generateWaterForceTasks());
// Update the collision task if necessary
wrapper.getPhysicsCalculations().getWorldCollision().tickUpdatingTheCollisionCache();
// Take the big collision and split into tiny ones
wrapper.getPhysicsCalculations().getWorldCollision().splitIntoCollisionTasks(collisionTasks);
} catch (Exception e) {
e.printStackTrace();
}
}
final List<Callable<Void>> allTasks = new ArrayList<>();
allTasks.addAll(collisionTasks);
allTasks.addAll(waterForcesTasks);
try {
// Run all the block collision and water physics tasks
ValkyrienSkiesMod.getPhysicsThreadPool().invokeAll(allTasks);
} catch (Exception e) {
e.printStackTrace();
}
// Handle the results of water force tasks
for (final WaterForcesTask waterForcesTask : waterForcesTasks) {
waterForcesTask.addForcesToShip();
}
// this thread. Thankfully this step is not cpu intensive.
for (ShipCollisionTask task : collisionTasks) {
task.getToTask().processCollisionTask(task);
}
for (PhysicsObject wrapper : shipsWithPhysics) {
try {
wrapper.getPhysicsCalculations().rawPhysTickPostCol();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations