remove some unneeded concurrency checks in render setup
This commit is contained in:
@@ -82,7 +82,6 @@ public class SharedApi
|
||||
|
||||
@Nullable
|
||||
private static AbstractDhWorld currentWorld;
|
||||
private static int lastWorldGenTickDelta = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
clientRenderState.close();
|
||||
// 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,21 +163,9 @@ 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)
|
||||
{
|
||||
this.ClientRenderStateRef.compareAndSet(ClientRenderState, null);
|
||||
ClientRenderState.close();
|
||||
}
|
||||
}
|
||||
|
||||
this.fullDataSourceProvider.removeDataSourceUpdateListener(this);
|
||||
}
|
||||
@@ -254,7 +225,7 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu
|
||||
{
|
||||
this.quadtree = new LodQuadTree(
|
||||
dhClientLevel,
|
||||
Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH * 2,
|
||||
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);
|
||||
@@ -262,6 +233,12 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu
|
||||
this.renderBufferHandler = new RenderBufferHandler(this.quadtree);
|
||||
}
|
||||
|
||||
public static int getQuadTreeBlockRadius()
|
||||
{
|
||||
return Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get()
|
||||
* LodUtil.CHUNK_WIDTH * 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
|
||||
Reference in New Issue
Block a user