minor fixes

This commit is contained in:
Leonardo
2021-08-21 14:32:27 +02:00
parent cbe242cd2f
commit 7654cac01d
8 changed files with 124 additions and 79 deletions
@@ -18,11 +18,15 @@
package com.seibel.lod.builders;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import com.sun.glass.ui.Window;
import net.minecraft.world.chunk.Chunk;
import org.lwjgl.opengl.GL11;
import com.seibel.lod.builders.worldGeneration.LodNodeGenWorker;
@@ -75,7 +79,11 @@ public class LodBufferBuilder
/** if this is true the LOD buffers are currently being
* regenerated. */
public boolean generatingBuffers = false;
/** if this is true the LOD buffers are currently being
* regenerated. */
public Set<ChunkPos> positionWaitingToBeGenerated = new HashSet<>();
/** if this is true new LOD buffers have been generated
* and are waiting to be swapped with the drawable buffers*/
private boolean switchVbos = false;
@@ -230,28 +238,28 @@ public class LodBufferBuilder
}
/**TODO make this automatic and config dependant*/
List<LevelPos> posListToGenerate = new ArrayList<>();
posListToGenerate.addAll(lodDim.getDataToGenerate( playerBlockPosRounded.getX(), playerBlockPosRounded.getZ(), 0, 10000000, (byte) DistanceGenerationMode.SURFACE.complexity, (byte) 9, 2));
if(posListToGenerate.isEmpty())
{
posListToGenerate.addAll(lodDim.getDataToGenerate(playerBlockPosRounded.getX(), playerBlockPosRounded.getZ(), 0, 400, (byte) DistanceGenerationMode.SURFACE.complexity, (byte) 0, 2));
}
//posListToGenerate.addAll(lodDim.getDataToGenerate( playerBlockPosRounded.getX(), playerBlockPosRounded.getZ(), 0, 1500, (byte) DistanceGenerationMode.SURFACE.complexity, (byte) 9, 16));
if(posListToGenerate.isEmpty()){
posListToGenerate.addAll(lodDim.getDataToGenerate( playerBlockPosRounded.getX(), playerBlockPosRounded.getZ(), 0, 10000000, (byte) DistanceGenerationMode.SURFACE.complexity, (byte) 0, 2));
posListToGenerate.addAll(lodDim.getDataToGenerate( playerBlockPosRounded.getX(), playerBlockPosRounded.getZ(), 0, 1000, (byte) DistanceGenerationMode.SURFACE.complexity, (byte) 0, 16));
}
for(LevelPos levelPos : posListToGenerate){
LevelPos chunkLevelPos = levelPos.convert((byte) 3);
int chunkX = chunkLevelPos.posX / 2;
int chunkZ = chunkLevelPos.posZ / 2;
// generate a new chunk if no chunk currently exists
// and we aren't waiting on any other chunks to generate
if (numberOfChunksWaitingToGenerate.get() < maxChunkGenRequests)
{
ChunkPos pos = new ChunkPos(chunkX, chunkZ);
if(positionWaitingToBeGenerated.contains(pos)){
System.out.println(pos + " asked again");
continue;
}
// alternate determining logic that
// can be used for debugging
@@ -306,6 +314,7 @@ public class LodBufferBuilder
chunkGenIndex = 0;
chunksToGen = new ChunkPos[maxChunkGenRequests];
chunksToGen[chunkGenIndex] = pos;
positionWaitingToBeGenerated.add(pos);
chunkGenIndex++;
}
else if (newDistance <= minChunkDist)
@@ -317,6 +326,7 @@ public class LodBufferBuilder
// we are still under the number of chunks to generate
// add this position to the list
chunksToGen[chunkGenIndex] = pos;
positionWaitingToBeGenerated.add(pos);
chunkGenIndex++;
}
}
@@ -355,6 +365,8 @@ public class LodBufferBuilder
numberOfChunksWaitingToGenerate.addAndGet(1);
LodNodeGenWorker genWorker = new LodNodeGenWorker(chunkPos, DistanceGenerationMode.SURFACE, LodDetail.FULL, renderer, LodQuadTreeNodeBuilder, this, lodDim, serverWorld);
WorldWorkerManager.addWorker(genWorker);
/**TODO optimize the use of positionWaitingToBeGenerated*/
positionWaitingToBeGenerated.remove(chunkPos);
}
}
@@ -179,7 +179,7 @@ public class LodBuilder
chunk.getPos().x * 16 + startX,
chunk.getPos().z * 16 + startZ);
data = new LodDataPoint(height, depth, color);
check = lodDim.addData(levelPos.convert((byte) detail.detailLevel),
lodDim.addData(levelPos.convert((byte) detail.detailLevel),
data,
config.distanceGenerationMode,
true,
@@ -24,73 +24,89 @@ import com.seibel.lod.enums.DistanceGenerationMode;
* Generally this will only be used if we want to generate a
* LodChunk using a incomplete Chunk, otherwise the defaults
* work best for a fully generated chunk (IE has correct surface blocks).
*
*
* @author James Seibel
* @version 8-14-2021
*/
public class LodBuilderConfig
{
/** default false */
public boolean useHeightmap;
/** default false */
public boolean useBiomeColors;
/** default true */
public boolean useSolidBlocksInColorGen;
/** default server */
public DistanceGenerationMode distanceGenerationMode;
/** default settings for a normal chunk <br>
* useHeightmap = false <br>
* useBiomeColors = false <br>
* useSolidBlocksInColorGen = true <br>
* generationMode = Server <br>
*/
public LodBuilderConfig()
{
useHeightmap = false;
useBiomeColors = false;
useSolidBlocksInColorGen = true;
distanceGenerationMode = DistanceGenerationMode.SERVER;
}
/**
* @param newUseHeightmap default = false
* @param newUseBiomeColors default = false
* @param newUseSolidBlocksInBiomeColor default = true
* @param newDistanceGenerationMode default = Server
*/
public LodBuilderConfig(boolean newUseHeightmap, boolean newUseBiomeColors,
boolean newUseSolidBlocksInBiomeColor, DistanceGenerationMode newDistanceGenerationMode)
{
useHeightmap = newUseHeightmap;
useBiomeColors = newUseBiomeColors;
useSolidBlocksInColorGen = newUseSolidBlocksInBiomeColor;
distanceGenerationMode = newDistanceGenerationMode;
}
/**
* @param newUseHeightmap default = false
* @param newUseBiomeColors default = false
* @param newUseSolidBlocksInBiomeColor default = true
* @param newDistanceGenerationMode default = Server
*/
public LodBuilderConfig(boolean newUseHeightmap, boolean newUseBiomeColors, boolean newUseSolidBlocksInBiomeColor)
{
this();
useHeightmap = newUseHeightmap;
useBiomeColors = newUseBiomeColors;
useSolidBlocksInColorGen = newUseSolidBlocksInBiomeColor;
}
/**
* @param newUseHeightmap default = false
* @param newUseBiomeColors default = false
* @param newUseSolidBlocksInBiomeColor default = true
* @param newDistanceGenerationMode default = Server
*/
public LodBuilderConfig(DistanceGenerationMode newDistanceGenerationMode)
{
this();
distanceGenerationMode = newDistanceGenerationMode;
}
/**
* default false
*/
public boolean useHeightmap;
/**
* default false
*/
public boolean useBiomeColors;
/**
* default true
*/
public boolean useSolidBlocksInColorGen;
/**
* default server
*/
public DistanceGenerationMode distanceGenerationMode;
/**
* default settings for a normal chunk <br>
* useHeightmap = false <br>
* useBiomeColors = false <br>
* useSolidBlocksInColorGen = true <br>
* generationMode = Server <br>
*/
public LodBuilderConfig()
{
useHeightmap = false;
useBiomeColors = false;
useSolidBlocksInColorGen = true;
distanceGenerationMode = DistanceGenerationMode.SERVER;
}
/**
* @param newUseHeightmap default = false
* @param newUseBiomeColors default = false
* @param newUseSolidBlocksInBiomeColor default = true
* @param newDistanceGenerationMode default = Server
*/
public LodBuilderConfig(boolean newUseHeightmap, boolean newUseBiomeColors,
boolean newUseSolidBlocksInBiomeColor, DistanceGenerationMode newDistanceGenerationMode)
{
useHeightmap = newUseHeightmap;
useBiomeColors = newUseBiomeColors;
useSolidBlocksInColorGen = newUseSolidBlocksInBiomeColor;
distanceGenerationMode = newDistanceGenerationMode;
}
/**
* @param newUseHeightmap default = false
* @param newUseBiomeColors default = false
* @param newUseSolidBlocksInBiomeColor default = true
* @param newDistanceGenerationMode default = Server
*/
public LodBuilderConfig(boolean newUseHeightmap, boolean newUseBiomeColors, boolean newUseSolidBlocksInBiomeColor)
{
this();
useHeightmap = newUseHeightmap;
useBiomeColors = newUseBiomeColors;
useSolidBlocksInColorGen = newUseSolidBlocksInBiomeColor;
if (newUseHeightmap)
{
distanceGenerationMode = DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT;
} else
{
distanceGenerationMode = DistanceGenerationMode.BIOME_ONLY;
}
}
/**
* @param newUseHeightmap default = false
* @param newUseBiomeColors default = false
* @param newUseSolidBlocksInBiomeColor default = true
* @param newDistanceGenerationMode default = Server
*/
public LodBuilderConfig(DistanceGenerationMode newDistanceGenerationMode)
{
this();
distanceGenerationMode = newDistanceGenerationMode;
}
}
@@ -193,8 +193,9 @@ public class LodNodeGenWorker implements IWorker
// only generate LodChunks if they can
// be added to the current LodDimension
if (lodDim.regionIsInRange(pos.x / LodUtil.REGION_WIDTH_IN_CHUNKS, pos.z / LodUtil.REGION_WIDTH_IN_CHUNKS))
{
/**TODO i must disable this if, i will find a way to replace it*/
//if (lodDim.regionIsInRange(pos.x / LodUtil.REGION_WIDTH_IN_CHUNKS, pos.z / LodUtil.REGION_WIDTH_IN_CHUNKS))
//{
// long startTime = System.currentTimeMillis();
switch(generationMode)
@@ -236,7 +237,7 @@ public class LodNodeGenWorker implements IWorker
// long endTime = System.currentTimeMillis();
// System.out.println(endTime - startTime);
}// if in range
//}// if in range
}
catch (Exception e)
@@ -200,6 +200,22 @@ public class LevelPos implements Cloneable
}
}
public int hashCode()
{
int hash = 7;
hash = 31 * hash + (int) detailLevel;
hash = 31 * hash + posX;
hash = 31 * hash + posZ;
return hash;
}
public boolean equals(LevelPos other)
{
return (this.detailLevel == other.detailLevel &&
this.posX == other.posX &&
this.posZ == other.posZ);
}
@Override
public String toString()
{
@@ -383,7 +383,7 @@ public class LodDimension
listOfData.addAll(region.getDataToGenerate(playerPosX, playerPosZ, start, end, generation, detailLevel, dataNumber));
}
}
Collections.sort(listOfData, LevelPos.getPosAndDetailComparator());
Collections.sort(listOfData, LevelPos.getPosComparator());
dataNumber = Math.min(dataNumber, listOfData.size());
return listOfData.stream().map(entry -> entry.getKey()).collect(Collectors.toList()).subList(0, dataNumber);
}
@@ -211,7 +211,7 @@ public class LodRegion implements Serializable
{
LevelPos levelPos = new LevelPos(LodUtil.REGION_DETAIL_LEVEL, 0, 0);
List<Map.Entry<LevelPos,Integer>> listOfPos = getDataToGenerate(levelPos, playerPosX, playerPosZ, start, end, generation, detailLevel);
Collections.sort(listOfPos, LevelPos.getPosAndDetailComparator());
Collections.sort(listOfPos, LevelPos.getPosComparator());
dataNumber = Math.min(dataNumber, listOfPos.size());
return listOfPos.subList(0,dataNumber);
@@ -152,7 +152,7 @@ public class ClientProxy
LodConfig.CLIENT.distanceGenerationMode.set(DistanceGenerationMode.FEATURES);
LodConfig.CLIENT.allowUnstableFeatureGeneration.set(false);
LodConfig.CLIENT.numberOfWorldGenerationThreads.set(2);
LodConfig.CLIENT.numberOfWorldGenerationThreads.set(16);
}