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

This commit is contained in:
TomTheFurry
2022-04-13 14:14:02 +08:00
parent 633b229d2e
commit 743e504ccc
4 changed files with 28 additions and 9 deletions
@@ -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)
@@ -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
@@ -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!");
}
}
@@ -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);