diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/PersistentGlBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/PersistentGlBuffer.java index 79f6148ef..fb783dc4f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/PersistentGlBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/PersistentGlBuffer.java @@ -12,7 +12,6 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.GlFence; import com.jozufozu.flywheel.backend.gl.error.GlError; import com.jozufozu.flywheel.backend.gl.error.GlException; -import com.jozufozu.flywheel.util.StringUtil; public class PersistentGlBuffer extends GlBuffer implements Mappable { @@ -49,13 +48,6 @@ public class PersistentGlBuffer extends GlBuffer implements Mappable { Backend.getInstance().compat.bufferStorage.bufferStorage(type, size, flags); - GlError error = GlError.poll(); - if (error != null) { - // If this error is being thrown but everything seems fine, - // GlError.poll() might be returning an error from something earlier. - throw new GlException(error, StringUtil.args("bufferStorage", type, size, flags)); - } - ByteBuffer byteBuffer = GL30.glMapBufferRange(type.glEnum, 0, size, flags); if (byteBuffer == null) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/error/GlError.java b/src/main/java/com/jozufozu/flywheel/backend/gl/error/GlError.java index 41b9ddf46..a0cdbded8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/error/GlError.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/error/GlError.java @@ -5,8 +5,6 @@ import java.util.function.Supplier; import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30; -import com.jozufozu.flywheel.Flywheel; - import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; @@ -41,10 +39,10 @@ public enum GlError { } public static void pollAndThrow(Supplier context) { - // TODO: build flag? to enable or disable this function - GlError err = GlError.poll(); - if (err != null) { - Flywheel.LOGGER.error("{}: {}", err.name(), context.get()); - } +// This was a bad idea. +// GlError err = GlError.poll(); +// if (err != null) { +// Flywheel.LOGGER.error("{}: {}", err.name(), context.get()); +// } } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java index 216cceebc..51755ed9f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java @@ -29,8 +29,11 @@ public class InstancedRenderDispatcher { * @param te The tile whose instance you want to update. */ public static void enqueueUpdate(BlockEntity te) { - if (te.hasLevel() && te.getLevel() instanceof ClientLevel) - getTiles(te.getLevel()).queueUpdate(te); + if (Backend.isOn() && te.hasLevel() && te.getLevel() instanceof ClientLevel) { + instanceWorlds.get(te.getLevel()) + .getTileEntityInstanceManager() + .queueUpdate(te); + } } /** @@ -38,17 +41,29 @@ public class InstancedRenderDispatcher { * @param entity The entity whose instance you want to update. */ public static void enqueueUpdate(Entity entity) { - getEntities(entity.level).queueUpdate(entity); + if (Backend.isOn()) { + instanceWorlds.get(entity.level) + .getEntityInstanceManager() + .queueUpdate(entity); + } } public static InstanceManager getTiles(LevelAccessor world) { - return instanceWorlds.get(world) - .getTileEntityInstanceManager(); + if (Backend.isOn()) { + return instanceWorlds.get(world) + .getTileEntityInstanceManager(); + } else { + throw new NullPointerException("Backend is off, cannot retrieve instance world."); + } } public static InstanceManager getEntities(LevelAccessor world) { - return instanceWorlds.get(world) - .getEntityInstanceManager(); + if (Backend.isOn()) { + return instanceWorlds.get(world) + .getEntityInstanceManager(); + } else { + throw new NullPointerException("Backend is off, cannot retrieve instance world."); + } } @SubscribeEvent @@ -61,12 +76,15 @@ public class InstancedRenderDispatcher { ClientLevel world = mc.level; AnimationTickHolder.tick(); - instanceWorlds.get(world).tick(); + if (Backend.isOn()) { + instanceWorlds.get(world) + .tick(); + } } @SubscribeEvent public static void onBeginFrame(BeginFrameEvent event) { - if (Backend.isGameActive()) { + if (Backend.isGameActive() && Backend.isOn()) { instanceWorlds.get(event.getWorld()) .beginFrame(event); } diff --git a/src/main/java/com/jozufozu/flywheel/event/EntityWorldHandler.java b/src/main/java/com/jozufozu/flywheel/event/EntityWorldHandler.java index 10707ea24..c68054208 100644 --- a/src/main/java/com/jozufozu/flywheel/event/EntityWorldHandler.java +++ b/src/main/java/com/jozufozu/flywheel/event/EntityWorldHandler.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.event; +import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import net.minecraftforge.api.distmarker.Dist; @@ -13,13 +14,13 @@ public class EntityWorldHandler { @SubscribeEvent public static void onEntityJoinWorld(EntityJoinWorldEvent event) { - if (event.getWorld().isClientSide) InstancedRenderDispatcher.getEntities(event.getWorld()) + if (event.getWorld().isClientSide && Backend.isOn()) InstancedRenderDispatcher.getEntities(event.getWorld()) .queueAdd(event.getEntity()); } @SubscribeEvent public static void onEntityLeaveWorld(EntityLeaveWorldEvent event) { - if (event.getWorld().isClientSide) InstancedRenderDispatcher.getEntities(event.getWorld()) + if (event.getWorld().isClientSide && Backend.isOn()) InstancedRenderDispatcher.getEntities(event.getWorld()) .remove(event.getEntity()); } } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java index 2ddc15562..861fa7c06 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java @@ -23,7 +23,7 @@ public class ChunkRebuildHooksMixin { @Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true) private void addAndFilterBEs(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set set, E be, CallbackInfo ci) { - if (Backend.isOn() && Backend.isFlywheelWorld(be.getLevel())) { + if (Backend.canUseInstancing(be.getLevel())) { InstancedRenderRegistry registry = InstancedRenderRegistry.getInstance(); if (registry.canInstance(be.getType())) diff --git a/src/main/java/com/jozufozu/flywheel/mixin/InstanceAddMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/InstanceAddMixin.java index dabee25e5..53137d485 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/InstanceAddMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/InstanceAddMixin.java @@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import net.minecraft.world.level.Level; @@ -26,7 +27,9 @@ public class InstanceAddMixin { @Inject(method = "setBlockEntity", at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")) private void tileAdded(BlockEntity be, CallbackInfo ci) { - if (level.isClientSide) InstancedRenderDispatcher.getTiles(this.level) - .add(be); + if (level.isClientSide && Backend.isOn()) { + InstancedRenderDispatcher.getTiles(this.level) + .add(be); + } } } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/InstanceRemoveMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/InstanceRemoveMixin.java index e0282a5c8..9a6862ddf 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/InstanceRemoveMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/InstanceRemoveMixin.java @@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import net.minecraft.client.multiplayer.ClientLevel; @@ -23,8 +24,10 @@ public class InstanceRemoveMixin { @Inject(at = @At("TAIL"), method = "setRemoved") private void removeInstance(CallbackInfo ci) { - if (level instanceof ClientLevel) InstancedRenderDispatcher.getTiles(this.level) - .remove((BlockEntity) (Object) this); + if (level instanceof ClientLevel && Backend.isOn()) { + InstancedRenderDispatcher.getTiles(this.level) + .remove((BlockEntity) (Object) this); + } } // /** diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java index 9e963213e..5452c100e 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java @@ -86,7 +86,9 @@ public class RenderHooksMixin { */ @Inject(at = @At("TAIL"), method = "setBlockDirty(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V") private void checkUpdate(BlockPos pos, BlockState lastState, BlockState newState, CallbackInfo ci) { - InstancedRenderDispatcher.getTiles(level) - .update(level.getBlockEntity(pos)); + if (Backend.isOn()) { + InstancedRenderDispatcher.getTiles(level) + .update(level.getBlockEntity(pos)); + } } }