From 743e504ccc1c932edf83776091607994e505ae2b Mon Sep 17 00:00:00 2001 From: TomTheFurry Date: Wed, 13 Apr 2022 14:14:02 +0800 Subject: [PATCH] Fix Sodium non-fabulious causing lightmap flicker + add more log for load/unload world + no longer unloading world 3 times on exit due to sub-dim stuff --- src/main/java/com/seibel/lod/core/api/EventApi.java | 12 +++++++++--- .../bufferBuilding/LodBufferBuilderFactory.java | 3 ++- .../java/com/seibel/lod/core/render/GLProxy.java | 10 ++++++---- .../com/seibel/lod/core/render/objects/GLState.java | 12 +++++++++++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/seibel/lod/core/api/EventApi.java b/src/main/java/com/seibel/lod/core/api/EventApi.java index c116a9ccf..fcd071fa2 100644 --- a/src/main/java/com/seibel/lod/core/api/EventApi.java +++ b/src/main/java/com/seibel/lod/core/api/EventApi.java @@ -28,7 +28,6 @@ import com.seibel.lod.core.objects.lod.LodDimension; import com.seibel.lod.core.objects.lod.RegionPos; import com.seibel.lod.core.render.GLProxy; import com.seibel.lod.core.render.LodRenderer; -import com.seibel.lod.core.util.DataPointUtil; import com.seibel.lod.core.util.DetailDistanceUtil; import com.seibel.lod.core.util.LodUtil; import com.seibel.lod.core.wrapperInterfaces.IVersionConstants; @@ -128,6 +127,8 @@ public class EventApi if (world.getWorldType() == WorldType.ServerWorld) return; isCurrentlyOnSinglePlayerServer = MC.hasSinglePlayerServer(); + if (!ApiShared.isShuttingDown) ApiShared.LOGGER.warn("WorldLoadEvent called on {} while another world is loaded!", + (world.getWorldType() == WorldType.ClientWorld ? "clientLevel" : "serverLevel")); ApiShared.isShuttingDown = false; //DataPointUtil.WORLD_HEIGHT = world.getHeight(); LodBuilder.MIN_WORLD_HEIGHT = world.getMinHeight(); // This updates the World height @@ -136,7 +137,10 @@ public class EventApi // ThreadMapUtil.clearMaps(); // the player just loaded a new world/dimension - ApiShared.lodWorld.selectWorld(LodUtil.getWorldID(world)); + String worldID = LodUtil.getWorldID(world); + ApiShared.LOGGER.info("Loading new world/dimension: {}",worldID); + ApiShared.lodWorld.selectWorld(worldID); + ApiShared.LOGGER.info("World/dimension loaded: {}",worldID); // make sure the correct LODs are being rendered // (if this isn't done the previous world's LODs may be drawn) @@ -158,9 +162,10 @@ public class EventApi // AFTER setting MC to not be in a singlePlayerServer if (isCurrentlyOnSinglePlayerServer && world.getWorldType() == WorldType.ClientWorld) return; - + // if this isn't done unfinished tasks may be left in the queue // preventing new LodChunks form being generated + if (ApiShared.isShuttingDown) return; // Don't do this if we're already shutting down ApiShared.isShuttingDown = true; // TODO Better report on when world gen is stuck and timeout @@ -181,6 +186,7 @@ public class EventApi // TODO: Check if after the refactoring, is this still needed ClientApi.renderer = new LodRenderer(ClientApi.lodBufferBuilderFactory); ClientApi.INSTANCE.rendererDisabledBecauseOfExceptions = false; + ApiShared.LOGGER.info("Distant Horizon unloaded"); } public void blockChangeEvent(IChunkWrapper chunk, IDimensionTypeWrapper dimType) diff --git a/src/main/java/com/seibel/lod/core/builders/lodBuilding/bufferBuilding/LodBufferBuilderFactory.java b/src/main/java/com/seibel/lod/core/builders/lodBuilding/bufferBuilding/LodBufferBuilderFactory.java index 08b71ed6b..31b984f93 100644 --- a/src/main/java/com/seibel/lod/core/builders/lodBuilding/bufferBuilding/LodBufferBuilderFactory.java +++ b/src/main/java/com/seibel/lod/core/builders/lodBuilding/bufferBuilding/LodBufferBuilderFactory.java @@ -312,7 +312,7 @@ public class LodBufferBuilderFactory { * May have to wait for the bufferLock to open. */ public void destroyBuffers() { - ApiShared.LOGGER.info("LodBufferBuilder Destroy"); + ApiShared.LOGGER.info("Destroying LodBufferBuilder..."); mainGenThread.shutdownNow(); mainGenThread = Executors.newSingleThreadExecutor(mainGenThreadFactory); regionsListLock.lock(); @@ -322,6 +322,7 @@ public class LodBufferBuilderFactory { } finally { regionsListLock.unlock(); } + ApiShared.LOGGER.info("LodBufferBuilder destroyed."); } /** Get the newly created VBOs diff --git a/src/main/java/com/seibel/lod/core/render/GLProxy.java b/src/main/java/com/seibel/lod/core/render/GLProxy.java index 2b4d1a2f8..60b8c36af 100644 --- a/src/main/java/com/seibel/lod/core/render/GLProxy.java +++ b/src/main/java/com/seibel/lod/core/render/GLProxy.java @@ -25,6 +25,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import com.seibel.lod.core.api.ApiShared; import com.seibel.lod.core.logging.ConfigBasedLogger; import org.apache.logging.log4j.LogManager; import org.lwjgl.glfw.GLFW; @@ -458,19 +459,20 @@ public class GLProxy } } - public static void ensureAllGLJobCompleted() { + public static void ensureAllGLJobCompleted() { // Uses global logger since it's a cleanup method if (!hasInstance()) return; - GL_LOGGER.info("Blocking until GL jobs finished!"); + ApiShared.LOGGER.info("Blocking until GL jobs finished..."); try { instance.workerThread.shutdown(); boolean worked = instance.workerThread.awaitTermination(30, TimeUnit.SECONDS); if (!worked) - GL_LOGGER.error("GLWorkerThread shutdown timed out! Game may crash on exit due to cleanup failure!"); + ApiShared.LOGGER.error("GLWorkerThread shutdown timed out! Game may crash on exit due to cleanup failure!"); } catch (InterruptedException e) { - GL_LOGGER.error("GLWorkerThread shutdown is interrupted! Game may crash on exit due to cleanup failure!"); + ApiShared.LOGGER.error("GLWorkerThread shutdown is interrupted! Game may crash on exit due to cleanup failure!"); e.printStackTrace(); } finally { instance.workerThread = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat(GLProxy.class.getSimpleName() + "-Worker-Thread").build()); } + ApiShared.LOGGER.info("All GL jobs finished!"); } } diff --git a/src/main/java/com/seibel/lod/core/render/objects/GLState.java b/src/main/java/com/seibel/lod/core/render/objects/GLState.java index 4805a54a1..35798cc3e 100644 --- a/src/main/java/com/seibel/lod/core/render/objects/GLState.java +++ b/src/main/java/com/seibel/lod/core/render/objects/GLState.java @@ -28,6 +28,8 @@ public class GLState { public int vbo; public int fbo; public int text; + public int activeTex; + public int text0; public boolean blend; public int blendSrc; public int blendDst; @@ -48,6 +50,10 @@ public class GLState { vbo = GL32.glGetInteger(GL32.GL_ARRAY_BUFFER_BINDING); fbo = GL32.glGetInteger(GL32.GL_FRAMEBUFFER_BINDING); text = GL32.glGetInteger(GL32.GL_TEXTURE_BINDING_2D); + activeTex = GL32.glGetInteger(GL32.GL_ACTIVE_TEXTURE); + GL32.glActiveTexture(GL32.GL_TEXTURE0); + text0 = GL32.glGetInteger(GL32.GL_TEXTURE_BINDING_2D); + GL32.glActiveTexture(activeTex); blend = GL32.glIsEnabled(GL32.GL_BLEND); blendSrc = GL32.glGetInteger(GL32.GL_BLEND_SRC); blendDst = GL32.glGetInteger(GL32.GL_BLEND_DST); @@ -66,7 +72,8 @@ public class GLState { @Override public String toString() { - return "GLState{" + "prog=" + prog + ", vao=" + vao + ", vbo=" + vbo + ", fbo=" + fbo + ", text=" + GLEnums.getString(text) + + return "GLState{" + "prog=" + prog + ", vao=" + vao + ", vbo=" + vbo + ", fbo=" + fbo + + ", text=" + GLEnums.getString(text) + "@"+activeTex+", text0=" + GLEnums.getString(text0) + ", blend=" + blend + ", blendMode=" + GLEnums.getString(blendSrc) + "," + GLEnums.getString(blendDst) + ", depth=" + depth + ", depthFunc=" + GLEnums.getString(depthFunc) + ", stencil=" + stencil + ", stencilFunc=" + @@ -83,6 +90,9 @@ public class GLState { } else { GL32.glDisable(GL32.GL_BLEND); } + GL32.glActiveTexture(GL32.GL_TEXTURE0); + GL32.glBindTexture(GL32.GL_TEXTURE_2D, text0); + GL32.glActiveTexture(activeTex); GL32.glBindTexture(GL32.GL_TEXTURE_2D, text); GL32.glBindVertexArray(vao); GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, vbo);