From 7c5713fac210726b578932830091dcce9f053c5d Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 27 Sep 2021 21:59:51 -0500 Subject: [PATCH] Refactor and comment LodWorld --- .../lod/handlers/LodDimensionFileHandler.java | 1 + .../java/com/seibel/lod/objects/LodWorld.java | 34 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java b/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java index 6256e423a..9d41b4baf 100644 --- a/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java +++ b/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java @@ -238,6 +238,7 @@ public class LodDimensionFileHandler { for (int j = 0; j < lodDimension.getWidth(); j++) { + // TODO shouldn't this use lodDimension.isRegionDirty? if (lodDimension.doesRegionNeedBufferRegen(i,j) && lodDimension.getRegionByArrayIndex(i,j) != null) { saveRegionToFile(lodDimension.getRegionByArrayIndex(i,j)); diff --git a/src/main/java/com/seibel/lod/objects/LodWorld.java b/src/main/java/com/seibel/lod/objects/LodWorld.java index d36c7588b..6cadc4813 100644 --- a/src/main/java/com/seibel/lod/objects/LodWorld.java +++ b/src/main/java/com/seibel/lod/objects/LodWorld.java @@ -36,24 +36,31 @@ public class LodWorld /** name of this world */ private String worldName; - + /** dimensions in this world */ private Map lodDimensions; /** If true then the LOD world is setup and ready to use */ private boolean isWorldLoaded = false; + /** the name given to the world if it isn't loaded */ public static final String NO_WORLD_LOADED = "No world loaded"; + public LodWorld() { worldName = NO_WORLD_LOADED; } + + /** - * Set up the LodQuadTreeWorld with the given newWorldName.
- * This should be done whenever loading a new world. - * + * Set up the LodWorld with the given newWorldName.
+ * This should be done whenever loading a new world.

+ * + * Note a System.gc() call may be in order after calling this
+ * since a lot of LOD data is now homeless.
+ * * @param newWorldName name of the world */ public void selectWorld(String newWorldName) @@ -77,7 +84,10 @@ public class LodWorld /** * Set the worldName to "No world loaded" * and clear the lodDimensions Map.
- * This should be done whenever unloaded a world. + * This should be done whenever unloaded a world.

+ * + * Note a System.gc() call may be in order after calling this
+ * since a lot of LOD data is now homeless.
*/ public void deselectWorld() { @@ -88,19 +98,19 @@ public class LodWorld /** - * Adds newStorage to this world, if a LodQuadTreeDimension + * Adds newDimension to this world, if a LodDimension * already exists for the given dimension it is replaced. */ - public void addLodDimension(LodDimension newStorage) + public void addLodDimension(LodDimension newDimension) { if (lodDimensions == null) return; - lodDimensions.put(newStorage.dimension, newStorage); + lodDimensions.put(newDimension.dimension, newDimension); } /** - * Returns null if no LodQuadTreeDimension exists for the given dimension + * Returns null if no LodDimension exists for the given dimension */ public LodDimension getLodDimension(DimensionType dimension) { @@ -114,7 +124,7 @@ public class LodWorld * Resizes the max width in regions that each LodDimension * should use. */ - public void resizeDimensionRegionWidth(int newWidth) + public void resizeDimensionRegionWidth(int newRegionWidth) { if (lodDimensions == null) return; @@ -122,7 +132,7 @@ public class LodWorld saveAllDimensions(); for (DimensionType key : lodDimensions.keySet()) - lodDimensions.get(key).setRegionWidth(newWidth); + lodDimensions.get(key).setRegionWidth(newRegionWidth); } /** @@ -133,6 +143,8 @@ public class LodWorld if (lodDimensions == null) return; + // TODO we should only print this if lods were actually saved to file + // but that requires a LodDimension.hasDirtyRegions() method or something similar ClientProxy.LOGGER.info("Saving LODs"); for (DimensionType key : lodDimensions.keySet())