From bb005f8fee3ad6a57996bd05b7ae4a3b8d9e2274 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 7 Jun 2024 17:12:31 -0400 Subject: [PATCH] fix partial ticks --- .../flywheel/api/event/RenderContext.java | 3 ++- .../backend/engine/uniform/LevelUniforms.java | 3 ++- .../impl/event/RenderContextImpl.java | 7 ++++--- .../impl/mixin/LevelRendererMixin.java | 21 +++---------------- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/common/src/api/java/dev/engine_room/flywheel/api/event/RenderContext.java b/common/src/api/java/dev/engine_room/flywheel/api/event/RenderContext.java index ef27d4169..c8f5e551b 100644 --- a/common/src/api/java/dev/engine_room/flywheel/api/event/RenderContext.java +++ b/common/src/api/java/dev/engine_room/flywheel/api/event/RenderContext.java @@ -6,6 +6,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Camera; +import net.minecraft.client.DeltaTracker; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderBuffers; @@ -26,5 +27,5 @@ public interface RenderContext { Camera camera(); - float partialTick(); + DeltaTracker deltaTracker(); } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/LevelUniforms.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/LevelUniforms.java index ae1422181..81b30d379 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/LevelUniforms.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/LevelUniforms.java @@ -17,7 +17,8 @@ public static void update(RenderContext context) { long ptr = BUFFER.ptr(); ClientLevel level = context.level(); - float partialTick = context.partialTick(); + //fixme checkover partialTick + float partialTick = context.deltaTracker().getGameTimeDeltaPartialTick(true); Vec3 skyColor = level.getSkyColor(context.camera().getPosition(), partialTick); Vec3 cloudColor = level.getCloudColor(partialTick); diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java index a211307ea..1f7ee1f7b 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java @@ -6,18 +6,19 @@ import dev.engine_room.flywheel.api.event.RenderContext; import net.minecraft.client.Camera; +import net.minecraft.client.DeltaTracker; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderBuffers; public record RenderContextImpl(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Matrix4f viewProjection, Camera camera, - float partialTick) implements RenderContext { - public static RenderContextImpl create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Camera camera, float partialTick) { + DeltaTracker deltaTracker) implements RenderContext { + public static RenderContextImpl create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Camera camera, DeltaTracker deltaTracker) { Matrix4f viewProjection = new Matrix4f(projection); viewProjection.mul(stack.last() .pose()); - return new RenderContextImpl(renderer, level, buffers, stack, projection, viewProjection, camera, partialTick); + return new RenderContextImpl(renderer, level, buffers, stack, projection, viewProjection, camera, deltaTracker); } } diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java index 5b2df6980..b9a16cb44 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java @@ -2,12 +2,6 @@ import java.util.SortedSet; -import com.llamalad7.mixinextras.sugar.Share; - -import com.llamalad7.mixinextras.sugar.ref.LocalRef; - -import net.minecraft.client.DeltaTracker; - import org.jetbrains.annotations.Nullable; import org.joml.Matrix4f; import org.objectweb.asm.Opcodes; @@ -19,7 +13,6 @@ import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.Group; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.mojang.blaze3d.vertex.PoseStack; @@ -30,6 +23,7 @@ import dev.engine_room.flywheel.impl.visualization.VisualizationManagerImpl; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import net.minecraft.client.Camera; +import net.minecraft.client.DeltaTracker; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LevelRenderer; @@ -57,19 +51,10 @@ abstract class LevelRendererMixin { // @Inject(method = "renderLevel", at = @At("HEAD")) @Inject(method = "renderLevel", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I")) - private void flywheel$beginRender(DeltaTracker deltaTracker, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, Matrix4f frustrumMatrix, CallbackInfo ci, @Share("poseStack") LocalRef sharedPose) { - PoseStack pose = new PoseStack(); - // fixme - is the delta stuff correct? no idea! - flywheel$renderContext = RenderContextImpl.create((LevelRenderer) (Object) this, level, renderBuffers, pose, projectionMatrix, camera, deltaTracker.getGameTimeDeltaTicks()); + private void flywheel$beginRender(DeltaTracker deltaTracker, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, Matrix4f frustrumMatrix, CallbackInfo ci) { + flywheel$renderContext = RenderContextImpl.create((LevelRenderer) (Object) this, level, renderBuffers, new PoseStack(), projectionMatrix, camera, deltaTracker); FlwImplXplat.INSTANCE.dispatchBeginFrameEvent(flywheel$renderContext); - - sharedPose.set(pose); - } - - @Redirect(method = "renderLevel", at = @At(value = "NEW", target = "com/mojang/blaze3d/vertex/PoseStack")) - private PoseStack flywheel$fixPoseStack(@Share("poseStack") LocalRef sharedPose) { - return sharedPose.get(); } @Inject(method = "renderLevel", at = @At("RETURN"))