From 1274a8e097d206373429897e203674300675678d Mon Sep 17 00:00:00 2001 From: JustAlittleWolf Date: Thu, 13 Jun 2024 13:15:39 +0200 Subject: [PATCH] Directly access childNodes in LodQuadTree This changes `LodQuadTree::recursivelyUpdateRenderSectionNode` to directly iterate on the children, instead of creating a childpositerator, and searching for the sectionpos. This lowers memory usage, as the iterators add quite a lot of object garbage (see https://i.imgur.com/r0qlxzc.png) --- .../distanthorizons/core/render/LodQuadTree.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/LodQuadTree.java b/core/src/main/java/com/seibel/distanthorizons/core/render/LodQuadTree.java index 731cba4d7..2c32c7e55 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/LodQuadTree.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/LodQuadTree.java @@ -302,13 +302,9 @@ public class LodQuadTree extends QuadTree implements IDebugRen boolean allChildrenSectionsAreLoaded = true; // recursively update all child render sections - LongIterator childPosIterator = quadNode.getChildPosIterator(); - while (childPosIterator.hasNext()) + for (int i = 0; i < 4; i++) { - long childPos = childPosIterator.nextLong(); - QuadNode childNode = rootNode.getNode(childPos); - - boolean childSectionLoaded = this.recursivelyUpdateRenderSectionNode(playerPos, rootNode, childNode, childPos, thisPosIsRendering || parentSectionIsRendering, nodesNeedingRetrieval, nodesNeedingLoading); + boolean childSectionLoaded = this.recursivelyUpdateRenderSectionNode(playerPos, rootNode, quadNode.getChildByIndex(i), DhSectionPos.getChildByIndex(sectionPos, i), thisPosIsRendering || parentSectionIsRendering, nodesNeedingRetrieval, nodesNeedingLoading); allChildrenSectionsAreLoaded = childSectionLoaded && allChildrenSectionsAreLoaded; } @@ -335,13 +331,9 @@ public class LodQuadTree extends QuadTree implements IDebugRen renderSection.renderingEnabled = false; // walk back down the tree and enable the child sections //TODO there are probably more efficient ways of doing this, but this will work for now - childPosIterator = quadNode.getChildPosIterator(); - while (childPosIterator.hasNext()) + for (int i = 0; i < 4; i++) { - long childPos = childPosIterator.nextLong(); - QuadNode childNode = rootNode.getNode(childPos); - - boolean childSectionLoaded = this.recursivelyUpdateRenderSectionNode(playerPos, rootNode, childNode, childPos, parentSectionIsRendering, nodesNeedingRetrieval, nodesNeedingLoading); + boolean childSectionLoaded = this.recursivelyUpdateRenderSectionNode(playerPos, rootNode, quadNode.getChildByIndex(i), DhSectionPos.getChildByIndex(sectionPos, i), parentSectionIsRendering, nodesNeedingRetrieval, nodesNeedingLoading); allChildrenSectionsAreLoaded = childSectionLoaded && allChildrenSectionsAreLoaded; } if (!allChildrenSectionsAreLoaded)