Fix LodNodeBufferBuilder queueing the same chunk for generation multiple times

This commit is contained in:
James Seibel
2021-08-07 18:29:20 -05:00
parent 87c803e4c6
commit ed188448f2
2 changed files with 56 additions and 43 deletions
@@ -189,7 +189,6 @@ public class LodNodeBufferBuilder
{
ChunkPos pos = new ChunkPos(chunkX, chunkZ);
// alternate determining logic that
// can be used for debugging
// if (chunksToGen == null)
@@ -317,9 +316,13 @@ public class LodNodeBufferBuilder
// start chunk generation
for(ChunkPos chunkPos : chunksToGen)
{
if(chunkPos == null)
// don't add null chunkPos (which shouldn't happen anyway)
// or add more to the generation queue
if(chunkPos == null || numberOfChunksWaitingToGenerate.get() >= maxChunkGenRequests)
break;
// TODO add a list of locations we are waiting to generate so we don't add the same position to the queue multiple times
numberOfChunksWaitingToGenerate.addAndGet(1);
LodNodeGenWorker genWorker = new LodNodeGenWorker(chunkPos, renderer, LodQuadTreeNodeBuilder, this, lodDim, serverWorld, biomeContainer);
@@ -122,8 +122,6 @@ public class LodNodeGenWorker implements IWorker
{
if (!threadStarted)
{
thread.lodBufferBuilder.numberOfChunksWaitingToGenerate.addAndGet(-1);
if (LodConfig.CLIENT.distanceGenerationMode.get() == DistanceGenerationMode.SERVER)
{
// if we are using SERVER generation that has to be done
@@ -182,48 +180,60 @@ public class LodNodeGenWorker implements IWorker
@Override
public void run()
{
// only generate LodChunks if they can
// be added to the current LodDimension
if (lodDim.regionIsInRange(pos.x / LodRegion.SIZE, pos.z / LodRegion.SIZE))
try
{
// long startTime = System.currentTimeMillis();
switch(LodConfig.CLIENT.distanceGenerationMode.get())
// only generate LodChunks if they can
// be added to the current LodDimension
if (lodDim.regionIsInRange(pos.x / LodRegion.SIZE, pos.z / LodRegion.SIZE))
{
case NONE:
// don't generate
break;
case BIOME_ONLY:
case BIOME_ONLY_SIMULATE_HEIGHT:
// fastest
generateUsingBiomesOnly();
break;
case SURFACE:
// faster
generateUsingSurface();
break;
case FEATURES:
// fast
generateUsingFeatures();
break;
case SERVER:
// very slow
generateWithServer();
break;
}
// long startTime = System.currentTimeMillis();
switch(LodConfig.CLIENT.distanceGenerationMode.get())
{
case NONE:
// don't generate
break;
case BIOME_ONLY:
case BIOME_ONLY_SIMULATE_HEIGHT:
// fastest
generateUsingBiomesOnly();
break;
case SURFACE:
// faster
generateUsingSurface();
break;
case FEATURES:
// fast
generateUsingFeatures();
break;
case SERVER:
// very slow
generateWithServer();
break;
}
lodRenderer.regenerateLODsNextFrame();
// if (lodDim.getLodFromCoordinates(pos) != null)
// ClientProxy.LOGGER.info(pos.x + " " + pos.z + " Success!");
// else
// ClientProxy.LOGGER.info(pos.x + " " + pos.z);
// shows the pool size, active threads, queued tasks and completed tasks
// ClientProxy.LOGGER.info(genThreads.toString());
// long endTime = System.currentTimeMillis();
// System.out.println(endTime - startTime);
}// if in range
lodRenderer.regenerateLODsNextFrame();
// if (lodDim.getLodFromCoordinates(pos.x, pos.z) != null)
// ClientProxy.LOGGER.info(pos.x + " " + pos.z + " Success!");
// else
// ClientProxy.LOGGER.info(pos.x + " " + pos.z);
// long endTime = System.currentTimeMillis();
// System.out.println(endTime - startTime);
}// if in range
}
finally
{
// decrement how many threads are running
thread.lodBufferBuilder.numberOfChunksWaitingToGenerate.addAndGet(-1);
}
}// run