From 1f8f47a57e67ff3cea73b88f7d86a124981e5e5f Mon Sep 17 00:00:00 2001 From: makamys Date: Sat, 4 Jun 2022 16:22:37 +0200 Subject: Watch chunk visibility via hooks instead of polling Increases fps from 340 to 360 when rendering nothing --- .../java/makamys/lodmod/ducks/IWorldRenderer.java | 1 - .../makamys/lodmod/mixin/MixinWorldRenderer.java | 35 +++++++++++++++++----- .../java/makamys/lodmod/renderer/LODRenderer.java | 6 ---- 3 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src/main/java/makamys/lodmod') diff --git a/src/main/java/makamys/lodmod/ducks/IWorldRenderer.java b/src/main/java/makamys/lodmod/ducks/IWorldRenderer.java index 56cfb7b..83857d6 100644 --- a/src/main/java/makamys/lodmod/ducks/IWorldRenderer.java +++ b/src/main/java/makamys/lodmod/ducks/IWorldRenderer.java @@ -9,5 +9,4 @@ import net.minecraft.client.renderer.WorldRenderer; public interface IWorldRenderer { public List getChunkMeshes(); - public void myTick(); } diff --git a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java index eba0a5e..7caecb1 100644 --- a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java +++ b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java @@ -45,11 +45,11 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Shadow private int glRenderList; - boolean lastDrawn; - @Shadow public boolean needsUpdate; + boolean savedDrawnStatus; + public List chunkMeshes; @Redirect(method = "setPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderAABB(Lnet/minecraft/util/AxisAlignedBB;)V")) @@ -70,6 +70,8 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Inject(method = "updateRenderer", at = @At(value = "HEAD")) private void preUpdateRenderer(CallbackInfo ci) { + saveDrawnStatus(); + if(LODMod.isActive()) { if(needsUpdate) { if(chunkMeshes != null) { @@ -83,8 +85,10 @@ abstract class MixinWorldRenderer implements IWorldRenderer { } } - @Inject(method = "updateRenderer", at = @At(value = "TAIL")) + @Inject(method = "updateRenderer", at = @At(value = "RETURN")) private void postUpdateRenderer(CallbackInfo ci) { + notifyIfDrawnStatusChanged(); + if(LODMod.isActive()) { if(chunkMeshes != null) { LODMod.renderer.onWorldRendererPost(WorldRenderer.class.cast(this)); @@ -150,11 +154,28 @@ abstract class MixinWorldRenderer implements IWorldRenderer { return chunkMeshes; } - public void myTick() { - boolean drawn = isInFrustum && (!skipRenderPass[0] || !skipRenderPass[1]); - if(drawn != lastDrawn) { + @Inject(method = "updateInFrustum", at = @At(value = "HEAD")) + private void preUpdateInFrustum(CallbackInfo ci) { + saveDrawnStatus(); + } + + @Inject(method = "updateInFrustum", at = @At(value = "RETURN")) + private void postUpdateInFrustum(CallbackInfo ci) { + notifyIfDrawnStatusChanged(); + } + + private void saveDrawnStatus() { + savedDrawnStatus = isDrawn(); + } + + private void notifyIfDrawnStatusChanged() { + boolean drawn = isDrawn(); + if(LODMod.isActive() && drawn != savedDrawnStatus) { LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), drawn); } - lastDrawn = drawn; + } + + private boolean isDrawn() { + return isInFrustum && (!skipRenderPass[0] || !skipRenderPass[1]); } } diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java index 942acdb..d13f4e4 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java +++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java @@ -115,12 +115,6 @@ public class LODRenderer { Minecraft.getMinecraft().entityRenderer.enableLightmap((double)alpha); if(hasInited) { - for(WorldRenderer wr : sortedWorldRenderers) { - if(wr != null) { - ((IWorldRenderer)wr).myTick(); - } - } - mainLoop(); if(LODMod.debugEnabled) { handleKeyboard(); -- cgit