diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java index 8e525b0b4..51260825a 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java @@ -82,7 +82,6 @@ public class SharedApi @Nullable private static AbstractDhWorld currentWorld; - private static int lastWorldGenTickDelta = 0; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/ClientLevelModule.java b/core/src/main/java/com/seibel/distanthorizons/core/level/ClientLevelModule.java index 73c0b2bd7..fae167694 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/ClientLevelModule.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/ClientLevelModule.java @@ -92,24 +92,16 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu return; } - // TODO this should probably be handled via a config change listener // recreate the RenderState if the render distance changes - if (clientRenderState.quadtree.blockRenderDistanceDiameter != Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH * 2) + if (clientRenderState.quadtree.blockRenderDistanceDiameter != ClientRenderState.getQuadTreeBlockRadius()) { - if (!this.ClientRenderStateRef.compareAndSet(clientRenderState, null)) - { - return; - } - + // close the older renderer clientRenderState.close(); + this.ClientRenderStateRef.set(null); + + // create the new renderer clientRenderState = new ClientRenderState(this.clientLevel, this.clientLevel.getFullDataProvider()); - if (!this.ClientRenderStateRef.compareAndSet(null, clientRenderState)) - { - //FIXME: How to handle this? - LOGGER.warn("Failed to set render state due to concurrency after changing view distance"); - clientRenderState.close(); - return; - } + this.ClientRenderStateRef.set(clientRenderState); } clientRenderState.quadtree.tryTick(new DhBlockPos2D(MC_CLIENT.getPlayerBlockPos())); @@ -121,14 +113,13 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu // render // //========// - // TODO start rendering during frame request public void startRenderer() { - ClientRenderState ClientRenderState = new ClientRenderState(this.clientLevel, this.clientLevel.getFullDataProvider()); - if (!this.ClientRenderStateRef.compareAndSet(null, ClientRenderState)) + ClientRenderState clientRenderState = new ClientRenderState(this.clientLevel, this.clientLevel.getFullDataProvider()); + if (!this.ClientRenderStateRef.compareAndSet(null, clientRenderState)) { - LOGGER.warn("Failed to start renderer due to concurrency"); - ClientRenderState.close(); + LOGGER.warn("Renderer already started for ["+this+"]."); + clientRenderState.close(); } } @@ -136,23 +127,15 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu public void stopRenderer() { - LOGGER.info("Stopping renderer for " + this); - ClientRenderState ClientRenderState = this.ClientRenderStateRef.get(); - if (ClientRenderState == null) + ClientRenderState clientRenderState = this.ClientRenderStateRef.get(); + if (clientRenderState == null) { - LOGGER.warn("Tried to stop renderer for " + this + " when it was not started!"); + LOGGER.warn("Tried to stop the renderer for [" + this + "] when it was not started."); return; } - // stop the render state - while (!this.ClientRenderStateRef.compareAndSet(ClientRenderState, null)) // TODO why is there a while loop here? - { - ClientRenderState = this.ClientRenderStateRef.get(); - if (ClientRenderState == null) - { - return; - } - } - ClientRenderState.close(); + + this.ClientRenderStateRef.compareAndSet(clientRenderState, null); + clientRenderState.close(); } @@ -180,20 +163,8 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu ClientRenderState ClientRenderState = this.ClientRenderStateRef.get(); if (ClientRenderState != null) { - // TODO does this have to be in a while loop, if so why? - while (!this.ClientRenderStateRef.compareAndSet(ClientRenderState, null)) - { - ClientRenderState = this.ClientRenderStateRef.get(); - if (ClientRenderState == null) - { - break; - } - } - - if (ClientRenderState != null) - { - ClientRenderState.close(); - } + this.ClientRenderStateRef.compareAndSet(ClientRenderState, null); + ClientRenderState.close(); } this.fullDataSourceProvider.removeDataSourceUpdateListener(this); @@ -253,15 +224,21 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu FullDataSourceProviderV2 fullDataSourceProvider) { this.quadtree = new LodQuadTree( - dhClientLevel, - Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH * 2, - // initial position is (0,0) just in case the player hasn't loaded in yet, the tree will be moved once the level starts ticking - 0, 0, - fullDataSourceProvider); + dhClientLevel, + getQuadTreeBlockRadius(), + // initial position is (0,0) just in case the player hasn't loaded in yet, the tree will be moved once the level starts ticking + 0, 0, + fullDataSourceProvider); this.renderBufferHandler = new RenderBufferHandler(this.quadtree); } + public static int getQuadTreeBlockRadius() + { + return Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() + * LodUtil.CHUNK_WIDTH * 2; + } + //================//