-
Notifications
You must be signed in to change notification settings - Fork 19
SurfaceTracker cleanup (WIP) #100
base: MC_1.17
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,7 +224,8 @@ public void onEnteringFeaturesStatus() { | |
} | ||
} | ||
|
||
lightHeightmap.loadCube(((CubicServerLevel) this.levelHeightAccessor).getHeightmapStorage(), this); | ||
SurfaceTrackerLeaf lightLeaf = lightHeightmap.loadCube(((CubicServerLevel) this.levelHeightAccessor).getHeightmapStorage(), this, null); | ||
sectionLoaded(lightLeaf, dx, dz); | ||
|
||
for (int z = 0; z < SECTION_DIAMETER; z++) { | ||
for (int x = 0; x < SECTION_DIAMETER; x++) { | ||
|
@@ -368,12 +369,11 @@ private SurfaceTrackerLeaf[] getHeightmapSections(Heightmap.Types type) { | |
for (int dx = 0; dx < CubeAccess.DIAMETER_IN_SECTIONS; dx++) { | ||
for (int dz = 0; dz < CubeAccess.DIAMETER_IN_SECTIONS; dz++) { | ||
int idx = dx + dz * CubeAccess.DIAMETER_IN_SECTIONS; | ||
SurfaceTrackerLeaf leaf = new SurfaceTrackerLeaf(cubePos.getY(), null, (byte) type.ordinal()); | ||
leaf.loadCube(dx, dz, ((CubicServerLevel) ((ServerLevelAccessor) this.levelHeightAccessor).getLevel()).getHeightmapStorage(), this); | ||
SurfaceTrackerLeaf leaf = new SurfaceTrackerLeaf(this, null, (byte) type.ordinal()); | ||
// On creation of a new node for a cube, both the node and its parents must be marked dirty | ||
leaf.setAllDirty(); | ||
leaf.markAncestorsDirty(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leaf is an unattached SurfaceTrackerLeaf. There is no point in calling "markAncestorsDirty" as it does not have any. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iirc this is used elsewhere too. It's really a "mark any positions dirty if they are below the new height in myself and ancestors" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setAllDirty() already sets everything within the leaf dirty without any checks. markAncestorsDirty() doesn't have any additional effect. |
||
surfaceTrackerLeaves[idx] = leaf; | ||
sectionLoaded(leaf, dx, dz); | ||
} | ||
} | ||
return surfaceTrackerLeaves; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ protected int updateHeight(int x, int z, int idx) { | |
} | ||
} | ||
|
||
@Override public void loadCube(int localSectionX, int localSectionZ, HeightmapStorage storage, HeightmapNode newNode) { | ||
public SurfaceTrackerLeaf loadCube(int localSectionX, int localSectionZ, HeightmapStorage storage, HeightmapNode newNode, @Nullable SurfaceTrackerLeaf protoLeaf) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. loadCube now accepts a protoLeaf to copy its data and it returns the newly created leaf. This enable promotion of "proto leaves" from ProtoCube into LevelCube. |
||
int newScale = scale - 1; | ||
|
||
// Attempt to load all children from storage | ||
|
@@ -56,18 +56,39 @@ protected int updateHeight(int x, int z, int idx) { | |
|
||
int idx = indexOfRawHeightNode(newNode.getNodeY(), scale, scaledY); | ||
int newScaledY = indexToScaledY(idx, scale, scaledY); | ||
if (children[idx] == null) { | ||
// If the child containing new node has not been loaded from storage, create it | ||
// Scale 1 nodes create leaf node children | ||
if (newScale == 0) { | ||
children[idx] = new SurfaceTrackerLeaf(newScaledY, this, this.heightmapType); | ||
|
||
// child is a leaf | ||
if (newScale == 0) { | ||
|
||
assert children[idx] == null : "Duplicate leaf!"; | ||
|
||
SurfaceTrackerLeaf newLeaf; | ||
if (protoLeaf == null) { | ||
newLeaf = new SurfaceTrackerLeaf(newNode, this, this.heightmapType); | ||
} else { | ||
newLeaf = new SurfaceTrackerLeaf(newNode, this, protoLeaf); | ||
} | ||
children[idx] = newLeaf; | ||
newNode.sectionLoaded(newLeaf, localSectionX, localSectionZ); | ||
newLeaf.markAncestorsDirty(); | ||
|
||
onChildLoaded(); | ||
|
||
return newLeaf; | ||
} | ||
|
||
// child is a branch | ||
else { | ||
|
||
if (children[idx] == null) { | ||
children[idx] = new SurfaceTrackerBranch(newScale, newScaledY, this, this.heightmapType); | ||
} | ||
|
||
return ((SurfaceTrackerBranch) children[idx]).loadCube(localSectionX, localSectionZ, storage, newNode, protoLeaf); | ||
} | ||
children[idx].loadCube(localSectionX, localSectionZ, storage, newNode); | ||
} | ||
|
||
|
||
@Override protected void unload(HeightmapStorage storage) { | ||
for (SurfaceTrackerNode child : this.children) { | ||
assert child == null : "Heightmap branch being unloaded while holding a child?!"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic was partly duplicated between the promotion constructor and postLoad. I moved all of it into the promotion constructor for now.