Skip to content

Commit

Permalink
fix partial ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Jun 7, 2024
1 parent 2f83dcc commit bb005f8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,5 +27,5 @@ public interface RenderContext {

Camera camera();

float partialTick();
DeltaTracker deltaTracker();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<PoseStack> 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<PoseStack> sharedPose) {
return sharedPose.get();
}

@Inject(method = "renderLevel", at = @At("RETURN"))
Expand Down

0 comments on commit bb005f8

Please sign in to comment.