From 66eb3a758626b0ac52a7b5adc79d4d886ecc1bec Mon Sep 17 00:00:00 2001 From: austin Date: Mon, 5 May 2025 14:36:41 -0400 Subject: [PATCH] centralize thread count declarations --- .../client/terrain/foliage/FoliageModel.java | 3 +- .../engine/threads/ThreadCounts.java | 48 +++++++++++++++++++ .../types/terrain/BlockChunkEntity.java | 3 +- .../entity/types/terrain/TerrainChunk.java | 3 +- .../ai/services/PathfindingService.java | 3 +- .../gridded/GriddedDataCellLoaderService.java | 3 +- .../gridded/GriddedDataCellManager.java | 3 +- .../block/manager/ServerBlockManager.java | 8 +--- .../terrain/manager/ServerTerrainManager.java | 10 ++-- 9 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 src/main/java/electrosphere/engine/threads/ThreadCounts.java diff --git a/src/main/java/electrosphere/client/terrain/foliage/FoliageModel.java b/src/main/java/electrosphere/client/terrain/foliage/FoliageModel.java index 9bb91e6a..f2700dbc 100644 --- a/src/main/java/electrosphere/client/terrain/foliage/FoliageModel.java +++ b/src/main/java/electrosphere/client/terrain/foliage/FoliageModel.java @@ -16,6 +16,7 @@ import electrosphere.client.terrain.cache.ChunkData; import electrosphere.engine.Globals; import electrosphere.engine.assetmanager.queue.QueuedTexture; import electrosphere.engine.assetmanager.queue.QueuedTexture.QueuedTextureType; +import electrosphere.engine.threads.ThreadCounts; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; @@ -153,7 +154,7 @@ public class FoliageModel { /** * Used for generating foliage cells */ - static final ExecutorService generationService = Executors.newFixedThreadPool(2); + static final ExecutorService generationService = Executors.newFixedThreadPool(ThreadCounts.FOLIAGE_MESHGEN_THREADS); /** * Creates a client foliage chunk based on weights and values provided diff --git a/src/main/java/electrosphere/engine/threads/ThreadCounts.java b/src/main/java/electrosphere/engine/threads/ThreadCounts.java new file mode 100644 index 00000000..98f2b0dd --- /dev/null +++ b/src/main/java/electrosphere/engine/threads/ThreadCounts.java @@ -0,0 +1,48 @@ +package electrosphere.engine.threads; + +/** + * Thread counts for various tasks + */ +public class ThreadCounts { + + /** + * Number of threads for foliage meshgen + */ + public static final int FOLIAGE_MESHGEN_THREADS = 2; + + /** + * Number of threads for block meshgen + */ + public static final int BLOCK_MESHGEN_THREADS = 4; + + /** + * Number of threads for terrain meshgen + */ + public static final int TERRAIN_MESHGEN_THREADS = 4; + + /** + * Number of threads for solving pathfinding + */ + public static final int PATHFINDING_THREADS = 1; + + /** + * Number of threads for gridded datacell manager chunk loading/unloading + */ + public static final int GRIDDED_DATACELL_LOADING_THREADS = 4; + + /** + * Number of threads for generating physics for the gridded datacell manager + */ + public static final int GRIDDED_DATACELL_PHYSICS_GEN_THREADS = 4; + + /** + * Number of threads for generating block chunks on the server + */ + public static final int SERVER_BLOCK_GENERATION_THREADS = 2; + + /** + * Number of threads for generating terrain chunks on the server + */ + public static final int SERVER_TERRAIN_GENERATION_THREADS = 2; + +} diff --git a/src/main/java/electrosphere/entity/types/terrain/BlockChunkEntity.java b/src/main/java/electrosphere/entity/types/terrain/BlockChunkEntity.java index 2c032f82..4202ae55 100644 --- a/src/main/java/electrosphere/entity/types/terrain/BlockChunkEntity.java +++ b/src/main/java/electrosphere/entity/types/terrain/BlockChunkEntity.java @@ -14,6 +14,7 @@ import electrosphere.collision.PhysicsEntityUtils; import electrosphere.collision.PhysicsUtils; import electrosphere.engine.Globals; import electrosphere.engine.assetmanager.queue.QueuedModel; +import electrosphere.engine.threads.ThreadCounts; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; @@ -35,7 +36,7 @@ public class BlockChunkEntity { /** * Used for generating block chunks */ - static final ExecutorService generationService = Executors.newFixedThreadPool(4); + static final ExecutorService generationService = Executors.newFixedThreadPool(ThreadCounts.BLOCK_MESHGEN_THREADS); /** * Creates a client block chunk based on weights and values provided diff --git a/src/main/java/electrosphere/entity/types/terrain/TerrainChunk.java b/src/main/java/electrosphere/entity/types/terrain/TerrainChunk.java index be0af912..1958e953 100644 --- a/src/main/java/electrosphere/entity/types/terrain/TerrainChunk.java +++ b/src/main/java/electrosphere/entity/types/terrain/TerrainChunk.java @@ -17,6 +17,7 @@ import electrosphere.client.terrain.manager.ClientTerrainManager; import electrosphere.collision.PhysicsEntityUtils; import electrosphere.collision.PhysicsUtils; import electrosphere.engine.Globals; +import electrosphere.engine.threads.ThreadCounts; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; @@ -38,7 +39,7 @@ public class TerrainChunk { /** * Used for generating terrain chunks */ - static final ExecutorService generationService = Executors.newFixedThreadPool(4); + static final ExecutorService generationService = Executors.newFixedThreadPool(ThreadCounts.TERRAIN_MESHGEN_THREADS); /** * Creates a client terrain chunk based on weights and values provided diff --git a/src/main/java/electrosphere/server/ai/services/PathfindingService.java b/src/main/java/electrosphere/server/ai/services/PathfindingService.java index 19db186a..5c47d96f 100644 --- a/src/main/java/electrosphere/server/ai/services/PathfindingService.java +++ b/src/main/java/electrosphere/server/ai/services/PathfindingService.java @@ -6,6 +6,7 @@ import java.util.concurrent.Executors; import org.joml.Vector3d; +import electrosphere.engine.threads.ThreadCounts; import electrosphere.server.datacell.interfaces.VoxelCellManager; import electrosphere.server.pathfinding.recast.PathingProgressiveData; import electrosphere.server.pathfinding.voxel.VoxelPathfinder; @@ -31,7 +32,7 @@ public class PathfindingService implements AIService { public PathingProgressiveData queuePathfinding(Vector3d start, Vector3d end, VoxelPathfinder pathfinder, VoxelCellManager voxelCellManager){ PathingProgressiveData rVal = new PathingProgressiveData(end); if(executorService == null){ - executorService = Executors.newFixedThreadPool(2); + executorService = Executors.newFixedThreadPool(ThreadCounts.PATHFINDING_THREADS); } executorService.submit(() -> { List points = pathfinder.findPath(voxelCellManager, start, end, VoxelPathfinder.DEFAULT_MAX_COST); diff --git a/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellLoaderService.java b/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellLoaderService.java index 59f77ead..83de24a7 100644 --- a/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellLoaderService.java +++ b/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellLoaderService.java @@ -9,6 +9,7 @@ import java.util.concurrent.Future; import java.util.concurrent.locks.ReentrantLock; import electrosphere.engine.Globals; +import electrosphere.engine.threads.ThreadCounts; import electrosphere.logger.LoggerInterface; /** @@ -19,7 +20,7 @@ public class GriddedDataCellLoaderService { /** * Used for loading/unloading the cells */ - protected static final ExecutorService ioThreadService = Executors.newFixedThreadPool(4); + protected static final ExecutorService ioThreadService = Executors.newFixedThreadPool(ThreadCounts.GRIDDED_DATACELL_LOADING_THREADS); /** * Lock for structures in this service diff --git a/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java b/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java index 015cf83a..0c30533e 100644 --- a/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java +++ b/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java @@ -18,6 +18,7 @@ import org.joml.Vector3i; import electrosphere.client.block.BlockChunkData; import electrosphere.engine.Globals; +import electrosphere.engine.threads.ThreadCounts; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityUtils; @@ -76,7 +77,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager /** * Used for generating physics chunks */ - static final ExecutorService generationService = Executors.newFixedThreadPool(4); + static final ExecutorService generationService = Executors.newFixedThreadPool(ThreadCounts.GRIDDED_DATACELL_PHYSICS_GEN_THREADS); /** * Tracks whether this manager has been flagged to unload cells or not diff --git a/src/main/java/electrosphere/server/physics/block/manager/ServerBlockManager.java b/src/main/java/electrosphere/server/physics/block/manager/ServerBlockManager.java index dbb13c9d..353b1c0a 100644 --- a/src/main/java/electrosphere/server/physics/block/manager/ServerBlockManager.java +++ b/src/main/java/electrosphere/server/physics/block/manager/ServerBlockManager.java @@ -3,6 +3,7 @@ package electrosphere.server.physics.block.manager; import electrosphere.client.block.BlockChunkCache; import electrosphere.client.block.BlockChunkData; import electrosphere.engine.Globals; +import electrosphere.engine.threads.ThreadCounts; import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.macro.MacroData; import electrosphere.server.physics.block.diskmap.ServerBlockChunkDiskMap; @@ -18,11 +19,6 @@ import org.joml.Vector3i; * Provides an interface for the server to query information about block chunks */ public class ServerBlockManager { - - /** - * The number of threads for chunk generation - */ - public static final int GENERATION_THREAD_POOL_SIZE = 2; /** * The parent world data @@ -50,7 +46,7 @@ public class ServerBlockManager { * The threadpool for chunk generation */ @Exclude - static final ExecutorService chunkExecutorService = Executors.newFixedThreadPool(GENERATION_THREAD_POOL_SIZE); + static final ExecutorService chunkExecutorService = Executors.newFixedThreadPool(ThreadCounts.SERVER_BLOCK_GENERATION_THREADS); /** * Constructor diff --git a/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java b/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java index 878829c8..c6b9695c 100644 --- a/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java +++ b/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java @@ -2,6 +2,7 @@ package electrosphere.server.physics.terrain.manager; import electrosphere.client.terrain.cache.ChunkData; import electrosphere.engine.Globals; +import electrosphere.engine.threads.ThreadCounts; import electrosphere.entity.scene.RealmDescriptor; import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.physics.terrain.diskmap.ChunkDiskMap; @@ -28,12 +29,7 @@ import org.joml.Vector3i; * Provides an interface for the server to query information about terrain */ public class ServerTerrainManager { - - /** - * The number of threads for chunk generation - */ - public static final int GENERATION_THREAD_POOL_SIZE = 2; - + /** * Full world discrete size */ @@ -82,7 +78,7 @@ public class ServerTerrainManager { * The threadpool for chunk generation */ @Exclude - static final ExecutorService chunkExecutorService = Executors.newFixedThreadPool(GENERATION_THREAD_POOL_SIZE); + static final ExecutorService chunkExecutorService = Executors.newFixedThreadPool(ThreadCounts.SERVER_TERRAIN_GENERATION_THREADS); /** * Constructor