Work on node manager

This commit is contained in:
mcrcortex
2025-04-16 09:21:42 +10:00
parent 99cfbb07b9
commit b0bd063ed6
4 changed files with 49 additions and 6 deletions

View File

@@ -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<<i))==0) continue;
childId++;
if ((reqMsk&(1<<i))!=0) {
//Its an entry from the request
long childPos = makeChildPos(request.getPosition(), i);
@@ -987,6 +1004,11 @@ public class NodeManager {
this.nodeData.free(oldChildPtr, oldChildCnt);
}
//If the old ptr was sentinal null, this node is now pure leaf children
if (oldChildPtr == SENTINEL_EMPTY_CHILD_PTR) {
this.nodeData.setAllChildrenAreLeaf(parentNodeId, true);
}
//Free request
this.childRequests.release(requestId);
@@ -1403,8 +1425,18 @@ public class NodeManager {
if (!this.topLevelNodes.contains(pos)) {
throw new IllegalStateException();
}
int id = node&NODE_ID_MSK;
var req = this.singleRequests.get(id);
if (req.getPosition() != pos) {
throw new IllegalStateException();
}
//TODO
} else {
int id = node&NODE_ID_MSK;
var req = this.childRequests.get(id);
if (req.getPosition() != makeParentPos(pos)) {
throw new IllegalStateException();
}
//TODO
}
} else {
@@ -1412,6 +1444,10 @@ public class NodeManager {
if (!this.nodeData.nodeExists(node)) {
throw new IllegalStateException();
}
//if (type != this.nodeData.getNodeType(node))
// throw new IllegalStateException();
if (this.nodeData.nodePosition(node) != pos) {
throw new IllegalStateException();
}
@@ -1469,7 +1505,7 @@ public class NodeManager {
}
//TODO: check SENTINEL_EMPTY_CHILD_PTR
if (childPtr != SENTINEL_EMPTY_CHILD_PTR) {
boolean allChildrenLeaf = true;
boolean allChildrenLeaf = true;//childCount != 0;
for (int i = 0; i < childCount; i++) {
if (!this.nodeData.nodeExists(i + childPtr))//All children must exist
throw new IllegalStateException();

View File

@@ -275,8 +275,14 @@ public final class NodeStore {
int w = 0;
short flags = 0;
flags |= (short) (this.isNodeRequestInFlight(nodeId)?1:0);
flags |= (short) ((this.getChildPtrCount(nodeId)-1)<<2);
flags |= (short) (this.isNodeRequestInFlight(nodeId)?1:0);//1 bit
flags |= (short) ((this.getChildPtrCount(nodeId)-1)<<2);//3 bit
boolean isEligibleForCleaning = false;
isEligibleForCleaning |= this.getAllChildrenAreLeaf(nodeId);
//isEligibleForCleaning |= this.getNodeType()
flags |= (short) (isEligibleForCleaning?1<<4:0);//1 bit
{
int geometry = this.getNodeGeometry(nodeId);

View File

@@ -268,7 +268,7 @@ public class TestNodeManager {
private final long pos;
private final Node[] children = new Node[8];
private byte childExistenceMask;
private boolean hasMesh;
private int meshId;
private Node(long pos) {
this.pos = pos;
}
@@ -285,7 +285,7 @@ public class TestNodeManager {
Logger.SHUTUP = true;
if (true) {
if (false) {
for (int q = 0; q < ITER_COUNT; q++) {
//Logger.info("Iteration "+ q);
if (runTest(INNER_ITER_COUNT, q, seenTraces, GEO_REM)) {

View File

@@ -49,6 +49,7 @@ public class WorldUpdater {
int iSecMsk1 =(~secMsk)+1;
int secIdx = 0;
//TODO: manually unroll and do e.g. 4 iterations per loop
for (int i = baseVIdx; i <= (0xFFF >> (lvl * 3)) + baseVIdx; i++) {
int cSecIdx = secIdx+baseSec;
secIdx = (secIdx + iSecMsk1)&secMsk;