Reformat, Refactor, and add comments

This commit is contained in:
James Seibel
2021-08-07 12:22:49 -05:00
parent 5eafe8f818
commit 3538e79a6b
6 changed files with 664 additions and 620 deletions
@@ -30,7 +30,6 @@ import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -43,11 +42,17 @@ import com.seibel.lod.enums.DistanceGenerationMode;
import com.seibel.lod.objects.LodDataPoint;
import com.seibel.lod.objects.LodQuadTreeDimension;
import com.seibel.lod.objects.LodQuadTreeNode;
import com.seibel.lod.objects.RegionPos;
import com.seibel.lod.util.BiomeColorsUtils;
import kaptainwutax.biomeutils.source.OverworldBiomeSource;
import kaptainwutax.mcutils.version.MCVersion;
/**
*
* @author Leonardo Amato
*
*/
@SuppressWarnings("serial")
public class QuadTreeImage extends JPanel
{
@@ -122,7 +127,7 @@ public class QuadTreeImage extends JPanel
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));
dim.move(new RegionPos(Math.floorDiv(playerX, 512), Math.floorDiv(playerZ, 512)));
/*
System.out.println(dim.getRegion(0, 0));
System.out.println(dim.getCenterX());
@@ -28,7 +28,7 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.seibel.lod.objects.LodQuadTree;
import com.seibel.lod.objects.LodQuadTreeRegion;
import com.seibel.lod.objects.LodQuadTreeDimension;
import com.seibel.lod.objects.LodQuadTreeNode;
import com.seibel.lod.proxy.ClientProxy;
@@ -98,7 +98,7 @@ public class LodQuadTreeDimensionFileHandler {
* Return the LodQuadTree region at the given coordinates.
* (null if the file doesn't exist)
*/
public LodQuadTree loadRegionFromFile(int regionX, int regionZ)
public LodQuadTreeRegion loadRegionFromFile(int regionX, int regionZ)
{
String fileName = getFileNameAndPathForRegion(regionX, regionZ);
@@ -195,7 +195,7 @@ public class LodQuadTreeDimensionFileHandler {
// problem reading the file
return null;
}
return new LodQuadTree(dataList,regionX, regionZ);
return new LodQuadTreeRegion(dataList,regionX, regionZ);
}
@@ -240,7 +240,7 @@ public class LodQuadTreeDimensionFileHandler {
* 2. This will save to the LodDimension that this
* handler is associated with.
*/
private void saveRegionToDisk(LodQuadTree region)
private void saveRegionToDisk(LodQuadTreeRegion region)
{
// convert chunk coordinates to region
// coordinates
@@ -306,7 +306,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(LodQuadTreeDimension.FULL_COMPLEXITY_MASK , true, true)))
for (LodQuadTreeNode lodQuadTreeNode : Collections.unmodifiableList(region.getNodeListWithMask(LodQuadTreeDimension.FULL_COMPLEXITY_MASK , true, true)))
{
fw.write(lodQuadTreeNode.toData() + "\n");
lodQuadTreeNode.dirty = false;
File diff suppressed because it is too large Load Diff
@@ -28,7 +28,8 @@ import com.seibel.lod.enums.DistanceGenerationMode;
* 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.
*/
public class LodQuadTree {
public class LodQuadTreeRegion
{
//notes
//The term node correspond to a LodQuadTree object
@@ -79,10 +80,10 @@ public class LodQuadTree {
//the four child based on the four diagonal cardinal direction
//the first index is for N and S and the second index is for W and S
//children should always be null for level 0.
private final LodQuadTree[][] children;
private final LodQuadTreeRegion[][] children;
//parent should always be null for level 9, and always not null for other levels.
private final LodQuadTree parent;
private final LodQuadTreeRegion parent;
/**
* Constructor for level 0 without LodNodeData (region level constructor)
@@ -91,7 +92,8 @@ public class LodQuadTree {
* @param regionZ indicate the z region position of the node
*/
//maybe the use of useLevelCoordinate could be changed. I could use a builder to do all this work.
public LodQuadTree(int regionX, int regionZ) {
public LodQuadTreeRegion(int regionX, int regionZ)
{
this(null, new LodQuadTreeNode(LodQuadTreeNode.REGION_LEVEL, regionX, regionZ));
}
@@ -103,7 +105,7 @@ public class LodQuadTree {
* @param posX position x in the level
* @param posZ position z in the level
*/
public LodQuadTree(LodQuadTree parent, byte level, int posX, int posZ) {
public LodQuadTreeRegion(LodQuadTreeRegion parent, byte level, int posX, int posZ) {
this(parent, new LodQuadTreeNode(level, posX, posZ));
}
@@ -112,10 +114,10 @@ public class LodQuadTree {
*
* @param lodNode object containing all the information of this node
*/
public LodQuadTree(LodQuadTree parent, LodQuadTreeNode lodNode) {
public LodQuadTreeRegion(LodQuadTreeRegion parent, LodQuadTreeNode lodNode) {
this.parent = parent;
this.lodNode = lodNode;
this.children = new LodQuadTree[2][2];
this.children = new LodQuadTreeRegion[2][2];
this.nodeEmpty = true;
this.nodeFull = false;
}
@@ -127,7 +129,7 @@ public class LodQuadTree {
* @param regionX x region coordinate
* @param regionZ z region coordinate
*/
public LodQuadTree(List<LodQuadTreeNode> dataList, int regionX, int regionZ) {
public LodQuadTreeRegion(List<LodQuadTreeNode> dataList, int regionX, int regionZ) {
this(null, new LodQuadTreeNode(LodQuadTreeNode.REGION_LEVEL, regionX, regionZ));
this.setNodesAtLowerLevel(dataList, true);
}
@@ -163,7 +165,7 @@ public class LodQuadTree {
if (getChild(NS, WE) == null) {
setChild(NS, WE);
}
LodQuadTree child = getChild(NS, WE);
LodQuadTreeRegion child = getChild(NS, WE);
if (lodNode.compareComplexity(newLodNode) > 0)
{
//the node we want to introduce is less complex than the current node
@@ -215,7 +217,7 @@ public class LodQuadTree {
{
return null;
}
LodQuadTree child = getChild(NS, WE);
LodQuadTreeRegion child = getChild(NS, WE);
return child.getNodeAtChunkPos(chunkPosX, chunkPosZ, targetLevel);
}
else
@@ -226,7 +228,7 @@ public class LodQuadTree {
}
public LodQuadTree getChild(int NS, int WE)
public LodQuadTreeRegion getChild(int NS, int WE)
{
return children[NS][WE];
}
@@ -240,7 +242,7 @@ public class LodQuadTree {
*/
public void setChild(LodQuadTreeNode newLodNode, int NS, int WE) {
if (newLodNode.detailLevel == lodNode.detailLevel - 1) {
children[NS][WE] = new LodQuadTree(this, lodNode);
children[NS][WE] = new LodQuadTreeRegion(this, lodNode);
}
}
@@ -253,7 +255,7 @@ public class LodQuadTree {
if (newLodNode.detailLevel == lodNode.detailLevel - 1) {
int WE = newLodNode.posX % lodNode.posX;
int NS = newLodNode.posZ % lodNode.posZ;
children[NS][WE] = new LodQuadTree(this, lodNode);
children[NS][WE] = new LodQuadTreeRegion(this, lodNode);
}
}
@@ -266,7 +268,7 @@ public class LodQuadTree {
public void setChild(int NS, int WE) {
int childX = lodNode.posX * 2 + WE;
int childZ = lodNode.posZ * 2 + NS;
children[NS][WE] = new LodQuadTree(this, (byte) (lodNode.detailLevel - 1), childX, childZ);
children[NS][WE] = new LodQuadTreeRegion(this, (byte) (lodNode.detailLevel - 1), childX, childZ);
}
/**
@@ -305,7 +307,7 @@ public class LodQuadTree {
* @param getOnlyLeaf if true it will return only leaf nodes
* @return list of nodes
*/
public List<LodQuadTreeNode> getNodeList(Set<DistanceGenerationMode> complexityMask, boolean getOnlyDirty, boolean getOnlyLeaf) {
public List<LodQuadTreeNode> getNodeListWithMask(Set<DistanceGenerationMode> complexityMask, boolean getOnlyDirty, boolean getOnlyLeaf) {
List<LodQuadTreeNode> nodeList = new ArrayList<>();
if (isThereAnyChild()) {
//There is at least 1 child
@@ -316,9 +318,9 @@ public class LodQuadTree {
}
for (int NS = 0; NS <= 1; NS++) {
for (int WE = 0; WE <= 1; WE++) {
LodQuadTree child = children[NS][WE];
LodQuadTreeRegion child = children[NS][WE];
if (child != null) {
nodeList.addAll(child.getNodeList(complexityMask, getOnlyDirty, getOnlyLeaf));
nodeList.addAll(child.getNodeListWithMask(complexityMask, getOnlyDirty, getOnlyLeaf));
}
}
}
@@ -363,7 +365,7 @@ public class LodQuadTree {
} else {
for (int NS = 0; NS <= 1; NS++) {
for (int WE = 0; WE <= 1; WE++) {
LodQuadTree child = getChild(NS, WE);
LodQuadTreeRegion child = getChild(NS, WE);
if (child != null) {
nodeList.addAll(child.getNodeToRender(x, z, targetLevel, complexityMask, maxDistance, minDistance));
}
@@ -25,93 +25,116 @@ import net.minecraft.world.DimensionType;
/**
* This stores all LODs for a given world.
*
* @author James Seibel
* @author Leonardo Amato
* @version 8-7-2021
*/
public class LodQuadTreeWorld
{
private String worldName;
private Map<DimensionType, LodQuadTreeDimension> lodDimensions;
/** If true then the LOD world is setup and ready to use */
private boolean isWorldLoaded = false;
public static final String NO_WORLD_LOADED = "No world loaded";
public LodQuadTreeWorld() {
worldName = NO_WORLD_LOADED;
}
/**
* Set up the LodWorld with the given newWorldName. <br>
* This should be done whenever loading a new world.
* @param newWorldName name of the world
*/
public void selectWorld(String newWorldName) {
if (newWorldName.isEmpty()) {
deselectWorld();
return;
}
if (worldName.equals(newWorldName))
// don't recreate everything if we
// didn't actually change worlds
return;
worldName = newWorldName;
private String worldName;
private Map<DimensionType, LodQuadTreeDimension> lodDimensions;
/** If true then the LOD world is setup and ready to use */
private boolean isWorldLoaded = false;
public static final String NO_WORLD_LOADED = "No world loaded";
public LodQuadTreeWorld()
{
worldName = NO_WORLD_LOADED;
}
/**
* Set up the LodQuadTreeWorld with the given newWorldName. <br>
* This should be done whenever loading a new world.
*
* @param newWorldName name of the world
*/
public void selectWorld(String newWorldName)
{
if (newWorldName.isEmpty())
{
deselectWorld();
return;
}
if (worldName.equals(newWorldName))
// don't recreate everything if we
// didn't actually change worlds
return;
worldName = newWorldName;
lodDimensions = new Hashtable<DimensionType, LodQuadTreeDimension>();
isWorldLoaded = true;
}
/**
* Set the worldName to "No world loaded"
* and clear the lodDimensions Map. <br>
* This should be done whenever unloaded a world.
*/
public void deselectWorld() {
worldName = NO_WORLD_LOADED;
lodDimensions = null;
isWorldLoaded = false;
}
public void addLodDimension(LodQuadTreeDimension newStorage) {
if (lodDimensions == null)
throw new IllegalStateException("LodWorld hasn't been given a world yet.");
lodDimensions.put(newStorage.dimension, newStorage);
}
public LodQuadTreeDimension getLodDimension(DimensionType dimension) {
if (lodDimensions == null) {
throw new IllegalStateException("LodWorld hasn't been given a world yet.");
}
return lodDimensions.get(dimension);
}
/**
* Resizes the max width in regions that each LodDimension
* should use.
*/
public void resizeDimensionRegionWidth(int newWidth) {
if (lodDimensions == null)
throw new IllegalStateException("LodWorld hasn't been given a world yet.");
for (DimensionType key : lodDimensions.keySet())
lodDimensions.get(key).setRegionWidth(newWidth);
}
public boolean getIsWorldLoaded() {
return isWorldLoaded;
}
public String getWorldName() {
return worldName;
}
@Override
public String toString() {
return "World name: " + worldName;
}
isWorldLoaded = true;
}
/**
* Set the worldName to "No world loaded"
* and clear the lodDimensions Map. <br>
* This should be done whenever unloaded a world.
*/
public void deselectWorld()
{
worldName = NO_WORLD_LOADED;
lodDimensions = null;
isWorldLoaded = false;
}
/**
* Adds newStorage to this world, if a LodQuadTreeDimension
* already exists for the given dimension it is replaced.
*/
public void addLodDimension(LodQuadTreeDimension newStorage)
{
if (lodDimensions == null)
throw new IllegalStateException("LodWorld hasn't been given a world yet.");
lodDimensions.put(newStorage.dimension, newStorage);
}
/**
* Returns null if no LodQuadTreeDimension exists for the given dimension
*/
public LodQuadTreeDimension getLodDimension(DimensionType dimension)
{
if (lodDimensions == null) {
throw new IllegalStateException("LodWorld hasn't been given a world yet.");
}
return lodDimensions.get(dimension);
}
/**
* Resizes the max width in regions that each LodDimension
* should use.
*/
public void resizeDimensionRegionWidth(int newWidth)
{
if (lodDimensions == null)
throw new IllegalStateException("LodWorld hasn't been given a world yet.");
for (DimensionType key : lodDimensions.keySet())
lodDimensions.get(key).setRegionWidth(newWidth);
}
public boolean getIsWorldLoaded()
{
return isWorldLoaded;
}
public String getWorldName()
{
return worldName;
}
@Override
public String toString()
{
return "World name: " + worldName;
}
}
@@ -31,6 +31,7 @@ import com.seibel.lod.objects.LodChunk;
import com.seibel.lod.objects.LodQuadTreeDimension;
import com.seibel.lod.objects.LodQuadTreeWorld;
import com.seibel.lod.objects.LodRegion;
import com.seibel.lod.objects.RegionPos;
import com.seibel.lod.render.LodNodeRenderer;
import com.seibel.lod.util.LodUtil;
@@ -116,7 +117,7 @@ public class ClientProxy
if (xOffset != 0 || zOffset != 0)
{
lodDim.move(xOffset, zOffset);
lodDim.move(new RegionPos(xOffset, zOffset));
}