convert server physics cell generation to executor
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-11-29 11:52:07 -05:00
parent 561576a758
commit 36d2271b35
5 changed files with 36 additions and 13 deletions

View File

@ -1167,6 +1167,7 @@ Fix particles not spawning in correct positions
(11/28/2024) (11/28/2024)
Fix block not firing Fix block not firing
Fix reentrant locking bug Fix reentrant locking bug
Convert server physics cell generation to executor service
# TODO # TODO

View File

@ -122,6 +122,9 @@ public class ThreadManager {
if(realm.getServerWorldData() != null && realm.getServerWorldData().getServerBlockManager() != null){ if(realm.getServerWorldData() != null && realm.getServerWorldData().getServerBlockManager() != null){
realm.getServerWorldData().getServerBlockManager().closeThreads(); realm.getServerWorldData().getServerBlockManager().closeThreads();
} }
if(realm.getDataCellManager() != null){
realm.getDataCellManager().halt();
}
} }
} }

View File

@ -8,13 +8,14 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import org.joml.Vector3d; import org.joml.Vector3d;
import org.joml.Vector3i; import org.joml.Vector3i;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.engine.threads.LabeledThread.ThreadLabel;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.ServerEntityUtils; import electrosphere.entity.ServerEntityUtils;
@ -56,6 +57,11 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
*/ */
static final int UNLOAD_FRAME_THRESHOLD = 100; static final int UNLOAD_FRAME_THRESHOLD = 100;
/**
* Used for generating physics chunks
*/
static final ExecutorService generationService = Executors.newFixedThreadPool(4);
/** /**
* Tracks whether this manager has been flagged to unload cells or not * Tracks whether this manager has been flagged to unload cells or not
*/ */
@ -568,21 +574,17 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
* @param worldPos * @param worldPos
*/ */
private void runPhysicsGenerationThread(Vector3i worldPos){ private void runPhysicsGenerationThread(Vector3i worldPos){
Thread thread = new Thread(new Runnable(){ generationService.submit(() -> {
@Override //create physics entities
public void run() { createTerrainPhysicsEntities(worldPos);
//create physics entities //set ready
createTerrainPhysicsEntities(worldPos); if(groundDataCells.get(getServerDataCellKey(worldPos)) != null){
//set ready groundDataCells.get(getServerDataCellKey(worldPos)).setReady(true);
if(groundDataCells.get(getServerDataCellKey(worldPos)) != null){ } else {
groundDataCells.get(getServerDataCellKey(worldPos)).setReady(true); LoggerInterface.loggerEngine.WARNING("Finished generating physics for server cell, but cell is null!");
} else {
LoggerInterface.loggerEngine.WARNING("Finished generating physics for server cell, but cell is null!");
}
} }
}); });
groundDataCells.get(getServerDataCellKey(worldPos)).setReady(false); groundDataCells.get(getServerDataCellKey(worldPos)).setReady(false);
Globals.threadManager.start(ThreadLabel.ASSET_LOADING, thread);
} }
/** /**
@ -793,4 +795,11 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
return Collections.unmodifiableCollection(this.groundDataCells.values()); return Collections.unmodifiableCollection(this.groundDataCells.values());
} }
/**
* Stops the executor service
*/
public void halt(){
generationService.shutdownNow();
}
} }

View File

@ -120,5 +120,10 @@ public class ViewportDataCellManager implements DataCellManager {
} }
return returnPos; return returnPos;
} }
@Override
public void halt(){
//does nothing
}
} }

View File

@ -81,5 +81,10 @@ public interface DataCellManager {
* @return Either the position if it is in bounds, or the closest position that is in bounds * @return Either the position if it is in bounds, or the closest position that is in bounds
*/ */
public Vector3d guaranteePositionIsInBounds(Vector3d positionToTest); public Vector3d guaranteePositionIsInBounds(Vector3d positionToTest);
/**
* Halts all asynchronous work being done in this data cell manager
*/
public void halt();
} }