From 82bf65d4a2627efcb9c63710f96ac74b7271afbd Mon Sep 17 00:00:00 2001 From: austin Date: Sun, 18 May 2025 16:10:44 -0400 Subject: [PATCH] macro data injection into voxel gen --- docs/src/progress/renderertodo.md | 1 + .../entity/scene/SceneLoader.java | 1 + .../gridded/GriddedDataCellManager.java | 2 +- .../generation/DefaultChunkGenerator.java | 3 +- .../terrain/generation/JSChunkGenerator.java | 3 +- .../generation/OverworldChunkGenerator.java | 3 +- .../generation/ProceduralChunkGenerator.java | 3 +- .../generation/interfaces/ChunkGenerator.java | 4 ++- .../manager/ChunkGenerationThread.java | 11 +++++- .../terrain/manager/ServerTerrainManager.java | 35 +++++++++++++++---- 10 files changed, 53 insertions(+), 13 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 571fa641..e30f9c58 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1878,6 +1878,7 @@ Scaffolding jobs assigned by town to characters Fix character position not saving on creating a player's character for the first time Server utility to move entities scans to see if it needs to create macro data if moving a player's entity Road macro data generation +Macro data is injected into voxel chunk generators diff --git a/src/main/java/electrosphere/entity/scene/SceneLoader.java b/src/main/java/electrosphere/entity/scene/SceneLoader.java index 3115d382..861d4759 100644 --- a/src/main/java/electrosphere/entity/scene/SceneLoader.java +++ b/src/main/java/electrosphere/entity/scene/SceneLoader.java @@ -151,6 +151,7 @@ public class SceneLoader { } //hook up macro data if relevant if(macroData != null){ + realm.getServerWorldData().getServerTerrainManager().setMacroData(macroData); realm.getServerWorldData().getServerBlockManager().setMacroData(macroData); } //load scripts diff --git a/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java b/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java index 3e70f48d..3c72040d 100644 --- a/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java +++ b/src/main/java/electrosphere/server/datacell/gridded/GriddedDataCellManager.java @@ -646,7 +646,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager int worldY = ServerWorldData.convertRealToChunkSpace(point.y); int worldZ = ServerWorldData.convertRealToChunkSpace(point.z); Vector3i worldPos = new Vector3i(worldX,worldY,worldZ); - return tryCreateCellAtPoint(worldPos); + return this.tryCreateCellAtPoint(worldPos); } /** diff --git a/src/main/java/electrosphere/server/physics/terrain/generation/DefaultChunkGenerator.java b/src/main/java/electrosphere/server/physics/terrain/generation/DefaultChunkGenerator.java index 7d0e8cf5..05fc6d5a 100644 --- a/src/main/java/electrosphere/server/physics/terrain/generation/DefaultChunkGenerator.java +++ b/src/main/java/electrosphere/server/physics/terrain/generation/DefaultChunkGenerator.java @@ -2,6 +2,7 @@ package electrosphere.server.physics.terrain.generation; import electrosphere.client.terrain.cache.ChunkData; import electrosphere.entity.scene.RealmDescriptor; +import electrosphere.server.macro.MacroData; import electrosphere.server.physics.terrain.generation.interfaces.ChunkGenerator; import electrosphere.server.physics.terrain.manager.ServerTerrainChunk; import electrosphere.server.physics.terrain.models.TerrainModel; @@ -23,7 +24,7 @@ public class DefaultChunkGenerator implements ChunkGenerator { } @Override - public ServerTerrainChunk generateChunk(int worldX, int worldY, int worldZ, int stride) { + public ServerTerrainChunk generateChunk(MacroData macroData, int worldX, int worldY, int worldZ, int stride) { //Each chunk also needs custody of the next chunk's first values so that they can perfectly overlap. //Hence, width should actually be chunk dimension + 1 float[][][] weights = new float[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE]; diff --git a/src/main/java/electrosphere/server/physics/terrain/generation/JSChunkGenerator.java b/src/main/java/electrosphere/server/physics/terrain/generation/JSChunkGenerator.java index ea54babc..cad34dcf 100644 --- a/src/main/java/electrosphere/server/physics/terrain/generation/JSChunkGenerator.java +++ b/src/main/java/electrosphere/server/physics/terrain/generation/JSChunkGenerator.java @@ -11,6 +11,7 @@ import org.graalvm.polyglot.Value; import electrosphere.engine.Globals; import electrosphere.server.datacell.ServerWorldData; +import electrosphere.server.macro.MacroData; import electrosphere.server.physics.terrain.generation.heightmap.EmptySkyGen; import electrosphere.server.physics.terrain.generation.heightmap.HeightmapGenerator; import electrosphere.server.physics.terrain.generation.heightmap.HillsGen; @@ -112,7 +113,7 @@ public class JSChunkGenerator implements ChunkGenerator { } @Override - public ServerTerrainChunk generateChunk(int worldX, int worldY, int worldZ, int stride) { + public ServerTerrainChunk generateChunk(MacroData macroData, int worldX, int worldY, int worldZ, int stride) { Globals.profiler.beginAggregateCpuSample("TestGenerationChunkGenerator.generateChunk"); ServerTerrainChunk rVal = new ServerTerrainChunk(worldX, worldY, worldZ); float[][][] weights = new float[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];; diff --git a/src/main/java/electrosphere/server/physics/terrain/generation/OverworldChunkGenerator.java b/src/main/java/electrosphere/server/physics/terrain/generation/OverworldChunkGenerator.java index a5840f53..bb539b99 100644 --- a/src/main/java/electrosphere/server/physics/terrain/generation/OverworldChunkGenerator.java +++ b/src/main/java/electrosphere/server/physics/terrain/generation/OverworldChunkGenerator.java @@ -1,6 +1,7 @@ package electrosphere.server.physics.terrain.generation; import electrosphere.client.terrain.cache.ChunkData; +import electrosphere.server.macro.MacroData; import electrosphere.server.physics.terrain.generation.interfaces.ChunkGenerator; import electrosphere.server.physics.terrain.manager.ServerTerrainChunk; import electrosphere.server.physics.terrain.models.TerrainModel; @@ -25,7 +26,7 @@ public class OverworldChunkGenerator implements ChunkGenerator { } @Override - public ServerTerrainChunk generateChunk(int worldX, int worldY, int worldZ, int stride) { + public ServerTerrainChunk generateChunk(MacroData macroData, int worldX, int worldY, int worldZ, int stride) { ServerTerrainChunk returnedChunk; //Each chunk also needs custody of the next chunk's first values so that they can perfectly overlap. //Hence, width should actually be chunk dimension + 1 diff --git a/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java b/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java index f68a61ca..b32e11c4 100644 --- a/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java +++ b/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java @@ -9,6 +9,7 @@ import electrosphere.data.biome.BiomeSurfaceGenerationParams; import electrosphere.data.voxel.sampler.SamplerFile; import electrosphere.engine.Globals; import electrosphere.server.datacell.ServerWorldData; +import electrosphere.server.macro.MacroData; import electrosphere.server.physics.terrain.generation.heightmap.EmptySkyGen; import electrosphere.server.physics.terrain.generation.heightmap.HeightmapGenerator; import electrosphere.server.physics.terrain.generation.heightmap.HeightmapNoiseGen; @@ -128,7 +129,7 @@ public class ProceduralChunkGenerator implements ChunkGenerator { } @Override - public ServerTerrainChunk generateChunk(int worldX, int worldY, int worldZ, int stride) { + public ServerTerrainChunk generateChunk(MacroData macroData, int worldX, int worldY, int worldZ, int stride) { Globals.profiler.beginAggregateCpuSample("TestGenerationChunkGenerator.generateChunk"); ServerTerrainChunk rVal = new ServerTerrainChunk(worldX, worldY, worldZ); float[][][] weights = new float[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];; diff --git a/src/main/java/electrosphere/server/physics/terrain/generation/interfaces/ChunkGenerator.java b/src/main/java/electrosphere/server/physics/terrain/generation/interfaces/ChunkGenerator.java index 08823ada..d4f27d29 100644 --- a/src/main/java/electrosphere/server/physics/terrain/generation/interfaces/ChunkGenerator.java +++ b/src/main/java/electrosphere/server/physics/terrain/generation/interfaces/ChunkGenerator.java @@ -1,5 +1,6 @@ package electrosphere.server.physics.terrain.generation.interfaces; +import electrosphere.server.macro.MacroData; import electrosphere.server.physics.terrain.manager.ServerTerrainChunk; import electrosphere.server.physics.terrain.models.TerrainModel; @@ -10,13 +11,14 @@ public interface ChunkGenerator { /** * Generates a chunk given an x, y, and z + * @param macroData The macro data * @param worldX The x component * @param worldY The y component * @param worldZ The z component * @param stride The stride of the data * @return The chunk */ - public ServerTerrainChunk generateChunk(int worldX, int worldY, int worldZ, int stride); + public ServerTerrainChunk generateChunk(MacroData macroData, int worldX, int worldY, int worldZ, int stride); /** * Gets the elevation at a given 2d coordinate diff --git a/src/main/java/electrosphere/server/physics/terrain/manager/ChunkGenerationThread.java b/src/main/java/electrosphere/server/physics/terrain/manager/ChunkGenerationThread.java index 96a4d8cb..e9ade87e 100644 --- a/src/main/java/electrosphere/server/physics/terrain/manager/ChunkGenerationThread.java +++ b/src/main/java/electrosphere/server/physics/terrain/manager/ChunkGenerationThread.java @@ -5,6 +5,7 @@ import java.util.function.Consumer; import electrosphere.engine.Globals; import electrosphere.logger.LoggerInterface; +import electrosphere.server.macro.MacroData; import electrosphere.server.physics.terrain.diskmap.ChunkDiskMap; import electrosphere.server.physics.terrain.generation.interfaces.ChunkGenerator; @@ -38,6 +39,11 @@ public class ChunkGenerationThread implements Runnable { */ ChunkGenerator chunkGenerator; + /** + * The macro data + */ + MacroData macroData; + /** * The world x coordinate */ @@ -65,6 +71,7 @@ public class ChunkGenerationThread implements Runnable { /** * Creates the chunk generation job + * @param macroData The macro data * @param chunkDiskMap The chunk disk map * @param chunkCache The chunk cache on the server * @param chunkGenerator The chunk generator @@ -75,6 +82,7 @@ public class ChunkGenerationThread implements Runnable { * @param onLoad The work to do once the chunk is available */ public ChunkGenerationThread( + MacroData macroData, ChunkDiskMap chunkDiskMap, ServerChunkCache chunkCache, ChunkGenerator chunkGenerator, @@ -82,6 +90,7 @@ public class ChunkGenerationThread implements Runnable { int stride, Consumer onLoad ){ + this.macroData = macroData; this.chunkDiskMap = chunkDiskMap; this.chunkCache = chunkCache; this.chunkGenerator = chunkGenerator; @@ -109,7 +118,7 @@ public class ChunkGenerationThread implements Runnable { } //generate if it does not exist if(chunk == null){ - chunk = chunkGenerator.generateChunk(worldX, worldY, worldZ, stride); + chunk = chunkGenerator.generateChunk(this.macroData, worldX, worldY, worldZ, stride); } if(chunk != null){ chunkCache.add(worldX, worldY, worldZ, stride, chunk); 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 986d9b00..147cb931 100644 --- a/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java +++ b/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java @@ -5,6 +5,7 @@ import electrosphere.engine.Globals; import electrosphere.engine.threads.ThreadCounts; import electrosphere.entity.scene.RealmDescriptor; import electrosphere.server.datacell.ServerWorldData; +import electrosphere.server.macro.MacroData; import electrosphere.server.physics.terrain.diskmap.ChunkDiskMap; import electrosphere.server.physics.terrain.generation.ProceduralChunkGenerator; import electrosphere.server.physics.terrain.generation.interfaces.ChunkGenerator; @@ -55,10 +56,14 @@ public class ServerTerrainManager { */ ServerWorldData parent; - //the seed for terrain generation + /** + * the seed for terrain generation + */ long seed; - //The model of the terrain this manager is managing + /** + * The model of the terrain this manager is managing + */ TerrainModel model; /** @@ -67,13 +72,23 @@ public class ServerTerrainManager { @Exclude ServerChunkCache chunkCache; - //The map of chunk position <-> file on disk containing chunk data + /** + * The map of chunk position <-> file on disk containing chunk data + */ ChunkDiskMap chunkDiskMap = null; - //The generation algorithm for this terrain manager + /** + * The generation algorithm for this terrain manager + */ @Exclude ChunkGenerator chunkGenerator; + /** + * The macro data for this world + */ + @Exclude + MacroData macroData; + /** * The threadpool for chunk generation */ @@ -289,7 +304,7 @@ public class ServerTerrainManager { } //generate if it does not exist if(returnedChunk == null){ - returnedChunk = chunkGenerator.generateChunk(worldX, worldY, worldZ, ChunkData.NO_STRIDE); + returnedChunk = chunkGenerator.generateChunk(this.macroData, worldX, worldY, worldZ, ChunkData.NO_STRIDE); } this.chunkCache.add(worldX, worldY, worldZ, ChunkData.NO_STRIDE, returnedChunk); } @@ -336,7 +351,7 @@ public class ServerTerrainManager { */ public void getChunkAsync(int worldX, int worldY, int worldZ, int stride, Consumer onLoad){ Globals.profiler.beginAggregateCpuSample("ServerTerrainManager.getChunkAsync"); - chunkExecutorService.submit(new ChunkGenerationThread(chunkDiskMap, chunkCache, chunkGenerator, worldX, worldY, worldZ, stride, onLoad)); + chunkExecutorService.submit(new ChunkGenerationThread(this.macroData, chunkDiskMap, chunkCache, chunkGenerator, worldX, worldY, worldZ, stride, onLoad)); Globals.profiler.endCpuSample(); } @@ -389,4 +404,12 @@ public class ServerTerrainManager { chunkExecutorService.shutdownNow(); } + /** + * Sets the macro data for the block manager + * @param macroData The macro data + */ + public void setMacroData(MacroData macroData){ + this.macroData = macroData; + } + }