Save yourself the trouble

- Don't initialize instancers if they have 0 instances
- Never shrink the index pool
- Actually process recently allocated meshes to avoid growing the list
  forever
This commit is contained in:
Jozufozu 2024-11-08 16:13:28 -08:00
parent 68453d8349
commit 5b97a56c8c
2 changed files with 10 additions and 11 deletions

View File

@ -58,8 +58,13 @@ public abstract class DrawManager<N extends AbstractInstancer<?>> {
public void flush(LightStorage lightStorage, EnvironmentStorage environmentStorage) {
// Thread safety: flush is called from the render thread after all visual updates have been made,
// so there are no:tm: threads we could be racing with.
for (var instancer : initializationQueue) {
initialize(instancer.key(), instancer.instancer());
for (var init : initializationQueue) {
var instancer = init.instancer();
if (instancer.instanceCount() > 0) {
initialize(init.key(), instancer);
} else {
instancers.remove(init.key());
}
}
initializationQueue.clear();
}

View File

@ -70,23 +70,17 @@ public class MeshPool {
if (anyToRemove) {
anyToRemove = false;
processDeletions();
}
// Might want to shrink the index pool if something was removed.
indexPool.reset();
for (PooledMesh mesh : meshList) {
indexPool.updateCount(mesh.mesh.indexSequence(), mesh.indexCount());
}
} else {
if (!recentlyAllocated.isEmpty()) {
// Otherwise, just update the index with the new counts.
for (PooledMesh mesh : recentlyAllocated) {
indexPool.updateCount(mesh.mesh.indexSequence(), mesh.indexCount());
}
indexPool.flush();
recentlyAllocated.clear();
}
// Always need to flush the index pool.
indexPool.flush();
uploadAll();
dirty = false;
}