From ce1d7dc44b0802d22bede0b120c4e4c891d34c50 Mon Sep 17 00:00:00 2001 From: Kneelawk Date: Mon, 4 Mar 2024 14:58:58 -0800 Subject: [PATCH] Update options --- .../backend/engine/uniform/Uniforms.java | 11 ++++++++- .../flywheel/backend/mixin/OptionsMixin.java | 23 +++++++++++++++++++ .../resources/flywheel.backend.mixins.json | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/jozufozu/flywheel/backend/mixin/OptionsMixin.java diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java b/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java index 5779444fe..abb6b751b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java @@ -29,6 +29,7 @@ public class Uniforms { private static @Nullable UniformBuffer options; private static @Nullable UniformBuffer player; private static @Nullable UniformBuffer level; + private static boolean optionsRequiresUpdate = false; public static UniformBuffer frame() { if (frame == null) { @@ -109,12 +110,20 @@ public class Uniforms { } } + public static void onOptionsUpdate() { + // this is sometimes called too early to do an actual update + optionsRequiresUpdate = true; + } + public static void updateContext(RenderContext ctx) { var ubo = frame(); ubo.provider.setContext(ctx); ubo.update(); - options(); + if (optionsRequiresUpdate) { + options().update(); + optionsRequiresUpdate = false; + } var player = player(); player.provider.setContext(ctx); diff --git a/src/main/java/com/jozufozu/flywheel/backend/mixin/OptionsMixin.java b/src/main/java/com/jozufozu/flywheel/backend/mixin/OptionsMixin.java new file mode 100644 index 000000000..76cb4f35b --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/mixin/OptionsMixin.java @@ -0,0 +1,23 @@ +package com.jozufozu.flywheel.backend.mixin; + +import com.jozufozu.flywheel.backend.engine.uniform.Uniforms; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.Options; + +@Mixin(Options.class) +public class OptionsMixin { + @Inject(method = "load()V", at = @At("RETURN")) + private void onLoad(CallbackInfo ci) { + Uniforms.onOptionsUpdate(); + } + + @Inject(method = "save", at = @At("HEAD")) + private void onSave(CallbackInfo ci) { + Uniforms.onOptionsUpdate(); + } +} diff --git a/src/main/resources/flywheel.backend.mixins.json b/src/main/resources/flywheel.backend.mixins.json index cabf78167..25dbe6fb9 100644 --- a/src/main/resources/flywheel.backend.mixins.json +++ b/src/main/resources/flywheel.backend.mixins.json @@ -9,6 +9,7 @@ "GameRendererAccessor", "GlStateManagerMixin", "LightTextureAccessor", + "OptionsMixin", "OverlayTextureAccessor", "RenderSystemMixin" ],