Added some comment, fixed the thread conflict problem

This commit is contained in:
Leonardo
2021-10-05 11:25:06 +02:00
parent f6ea990ab0
commit fca926bc8f
4 changed files with 58 additions and 32 deletions
@@ -101,9 +101,9 @@ public class LodNodeGenWorker implements IWorker
if (newServerWorld == null)
throw new IllegalArgumentException("LodChunkGenThread requires a non-null ServerWorld");
thread = new LodChunkGenThread(newPos, newGenerationMode,
newLodBuilder,
newLodDimension, newServerWorld);
@@ -615,7 +615,7 @@ public class LodNodeGenWorker implements IWorker
{
genThreads.shutdownNow();
}
genThreads = Executors.newFixedThreadPool(LodConfig.CLIENT.threading.numberOfWorldGenerationThreads.get(), new LodThreadFactory(LodNodeGenWorker.class.getSimpleName()));
genThreads = Executors.newFixedThreadPool(LodConfig.CLIENT.threading.numberOfWorldGenerationThreads.get(), new ThreadFactoryBuilder().setNameFormat("Gen-Worker-Thread-%d").build());
}
@@ -126,13 +126,11 @@ public class LodWorldGenerator
nearIndex++;
ChunkPos chunkPos = new ChunkPos(LevelPosUtil.getChunkPos(detailLevel, posX), LevelPosUtil.getChunkPos(detailLevel, posZ));
if (numberOfChunksWaitingToGenerate.get() < maxChunkGenRequests)
{
// prevent generating the same chunk multiple times
if (positionsWaitingToBeGenerated.contains(chunkPos))
continue;
}
// prevent generating the same chunk multiple times
if (positionsWaitingToBeGenerated.contains(chunkPos))
continue;
// don't add more to the generation queue then allowed
if (numberOfChunksWaitingToGenerate.get() >= maxChunkGenRequests)
break;
@@ -153,17 +151,16 @@ public class LodWorldGenerator
farIndex++;
ChunkPos chunkPos = new ChunkPos(LevelPosUtil.getChunkPos(detailLevel, posX), LevelPosUtil.getChunkPos(detailLevel, posZ));
if (numberOfChunksWaitingToGenerate.get() < maxChunkGenRequests)
{
// prevent generating the same chunk multiple times
if (positionsWaitingToBeGenerated.contains(chunkPos))
continue;
}
// don't add more to the generation queue then allowed
if (numberOfChunksWaitingToGenerate.get() >= maxChunkGenRequests)
break;
continue;
//break;
// prevent generating the same chunk multiple times
if (positionsWaitingToBeGenerated.contains(chunkPos))
continue;
positionsWaitingToBeGenerated.add(chunkPos);
numberOfChunksWaitingToGenerate.addAndGet(1);
LodNodeGenWorker genWorker = new LodNodeGenWorker(chunkPos, DetailDistanceUtil.getDistanceGenerationMode(detailLevel), lodBuilder, lodDim, serverWorld);
@@ -231,7 +231,8 @@ public class ClientProxy
public void worldLoadEvent(WorldEvent.Load event)
{
DataPointUtil.worldHeight = event.getWorld().getHeight();
ThreadMapUtil.clearMaps();
//LodNodeGenWorker.restartExecuterService();
//ThreadMapUtil.clearMaps();
// the player just loaded a new world/dimension
lodWorld.selectWorld(LodUtil.getWorldID(event.getWorld()));
@@ -254,8 +255,8 @@ public class ClientProxy
// if this isn't done unfinished tasks may be left in the queue
// preventing new LodChunks form being generated
LodNodeGenWorker.restartExecuterService();
ThreadMapUtil.clearMaps();
//LodNodeGenWorker.restartExecuterService();
//ThreadMapUtil.clearMaps();
LodWorldGenerator.INSTANCE.numberOfChunksWaitingToGenerate.set(0);
lodWorld.deselectWorld();
@@ -366,6 +367,16 @@ public class ClientProxy
firstTimeSetupComplete = true;
}
/**
* this method reset some of the static data everytime we change world
**/
private void resetMod()
{
ThreadMapUtil.clearMaps();
LodNodeGenWorker.restartExecuterService();
}
//================//
// public getters //
@@ -174,7 +174,13 @@ public class DataPointUtil
{
return (int) (((dataPoint >>> COLOR_SHIFT) & COLOR_MASK) | (((dataPoint >>> (ALPHA_SHIFT - ALPHA_DOWNSIZE_SHIFT)) | 0b1111) << 24));
}
/**
* This method apply the lightmap to the color to use
* @param dataPoint
* @param lightMap
* @return
*/
public static int getLightColor(long dataPoint, NativeImage lightMap)
{
int lightBlock = getLightBlock(dataPoint);
@@ -186,7 +192,12 @@ public class DataPointUtil
return ColorUtil.multiplyRGBcolors(getColor(dataPoint), ColorUtil.rgbToInt(red, green, blue));
}
/**
* This is used to convert a dataPoint to string (usefull for the print function)
* @param dataPoint
* @return
*/
public static String toString(long dataPoint)
{
StringBuilder s = new StringBuilder();
@@ -214,7 +225,12 @@ public class DataPointUtil
s.append('\n');
return s.toString();
}
/**
* This method merge column of single data together
* @param dataToMerge
* @return
*/
public static long mergeSingleData(long[] dataToMerge)
{
int numberOfChildren = 0;
@@ -275,7 +291,14 @@ public class DataPointUtil
return DataPointUtil.createDataPoint(tempAlpha, tempRed, tempGreen, tempBlue, tempHeight, tempDepth, tempLightSky, tempLightBlock, tempGenMode);
}
}
/**
* This method merge column of multiple data together
* @param dataToMerge
* @param inputVerticalData vertical size of an input data
* @param maxVerticalData max vertical size of the merged data
* @return
*/
public static long[] mergeMultiData(long[] dataToMerge, int inputVerticalData, int maxVerticalData)
{
int size = dataToMerge.length / inputVerticalData;
@@ -422,9 +445,4 @@ public class DataPointUtil
}
return dataPoint;
}
public static long[] compress(long[] data, byte detailLevel)
{
return null;
}
}