From 71ff2363a5e72450c77102fea4ab1c43afc95620 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Mon, 2 Aug 2021 23:52:24 -0700 Subject: [PATCH] Miscellaneous documentation --- .../backend/instancing/IInstance.java | 9 ++++ .../backend/instancing/InstanceManager.java | 49 ++++++++++++++++--- .../flywheel/mixin/RenderHooksMixin.java | 2 +- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java index fa424ffa6..e3b969f7a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java @@ -16,6 +16,15 @@ public interface IInstance { void remove(); + /** + * When an instance is reset, the instance is deleted and re-created. + * + *

+ * This is used to handle things like block state changes. + *

+ * + * @return true if this instance should be reset + */ boolean shouldReset(); void update(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java index 7a8800bc3..6b9dbc8f6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java @@ -49,17 +49,41 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL materialManager.addListener(this); } + /** + * Is the given object capable of being instanced at all? + * + * @return false if on object cannot be instanced. + */ protected abstract boolean canInstance(T obj); + /** + * Is the given object currently capable of being instanced? + * + *

+ * This won't be the case for TEs or entities that are outside of loaded chunks. + *

+ * + * @return true if the object is currently capable of being instanced. + */ + protected abstract boolean canCreateInstance(T obj); + + @Nullable protected abstract IInstance createRaw(T obj); - protected abstract boolean canCreateInstance(T entity); - + /** + * Ticks the InstanceManager. + * + *

+ * {@link ITickableInstance}s get ticked. + *
+ * Queued updates are processed. + *

+ */ public void tick(double cameraX, double cameraY, double cameraZ) { tick++; processQueuedUpdates(); - // integer camera pos + // integer camera pos as a micro-optimization int cX = (int) cameraX; int cY = (int) cameraY; int cZ = (int) cameraZ; @@ -117,7 +141,7 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL } } - public synchronized void queueAdd(T obj) { + public void queueAdd(T obj) { if (!Backend.getInstance() .canUseInstancing()) return; @@ -126,6 +150,17 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL } } + /** + * Update the instance associated with an object. + * + *

+ * By default this is the only hook an IInstance has to change its internal state. This is the lowest frequency + * update hook IInstance gets. For more frequent updates, see {@link ITickableInstance} and + * {@link IDynamicInstance}. + *

+ * + * @param obj the object to update. + */ public void update(T obj) { if (!Backend.getInstance() .canUseInstancing()) return; @@ -135,9 +170,11 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL if (instance != null) { + // resetting instances is by default used to handle block state changes. if (instance.shouldReset()) { + // delete and re-create the instance. + // resetting an instance supersedes updating it. removeInternal(obj, instance); - createInternal(obj); } else { instance.update(); @@ -146,7 +183,7 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL } } - public synchronized void queueUpdate(T obj) { + public void queueUpdate(T obj) { if (!Backend.getInstance() .canUseInstancing()) return; synchronized (queuedUpdates) { diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java index 47002e44e..80abdb73e 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java @@ -45,7 +45,7 @@ public class RenderHooksMixin { private RenderTypeBuffers renderBuffers; @Inject(at = @At(value = "INVOKE", target = "net.minecraft.client.renderer.WorldRenderer.compileChunksUntil(J)V"), method = "renderLevel") - private void setupFrame(MatrixStack stack, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, ActiveRenderInfo info, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f p_228426_9_, CallbackInfo ci) { + private void setupFrame(MatrixStack stack, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, ActiveRenderInfo info, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo ci) { MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(level, stack, info, gameRenderer, lightTexture, Clipping.HELPER)); }