From 5b97a56c8cf8a58930c4e101011e89d276041005 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Fri, 8 Nov 2024 16:13:28 -0800 Subject: [PATCH] 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 --- .../flywheel/backend/engine/DrawManager.java | 9 +++++++-- .../flywheel/backend/engine/MeshPool.java | 12 +++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/DrawManager.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/DrawManager.java index b81502d1f..10562ee7f 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/DrawManager.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/DrawManager.java @@ -58,8 +58,13 @@ public abstract class DrawManager> { 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(); } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/MeshPool.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/MeshPool.java index 5a41c1068..6cfa31424 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/MeshPool.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/MeshPool.java @@ -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; }