From 987165649f221f020e9147e494236f707c871f66 Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 29 Oct 2024 14:10:10 -0400 Subject: [PATCH] generation testing menu with regenerate button --- .../generation/terraingenerationprocess.md | 2 +- .../client/terrain/cells/DrawCellManager.java | 16 +++++++ .../client/ui/menu/debug/ImGuiTestGen.java | 48 +++++++++++++++++++ .../ui/menu/debug/ImGuiWindowMacros.java | 12 +++++ .../datacell/GriddedDataCellManager.java | 31 ++++++++++++ .../server/datacell/RealmManager.java | 3 ++ 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/main/java/electrosphere/client/ui/menu/debug/ImGuiTestGen.java diff --git a/docs/src/architecture/generation/terraingenerationprocess.md b/docs/src/architecture/generation/terraingenerationprocess.md index e42e8d08..fc7551dc 100644 --- a/docs/src/architecture/generation/terraingenerationprocess.md +++ b/docs/src/architecture/generation/terraingenerationprocess.md @@ -3,7 +3,7 @@ have a heightmap generated by tectonic sim is interpolated to 2000x2000 saved as a byte per pixel -this map is used to determine what type of noise to sample from (ie mountain noise vs ocean noise vs plains noise) +~~~~~this map is used to determine what type of noise to sample from (ie mountain noise vs ocean noise vs plains noise)~~~~~ generate a separate map for biomes that is also 2000x2000 this is stored as shorts, where value is the id of the biome "civilization" gradient map generated with simplex noise (1byte resolution) diff --git a/src/main/java/electrosphere/client/terrain/cells/DrawCellManager.java b/src/main/java/electrosphere/client/terrain/cells/DrawCellManager.java index ef4eb85c..0960b318 100644 --- a/src/main/java/electrosphere/client/terrain/cells/DrawCellManager.java +++ b/src/main/java/electrosphere/client/terrain/cells/DrawCellManager.java @@ -475,6 +475,22 @@ public class DrawCellManager { updateable.add(getCellKey(chunkX, chunkY, chunkZ)); } + /** + * Evicts all chunks + */ + public void evictAll(){ + //destroy models + for(String key : drawable){ + keyCellMap.get(key).destroy(); + } + keyCellMap.clear(); + hasNotRequested.clear(); + requested.clear(); + drawable.clear(); + undrawable.clear(); + updateable.clear(); + } + /** * Gets the radius within which full-detail models are drawn diff --git a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiTestGen.java b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiTestGen.java new file mode 100644 index 00000000..1e0f6490 --- /dev/null +++ b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiTestGen.java @@ -0,0 +1,48 @@ +package electrosphere.client.ui.menu.debug; + +import electrosphere.engine.Globals; +import electrosphere.renderer.ui.imgui.ImGuiWindow; +import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback; +import electrosphere.server.datacell.GriddedDataCellManager; +import imgui.ImGui; + +/** + * Menu for altering parameters of the test terrain generator + */ +public class ImGuiTestGen { + + //window for viewing information about the ai state + protected static ImGuiWindow testGenWindow; + + /** + * Creates the windows in this file + */ + protected static void createTestGenWindows(){ + createTestGenDebugWindow(); + } + + /** + * Client scene entity view + */ + protected static void createTestGenDebugWindow(){ + testGenWindow = new ImGuiWindow("Test Terrain Generation"); + testGenWindow.setCallback(new ImGuiWindowCallback() { + @Override + public void exec() { + //ui framework text + ImGui.text("Test Terrain Generation"); + + //regenerate the test area + if(ImGui.button("Regenerate")){ + GriddedDataCellManager gridManager = (GriddedDataCellManager)Globals.realmManager.first().getDataCellManager(); + gridManager.evictAll(); + Globals.drawCellManager.evictAll(); + } + + } + }); + testGenWindow.setOpen(false); + Globals.renderingEngine.getImGuiPipeline().addImGuiWindow(testGenWindow); + } + +} 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 b9a27080..f0962f94 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiWindowMacros.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiWindowMacros.java @@ -11,6 +11,7 @@ import electrosphere.renderer.ui.imgui.ImGuiWindow; import electrosphere.renderer.ui.imgui.ImGuiLinePlot.ImGuiLinePlotDataset; import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback; import electrosphere.server.fluid.manager.ServerFluidManager; +import electrosphere.server.terrain.generation.TestGenerationChunkGenerator; import imgui.ImGui; /** @@ -49,6 +50,7 @@ public class ImGuiWindowMacros { ImGuiAudio.createAudioDebugMenu(); ImGuiLogger.createLoggersWindows(); ImGuiRenderer.createRendererWindows(); + ImGuiTestGen.createTestGenWindows(); } /** @@ -171,6 +173,16 @@ public class ImGuiWindowMacros { if(ImGui.button("UI")){ ImGuiUIFramework.uiFrameworkWindow.setOpen(true); } + //test gen window (only drawn if realm is a test generation realm) + if( + Globals.realmManager != null && + Globals.realmManager.first() != null && + Globals.realmManager.first().getServerWorldData() != null && + Globals.realmManager.first().getServerWorldData().getServerTerrainManager().getChunkGenerator() instanceof TestGenerationChunkGenerator && + ImGui.button("Test Terrain Gen") + ){ + ImGuiTestGen.testGenWindow.setOpen(true); + } //close button if(ImGui.button("Close")){ mainDebugWindow.setOpen(false); diff --git a/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java b/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java index 7714e459..eabdaf0c 100644 --- a/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java +++ b/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java @@ -315,6 +315,37 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager } } + /** + * Evicts all loaded chunks. + *

+ * Note: Does not save to disk. + *

+ */ + public void evictAll(){ + //TODO: improve to make have less performance impact + for(ServerDataCell cell : loadedCells){ + loadedCellsLock.acquireUninterruptibly(); + int frameCount = cellPlayerlessFrameMap.get(cell) + 1; + cellPlayerlessFrameMap.put(cell,frameCount); + toCleanQueue.add(cell); + loadedCellsLock.release(); + } + for(ServerDataCell cell : toCleanQueue){ + parent.deregisterCell(cell); + loadedCells.remove(cell); + Vector3i worldPos = getCellWorldPosition(cell); + String key = getServerDataCellKey(worldPos); + groundDataCells.remove(key); + //offload all entities in cell to chunk file + serverContentManager.saveContentToDisk(key, cell.getScene().getEntityList()); + //clear all entities in cell + for(Entity entity : cell.getScene().getEntityList()){ + ClientEntityUtils.destroyEntity(entity); + } + } + toCleanQueue.clear(); + } + /** * Get data cell at a given real point in this realm * @param point The real point diff --git a/src/main/java/electrosphere/server/datacell/RealmManager.java b/src/main/java/electrosphere/server/datacell/RealmManager.java index ca3bd7a3..9542353a 100644 --- a/src/main/java/electrosphere/server/datacell/RealmManager.java +++ b/src/main/java/electrosphere/server/datacell/RealmManager.java @@ -199,6 +199,9 @@ public class RealmManager { * @return The first realm in the manager */ public Realm first(){ + if(realms.size() == 0){ + return null; + } return realms.iterator().next(); }