The lodQuadTree is now correctly converted to use LodDataPoint and DistanceGenerationMode

This commit is contained in:
Leonardo
2021-07-13 15:38:20 +02:00
parent 2c719c41d9
commit 3cc78c62a0
10 changed files with 44 additions and 46 deletions
@@ -130,7 +130,7 @@ public class LodNodeBufferBuilder
List<LodQuadTreeNode> lodToRender = new ArrayList<>();
lodToRender.addAll(lodDim.getNodeToRender((int) playerX,(int)playerZ,(byte) 0, 100000,0));
lodToRender.addAll(lodDim.getNodeToRender((int) playerX,(int)playerZ,(byte) 0, LodQuadTreeDimension.FULL_COMPLEXITY_MASK, 100000,0));
/*
lodToRender.addAll(lodDim.getNodeToRender((int) playerX,(int)playerZ,(byte) 9, 100000,8000));
lodToRender.addAll(lodDim.getNodeToRender((int)playerX,(int)playerZ,(byte) 8, 8000,4000));
@@ -1,5 +1,7 @@
package com.seibel.lod.builders;
import com.seibel.lod.enums.DistanceGenerationMode;
import com.seibel.lod.objects.LodDataPoint;
import com.seibel.lod.objects.LodQuadTreeNode;
import com.seibel.lod.objects.LodQuadTreeDimension;
import com.seibel.lod.objects.LodQuadTreeWorld;
@@ -134,7 +136,7 @@ public class LodNodeBuilder {
depth = determineBottomPointForArea(chunk.getSections(), startX, startZ, endX, endZ);
return new LodQuadTreeNode(LodQuadTreeNode.CHUNK_LEVEL, chunk.getPos().x, chunk.getPos().z, height, depth, color, true);
return new LodQuadTreeNode(LodQuadTreeNode.CHUNK_LEVEL, chunk.getPos().x, chunk.getPos().z, new LodDataPoint(height, depth, color) , DistanceGenerationMode.SERVER);
}
@@ -42,15 +42,15 @@ public class CubicLodNodeTemplate extends AbstractLodNodeTemplate {
// returns null if the lod is empty at the given location
bbox = generateBoundingBox(
lod.height,
lod.height,
lod.lodDataPoint.height,
lod.lodDataPoint.height,
detail.dataPointWidth,
xOffset - (halfWidth / 2) + startX,
yOffset,
zOffset - (halfWidth / 2) + startZ);
if (bbox != null) {
addBoundingBoxToBuffer(buffer, bbox, lod.color);
addBoundingBoxToBuffer(buffer, bbox, lod.lodDataPoint.color);
}
}
@@ -14,6 +14,9 @@ package com.seibel.lod.enums;
*/
public enum DistanceGenerationMode
{
/** No generation has be used*/
NONE,
/** Only generate the biomes and use biome
* grass/foliage color, water color, or ice color
* to generate the color.
@@ -275,7 +275,7 @@ public class LodQuadTreeDimensionFileHandler {
fw.write(LOD_FILE_VERSION_PREFIX + " " + LOD_SAVE_FILE_VERSION + "\n");
// add each LodChunk to the file
for(LodQuadTreeNode lodQuadTreeNode : Collections.unmodifiableList(region.getNodeList(false, true, true))) {
for(LodQuadTreeNode lodQuadTreeNode : Collections.unmodifiableList(region.getNodeList(LodQuadTreeDimension.FULL_COMPLEXITY_MASK , true, true))) {
fw.write(lodQuadTreeNode.toData() + "\n");
lodQuadTreeNode.dirty = false;
}
@@ -149,14 +149,11 @@ public class LodQuadTree {
if(posX<0) WE = 1 - WE;
if(posZ<0) NS = 1 - NS;
*/
if(posX<0) System.out.println(WE);
if(posZ<0) System.out.println(NS);
if (getChild(NS, WE) == null) {
setChild(NS, WE);
}
LodQuadTree child = getChild(NS, WE);
if (lodNode.compareComplexity(newLodNode) < 0) {
if (lodNode.compareComplexity(newLodNode) > 0) {
//the node we want to introduce is less complex than the current node
//we don't want to override higher complexity with lower complexity
return false;
@@ -318,7 +315,7 @@ public class LodQuadTree {
*/
public List<LodQuadTreeNode> getNodeToRender(int x, int z, byte targetLevel, Set<DistanceGenerationMode> complexityMask, int maxDistance, int minDistance) {
List<Integer> distances = new ArrayList();
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getCenterX(), 2) + Math.pow(z - lodNode.getCenterX(), 2)));
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getCenterX(), 2) + Math.pow(z - lodNode.getCenterZ(), 2)));
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getStartX(), 2) + Math.pow(z - lodNode.getStartZ(), 2)));
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getStartX(), 2) + Math.pow(z - lodNode.getEndZ(), 2)));
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getEndX(), 2) + Math.pow(z - lodNode.getStartZ(), 2)));
@@ -362,7 +359,7 @@ public class LodQuadTree {
public List<AbstractMap.SimpleEntry<LodQuadTree, Integer>> getLevelToGenerate(int x, int z, byte targetLevel, DistanceGenerationMode complexityToGenerate, int maxDistance, int minDistance) {
List<Integer> distances = new ArrayList();
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getCenterX(), 2) + Math.pow(z - lodNode.getCenterX(), 2)));
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getCenterX(), 2) + Math.pow(z - lodNode.getCenterZ(), 2)));
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getStartX(), 2) + Math.pow(z - lodNode.getStartZ(), 2)));
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getStartX(), 2) + Math.pow(z - lodNode.getEndZ(), 2)));
distances.add((int) Math.sqrt(Math.pow(x - lodNode.getEndX(), 2) + Math.pow(z - lodNode.getStartZ(), 2)));
@@ -389,7 +386,7 @@ public class LodQuadTree {
}else{
if(this.lodNode.getComplexity().compareTo(complexityToGenerate) > 0) {
//we want to regenerate a level only if we ask for higher complexity
nodeList.add(new AbstractMap.SimpleEntry<>(this, min)
nodeList.add(new AbstractMap.SimpleEntry<>(this, min));
}
}
} else {
@@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.world.DimensionType;
import net.minecraft.world.server.ServerChunkProvider;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist;
import java.io.File;
import java.io.IOException;
@@ -20,6 +21,14 @@ public class LodQuadTreeDimension {
private volatile int halfWidth;
public long seed;
public static final Set<DistanceGenerationMode> FULL_COMPLEXITY_MASK = new HashSet(){{
add(DistanceGenerationMode.BIOME_ONLY);
add(DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT);
add(DistanceGenerationMode.SURFACE);
add(DistanceGenerationMode.FEATURES);
add(DistanceGenerationMode.SERVER);
}};
public volatile LodQuadTree regions[][];
public volatile boolean isRegionDirty[][];
@@ -316,7 +325,7 @@ public class LodQuadTreeDimension {
*/
public boolean hasThisPositionBeenGenerated(int posX, int posZ, byte level)
{
return getLodFromCoordinates(posX,posZ,level).level == level
return getLodFromCoordinates(posX,posZ,level).level == level;
}
/**
@@ -338,7 +347,7 @@ public class LodQuadTreeDimension {
* method to get all the quadtree level that have to be generated based on the position of the player
* @return list of quadTrees
*/
public List<LodQuadTree> getNodeToGenerate(int x, int z, byte level, int maxDistance, int minDistance){
public List<LodQuadTree> getNodeToGenerate(int x, int z, byte level, DistanceGenerationMode complexity, int maxDistance, int minDistance){
int n = regions.length;
int xIndex;
@@ -354,7 +363,7 @@ public class LodQuadTreeDimension {
region = new LodQuadTree(xIndex, zIndex);
setRegion(region);
}
listOfQuadTree.addAll(region.getLevelToGenerate(x,z,level,maxDistance,minDistance));
listOfQuadTree.addAll(region.getLevelToGenerate(x,z,level,complexity,maxDistance,minDistance));
}
}
Collections.sort(listOfQuadTree,Map.Entry.comparingByValue());
@@ -438,10 +447,9 @@ public class LodQuadTreeDimension {
if(region == null)
continue;
numbLods= region.getNodeList(false,false,true).size();
numbLods= region.getNodeList(FULL_COMPLEXITY_MASK,false,true).size();
}
}
return numbLods;
}
@@ -81,7 +81,7 @@ public class LodQuadTreeNode {
centerX = startX + width/2;
centerZ = startZ + width/2;
lodDataPoint = new LodDataPoint();
complexity = null;
complexity = DistanceGenerationMode.NONE;
dirty = true;
voidNode = true;
}
@@ -221,11 +221,11 @@ public class LodQuadTreeNode {
//the new complexity equal to the lowest complexity of the list
DistanceGenerationMode minComplexity = DistanceGenerationMode.SERVER;
dataList.forEach(x -> {
if (minComplexity.compareTo(x.complexity) < 0){
minComplexity = x.complexity;
for(LodQuadTreeNode node: dataList){
if (minComplexity.compareTo(node.complexity) < 0){
minComplexity = node.complexity;
}
});
}
complexity = minComplexity;
voidNode = dataList.stream().filter(x -> !x.voidNode).count() == 0;
@@ -68,28 +68,16 @@ public class QuadTreeImage extends JPanel {
}
private static void createAndShowGui() {
int playerX = 0;
int playerZ = 0;
LodQuadTreeDimension dim = new LodQuadTreeDimension(null, null, 4);
int playerX = 32*512;
int playerZ = 32*512;
LodQuadTreeDimension dim = new LodQuadTreeDimension(null, null, 64);
System.out.println(dim.getRegion(0, 0));
dim.move(Math.floorDiv(playerX,512),Math.floorDiv(playerZ,512));
System.out.println(dim.getCenterX());
System.out.println(dim.getCenterZ());
System.out.println(dim.getWidth());
LodQuadTree level2 = dim.getRegion(
-1,
-1
);
int startX2 = level2.getLodNodeData().startX;
int startZ2 = level2.getLodNodeData().startZ;
int endX2 = level2.getLodNodeData().endX;
int endZ2 = level2.getLodNodeData().endZ;
int centerX2 = level2.getLodNodeData().centerX;
int centerZ2 = level2.getLodNodeData().centerZ;
int width2 = level2.getLodNodeData().width;
System.out.println(startX2+" "+startZ2+" "+centerX2+" "+centerZ2);
final QuadTreeImage quadTreeImage = new QuadTreeImage();
@@ -105,7 +93,7 @@ public class QuadTreeImage extends JPanel {
int[] distances = {100000,8000,4000,2000,1000,500,250,100,50,25};
for (int i = 0; i <= (9 - 2); i++) {
for (int j = 0; j < 1; j++) {
List<LodQuadTree> levelToGenerate = dim.getNodeToGenerate(playerX, playerZ, (byte) (9 - i), distances[i], 0);
List<LodQuadTree> levelToGenerate = dim.getNodeToGenerate(playerX, playerZ, (byte) (9 - i), DistanceGenerationMode.SERVER , distances[i], 0);
//System.out.println(levelToGenerate);
for (LodQuadTree level : levelToGenerate) {
Color color;
@@ -141,7 +129,7 @@ public class QuadTreeImage extends JPanel {
//System.out.println(posX + " " + posZ);
color = BiomeColorsUtils.getColorFromBiomeManual(biomeSource.getBiome(posX, 0, posZ));
//color = BiomeColorsUtils.getColorFromIdCB(biomeSource.getBiome(posZ, 0, posX).getId());
LodQuadTreeNode node = new LodQuadTreeNode(otherLevel, posX, posZ, 0, 0, color, true);
LodQuadTreeNode node = new LodQuadTreeNode(otherLevel, posX, posZ, new LodDataPoint(0, 0, color) , DistanceGenerationMode.SERVER);
dim.addNode(node);
}
}
@@ -191,7 +179,7 @@ public class QuadTreeImage extends JPanel {
} else {
if(drawCount==0) quadTreeImage.clearAll();
final List<MyDrawable> myDrawables = new ArrayList<>();
double amp = 0.4;
double amp = 0.025;
Collection<LodQuadTreeNode> lodList = listOfList.get(drawCount);
for (LodQuadTreeNode data : lodList) {
myDrawables.add(new MyDrawable(new Rectangle2D.Double(
@@ -199,7 +187,7 @@ public class QuadTreeImage extends JPanel {
((data.startZ - zOffset) * amp),
data.width * amp,
data.width * amp),
data.color, new BasicStroke(1)));
data.lodDataPoint.color, new BasicStroke(1)));
}
myDrawables.add(new MyDrawable(new Rectangle2D.Double(
(playerX - 10 - xOffset) * amp,
@@ -277,9 +265,9 @@ class MyDrawable {
Stroke oldStroke = g2.getStroke();
g2.setColor(color);
//g2.fill(shape);
g2.fill(shape);
g2.setStroke(stroke);
//g2.setStroke(stroke);
g2.draw(shape);
g2.setColor(oldColor);
@@ -128,7 +128,7 @@ public class LodNodeRenderer
* Besides drawing the LODs this method also starts
* the async process of generating the Buffers that hold those LODs.
*
* @param newDimension The dimension to draw, if null doesn't replace the current dimension.
* @param newDim The dimension to draw, if null doesn't replace the current dimension.
* @param partialTicks how far into the current tick this method was called.
*/
public void drawLODs(LodQuadTreeDimension lodDim, float partialTicks, IProfiler newProfiler)
@@ -788,7 +788,7 @@ public class LodNodeRenderer
LodQuadTreeNode lod = lodDim.getLodFromCoordinates(x, z, (byte) 4);
if (lod != null)
{
short lodHighestPoint = lod.height;
short lodHighestPoint = lod.lodDataPoint.height;
if (playerPos.getY() < lodHighestPoint)
{