remove some unneeded concurrency checks in render setup

This commit is contained in:
James Seibel
2026-02-11 07:34:55 -06:00
parent dfc920d9bb
commit e2d663ee34
2 changed files with 29 additions and 53 deletions
@@ -82,7 +82,6 @@ public class SharedApi
@Nullable @Nullable
private static AbstractDhWorld currentWorld; private static AbstractDhWorld currentWorld;
private static int lastWorldGenTickDelta = 0;
@@ -92,24 +92,16 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu
return; return;
} }
// TODO this should probably be handled via a config change listener
// recreate the RenderState if the render distance changes // 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)) // close the older renderer
{
return;
}
clientRenderState.close(); clientRenderState.close();
this.ClientRenderStateRef.set(null);
// create the new renderer
clientRenderState = new ClientRenderState(this.clientLevel, this.clientLevel.getFullDataProvider()); clientRenderState = new ClientRenderState(this.clientLevel, this.clientLevel.getFullDataProvider());
if (!this.ClientRenderStateRef.compareAndSet(null, clientRenderState)) this.ClientRenderStateRef.set(clientRenderState);
{
//FIXME: How to handle this?
LOGGER.warn("Failed to set render state due to concurrency after changing view distance");
clientRenderState.close();
return;
}
} }
clientRenderState.quadtree.tryTick(new DhBlockPos2D(MC_CLIENT.getPlayerBlockPos())); clientRenderState.quadtree.tryTick(new DhBlockPos2D(MC_CLIENT.getPlayerBlockPos()));
@@ -121,14 +113,13 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu
// render // // render //
//========// //========//
// TODO start rendering during frame request
public void startRenderer() public void startRenderer()
{ {
ClientRenderState ClientRenderState = new ClientRenderState(this.clientLevel, this.clientLevel.getFullDataProvider()); ClientRenderState clientRenderState = new ClientRenderState(this.clientLevel, this.clientLevel.getFullDataProvider());
if (!this.ClientRenderStateRef.compareAndSet(null, ClientRenderState)) if (!this.ClientRenderStateRef.compareAndSet(null, clientRenderState))
{ {
LOGGER.warn("Failed to start renderer due to concurrency"); LOGGER.warn("Renderer already started for ["+this+"].");
ClientRenderState.close(); clientRenderState.close();
} }
} }
@@ -136,23 +127,15 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu
public void stopRenderer() public void stopRenderer()
{ {
LOGGER.info("Stopping renderer for " + this); ClientRenderState clientRenderState = this.ClientRenderStateRef.get();
ClientRenderState ClientRenderState = this.ClientRenderStateRef.get(); if (clientRenderState == null)
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; return;
} }
// stop the render state
while (!this.ClientRenderStateRef.compareAndSet(ClientRenderState, null)) // TODO why is there a while loop here? this.ClientRenderStateRef.compareAndSet(clientRenderState, null);
{ clientRenderState.close();
ClientRenderState = this.ClientRenderStateRef.get();
if (ClientRenderState == null)
{
return;
}
}
ClientRenderState.close();
} }
@@ -180,20 +163,8 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu
ClientRenderState ClientRenderState = this.ClientRenderStateRef.get(); ClientRenderState ClientRenderState = this.ClientRenderStateRef.get();
if (ClientRenderState != null) if (ClientRenderState != null)
{ {
// TODO does this have to be in a while loop, if so why? this.ClientRenderStateRef.compareAndSet(ClientRenderState, null);
while (!this.ClientRenderStateRef.compareAndSet(ClientRenderState, null)) ClientRenderState.close();
{
ClientRenderState = this.ClientRenderStateRef.get();
if (ClientRenderState == null)
{
break;
}
}
if (ClientRenderState != null)
{
ClientRenderState.close();
}
} }
this.fullDataSourceProvider.removeDataSourceUpdateListener(this); this.fullDataSourceProvider.removeDataSourceUpdateListener(this);
@@ -253,15 +224,21 @@ public class ClientLevelModule implements Closeable, IDataSourceUpdateListenerFu
FullDataSourceProviderV2 fullDataSourceProvider) FullDataSourceProviderV2 fullDataSourceProvider)
{ {
this.quadtree = new LodQuadTree( this.quadtree = new LodQuadTree(
dhClientLevel, 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 // 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, 0, 0,
fullDataSourceProvider); fullDataSourceProvider);
this.renderBufferHandler = new RenderBufferHandler(this.quadtree); this.renderBufferHandler = new RenderBufferHandler(this.quadtree);
} }
public static int getQuadTreeBlockRadius()
{
return Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get()
* LodUtil.CHUNK_WIDTH * 2;
}
//================// //================//