From 5eafe8f818b1a35575380c9fcbbb37262f7ebe88 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 5 Aug 2021 21:42:58 -0500 Subject: [PATCH] Improve formatting and a few variable names --- .../com/seibel/lod/objects/LodQuadTree.java | 36 +++++++---- .../lod/objects/LodQuadTreeDimension.java | 63 ++++++++++++------- 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/seibel/lod/objects/LodQuadTree.java b/src/main/java/com/seibel/lod/objects/LodQuadTree.java index 4a0fbd3ab..efafd31a7 100644 --- a/src/main/java/com/seibel/lod/objects/LodQuadTree.java +++ b/src/main/java/com/seibel/lod/objects/LodQuadTree.java @@ -149,7 +149,8 @@ public class LodQuadTree { * @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(LodQuadTreeNode newLodNode, boolean updateHigherLevel) { + public boolean setNodeAtLowerLevel(LodQuadTreeNode newLodNode, boolean updateHigherLevel) + { //check if we try to introduce a level that is higher or equal than the current one byte targetLevel = newLodNode.detailLevel; byte currentLevel = lodNode.detailLevel; @@ -163,31 +164,39 @@ public class LodQuadTree { 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; - } else { - if (targetLevel == currentLevel - 1) { + } + else + { + if (targetLevel == currentLevel - 1) + { child.setLodNodeData(newLodNode, true); return true; - } else { + } + else + { return child.setNodeAtLowerLevel(newLodNode, updateHigherLevel); } } - } else { + } + else + { return false; } } /** - * @param posX - * @param posZ + * @param chunkPosX + * @param chunkPosZ * @param targetLevel * @return */ - public LodQuadTreeNode getNodeAtLevelPosition(int posX, int posZ, int targetLevel) + public LodQuadTreeNode getNodeAtChunkPos(int chunkPosX, int chunkPosZ, int targetLevel) { if (targetLevel > LodQuadTreeNode.REGION_LEVEL) throw new IllegalArgumentException("getLodFromCoordinates given a level of \"" + targetLevel + "\" when \"" + LodQuadTreeNode.REGION_LEVEL + "\" is the max."); @@ -200,14 +209,14 @@ public class LodQuadTree { else if (targetLevel < currentLevel) { short widthRatio = (short) (lodNode.width / (2 * Math.pow(2, targetLevel))); - int WE = Math.abs(Math.floorDiv(posX , widthRatio) % 2); - int NS = Math.abs(Math.floorDiv(posZ , widthRatio) % 2); + int WE = Math.abs(Math.floorDiv(chunkPosX , widthRatio) % 2); + int NS = Math.abs(Math.floorDiv(chunkPosZ , widthRatio) % 2); if (getChild(NS, WE) == null) { return null; } LodQuadTree child = getChild(NS, WE); - return child.getNodeAtLevelPosition(posX, posZ, targetLevel); + return child.getNodeAtChunkPos(chunkPosX, chunkPosZ, targetLevel); } else { @@ -217,7 +226,8 @@ public class LodQuadTree { } - public LodQuadTree getChild(int NS, int WE) { + public LodQuadTree getChild(int NS, int WE) + { return children[NS][WE]; } diff --git a/src/main/java/com/seibel/lod/objects/LodQuadTreeDimension.java b/src/main/java/com/seibel/lod/objects/LodQuadTreeDimension.java index 17d64e20b..214721f4b 100644 --- a/src/main/java/com/seibel/lod/objects/LodQuadTreeDimension.java +++ b/src/main/java/com/seibel/lod/objects/LodQuadTreeDimension.java @@ -93,7 +93,9 @@ public class LodQuadTreeDimension // the compiler from complaining ServerChunkProvider provider = serverWorld.getChunkSource(); saveDir = new File(provider.dataStorage.dataFolder.getCanonicalFile().getPath() + File.separatorChar + "lod"); - } else { + } + else + { // connected to server saveDir = new File(mc.gameDirectory.getCanonicalFile().getPath() + @@ -102,7 +104,9 @@ public class LodQuadTreeDimension fileHandler = new LodQuadTreeDimensionFileHandler(saveDir, this); - } catch (IOException e) { + } + catch (IOException e) + { // the file handler wasn't able to be created // we won't be able to read or write any files } @@ -272,16 +276,20 @@ public class LodQuadTreeDimension /** *this method create all the regions that are null */ - public void initializeNullRegions(){ + public void initializeNullRegions() + { int n = regions.length; int xIndex; int zIndex; LodQuadTree region; - for(int xRegion=0; xRegion + * Returns null if the LodChunk doesn't exist or + * is outside the loaded area. */ public LodQuadTreeNode getLodFromCoordinates(ChunkPos chunkPos) { return getLodFromCoordinates(chunkPos.x, chunkPos.z, LodQuadTreeNode.CHUNK_LEVEL); } - + /** + * Get the LodNodeData at the given X and Z coordinates + * in this dimension. + *
+ * Returns null if the LodChunk doesn't exist or + * is outside the loaded area. */ public LodQuadTreeNode getLodFromCoordinates(int chunkPosX, int chunkPosZ) { @@ -351,12 +370,12 @@ public class LodQuadTreeDimension * Returns null if the LodChunk doesn't exist or * is outside the loaded area. */ - public LodQuadTreeNode getLodFromCoordinates(int posX, int posZ, int detailLevel) + public LodQuadTreeNode getLodFromCoordinates(int chunkPosX, int chunkPosZ, int detailLevel) { if (detailLevel > LodQuadTreeNode.REGION_LEVEL) throw new IllegalArgumentException("getLodFromCoordinates given a level of \"" + detailLevel + "\" when \"" + LodQuadTreeNode.REGION_LEVEL + "\" is the max."); - RegionPos regionPos = LodUtil.convertChunkPosToRegionPos(new ChunkPos(posX, posZ)); + RegionPos regionPos = LodUtil.convertChunkPosToRegionPos(new ChunkPos(chunkPosX, chunkPosZ)); LodQuadTree region = getRegion(regionPos.x, regionPos.z); if(region == null) @@ -365,7 +384,7 @@ public class LodQuadTreeDimension return null; } - return region.getNodeAtLevelPosition(posX, posZ, detailLevel); + return region.getNodeAtChunkPos(chunkPosX, chunkPosZ, detailLevel); /* RegionPos pos = LodUtil.convertChunkPosToRegionPos(new ChunkPos(chunkX, chunkZ)); @@ -436,7 +455,8 @@ public class LodQuadTreeDimension * getNodes * @return list of quadTrees */ - public List getNodes(Set complexityMask, boolean getOnlyDirty, boolean getOnlyLeaf){ + public List getNodes(Set complexityMask, boolean getOnlyDirty, boolean getOnlyLeaf) + { int n = regions.length; List listOfNodes = new ArrayList<>(); int xIndex; @@ -540,13 +560,14 @@ public class LodQuadTreeDimension } else { - return width; - } + return width; + } } public void setRegionWidth(int newWidth) { width = newWidth; + halfWidth = (int)Math.floor(width / 2); regions = new LodQuadTree[width][width]; isRegionDirty = new boolean[width][width];