From 388f622c9bed98d326c9d25894bd1266fe4cdc8b Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 29 Apr 2025 17:19:57 -0400 Subject: [PATCH] voxel value generation work --- docs/src/progress/currenttarget.md | 4 +++- docs/src/progress/renderertodo.md | 2 ++ .../client/ui/menu/debug/ImGuiTestGen.java | 4 ++-- .../ui/menu/debug/ImGuiWindowMacros.java | 4 ++-- .../ChunkGenerationTestLoading.java | 4 ++-- .../entity/scene/SceneGenerator.java | 4 ++-- .../server/datacell/ServerWorldData.java | 18 +++++++++--------- ...ator.java => ProceduralChunkGenerator.java} | 4 ++-- .../generation/voxelphase/NoiseVoxelGen.java | 10 +++++----- .../terrain/manager/ServerTerrainManager.java | 4 ++-- .../physics/terrain/models/TerrainModel.java | 8 ++++---- .../electrosphere/server/saves/SaveUtils.java | 4 ++-- 12 files changed, 37 insertions(+), 33 deletions(-) rename src/main/java/electrosphere/server/physics/terrain/generation/{TestGenerationChunkGenerator.java => ProceduralChunkGenerator.java} (99%) diff --git a/docs/src/progress/currenttarget.md b/docs/src/progress/currenttarget.md index 4999b68d..1a476ae9 100644 --- a/docs/src/progress/currenttarget.md +++ b/docs/src/progress/currenttarget.md @@ -7,6 +7,9 @@ + non-feedback requirements + feedback driven requirements + Spawn a town in macro data + - Place a building + - Elevation calls give you the ACTUAL elevation Crouching Model clothing, hair for the human particles, light on sword collision @@ -17,6 +20,5 @@ + bug fixes - Window does not play nice with its minWidth/minHeight being set differently - - Interaction block cursor is overwriting fab cursor + unreproducible bugs diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index d2693f6f..3e3e3cfd 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1595,6 +1595,8 @@ Unit tests for unhash func Filter client entity list to terrain Fix server loading full res chunks from disk as strided chunks Debugging tooling for foliage manager +Refactor ProceduralChunkGenerator +NoiseVoxelGen work to make elevation values align with voxel values that are generated diff --git a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiTestGen.java b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiTestGen.java index cf256fd0..fbe11404 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiTestGen.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiTestGen.java @@ -5,7 +5,7 @@ import electrosphere.engine.signal.Signal.SignalType; import electrosphere.renderer.ui.imgui.ImGuiWindow; import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback; import electrosphere.server.datacell.gridded.GriddedDataCellManager; -import electrosphere.server.physics.terrain.generation.TestGenerationChunkGenerator; +import electrosphere.server.physics.terrain.generation.ProceduralChunkGenerator; import electrosphere.server.physics.terrain.models.TerrainModel; import imgui.ImGui; import imgui.type.ImInt; @@ -62,7 +62,7 @@ public class ImGuiTestGen { } //set macro data scale in terrain model - if(ImGui.sliderInt("Macro Data Scale", macroDataScaleInput, TestGenerationChunkGenerator.GENERATOR_REALM_SIZE / terrainModel.getBiome().length, TerrainModel.DEFAULT_MACRO_DATA_SCALE)){ + if(ImGui.sliderInt("Macro Data Scale", macroDataScaleInput, ProceduralChunkGenerator.GENERATOR_REALM_SIZE / terrainModel.getBiome().length, TerrainModel.DEFAULT_MACRO_DATA_SCALE)){ terrainModel.setMacroDataScale(macroDataScaleInput[0]); } diff --git a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiWindowMacros.java b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiWindowMacros.java index 8b8087e6..6def08f6 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiWindowMacros.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiWindowMacros.java @@ -11,7 +11,7 @@ import electrosphere.renderer.ui.imgui.ImGuiLinePlot; import electrosphere.renderer.ui.imgui.ImGuiWindow; import electrosphere.renderer.ui.imgui.ImGuiLinePlot.ImGuiLinePlotDataset; import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback; -import electrosphere.server.physics.terrain.generation.TestGenerationChunkGenerator; +import electrosphere.server.physics.terrain.generation.ProceduralChunkGenerator; import imgui.ImGui; /** @@ -161,7 +161,7 @@ public class ImGuiWindowMacros { Globals.realmManager != null && Globals.realmManager.first() != null && Globals.realmManager.first().getServerWorldData() != null && - Globals.realmManager.first().getServerWorldData().getServerTerrainManager().getChunkGenerator() instanceof TestGenerationChunkGenerator && + Globals.realmManager.first().getServerWorldData().getServerTerrainManager().getChunkGenerator() instanceof ProceduralChunkGenerator && ImGui.button("Test Terrain Gen") ){ ImGuiTestGen.testGenWindow.setOpen(true); diff --git a/src/main/java/electrosphere/engine/loadingthreads/ChunkGenerationTestLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ChunkGenerationTestLoading.java index a4a3cc75..0862a571 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ChunkGenerationTestLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ChunkGenerationTestLoading.java @@ -13,7 +13,7 @@ import electrosphere.logger.LoggerInterface; import electrosphere.net.parser.net.message.TerrainMessage; import electrosphere.net.server.ServerConnectionHandler; import electrosphere.renderer.ui.elements.Window; -import electrosphere.server.physics.terrain.generation.TestGenerationChunkGenerator; +import electrosphere.server.physics.terrain.generation.ProceduralChunkGenerator; import electrosphere.server.saves.SaveUtils; /** @@ -43,7 +43,7 @@ public class ChunkGenerationTestLoading { }); //wait on script engine to load - if(TestGenerationChunkGenerator.DEFAULT_USE_JAVASCRIPT){ + if(ProceduralChunkGenerator.DEFAULT_USE_JAVASCRIPT){ WindowUtils.updateLoadingWindow("Waiting on scripting engine"); while(!Globals.scriptEngine.isInitialized()){ try { diff --git a/src/main/java/electrosphere/entity/scene/SceneGenerator.java b/src/main/java/electrosphere/entity/scene/SceneGenerator.java index 92b14ebc..e27cfd55 100644 --- a/src/main/java/electrosphere/entity/scene/SceneGenerator.java +++ b/src/main/java/electrosphere/entity/scene/SceneGenerator.java @@ -3,7 +3,7 @@ package electrosphere.entity.scene; import java.util.Objects; import electrosphere.server.datacell.gridded.GriddedDataCellManager; -import electrosphere.server.physics.terrain.generation.TestGenerationChunkGenerator; +import electrosphere.server.physics.terrain.generation.ProceduralChunkGenerator; /** * Generates scene files where appropriate (ie, if playing the procedurally generated level) @@ -37,7 +37,7 @@ public class SceneGenerator { SceneFile file = SceneFile.createSceneFile(); //realm descriptor stuff file.realmDescriptor.type = RealmDescriptor.REALM_DESCRIPTOR_GENERATION_TESTING; - file.realmDescriptor.griddedRealmSize = TestGenerationChunkGenerator.GENERATOR_REALM_SIZE; + file.realmDescriptor.griddedRealmSize = ProceduralChunkGenerator.GENERATOR_REALM_SIZE; file.createSaveInstance = true; //won't have a predefined scene to load, so must create one in the save file.loadAllCells = false; // do not load all cells on init diff --git a/src/main/java/electrosphere/server/datacell/ServerWorldData.java b/src/main/java/electrosphere/server/datacell/ServerWorldData.java index f79af2ef..52e22ae6 100644 --- a/src/main/java/electrosphere/server/datacell/ServerWorldData.java +++ b/src/main/java/electrosphere/server/datacell/ServerWorldData.java @@ -5,7 +5,7 @@ import electrosphere.server.physics.block.manager.ServerBlockManager; import electrosphere.server.physics.fluid.generation.DefaultFluidGenerator; import electrosphere.server.physics.fluid.manager.ServerFluidManager; import electrosphere.server.physics.terrain.generation.DefaultChunkGenerator; -import electrosphere.server.physics.terrain.generation.TestGenerationChunkGenerator; +import electrosphere.server.physics.terrain.generation.ProceduralChunkGenerator; import electrosphere.server.physics.terrain.manager.ServerTerrainChunk; import electrosphere.server.physics.terrain.manager.ServerTerrainManager; import electrosphere.server.physics.terrain.models.TerrainModel; @@ -147,7 +147,7 @@ public class ServerWorldData { } else { //TODO: Allow loading procedurally generated terrain from disk (the chunk generator is always default currently) serverWorldData = FileUtils.loadObjectFromSavePath(sceneOrSaveName, "world.json", ServerWorldData.class); - serverTerrainManager = new ServerTerrainManager(serverWorldData, 0, new TestGenerationChunkGenerator(serverWorldData, false)); + serverTerrainManager = new ServerTerrainManager(serverWorldData, 0, new ProceduralChunkGenerator(serverWorldData, false)); serverTerrainManager.load(sceneOrSaveName); serverFluidManager = new ServerFluidManager(serverWorldData, serverTerrainManager, 0, new DefaultFluidGenerator()); serverBlockManager = new ServerBlockManager(serverWorldData); @@ -170,13 +170,13 @@ public class ServerWorldData { ServerFluidManager serverFluidManager = null; ServerBlockManager serverBlockManager = null; //TODO: Allow loading procedurally generated terrain from disk (the chunk generator is always default currently) - serverWorldData = ServerWorldData.createFixedWorldData(new Vector3d(0),new Vector3d(TestGenerationChunkGenerator.GENERATOR_REALM_SIZE * ServerTerrainChunk.CHUNK_DIMENSION)); - serverWorldData.worldSizeDiscrete = TestGenerationChunkGenerator.GENERATOR_REALM_SIZE; - serverWorldData.worldSizeDiscreteVertical = TestGenerationChunkGenerator.GENERATOR_REALM_SIZE; + serverWorldData = ServerWorldData.createFixedWorldData(new Vector3d(0),new Vector3d(ProceduralChunkGenerator.GENERATOR_REALM_SIZE * ServerTerrainChunk.CHUNK_DIMENSION)); + serverWorldData.worldSizeDiscrete = ProceduralChunkGenerator.GENERATOR_REALM_SIZE; + serverWorldData.worldSizeDiscreteVertical = ProceduralChunkGenerator.GENERATOR_REALM_SIZE; //test terrain gen { - TestGenerationChunkGenerator chunkGen = new TestGenerationChunkGenerator(serverWorldData, TestGenerationChunkGenerator.DEFAULT_USE_JAVASCRIPT); + ProceduralChunkGenerator chunkGen = new ProceduralChunkGenerator(serverWorldData, ProceduralChunkGenerator.DEFAULT_USE_JAVASCRIPT); serverTerrainManager = new ServerTerrainManager(serverWorldData, 0, chunkGen); serverTerrainManager.genTestData(chunkGen); } @@ -278,12 +278,12 @@ public class ServerWorldData { /** * Converts a chunk space coordinate to a real space coordinate - * @param chunk The position within the chunk + * @param voxelPos The voxel's position within the chunk * @param worldPos The world pos of the chunk * @return The real pos */ - public double convertVoxelToRealSpace(int chunk, int worldPos){ - return chunk + this.convertWorldToReal(worldPos); + public double convertVoxelToRealSpace(int voxelPos, int worldPos){ + return voxelPos + this.convertWorldToReal(worldPos); } public double getRelativeLocation(double real, int world){ diff --git a/src/main/java/electrosphere/server/physics/terrain/generation/TestGenerationChunkGenerator.java b/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java similarity index 99% rename from src/main/java/electrosphere/server/physics/terrain/generation/TestGenerationChunkGenerator.java rename to src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java index 914a087f..e5830a92 100644 --- a/src/main/java/electrosphere/server/physics/terrain/generation/TestGenerationChunkGenerator.java +++ b/src/main/java/electrosphere/server/physics/terrain/generation/ProceduralChunkGenerator.java @@ -32,7 +32,7 @@ import io.github.studiorailgun.MathUtils; /** * A generator for testing terrain generation */ -public class TestGenerationChunkGenerator implements ChunkGenerator { +public class ProceduralChunkGenerator implements ChunkGenerator { /** * The size of the realm for testing generation @@ -87,7 +87,7 @@ public class TestGenerationChunkGenerator implements ChunkGenerator { /** * Constructor */ - public TestGenerationChunkGenerator(ServerWorldData serverWorldData, boolean useJavascript){ + public ProceduralChunkGenerator(ServerWorldData serverWorldData, boolean useJavascript){ this.serverWorldData = serverWorldData; this.registerAllGenerators(); this.useJavascript = useJavascript; diff --git a/src/main/java/electrosphere/server/physics/terrain/generation/voxelphase/NoiseVoxelGen.java b/src/main/java/electrosphere/server/physics/terrain/generation/voxelphase/NoiseVoxelGen.java index a716da53..45b99a75 100644 --- a/src/main/java/electrosphere/server/physics/terrain/generation/voxelphase/NoiseVoxelGen.java +++ b/src/main/java/electrosphere/server/physics/terrain/generation/voxelphase/NoiseVoxelGen.java @@ -85,28 +85,28 @@ public class NoiseVoxelGen implements VoxelGenerator { } sample = Math.min(sample,1.0); if(heightDiff < -strideMultiplier * SURFACE_VOXEL_WIDTH){ - //below surface + //below surface, ie generate stone here double finalSurface = sample; voxel.weight = (float)finalSurface; voxel.type = 1; } else if(heightDiff > 0) { - //above surface + //above surface, ie generate air here voxel.weight = -1.0f; voxel.type = 0; } else if(heightDiff < -strideMultiplier){ BiomeFloorElement floorEl = surfaceParams.getFloorVariant((float)surfaceSelectionNoise); - //generate full-size surface-type voxel + //generate full-size surface-type voxel, ie generate grass here double finalHeight = sample; voxel.weight = (float)finalHeight; voxel.type = floorEl.getVoxelId(); } else { BiomeFloorElement floorEl = surfaceParams.getFloorVariant((float)surfaceSelectionNoise); - //surface + //surface, ie generate grass here double surfacePercent = -heightDiff / strideMultiplier; if(surfacePercent > 1.0 || surfacePercent < 0){ throw new Error("surfacePercent " + surfacePercent + " " + realY + " " + surfaceHeight + " " + heightDiff + " " + strideMultiplier); } - double finalHeight = sample * surfacePercent * 2 - 1; + double finalHeight = sample * surfacePercent * 2; voxel.weight = (float)(finalHeight * sample); voxel.type = floorEl.getVoxelId(); } 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 454b2bb7..878829c8 100644 --- a/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java +++ b/src/main/java/electrosphere/server/physics/terrain/manager/ServerTerrainManager.java @@ -5,7 +5,7 @@ import electrosphere.engine.Globals; import electrosphere.entity.scene.RealmDescriptor; import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.physics.terrain.diskmap.ChunkDiskMap; -import electrosphere.server.physics.terrain.generation.TestGenerationChunkGenerator; +import electrosphere.server.physics.terrain.generation.ProceduralChunkGenerator; import electrosphere.server.physics.terrain.generation.interfaces.ChunkGenerator; import electrosphere.server.physics.terrain.generation.macro.DefaultMacroGenerator; import electrosphere.server.physics.terrain.generation.macro.HomogenousMacroGenerator; @@ -234,7 +234,7 @@ public class ServerTerrainManager { * Generates a test terrain model * @param chunkGen The chunk generator */ - public void genTestData(TestGenerationChunkGenerator chunkGen){ + public void genTestData(ProceduralChunkGenerator chunkGen){ this.model = TerrainModel.generateTestModel(); chunkGen.setModel(model); } diff --git a/src/main/java/electrosphere/server/physics/terrain/models/TerrainModel.java b/src/main/java/electrosphere/server/physics/terrain/models/TerrainModel.java index a3247111..38cddd2d 100644 --- a/src/main/java/electrosphere/server/physics/terrain/models/TerrainModel.java +++ b/src/main/java/electrosphere/server/physics/terrain/models/TerrainModel.java @@ -2,7 +2,7 @@ package electrosphere.server.physics.terrain.models; import electrosphere.engine.Globals; import electrosphere.game.data.biome.BiomeData; -import electrosphere.server.physics.terrain.generation.TestGenerationChunkGenerator; +import electrosphere.server.physics.terrain.generation.ProceduralChunkGenerator; import electrosphere.server.physics.terrain.manager.ServerTerrainChunk; import electrosphere.util.annotation.Exclude; @@ -109,12 +109,12 @@ public class TerrainModel { */ public static TerrainModel generateTestModel(){ TerrainModel rVal = new TerrainModel(); - rVal.discreteArrayDimension = TestGenerationChunkGenerator.GENERATOR_REALM_SIZE; - int macroDataImageScale = TestGenerationChunkGenerator.GENERATOR_REALM_SIZE / DEFAULT_MACRO_DATA_SCALE + 1; + rVal.discreteArrayDimension = ProceduralChunkGenerator.GENERATOR_REALM_SIZE; + int macroDataImageScale = ProceduralChunkGenerator.GENERATOR_REALM_SIZE / DEFAULT_MACRO_DATA_SCALE + 1; rVal.biome = new short[macroDataImageScale][macroDataImageScale]; for(int x = 0; x < macroDataImageScale; x++){ for(int z = 0; z < macroDataImageScale; z++){ - rVal.biome[x][z] = TestGenerationChunkGenerator.DEFAULT_BIOME_INDEX; + rVal.biome[x][z] = ProceduralChunkGenerator.DEFAULT_BIOME_INDEX; } } rVal.biome[1][0] = 0; diff --git a/src/main/java/electrosphere/server/saves/SaveUtils.java b/src/main/java/electrosphere/server/saves/SaveUtils.java index 42d01da7..9653712a 100644 --- a/src/main/java/electrosphere/server/saves/SaveUtils.java +++ b/src/main/java/electrosphere/server/saves/SaveUtils.java @@ -14,7 +14,7 @@ import electrosphere.server.macro.MacroData; import electrosphere.server.physics.fluid.generation.DefaultFluidGenerator; import electrosphere.server.physics.fluid.manager.ServerFluidManager; import electrosphere.server.physics.terrain.generation.DefaultChunkGenerator; -import electrosphere.server.physics.terrain.generation.TestGenerationChunkGenerator; +import electrosphere.server.physics.terrain.generation.ProceduralChunkGenerator; import electrosphere.server.physics.terrain.manager.ServerTerrainManager; import electrosphere.util.FileUtils; @@ -117,7 +117,7 @@ public class SaveUtils { ServerWorldData serverWorldData = ServerWorldData.createGriddedRealmWorldData(ServerWorldData.PROCEDURAL_WORLD_SIZE); FileUtils.serializeObjectToSavePath(saveName, "./world.json", serverWorldData); //terrain manager - ServerTerrainManager serverTerrainManager = new ServerTerrainManager(serverWorldData, sceneFile.getSeed(), new TestGenerationChunkGenerator(serverWorldData, false)); + ServerTerrainManager serverTerrainManager = new ServerTerrainManager(serverWorldData, sceneFile.getSeed(), new ProceduralChunkGenerator(serverWorldData, false)); serverTerrainManager.generate(sceneFile.getRealmDescriptor()); serverTerrainManager.save(saveName); //fluid manager