diff --git a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java index c485f6ed5..c9de28113 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; +import java.util.function.Consumer; import java.util.function.Supplier; import static com.simibubi.create.foundation.render.SuperByteBufferCache.PARTIAL; @@ -79,15 +80,25 @@ public class FastKineticRenderer { * guaranteed to be no race conditions with the render thread, i.e. when constructing a FastContraptionRenderer. */ public void markAllDirty() { + runOnAll(InstanceBuffer::markDirty); + } + + public void invalidate() { + runOnAll(InstanceBuffer::delete); + belts.values().forEach(Cache::invalidateAll); + rotating.values().forEach(Cache::invalidateAll); + } + + private void runOnAll(Consumer> f) { for (Cache> cache : rotating.values()) { for (InstanceBuffer renderer : cache.asMap().values()) { - renderer.markDirty(); + f.accept(renderer); } } for (Cache> cache : belts.values()) { for (InstanceBuffer renderer : cache.asMap().values()) { - renderer.markDirty(); + f.accept(renderer); } } } @@ -250,18 +261,6 @@ public class FastKineticRenderer { return new BeltBuffer(builder); } - public void invalidate() { - for (Cache> objectInstanceBufferCache : rotating.values()) { - objectInstanceBufferCache.asMap().values().forEach(InstanceBuffer::delete); - objectInstanceBufferCache.invalidateAll(); - } - - for (Cache> cache : belts.values()) { - cache.asMap().values().forEach(InstanceBuffer::delete); - cache.invalidateAll(); - } - } - public static RenderType getKineticRenderLayer() { return RenderType.getCutoutMipped(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index 54bca6390..17953fedd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -84,6 +84,7 @@ public abstract class InstanceBuffer extends TemplateBuf } public void clearInstanceData() { + instanceCount = 0; shouldBuild = true; }