test(ChunkMeshWorker): implement more tests
They are beginning to look readable.
@@ -93,6 +93,7 @@ public static ChunkMeshWorker create(ChunkTessellator chunkTessellator,
}
public void add(Chunk chunk) {
+ // FIXME: avoid adding duplicates
chunksInProximityOfCamera.add(chunk);
}
@@ -117,18 +118,31 @@ public void remove(Vector3ic coord) {
}
}
+ /**
+ * Queue all dirty items in our collection, in priority order.
+ *
+ * @return the number of dirty chunks added to the queue
+ */
public int update() {
int statDirtyChunks = 0;
chunksInProximityOfCamera.sort(frontToBackComparator);
for (Chunk chunk : chunksInProximityOfCamera) {
- if (chunk.isReady() && chunk.isDirty()) {
+ if (!chunk.isReady()) {
+ // Chunk was added as part of some region, but not yet ready.
+ // Leave it here with the expectation that it will be ready later.
+ continue;
+ }
+ if (!chunk.isDirty()) {
+ // Chunk is in proximity list, but is no longer dirty. Probably already processed.
+ // Will poll it again next tick to see if it got dirty since then.
+ continue;
+ }
statDirtyChunks++;
Sinks.EmitResult result = chunkMeshPublisher.tryEmitNext(chunk);
if (result.isFailure()) {
logger.error("failed to process chunk {} : {}", chunk, result);
}
}
- }
return statDirtyChunks;
}
