diff options
author | makamys <makamys@outlook.com> | 2022-06-04 16:22:37 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-04 16:34:56 +0200 |
commit | 1f8f47a57e67ff3cea73b88f7d86a124981e5e5f (patch) | |
tree | cc83fe7f09ec33697210da567ad367eb3a9f845d /src | |
parent | a4553bb86b1ed25e035abd9ddd4d7452e3f0a151 (diff) | |
download | Neodymium-1f8f47a57e67ff3cea73b88f7d86a124981e5e5f.tar.gz Neodymium-1f8f47a57e67ff3cea73b88f7d86a124981e5e5f.tar.bz2 Neodymium-1f8f47a57e67ff3cea73b88f7d86a124981e5e5f.zip |
Watch chunk visibility via hooks instead of polling
Increases fps from 340 to 360 when rendering nothing
Diffstat (limited to 'src')
3 files changed, 28 insertions, 14 deletions
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<ChunkMesh> 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<ChunkMesh> 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(); |