From e8b46a6fd26e6fc8624c8ff22123b99a0835e40e Mon Sep 17 00:00:00 2001 From: Leonardo Date: Tue, 13 Jul 2021 00:52:24 +0200 Subject: [PATCH] Converting the quadTree to use the LodDataPoint class --- .../com/seibel/lod/objects/LodDataPoint.java | 14 +- .../objects/{quadTree => }/LodQuadTree.java | 176 +++++++++--------- .../LodNodeData.java => LodQuadTreeNode.java} | 88 ++++----- 3 files changed, 143 insertions(+), 135 deletions(-) rename src/main/java/com/seibel/lod/objects/{quadTree => }/LodQuadTree.java (67%) rename src/main/java/com/seibel/lod/objects/{quadTree/LodNodeData.java => LodQuadTreeNode.java} (76%) diff --git a/src/main/java/com/seibel/lod/objects/LodDataPoint.java b/src/main/java/com/seibel/lod/objects/LodDataPoint.java index 964d541c5..bed05956e 100644 --- a/src/main/java/com/seibel/lod/objects/LodDataPoint.java +++ b/src/main/java/com/seibel/lod/objects/LodDataPoint.java @@ -1,6 +1,7 @@ package com.seibel.lod.objects; import java.awt.Color; +import java.util.Objects; import com.seibel.lod.handlers.LodDimensionFileHandler; @@ -55,8 +56,17 @@ public class LodDataPoint depth = (short) newDepth; color = newColor; } - - + + public int hashCode(){ + return Objects.hash(this.height, this.depth, this.color); + } + + public boolean equals(LodDataPoint other){ + return (this.height == other.height + && this.depth == other.depth + && this.color == other.color); + } + /** * Outputs all data in a csv format * with the given delimiter. diff --git a/src/main/java/com/seibel/lod/objects/quadTree/LodQuadTree.java b/src/main/java/com/seibel/lod/objects/LodQuadTree.java similarity index 67% rename from src/main/java/com/seibel/lod/objects/quadTree/LodQuadTree.java rename to src/main/java/com/seibel/lod/objects/LodQuadTree.java index 16bd0a101..82378f58b 100644 --- a/src/main/java/com/seibel/lod/objects/quadTree/LodQuadTree.java +++ b/src/main/java/com/seibel/lod/objects/LodQuadTree.java @@ -1,8 +1,10 @@ -package com.seibel.lod.objects.quadTree; +package com.seibel.lod.objects; import java.util.AbstractMap; import java.util.ArrayList; import java.util.List; +import java.util.Set; + /** * This object contains all data useful to render LodBlock in a region (32x32 chunk o 512x512 block) * for every node it contains the border of the block, the size, the position at it's level, the color, the height and the depth. @@ -35,7 +37,7 @@ public class LodQuadTree { //data useful to render //if children are present then lodNodeData should be a combination of the lodData of the child. This can be //turned off by deselecting the recursive update in all update method. - private LodNodeData lodNodeData; + private LodQuadTreeNode lodQuadTreeNode; /* .____.____. | NW | NE | | @@ -71,7 +73,7 @@ public class LodQuadTree { */ //maybe the use of useLevelCoordinate could be changed. I could use a builder to do all this work. public LodQuadTree(int regionX, int regionZ) { - this(null, new LodNodeData(LodNodeData.REGION_LEVEL, regionX, regionZ)); + this(null, new LodQuadTreeNode(LodQuadTreeNode.REGION_LEVEL, regionX, regionZ)); } /** @@ -83,17 +85,17 @@ public class LodQuadTree { * @param posZ position z in the level */ public LodQuadTree(LodQuadTree parent, byte level, int posX, int posZ) { - this(parent, new LodNodeData(level, posX, posZ)); + this(parent, new LodQuadTreeNode(level, posX, posZ)); } /** * Constructor for generic level via the LodNodeData * - * @param lodNodeData object containing all the information of this node + * @param lodQuadTreeNode object containing all the information of this node */ - public LodQuadTree(LodQuadTree parent, LodNodeData lodNodeData) { + public LodQuadTree(LodQuadTree parent, LodQuadTreeNode lodQuadTreeNode) { this.parent = parent; - this.lodNodeData = lodNodeData; + this.lodQuadTreeNode = lodQuadTreeNode; this.children = new LodQuadTree[2][2]; this.nodeEmpty = true; this.nodeFull = false; @@ -106,8 +108,8 @@ public class LodQuadTree { * @param regionX x region coordinate * @param regionZ z region coordinate */ - public LodQuadTree(List dataList, int regionX, int regionZ) { - this(null, new LodNodeData(LodNodeData.REGION_LEVEL, regionX, regionZ)); + public LodQuadTree(List dataList, int regionX, int regionZ) { + this(null, new LodQuadTreeNode(LodQuadTreeNode.REGION_LEVEL, regionX, regionZ)); this.setNodesAtLowerLevel(dataList, true); } @@ -116,26 +118,26 @@ public class LodQuadTree { * @param dataList list of data to put in the node * @param updateHigherLevel will update the color and height of higher level only if true */ - public void setNodesAtLowerLevel(List dataList, boolean updateHigherLevel) { - for (LodNodeData lodNodeData : dataList) { + public void setNodesAtLowerLevel(List dataList, boolean updateHigherLevel) { + for (LodQuadTreeNode lodQuadTreeNode : dataList) { //this is slow, you could set update to false and use an only top down update method. - this.setNodeAtLowerLevel(lodNodeData, updateHigherLevel); + this.setNodeAtLowerLevel(lodQuadTreeNode, updateHigherLevel); } } /** - * @param newLodNodeData data to put in the node + * @param newLodQuadTreeNode data to put in the node * @param updateHigherLevel will update the color and height of higher level only if true * @return true only if the QuadTree has been changed */ - public boolean setNodeAtLowerLevel(LodNodeData newLodNodeData, boolean updateHigherLevel) { + public boolean setNodeAtLowerLevel(LodQuadTreeNode newLodQuadTreeNode, boolean updateHigherLevel) { //check if we try to introduce a level that is higher or equal than the current one - byte targetLevel = newLodNodeData.level; - byte currentLevel = lodNodeData.level; + byte targetLevel = newLodQuadTreeNode.level; + byte currentLevel = lodQuadTreeNode.level; if (targetLevel < currentLevel) { - int posX = newLodNodeData.posX; - int posZ = newLodNodeData.posZ; - short widthRatio = (short) (lodNodeData.width / (2 * newLodNodeData.width)); + int posX = newLodQuadTreeNode.posX; + int posZ = newLodQuadTreeNode.posZ; + short widthRatio = (short) (lodQuadTreeNode.width / (2 * newLodQuadTreeNode.width)); int WE = Math.abs(Math.floorDiv(posX , widthRatio) % 2); int NS = Math.abs(Math.floorDiv(posZ , widthRatio) % 2); //These two if fix the negative coordinate problema @@ -151,14 +153,14 @@ public class LodQuadTree { setChild(NS, WE); } LodQuadTree child = getChild(NS, WE); - if (!newLodNodeData.real && child.isNodeReal()) { + if (!newLodQuadTreeNode.real && child.isNodeReal()) { return false; } else { if (targetLevel == currentLevel - 1) { - child.setLodNodeData(newLodNodeData, true); + child.setLodNodeData(newLodQuadTreeNode, true); return true; } else { - return child.setNodeAtLowerLevel(newLodNodeData, updateHigherLevel); + return child.setNodeAtLowerLevel(newLodQuadTreeNode, updateHigherLevel); } } } else { @@ -173,13 +175,13 @@ public class LodQuadTree { * @param level * @return */ - public LodNodeData getNodeAtLevelPosition(int posX, int posZ, byte level) { + public LodQuadTreeNode getNodeAtLevelPosition(int posX, int posZ, byte level) { byte targetLevel = level; - byte currentLevel = lodNodeData.level; + byte currentLevel = lodQuadTreeNode.level; if (targetLevel == currentLevel) { - return lodNodeData; + return lodQuadTreeNode; } else if (targetLevel < currentLevel) { - short widthRatio = (short) (lodNodeData.width / (2 * Math.pow(2, level))); + short widthRatio = (short) (lodQuadTreeNode.width / (2 * Math.pow(2, level))); int WE = Math.abs(Math.floorDiv(posX , widthRatio) % 2); int NS = Math.abs(Math.floorDiv(posZ , widthRatio) % 2); if (getChild(NS, WE) == null) { @@ -201,26 +203,26 @@ public class LodQuadTree { /** * setChild will put a child with given data in the given position * - * @param newLodNodeData data to put in the child + * @param newLodQuadTreeNode data to put in the child * @param NS North-South position * @param WE West-East position */ - public void setChild(LodNodeData newLodNodeData, int NS, int WE) { - if (newLodNodeData.level == lodNodeData.level - 1) { - children[NS][WE] = new LodQuadTree(this, lodNodeData); + public void setChild(LodQuadTreeNode newLodQuadTreeNode, int NS, int WE) { + if (newLodQuadTreeNode.level == lodQuadTreeNode.level - 1) { + children[NS][WE] = new LodQuadTree(this, lodQuadTreeNode); } } /** * setChild will put a child with given data in the given position * - * @param newLodNodeData data to put in the child + * @param newLodQuadTreeNode data to put in the child */ - public void setChild(LodNodeData newLodNodeData) { - if (newLodNodeData.level == lodNodeData.level - 1) { - int WE = newLodNodeData.posX % lodNodeData.posX; - int NS = newLodNodeData.posZ % lodNodeData.posZ; - children[NS][WE] = new LodQuadTree(this, lodNodeData); + public void setChild(LodQuadTreeNode newLodQuadTreeNode) { + if (newLodQuadTreeNode.level == lodQuadTreeNode.level - 1) { + int WE = newLodQuadTreeNode.posX % lodQuadTreeNode.posX; + int NS = newLodQuadTreeNode.posZ % lodQuadTreeNode.posZ; + children[NS][WE] = new LodQuadTree(this, lodQuadTreeNode); } } @@ -231,9 +233,9 @@ public class LodQuadTree { * @param WE West-East position */ public void setChild(int NS, int WE) { - int childX = lodNodeData.posX * 2 + WE; - int childZ = lodNodeData.posZ * 2 + NS; - children[NS][WE] = new LodQuadTree(this, (byte) (lodNodeData.level - 1), childX, childZ); + int childX = lodQuadTreeNode.posX * 2 + WE; + int childZ = lodQuadTreeNode.posZ * 2 + NS; + children[NS][WE] = new LodQuadTree(this, (byte) (lodQuadTreeNode.level - 1), childX, childZ); } /** @@ -244,7 +246,7 @@ public class LodQuadTree { private void updateLevel(boolean recursiveUpdate) { boolean isFull = true; boolean isEmpty = true; - List dataList = new ArrayList<>(); + List dataList = new ArrayList<>(); for (int NS = 0; NS <= 1; NS++) { for (int WE = 0; WE <= 1; WE++) { if (getChild(NS,WE) != null) { @@ -257,42 +259,46 @@ public class LodQuadTree { } nodeFull = isFull; nodeEmpty = isEmpty; - lodNodeData.combineData(dataList); - if (lodNodeData.level < 9 && recursiveUpdate) { + lodQuadTreeNode.combineData(dataList); + if (lodQuadTreeNode.level < 9 && recursiveUpdate) { this.parent.updateLevel(recursiveUpdate); } } /** + * * method to get certain nodes from the LodQuadTree * - * @param getOnlyReal if true it will return only real nodes + * @param complexityMask set of complexity to accept * @param getOnlyDirty if true it will return only dirty nodes * @param getOnlyLeaf if true it will return only leaf nodes * @return list of nodes */ - public List getNodeList(boolean getOnlyReal, boolean getOnlyDirty, boolean getOnlyLeaf) { - List nodeList = new ArrayList<>(); - if (!isThereAnyChild()) { - if (!(getOnlyReal && !lodNodeData.dirty) - && !(getOnlyReal && !lodNodeData.real)) { - nodeList.add(lodNodeData); - } - } else { + public List getNodeList(Set complexityMask, boolean getOnlyDirty, boolean getOnlyLeaf) { + List nodeList = new ArrayList<>(); + if (isThereAnyChild()) { + //There is at least 1 child if (!getOnlyLeaf - && !(getOnlyDirty && !lodNodeData.dirty) - && !(getOnlyReal && !lodNodeData.real)) { - nodeList.add(lodNodeData); + && !(getOnlyDirty && !lodQuadTreeNode.dirty) + && complexityMask.contains(lodQuadTreeNode.complexity)) { + nodeList.add(lodQuadTreeNode); } for (int NS = 0; NS <= 1; NS++) { for (int WE = 0; WE <= 1; WE++) { LodQuadTree child = children[NS][WE]; if (child != null) { - nodeList.addAll(child.getNodeList(getOnlyReal, getOnlyDirty, getOnlyLeaf)); + nodeList.addAll(child.getNodeList(complexityMask, getOnlyDirty, getOnlyLeaf)); } } } + } else { + //There are no children + if (!(getOnlyDirty && !lodQuadTreeNode.dirty) + || (complexityMask.contains((int) lodQuadTreeNode.complexity))){ + nodeList.add(lodQuadTreeNode); + } } + return nodeList; } @@ -306,29 +312,29 @@ public class LodQuadTree { * @param minDistance minimum distance from the player * @return */ - public List getNodeToRender(int x, int z, byte targetLevel, int maxDistance, int minDistance) { - int distance = (int) Math.sqrt(Math.pow(x - lodNodeData.centerX, 2) + Math.pow(z - lodNodeData.centerZ, 2)); + public List getNodeToRender(int x, int z, byte targetLevel, int maxDistance, int minDistance) { + int distance = (int) Math.sqrt(Math.pow(x - lodQuadTreeNode.centerX, 2) + Math.pow(z - lodQuadTreeNode.centerZ, 2)); List distances = new ArrayList(); distances.add(distance); - distances.add((int) Math.sqrt(Math.pow(x - lodNodeData.startX, 2) + Math.pow(z - lodNodeData.startZ, 2))); - distances.add((int) Math.sqrt(Math.pow(x - lodNodeData.startX, 2) + Math.pow(z - lodNodeData.endZ, 2))); - distances.add((int) Math.sqrt(Math.pow(x - lodNodeData.endX, 2) + Math.pow(z - lodNodeData.startZ, 2))); - distances.add((int) Math.sqrt(Math.pow(x - lodNodeData.endX, 2) + Math.pow(z - lodNodeData.endZ, 2))); + distances.add((int) Math.sqrt(Math.pow(x - lodQuadTreeNode.startX, 2) + Math.pow(z - lodQuadTreeNode.startZ, 2))); + distances.add((int) Math.sqrt(Math.pow(x - lodQuadTreeNode.startX, 2) + Math.pow(z - lodQuadTreeNode.endZ, 2))); + distances.add((int) Math.sqrt(Math.pow(x - lodQuadTreeNode.endX, 2) + Math.pow(z - lodQuadTreeNode.startZ, 2))); + distances.add((int) Math.sqrt(Math.pow(x - lodQuadTreeNode.endX, 2) + Math.pow(z - lodQuadTreeNode.endZ, 2))); int min = distances.stream().mapToInt(Integer::intValue).min().getAsInt(); int max = distances.stream().mapToInt(Integer::intValue).max().getAsInt(); - List nodeList = new ArrayList<>(); - if (targetLevel > lodNodeData.level) { + List nodeList = new ArrayList<>(); + if (targetLevel > lodQuadTreeNode.level) { return nodeList; } if ((min > maxDistance || max < minDistance) /*&& !isCoordinateInLevel(x,z)*/){ return nodeList; } - if (targetLevel == lodNodeData.level || !isNodeFull()) { - if (lodNodeData.voidNode) { - nodeList.add(lodNodeData); + if (targetLevel == lodQuadTreeNode.level || !isNodeFull()) { + if (lodQuadTreeNode.voidNode) { + nodeList.add(lodQuadTreeNode); return nodeList; } else { - nodeList.add(lodNodeData); + nodeList.add(lodQuadTreeNode); return nodeList; } } else { @@ -355,17 +361,17 @@ public class LodQuadTree { * @return */ public List> getLevelToGenerate(int x, int z, byte targetLevel, int maxDistance, int minDistance) { - int distance = (int) Math.sqrt(Math.pow(x - lodNodeData.centerX, 2) + Math.pow(z - lodNodeData.centerZ, 2)); + int distance = (int) Math.sqrt(Math.pow(x - lodQuadTreeNode.centerX, 2) + Math.pow(z - lodQuadTreeNode.centerZ, 2)); List distances = new ArrayList(); distances.add(distance); - distances.add((int) Math.sqrt(Math.pow(x - lodNodeData.startX, 2) + Math.pow(z - lodNodeData.startZ, 2))); - distances.add((int) Math.sqrt(Math.pow(x - lodNodeData.startX, 2) + Math.pow(z - lodNodeData.endZ, 2))); - distances.add((int) Math.sqrt(Math.pow(x - lodNodeData.endX, 2) + Math.pow(z - lodNodeData.startZ, 2))); - distances.add((int) Math.sqrt(Math.pow(x - lodNodeData.endX, 2) + Math.pow(z - lodNodeData.endZ, 2))); + distances.add((int) Math.sqrt(Math.pow(x - lodQuadTreeNode.startX, 2) + Math.pow(z - lodQuadTreeNode.startZ, 2))); + distances.add((int) Math.sqrt(Math.pow(x - lodQuadTreeNode.startX, 2) + Math.pow(z - lodQuadTreeNode.endZ, 2))); + distances.add((int) Math.sqrt(Math.pow(x - lodQuadTreeNode.endX, 2) + Math.pow(z - lodQuadTreeNode.startZ, 2))); + distances.add((int) Math.sqrt(Math.pow(x - lodQuadTreeNode.endX, 2) + Math.pow(z - lodQuadTreeNode.endZ, 2))); int min = distances.stream().mapToInt(Integer::intValue).min().getAsInt(); int max = distances.stream().mapToInt(Integer::intValue).max().getAsInt(); List> nodeList = new ArrayList<>(); - if ( targetLevel > lodNodeData.level ) { + if ( targetLevel > lodQuadTreeNode.level ) { return nodeList; } if ((min > maxDistance || max < minDistance)/* && !isCoordinateInLevel(x,z)*/){ @@ -373,7 +379,7 @@ public class LodQuadTree { } if(isNodeFull()) { //THIS LEVEL HAS CHILD SO IT'S GENERATED. - if (targetLevel != lodNodeData.level) { + if (targetLevel != lodQuadTreeNode.level) { for (int NS = 0; NS <= 1; NS++) { for (int WE = 0; WE <= 1; WE++) { if (getChild(NS,WE) == null) { @@ -412,21 +418,21 @@ public class LodQuadTree { * * @return lodNodeData */ - public LodNodeData getLodNodeData() { - return lodNodeData; + public LodQuadTreeNode getLodNodeData() { + return lodQuadTreeNode; } /** * setter for lodNodeData, to maintain a correct relationship between level this method force update on all parent * - * @param newLodNodeData data to set + * @param newLodQuadTreeNode data to set * @param updateHigherLevel if true it will update all the upper levels. */ - public void setLodNodeData(LodNodeData newLodNodeData, boolean updateHigherLevel) { - if (this.lodNodeData == null) { - this.lodNodeData = newLodNodeData; + public void setLodNodeData(LodQuadTreeNode newLodQuadTreeNode, boolean updateHigherLevel) { + if (this.lodQuadTreeNode == null) { + this.lodQuadTreeNode = newLodQuadTreeNode; } else { - this.lodNodeData.update(newLodNodeData); + this.lodQuadTreeNode.update(newLodQuadTreeNode); } //a recursive update is necessary to change higher level if (parent != null && updateHigherLevel) parent.updateLevel(true); @@ -441,20 +447,20 @@ public class LodQuadTree { } public boolean isNodeReal() { - return lodNodeData.real; + return lodQuadTreeNode.real; } public boolean isRenderable() { - return (lodNodeData != null); + return (lodQuadTreeNode != null); } public boolean isCoordinateInLevel(int x, int z){ - return !(lodNodeData.startX > x || lodNodeData.startZ > z || lodNodeData.endX < x || lodNodeData.endZ < z); + return !(lodQuadTreeNode.startX > x || lodQuadTreeNode.startZ > z || lodQuadTreeNode.endX < x || lodQuadTreeNode.endZ < z); } public String toString(){ - String s = lodNodeData.toString(); + String s = lodQuadTreeNode.toString(); return s; /* if(isThereAnyChild()){ diff --git a/src/main/java/com/seibel/lod/objects/quadTree/LodNodeData.java b/src/main/java/com/seibel/lod/objects/LodQuadTreeNode.java similarity index 76% rename from src/main/java/com/seibel/lod/objects/quadTree/LodNodeData.java rename to src/main/java/com/seibel/lod/objects/LodQuadTreeNode.java index 7a818fa30..a5edd4ebe 100644 --- a/src/main/java/com/seibel/lod/objects/quadTree/LodNodeData.java +++ b/src/main/java/com/seibel/lod/objects/LodQuadTreeNode.java @@ -1,4 +1,4 @@ -package com.seibel.lod.objects.quadTree; +package com.seibel.lod.objects; import com.seibel.lod.handlers.LodQuadTreeDimensionFileHandler; @@ -6,7 +6,7 @@ import java.awt.*; import java.util.*; import java.util.List; -public class LodNodeData { +public class LodQuadTreeNode { /** This is what separates each piece of data in the toData method */ private static final char DATA_DELIMITER = LodQuadTreeDimensionFileHandler.DATA_DELIMITER; @@ -17,6 +17,11 @@ public class LodNodeData { private static final Color INVISIBLE = new Color(0,0,0,0); + //Complexity indicate how complex is this node. For example a node that has been generated starting + //from a real chunk have the maximum complexity. A node that is generated starting from a fake approximated chunk + //has a low complexity + public byte complexity; + //level height goes from 0 to 9 with 0 the deepest (block size) and 9 the highest (region size) public final byte level; public static final byte REGION_LEVEL = 9; //at level 9 we reach the dimension of a single region @@ -48,16 +53,9 @@ public class LodNodeData { public final int centerX; public final int centerZ; - /** highest point */ - public short height; + public LodDataPoint lodDataPoint; - /** lowest point */ - public short depth; - - /** The average color for the 6 cardinal directions */ - public Color color; - - public boolean real; + //void node is used public boolean voidNode; //if dirty is true, then this node have unsaved changes public boolean dirty; @@ -70,7 +68,7 @@ public class LodNodeData { * @param posX position x in the level * @param posZ posizion z in the level */ - public LodNodeData(byte level, int posX, int posZ){ + public LodQuadTreeNode(byte level, int posX, int posZ){ this.level = level; this.posX = posX; this.posZ = posZ; @@ -81,9 +79,7 @@ public class LodNodeData { endZ = startZ + width - 1; centerX = startX + width/2; centerZ = startZ + width/2; - height = -1; - depth = -1; - color = INVISIBLE; + lodDataPoint = new LodDataPoint() real = false; dirty = true; voidNode = true; @@ -94,12 +90,9 @@ public class LodNodeData { * @param level level of this * @param posX * @param posZ - * @param height - * @param depth - * @param color - * @param real + * @param complexity */ - public LodNodeData(byte level, int posX, int posZ, short height, short depth, Color color, boolean real){ + public LodQuadTreeNode(byte level, int posX, int posZ, LodDataPoint lodDataPoint, byte complexity){ this.level = level; this.posX = posX; this.posZ = posZ; @@ -110,19 +103,13 @@ public class LodNodeData { endZ = startZ + width - 1; centerX = startX + width/2; centerZ = startZ + width/2; - this.height = height; - this.depth = depth; - this.color = color; + this.lodDataPoint = lodDataPoint; this.real = real; dirty = true; voidNode = false; } - public LodNodeData(byte level, int posX, int posZ, int height, int depth, Color color, boolean real) { - this(level, posX, posZ, (short) height,(short) depth, color, real); - } - - public LodNodeData(String data) + public LodQuadTreeNode(String data) { int index = 0; int lastIndex = 0; @@ -160,7 +147,7 @@ public class LodNodeData { int a = Integer.parseInt(data.substring(lastIndex+1,index)); this.color = new Color(r,g,b,a); - int val = Integer.parseInt(data.substring(lastIndex+1,index)); + int complexity = Integer.parseInt(data.substring(lastIndex+1,index)); this.real = (val == 1); width = (short) Math.pow(2, level); @@ -175,29 +162,34 @@ public class LodNodeData { dirty = false; } - public void update(LodNodeData lodNodeData){ - this.height = lodNodeData.height; - this.depth = lodNodeData.depth; - this.color = lodNodeData.color; - this.real = lodNodeData.real; + public void update(LodQuadTreeNode lodQuadTreeNode){ + this.lodDataPoint = lodQuadTreeNode.lodDataPoint + this.complexity = lodQuadTreeNode.complexity; + this.voidNode = lodQuadTreeNode.voidNode; dirty = true; } - public void combineData(List dataList){ + public LodDataPoint getLodDataPoint(){ + return lodDataPoint; + } + public byte getComplexity(){ + return complexity; + } + + public void combineData(List dataList){ if(dataList.isEmpty()){ - height = -1; - depth = -1; - color = INVISIBLE; + lodDataPoint = new LodDataPoint(); }else { - short height = (short) dataList.stream().mapToInt(x -> (int) x.height).min().getAsInt(); - short depth = (short) dataList.stream().mapToInt(x -> (int) x.depth).max().getAsInt(); + short height = (short) dataList.stream().mapToInt(x -> (int) x.getLodDataPoint().height).min().getAsInt(); + short depth = (short) dataList.stream().mapToInt(x -> (int) x.getLodDataPoint().depth).max().getAsInt(); height = height; depth = depth; - int red= dataList.stream().mapToInt(x -> x.color.getRed()).sum()/dataList.size(); - int green= dataList.stream().mapToInt(x -> x.color.getGreen()).sum()/dataList.size(); - int blue = dataList.stream().mapToInt(x -> x.color.getBlue()).sum()/dataList.size(); - color = new Color(red,green,blue); - real = dataList.stream().filter(x -> x.real).count() == 4; + int red= dataList.stream().mapToInt(x -> x.getLodDataPoint().color.getRed()).sum()/dataList.size(); + int green= dataList.stream().mapToInt(x -> x.getLodDataPoint().color.getGreen()).sum()/dataList.size(); + int blue = dataList.stream().mapToInt(x -> x.getLodDataPoint().color.getBlue()).sum()/dataList.size(); + Color color = new Color(red,green,blue); + lodDataPoint = new LodDataPoint(height,depth,color); + complexity = (byte) dataList.stream().mapToInt(x -> x.complexity).max().getAsInt(); voidNode = dataList.stream().filter(x -> !x.voidNode).count() == 0; } dirty = true; @@ -205,12 +197,12 @@ public class LodNodeData { public int hashCode(){ - return Objects.hash(this.real, this.level, this.posX, this.posZ, this.color, this.real, this.voidNode); + return Objects.hash(this.complexity, this.level, this.posX, this.posZ, this.color, this.real, this.voidNode); } - public boolean equals(LodNodeData other){ - return (this.real == other.real + public boolean equals(LodQuadTreeNode other){ + return (this.complexity == other.complexity && this.level == other.level && this.posX == other.posX && this.posZ == other.posZ