From 3436ffa97c0ede150062878cfee9841a0460fba4 Mon Sep 17 00:00:00 2001 From: LAX1DUDE Date: Sat, 23 Apr 2022 20:03:15 -0700 Subject: [PATCH] fixed chunk flickering --- .../lax1dude/eaglercraft/ConfigConstants.java | 2 +- .../java/net/minecraft/src/RenderGlobal.java | 41 ++++++++++++++----- .../java/net/minecraft/src/WorldRenderer.java | 3 +- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java b/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java index 214a41c..e6ecf41 100644 --- a/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java +++ b/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java @@ -4,7 +4,7 @@ public class ConfigConstants { public static boolean profanity = false; - public static final String version = "22w16g"; + public static final String version = "22w16h"; public static final String mainMenuString = "eaglercraft " + version; public static final String forkMe = "https://github.com/LAX1DUDE/eaglercraft"; diff --git a/src/main/java/net/minecraft/src/RenderGlobal.java b/src/main/java/net/minecraft/src/RenderGlobal.java index 9af747c..1a1e8cd 100644 --- a/src/main/java/net/minecraft/src/RenderGlobal.java +++ b/src/main/java/net/minecraft/src/RenderGlobal.java @@ -320,7 +320,8 @@ public class RenderGlobal implements IWorldAccess { int i = (var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4; this.worldRenderers[i] = new WorldRenderer(this.theWorld, this.tileEntities, var4 * 16, var5 * 16, var6 * 16, this.glRenderListBase + var2); this.worldRenderers[i].isWaitingOnOcclusionQuery = false; - this.worldRenderers[i].isVisible = true; + this.worldRenderers[i].isNowVisible = true; + this.worldRenderers[i].isVisible = 100; this.worldRenderers[i].isInFrustum = true; this.worldRenderers[i].chunkIndex = var3++; this.worldRenderers[i].markDirty(); @@ -502,6 +503,8 @@ public class RenderGlobal implements IWorldAccess { } } + // GOSH FUCKING DAMMIT WHY IN THE FUCK IS GODDAMN WEBGL THIS UNSTABLE + private long lastOcclusionQuery = 0l; private boolean[] occlusionQueryAvailable; private long[] occlusionQueryStalled; @@ -563,7 +566,9 @@ public class RenderGlobal implements IWorldAccess { int var34; long queryRate = 50l; - long stallRate = 150l; + long stallRateVisible = 50l; + long stallRate = 500l; + int cooldownRate = 10; long ct = System.currentTimeMillis(); if(par2 == 0) { @@ -574,14 +579,25 @@ public class RenderGlobal implements IWorldAccess { int ccy = c.chunkY - fy; int ccz = c.chunkZ - fz; if((ccx < 2 && ccx > -2 && ccy < 2 && ccy > -2 && ccz < 2 && ccz > -2) || glOcclusionQuery[c.chunkIndex] == -1) { - c.isVisible = true; + c.isNowVisible = true; + c.isVisible = cooldownRate; }else if(!c.skipAllRenderPasses() && c.isInFrustum) { - if(occlusionQueryAvailable[c.chunkIndex] && EaglerAdapter.glGetQueryResultAvailable(glOcclusionQuery[c.chunkIndex])) { - c.isVisible = EaglerAdapter.glGetQueryResult(glOcclusionQuery[c.chunkIndex]); - occlusionQueryAvailable[c.chunkIndex] = false; - occlusionQueryStalled[c.chunkIndex] = 0l; - }else if(occlusionQueryStalled[c.chunkIndex] != 0l && ct - occlusionQueryStalled[c.chunkIndex] > stallRate) { - c.isVisible = true; + if(occlusionQueryAvailable[c.chunkIndex]) { + if(EaglerAdapter.glGetQueryResultAvailable(glOcclusionQuery[c.chunkIndex])) { + if(EaglerAdapter.glGetQueryResult(glOcclusionQuery[c.chunkIndex])) { + c.isNowVisible = true; + c.isVisible = cooldownRate; + }else { + if(c.isVisible <= 0) { + c.isNowVisible = false; + } + } + occlusionQueryAvailable[c.chunkIndex] = false; + occlusionQueryStalled[c.chunkIndex] = 0l; + }else if(occlusionQueryStalled[c.chunkIndex] != 0l && ct - occlusionQueryStalled[c.chunkIndex] > stallRateVisible) { + c.isNowVisible = true; + c.isVisible = cooldownRate; + } } } } @@ -627,6 +643,9 @@ public class RenderGlobal implements IWorldAccess { EaglerAdapter.glEndQuery(); } } + if(c.isVisible > 0) { + --c.isVisible; + } } EaglerAdapter.glEndOcclusionBB(); EaglerAdapter.glColorMask(true, true, true, true); @@ -654,14 +673,14 @@ public class RenderGlobal implements IWorldAccess { ++this.renderersSkippingRenderPass; } else if (!this.sortedWorldRenderers[var7].isInFrustum) { ++this.renderersBeingClipped; - } else if (!this.sortedWorldRenderers[var7].isVisible) { + } else if(!this.sortedWorldRenderers[var7].isNowVisible) { ++this.renderersBeingOccluded; } else { ++this.renderersBeingRendered; } } - if (!this.sortedWorldRenderers[var7].skipRenderPass[par3] && this.sortedWorldRenderers[var7].isInFrustum && this.sortedWorldRenderers[var7].isVisible) { + if (!this.sortedWorldRenderers[var7].skipRenderPass[par3] && this.sortedWorldRenderers[var7].isInFrustum && this.sortedWorldRenderers[var7].isNowVisible) { int var8 = this.sortedWorldRenderers[var7].getGLCallListForPass(par3); if (var8 >= 0) { diff --git a/src/main/java/net/minecraft/src/WorldRenderer.java b/src/main/java/net/minecraft/src/WorldRenderer.java index 80567a3..f775040 100644 --- a/src/main/java/net/minecraft/src/WorldRenderer.java +++ b/src/main/java/net/minecraft/src/WorldRenderer.java @@ -63,7 +63,8 @@ public class WorldRenderer { public int chunkIndex; /** Is this renderer visible according to the occlusion query */ - public boolean isVisible = true; + public int isVisible = 0; + public boolean isNowVisible = true; /** Is this renderer waiting on the result of the occlusion query */ public boolean isWaitingOnOcclusionQuery;