Skip to content

Commit

Permalink
only start preparing node reuse on the second build of a section
Browse files Browse the repository at this point in the history
  • Loading branch information
douira committed Dec 5, 2023
1 parent bb6b623 commit 7563bdd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ class BSPWorkspace {

final BSPResult result = new BSPResult();

BSPWorkspace(TQuad[] quads, ChunkSectionPos sectionPos) {
final boolean prepareNodeReuse;

BSPWorkspace(TQuad[] quads, ChunkSectionPos sectionPos, boolean prepareNodeReuse) {
this.quads = quads;
this.sectionPos = sectionPos;
this.prepareNodeReuse = prepareNodeReuse;
}

// TODO: better bidirectional triggering: integrate bidirectionality in GFNI if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static NodeReuseData prepareNodeReuse(BSPWorkspace workspace, IntArrayList index
// TODO: more sophisticated reuse scheduling (make uset configurable, and only
// do once the section has been modified at least once already to avoid making
// this data on terrain sections that are never touched)
if (depth == 1 && indexes.size() > NODE_REUSE_THRESHOLD) {
if (workspace.prepareNodeReuse && depth == 1 && indexes.size() > NODE_REUSE_THRESHOLD) {
// collect the extents of the indexed quads and hash them
var quadExtents = new float[indexes.size()][];
int maxIndex = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
import net.minecraft.util.math.ChunkSectionPos;

public class BSPDynamicData extends DynamicData {
private static final int NODE_REUSE_MIN_GENERATION = 1;

private final BSPNode rootNode;
private final int generation;

private BSPDynamicData(ChunkSectionPos sectionPos,
NativeBuffer buffer, VertexRange range, BSPResult result) {
NativeBuffer buffer, VertexRange range, BSPResult result, int generation) {
super(sectionPos, buffer, range, result);
this.rootNode = result.getRootNode();
this.generation = generation;
}

@Override
Expand All @@ -34,16 +38,22 @@ public static BSPDynamicData fromMesh(BuiltSectionMeshParts translucentMesh,
Vector3fc cameraPos, TQuad[] quads, ChunkSectionPos sectionPos,
NativeBuffer buffer, TranslucentData oldData) {
BSPNode oldRoot = null;
int generation = 0;
boolean prepareNodeReuse = false;
if (oldData instanceof BSPDynamicData oldBSPData) {
generation = oldBSPData.generation + 1;
oldRoot = oldBSPData.rootNode;
}

var result = BSPNode.buildBSP(quads, sectionPos, oldRoot);
// only enable partial updates after a certain number of generations
// (times the section has been built)
prepareNodeReuse = generation >= NODE_REUSE_MIN_GENERATION;
}
var result = BSPNode.buildBSP(quads, sectionPos, oldRoot, prepareNodeReuse);

VertexRange range = TranslucentData.getUnassignedVertexRange(translucentMesh);
buffer = PresentTranslucentData.nativeBufferForQuads(buffer, quads);

var dynamicData = new BSPDynamicData(sectionPos, buffer, range, result);
var dynamicData = new BSPDynamicData(sectionPos, buffer, range, result, generation);
dynamicData.sort(cameraPos);

// prepare accumulation groups for integration into GFNI triggering
Expand Down

0 comments on commit 7563bdd

Please sign in to comment.