convert server physics cell generation to executor
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
561576a758
commit
36d2271b35
@ -1167,6 +1167,7 @@ Fix particles not spawning in correct positions
|
||||
(11/28/2024)
|
||||
Fix block not firing
|
||||
Fix reentrant locking bug
|
||||
Convert server physics cell generation to executor service
|
||||
|
||||
|
||||
# TODO
|
||||
|
||||
@ -122,6 +122,9 @@ public class ThreadManager {
|
||||
if(realm.getServerWorldData() != null && realm.getServerWorldData().getServerBlockManager() != null){
|
||||
realm.getServerWorldData().getServerBlockManager().closeThreads();
|
||||
}
|
||||
if(realm.getDataCellManager() != null){
|
||||
realm.getDataCellManager().halt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,13 +8,14 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.engine.threads.LabeledThread.ThreadLabel;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.ServerEntityUtils;
|
||||
@ -56,6 +57,11 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@ -568,21 +574,17 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
||||
* @param worldPos
|
||||
*/
|
||||
private void runPhysicsGenerationThread(Vector3i worldPos){
|
||||
Thread thread = new Thread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
//create physics entities
|
||||
createTerrainPhysicsEntities(worldPos);
|
||||
//set ready
|
||||
if(groundDataCells.get(getServerDataCellKey(worldPos)) != null){
|
||||
groundDataCells.get(getServerDataCellKey(worldPos)).setReady(true);
|
||||
} else {
|
||||
LoggerInterface.loggerEngine.WARNING("Finished generating physics for server cell, but cell is null!");
|
||||
}
|
||||
generationService.submit(() -> {
|
||||
//create physics entities
|
||||
createTerrainPhysicsEntities(worldPos);
|
||||
//set ready
|
||||
if(groundDataCells.get(getServerDataCellKey(worldPos)) != null){
|
||||
groundDataCells.get(getServerDataCellKey(worldPos)).setReady(true);
|
||||
} else {
|
||||
LoggerInterface.loggerEngine.WARNING("Finished generating physics for server cell, but cell is null!");
|
||||
}
|
||||
});
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the executor service
|
||||
*/
|
||||
public void halt(){
|
||||
generationService.shutdownNow();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -120,5 +120,10 @@ public class ViewportDataCellManager implements DataCellManager {
|
||||
}
|
||||
return returnPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void halt(){
|
||||
//does nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -81,5 +81,10 @@ public interface DataCellManager {
|
||||
* @return Either the position if it is in bounds, or the closest position that is in bounds
|
||||
*/
|
||||
public Vector3d guaranteePositionIsInBounds(Vector3d positionToTest);
|
||||
|
||||
/**
|
||||
* Halts all asynchronous work being done in this data cell manager
|
||||
*/
|
||||
public void halt();
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user