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,9 +574,7 @@ 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
public void run() {
//create physics entities //create physics entities
createTerrainPhysicsEntities(worldPos); createTerrainPhysicsEntities(worldPos);
//set ready //set ready
@ -579,10 +583,8 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
} else { } else {
LoggerInterface.loggerEngine.WARNING("Finished generating physics for server cell, but cell is null!"); 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

@ -121,4 +121,9 @@ public class ViewportDataCellManager implements DataCellManager {
return returnPos; return returnPos;
} }
@Override
public void halt(){
//does nothing
}
} }

View File

@ -82,4 +82,9 @@ public interface DataCellManager {
*/ */
public Vector3d guaranteePositionIsInBounds(Vector3d positionToTest); public Vector3d guaranteePositionIsInBounds(Vector3d positionToTest);
/**
* Halts all asynchronous work being done in this data cell manager
*/
public void halt();
} }