From 782b31954eff1f6393a8823e9aef75afa567a108 Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 29 Apr 2025 17:03:54 -0400 Subject: [PATCH] foliage debug tooling --- docs/src/progress/renderertodo.md | 1 + .../client/terrain/foliage/FoliageCell.java | 34 +++++++++++++++++++ .../terrain/foliage/FoliageCellManager.java | 17 ++++++---- .../client/ui/menu/debug/ImGuiDrawCell.java | 8 ++++- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index abeb2fbf..d2693f6f 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1594,6 +1594,7 @@ Unhashing ivec hashed keys in chunk caches 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 diff --git a/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java b/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java index ce12319f..0721ae1a 100644 --- a/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java +++ b/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java @@ -175,6 +175,11 @@ public class FoliageCell { * The number of cells that have alerted this one */ int generationAlertCount = 0; + + /** + * If set to true, FoliageCellManager should debug when evaluating this cell + */ + boolean tripDebugFlag = false; /** @@ -467,6 +472,35 @@ public class FoliageCell { return cachedMinDistance; } } + + @Override + public String toString(){ + return "" + + "worldPos: " + worldPos + "\n" + + "voxelPos: " + voxelPos + "\n" + + "lod: " + lod + "\n" + + "modelEntity: " + modelEntity + "\n" + + "hasRequested: " + hasRequested + "\n" + + "hasGenerated: " + hasGenerated + "\n" + + "homogenous: " + homogenous + "\n" + + ""; + } + + /** + * Sets whether this cell should trip the debug flag on its next evaluation or not + * @param trip true to debug on next evaluation, false otherwise + */ + public void setTripDebug(boolean trip){ + this.tripDebugFlag = trip; + } + + /** + * Gets whether this cell should trigger debugging on next evaluation or not + * @return true to debug on next evaluation, false otherwise + */ + public boolean getTripDebug(){ + return tripDebugFlag; + } } diff --git a/src/main/java/electrosphere/client/terrain/foliage/FoliageCellManager.java b/src/main/java/electrosphere/client/terrain/foliage/FoliageCellManager.java index 5317b1b5..45129cc5 100644 --- a/src/main/java/electrosphere/client/terrain/foliage/FoliageCellManager.java +++ b/src/main/java/electrosphere/client/terrain/foliage/FoliageCellManager.java @@ -226,17 +226,20 @@ public class FoliageCellManager { */ private boolean recursivelyUpdateCells(WorldOctTreeNode node, Vector3i absVoxelPos, Map,Boolean> evaluationMap, int minLeafLod, int distCache){ boolean updated = false; + if(node.getData().getTripDebug()){ + node.getData().setTripDebug(false); + } //breakpoint handling if(this.breakPoints.size() > 0){ for(Vector3i breakpoint : breakPoints){ if(GeomUtils.approxMinDistanceAABB(breakpoint, node.getMinBound(), node.getMaxBound()) == 0){ - System.out.println("Break at " + breakpoint + " " + node.getLevel()); - System.out.println(" " + node.getMinBound() + " " + node.getMaxBound()); - System.out.println(" Generated: " + node.getData().hasGenerated()); - System.out.println(" Homogenous: " + node.getData().isHomogenous()); - System.out.println(" Leaf: " + node.isLeaf()); - System.out.println(" Cached min dist: " + node.getData().cachedMinDistance); - System.out.println(" Actual min dist: " + GeomUtils.approxMinDistanceAABB(breakpoint, node.getMinBound(), node.getMaxBound())); + LoggerInterface.loggerEngine.WARNING("Break at " + breakpoint + " " + node.getLevel()); + LoggerInterface.loggerEngine.WARNING(" " + node.getMinBound() + " " + node.getMaxBound()); + LoggerInterface.loggerEngine.WARNING(" Generated: " + node.getData().hasGenerated()); + LoggerInterface.loggerEngine.WARNING(" Homogenous: " + node.getData().isHomogenous()); + LoggerInterface.loggerEngine.WARNING(" Leaf: " + node.isLeaf()); + LoggerInterface.loggerEngine.WARNING(" Cached min dist: " + node.getData().cachedMinDistance); + LoggerInterface.loggerEngine.WARNING(" Actual min dist: " + GeomUtils.approxMinDistanceAABB(breakpoint, node.getMinBound(), node.getMaxBound())); } } } diff --git a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiDrawCell.java b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiDrawCell.java index 181e7d02..62655f9d 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiDrawCell.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiDrawCell.java @@ -5,6 +5,7 @@ import org.joml.Vector3i; import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.client.terrain.cache.ChunkData; import electrosphere.client.terrain.cells.DrawCell; +import electrosphere.client.terrain.foliage.FoliageCell; import electrosphere.engine.Globals; import electrosphere.logger.LoggerInterface; import electrosphere.renderer.ui.imgui.ImGuiWindow; @@ -36,7 +37,7 @@ public class ImGuiDrawCell { drawCellWindow.setCallback(new ImGuiWindowCallback() { @Override public void exec() { - if(ImGui.button("Debug camera position")){ + if(ImGui.button("Debug DrawCell at camera position")){ Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); DrawCell cell = Globals.clientDrawCellManager.getDrawCell(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z); LoggerInterface.loggerEngine.WARNING("" + cell); @@ -62,6 +63,11 @@ public class ImGuiDrawCell { LoggerInterface.loggerEngine.WARNING("Chunk not in cache! " + cameraWorldPos); } } + if(ImGui.button("Debug FoliageCell at camera position")){ + Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + FoliageCell cell = Globals.foliageCellManager.getFoliageCell(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z); + LoggerInterface.loggerEngine.WARNING("" + cell); + } if(ImGui.button("Request terrain at camera position")){ Vector3i cameraWorldPos = Globals.clientWorldData.convertRealToWorldSpace(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Globals.clientTerrainManager.requestChunk(cameraWorldPos.x, cameraWorldPos.y, cameraWorldPos.z, 1);