From bc8188beb0914e9c9d2d15aea0703ca5e7068dc2 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Wed, 21 Jul 2021 10:43:51 +0200 Subject: [PATCH] Added important TODOs --- .../com/seibel/lod/objects/LodQuadTree.java | 2 +- .../lod/objects/LodQuadTreeDimension.java | 7 +++ .../seibel/lod/objects/LodQuadTreeNode.java | 8 +++ .../com/seibel/lod/objects/QuadTreeImage.java | 63 ++++++++++++------- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/seibel/lod/objects/LodQuadTree.java b/src/main/java/com/seibel/lod/objects/LodQuadTree.java index 692d01755..6d6e49ad6 100644 --- a/src/main/java/com/seibel/lod/objects/LodQuadTree.java +++ b/src/main/java/com/seibel/lod/objects/LodQuadTree.java @@ -315,7 +315,7 @@ public class LodQuadTree { int max = distances.stream().mapToInt(Integer::intValue).max().getAsInt(); List nodeList = new ArrayList<>(); - if (targetLevel <= lodNode.level && ((min <= maxDistance && max >= minDistance) || isCoordinateInLevel(x, z))) { + if (targetLevel <= lodNode.level && ((min <= maxDistance && max >= minDistance) /*|| isCoordinateInLevel(x, z)*/)) { if (targetLevel == lodNode.level || !isNodeFull()) { if (!lodNode.isVoidNode() && complexityMask.contains(lodNode.getComplexity())) { nodeList.add(lodNode); diff --git a/src/main/java/com/seibel/lod/objects/LodQuadTreeDimension.java b/src/main/java/com/seibel/lod/objects/LodQuadTreeDimension.java index fd355223b..c94057cc3 100644 --- a/src/main/java/com/seibel/lod/objects/LodQuadTreeDimension.java +++ b/src/main/java/com/seibel/lod/objects/LodQuadTreeDimension.java @@ -16,6 +16,13 @@ import java.util.*; import java.util.stream.Collectors; public class LodQuadTreeDimension { + + /**TODO a dimension should support two different type of quadTree. + * The ones that are near from the player should always be saved and can be fully generated (even at block level) + * The ones that are far from the player should always be non-savable and at a high level + * If this is not done then you could see how heavy a fully generated 64 region dimension can get. + * IDEA : use a mask like the "isRegionDirty" to achieve this*/ + public final DimensionType dimension; private volatile int width; diff --git a/src/main/java/com/seibel/lod/objects/LodQuadTreeNode.java b/src/main/java/com/seibel/lod/objects/LodQuadTreeNode.java index d413b616f..4ada99b1c 100644 --- a/src/main/java/com/seibel/lod/objects/LodQuadTreeNode.java +++ b/src/main/java/com/seibel/lod/objects/LodQuadTreeNode.java @@ -62,6 +62,14 @@ public class LodQuadTreeNode { public boolean dirty; + /**TODO There should be a check for the level. Level must be positive, i could use runtime exception or simple if*/ + /**TODO There should be a good way to create node that must not be saved + * For example loading a 64 region wide dimension that is fully generated is too much memory heavy. + * There should be a way to create Node that are approximated and at region level, so you could load those + * for far region, and then when you get closer you load the actual region from the file or you generate it. + * */ + + /** * Creates and empty LodDataPoint * This LodDataPoint only contains the position data diff --git a/src/main/java/com/seibel/lod/objects/QuadTreeImage.java b/src/main/java/com/seibel/lod/objects/QuadTreeImage.java index 470627c46..eb59ed880 100644 --- a/src/main/java/com/seibel/lod/objects/QuadTreeImage.java +++ b/src/main/java/com/seibel/lod/objects/QuadTreeImage.java @@ -81,16 +81,16 @@ public class QuadTreeImage extends JPanel { List> listOfList = new ArrayList<>(); OverworldBiomeSource biomeSource = new OverworldBiomeSource(MCVersion.v1_16_5, 1000); //EndBiomeSource biomeSource = new EndBiomeSource(MCVersion.v1_16_5, 1000); - int sizeOfTheWorld = 2; + int sizeOfTheWorld = 32; LodQuadTreeDimension dim = new LodQuadTreeDimension(null, null, sizeOfTheWorld); //SIMULATING A PLAYER MOVING, - int[] playerXs = {0, 100, 200, 300, 400, 500}; + int[] playerXs = {0, 100, 200, 300, 400, 1000}; int[] playerZs = {0, 100, 200, 300, 400, 500}; for (int pos = 0; pos < 1; pos++) { int playerX = 0 + playerXs[pos]; //2097152 - int playerZ = 0 + playerZs[pos]; + int playerZ = 0 + playerZs[pos]/2; //int sizeOfTheWorld=512; //TRY THIS TO SEE A 250'000 BLOCK RENDER DISTANCE dim.move(Math.floorDiv(playerX, 512), Math.floorDiv(playerZ, 512)); @@ -104,11 +104,11 @@ public class QuadTreeImage extends JPanel { System.out.println(dim.getLodFromCoordinates(-6, -6)); */ - DistanceGenerationMode[] complexities = {DistanceGenerationMode.BIOME_ONLY, DistanceGenerationMode.BIOME_ONLY, DistanceGenerationMode.BIOME_ONLY, DistanceGenerationMode.SURFACE, DistanceGenerationMode.SURFACE, DistanceGenerationMode.FEATURES, DistanceGenerationMode.FEATURES, DistanceGenerationMode.FEATURES, DistanceGenerationMode.FEATURES, DistanceGenerationMode.FEATURES}; - int[] distances = {100000, 8000, 4000, 2000, 1000, 500, 250, 100, 50, 25}; - for (int i = 0; i <= (9); i++) { - List levelToGenerate = dim.getNodesToGenerate(playerX, playerZ, (byte) (9 - i), complexities[i], distances[i], 0); - System.out.println(levelToGenerate); + DistanceGenerationMode[] complexities = {DistanceGenerationMode.BIOME_ONLY, DistanceGenerationMode.BIOME_ONLY, DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT, DistanceGenerationMode.SURFACE, DistanceGenerationMode.SURFACE, DistanceGenerationMode.FEATURES, DistanceGenerationMode.FEATURES, DistanceGenerationMode.FEATURES, DistanceGenerationMode.FEATURES, DistanceGenerationMode.FEATURES}; + int[] distances = {1000000, 8000, 4000, 2000, 1000, 500, 250, 100, 50, 25}; + for (int i = 0; i <= (9-2); i++) { + List levelToGenerate = dim.getNodesToGenerate(playerX, playerZ, (byte) (9 - i), complexities[i], distances[i]*2, 0); + //System.out.println(levelToGenerate); for (LodQuadTreeNode node : levelToGenerate) { Color color; int startX = node.startX; @@ -146,21 +146,23 @@ public class QuadTreeImage extends JPanel { //complexityMask.add(DistanceGenerationMode.SURFACE); //complexityMask.add(DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT); //complexityMask.add(DistanceGenerationMode.BIOME_ONLY); - Set complexityMask = LodQuadTreeDimension.FULL_COMPLEXITY_MASK; -/* List lodList = new ArrayList<>(); //The min and max distances should increase quadratically - int[] distances2 = {100000, 8000, 4000, 2000, 1000, 500, 250, 0}; + //int[] distances2 = {100000, 8000, 4000, 2000, 1000, 500, 250, 0}; + int[] distances2 = {0, 250, 500, 1000, 2000, 4000, 8000, 100000}; for (int h = 0; h <= (9 - 3); h++) { - lodList.addAll(dim.getNodeToRender(playerX, playerZ, (byte) (9-h), complexityMask, distances2[h], distances2[h+1])); + lodList.addAll(dim.getNodeToRender(playerX, playerZ, (byte) (3+h), complexityMask, distances2[h+1], distances2[h])); } System.out.println("Number of node to render " + lodList.size()); listOfList.add(lodList); - */ + System.out.println("Number of list " + listOfList.size()); + /* List lodList = dim.getNodes(complexityMask, false, false); //USE THIS TO SEE AL THE LODS listOfList.add(lodList); + */ + } } @@ -192,6 +194,27 @@ public class QuadTreeImage extends JPanel { double amp = ((double) 2) / ((double) sizeOfTheWorld); Collection lodList = listOfList.get(drawCount); for (LodQuadTreeNode data : lodList) { + Color colorOfComplexity = Color.black; + switch (data.complexity){ + case NONE: + colorOfComplexity = Color.black; + break; + case BIOME_ONLY: + colorOfComplexity = Color.red; + break; + case BIOME_ONLY_SIMULATE_HEIGHT: + colorOfComplexity = Color.yellow; + break; + case SURFACE: + colorOfComplexity = Color.blue; + break; + case FEATURES: + colorOfComplexity = Color.cyan; + break; + case SERVER: + colorOfComplexity = Color.green; + break; + } myDrawables.add(new MyDrawable(new Rectangle2D.Double( ((data.startX - xOffset) * amp), ((data.startZ - zOffset) * amp), @@ -199,14 +222,12 @@ public class QuadTreeImage extends JPanel { data.width * amp), data.lodDataPoint.color, new BasicStroke(1))); } - for(int k=0; k<1; k++) { myDrawables.add(new MyDrawable(new Rectangle2D.Double( - (playerXs[k] - 10 - xOffset) * amp, - (playerZs[k] - 10 - zOffset) * amp, - 20 * amp, - 20 * amp), + (playerXs[0] - xOffset) * amp, + (playerZs[0] - zOffset) * amp, + 20, + 20), Color.yellow, new BasicStroke(1))); - } for (int k = 0; k < myDrawables.size(); k++) { quadTreeImage.addMyDrawable(myDrawables.get(k)); } @@ -291,8 +312,8 @@ class MyDrawable { Stroke oldStroke = g2.getStroke(); g2.setColor(color); - //g2.fill(shape); - g2.setStroke(stroke); + g2.fill(shape); + //g2.setStroke(stroke); g2.draw(shape); g2.setColor(oldColor);