diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java index 204c00bb..08d81cb1 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java @@ -426,7 +426,8 @@ public class NodeManager { //Remove child from being watched and activeSections long cPos = makeChildPos(pos, i); - if (this.activeSectionMap.remove(cPos) == -1) {//TODO: verify the removed section is a request type of child and the request id matches this + int cnid = this.activeSectionMap.remove(cPos); + if (cnid == -1 || (cnid&NODE_TYPE_MSK) != NODE_TYPE_REQUEST) {//TODO: verify the removed section is a request type of child and the request id matches this throw new IllegalStateException("Child pos was in a request but not in active section map"); } if (!this.watcher.unwatch(cPos, WorldEngine.UPDATE_FLAGS)) { @@ -487,6 +488,7 @@ public class NodeManager { int prevChildId = oldPtr - 1; int newChildId = newPtr - 1; + boolean allChildNodesLeaf = true; //Need to compact the old into the new for (int i = 0; i < 8; i++) { if ((oldExistence & (1 << i)) == 0) continue; @@ -515,6 +517,7 @@ public class NodeManager { if ((prevNodeId & NODE_ID_MSK) != prevChildId) { throw new IllegalStateException("State inconsistency"); } + allChildNodesLeaf &= (prevNodeId & NODE_TYPE_MSK) == NODE_TYPE_LEAF; this.activeSectionMap.put(cPos, (prevNodeId & NODE_TYPE_MSK) | newChildId); //Release the old entry @@ -524,6 +527,7 @@ public class NodeManager { this.invalidateNode(newChildId); } } + this.nodeData.setAllChildrenAreLeaf(nodeId, allChildNodesLeaf); //Put the new childPtr into the map this.nodeData.setChildPtr(nodeId, newPtr); @@ -747,6 +751,8 @@ public class NodeManager { throw new IllegalStateException("Pos was not being watched"); } } else { + //All children removed, clear marker + this.nodeData.setAllChildrenAreLeaf(nodeId, false); //TODO: probably need this.clearId(nodeId); this.invalidateNode(nodeId); } @@ -882,6 +888,15 @@ public class NodeManager { this.nodeData.setAllChildrenAreLeaf(parentNodeId, true); //TODO: Need to set AllChildrenAreLeaf of the parent of the parent to false + //Update the parentParent that all the children are leaf + if (!this.topLevelNodes.contains(request.getPosition())) { + int ppnId = this.activeSectionMap.get(makeParentPos(request.getPosition())); + if ((ppnId&NODE_TYPE_MSK) != NODE_TYPE_INNER) { + throw new IllegalStateException(); + } + //Since this node isnt a leaf node anymore + this.nodeData.setAllChildrenAreLeaf(ppnId&NODE_ID_MSK, false); + } } else if (parentNodeType==NODE_TYPE_INNER) { //For this, only need to add the nodes to the existing child set thing (shuffle around whatever) dont ever have to remove nodes @@ -925,11 +940,13 @@ public class NodeManager { // FOR OLD ALLOCATIONS, NEED TO UPDATE POINTERS int childId = newChildPtr-1; int prevChildId = oldChildPtr-1; + for (int i = 0; i < 8; i++) { if ((newMsk&(1<> (lvl * 3)) + baseVIdx; i++) { int cSecIdx = secIdx+baseSec; secIdx = (secIdx + iSecMsk1)&secMsk;