Refactoring and Commenting
This commit is contained in:
@@ -147,12 +147,12 @@ public class QuadTreeImage extends JPanel
|
||||
//System.out.println(levelToGenerate);
|
||||
for (LodQuadTreeNode node : levelToGenerate) {
|
||||
Color color;
|
||||
int startX = node.startX;
|
||||
int startZ = node.startZ;
|
||||
int endX = node.endX;
|
||||
int endZ = node.endZ;
|
||||
int centerX = node.centerX;
|
||||
int centerZ = node.centerZ;
|
||||
int startX = node.startBlockPos.getX();
|
||||
int startZ = node.startBlockPos.getZ();
|
||||
int endX = node.endBlockPos.getX();
|
||||
int endZ = node.endBlockPos.getZ();
|
||||
int centerX = node.center.getX();
|
||||
int centerZ = node.center.getZ();
|
||||
int width = node.width;
|
||||
byte otherLevel = LodQuadTreeNode.BLOCK_LEVEL;
|
||||
int otherWidth = LodQuadTreeNode.BLOCK_WIDTH;
|
||||
@@ -210,10 +210,10 @@ public class QuadTreeImage extends JPanel
|
||||
System.out.println("STARTING");
|
||||
System.out.println(dim.getWidth());
|
||||
System.out.println(dim.getCenterX());
|
||||
int xOffset = listOfList.stream().mapToInt(x -> x.stream().mapToInt(y -> y.startX).min().getAsInt()).min().getAsInt();
|
||||
int zOffset = listOfList.stream().mapToInt(x -> x.stream().mapToInt(y -> y.startZ).min().getAsInt()).min().getAsInt();
|
||||
int maxX = listOfList.stream().mapToInt(x -> x.stream().mapToInt(y -> y.startX).max().getAsInt()).min().getAsInt();
|
||||
int maxZ = listOfList.stream().mapToInt(x -> x.stream().mapToInt(y -> y.startZ).max().getAsInt()).min().getAsInt();
|
||||
int xOffset = listOfList.stream().mapToInt(x -> x.stream().mapToInt(y -> y.startBlockPos.getX()).min().getAsInt()).min().getAsInt();
|
||||
int zOffset = listOfList.stream().mapToInt(x -> x.stream().mapToInt(y -> y.startBlockPos.getZ()).min().getAsInt()).min().getAsInt();
|
||||
int maxX = listOfList.stream().mapToInt(x -> x.stream().mapToInt(y -> y.startBlockPos.getX()).max().getAsInt()).min().getAsInt();
|
||||
int maxZ = listOfList.stream().mapToInt(x -> x.stream().mapToInt(y -> y.startBlockPos.getZ()).max().getAsInt()).min().getAsInt();
|
||||
int maxSize = Math.max(maxX - xOffset, maxZ - zOffset) / 512;
|
||||
System.out.println(xOffset);
|
||||
System.out.println(zOffset);
|
||||
@@ -252,8 +252,8 @@ public class QuadTreeImage extends JPanel
|
||||
break;
|
||||
}
|
||||
myDrawables.add(new MyDrawable(new Rectangle2D.Double(
|
||||
((data.startX - xOffset) * amp),
|
||||
((data.startZ - zOffset) * amp),
|
||||
((data.startBlockPos.getX() - xOffset) * amp),
|
||||
((data.startBlockPos.getZ() - zOffset) * amp),
|
||||
data.width * amp,
|
||||
data.width * amp),
|
||||
data.lodDataPoint.color, new BasicStroke(1)));
|
||||
|
||||
@@ -133,7 +133,8 @@ public class LodNodeBuilder {
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if either the chunk or world is null.
|
||||
*/
|
||||
public LodQuadTreeNode generateLodNodeFromChunk(IChunk chunk) throws IllegalArgumentException {
|
||||
public LodQuadTreeNode generateLodNodeFromChunk(IChunk chunk) throws IllegalArgumentException
|
||||
{
|
||||
return generateLodNodeFromChunk(chunk, new LodBuilderConfig());
|
||||
}
|
||||
|
||||
@@ -143,12 +144,13 @@ public class LodNodeBuilder {
|
||||
* @throws IllegalArgumentException thrown if either the chunk or world is null.
|
||||
* @return
|
||||
*/
|
||||
public LodQuadTreeNode generateLodNodeFromChunk(IChunk chunk, LodBuilderConfig config) throws IllegalArgumentException {
|
||||
public LodQuadTreeNode generateLodNodeFromChunk(IChunk chunk, LodBuilderConfig config) throws IllegalArgumentException
|
||||
{
|
||||
if (chunk == null)
|
||||
throw new IllegalArgumentException("generateLodFromChunk given a null chunk");
|
||||
|
||||
// TODO startX/Z and endX/Z are relative coordinates
|
||||
// getMin/Max appears to return world block coordinates
|
||||
// getMin/Max appear to return world block coordinates
|
||||
int startX = 0; //chunk.getPos().getMinBlockX();
|
||||
int startZ = 0; //chunk.getPos().getMinBlockZ();
|
||||
int endX = 15; //chunk.getPos().getMaxBlockX();
|
||||
@@ -163,8 +165,7 @@ public class LodNodeBuilder {
|
||||
height = determineHeightPointForArea(chunk.getSections(), startX, startZ, endX, endZ);
|
||||
depth = determineBottomPointForArea(chunk.getSections(), startX, startZ, endX, endZ);
|
||||
|
||||
|
||||
return new LodQuadTreeNode(LodQuadTreeNode.CHUNK_LEVEL, chunk.getPos().x, chunk.getPos().z, new LodDataPoint(height, depth, color) , DistanceGenerationMode.SERVER);
|
||||
return new LodQuadTreeNode(LodQuadTreeNode.CHUNK_LEVEL, chunk.getPos().x, chunk.getPos().z, new LodDataPoint(height, depth, color), DistanceGenerationMode.SERVER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ public class LodNodeGenWorker implements IWorker
|
||||
// if we are in the end, don't generate any chunks.
|
||||
// Since we don't know where the islands are, everything
|
||||
// generates the same and it looks really bad.
|
||||
lod = new LodQuadTreeNode(LodQuadTreeNode.CHUNK_LEVEL,chunk.getPos().x, chunk.getPos().z);
|
||||
lod = lodChunkBuilder.generateLodNodeFromChunk(chunk, new LodBuilderConfig(true, true, false));
|
||||
}
|
||||
lodDim.addNode(lod);
|
||||
}
|
||||
|
||||
@@ -395,10 +395,10 @@ public class LodQuadTree
|
||||
int z = playerPos.getZ();
|
||||
|
||||
List<Integer> distances = new ArrayList<>();
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.startX, 2) + Math.pow(z - lodNode.startZ, 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.startX, 2) + Math.pow(z - lodNode.endZ, 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.endX, 2) + Math.pow(z - lodNode.startZ, 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.endX, 2) + Math.pow(z - lodNode.endZ, 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.startBlockPos.getX(), 2) + Math.pow(z - lodNode.startBlockPos.getZ(), 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.startBlockPos.getX(), 2) + Math.pow(z - lodNode.endBlockPos.getZ(), 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.endBlockPos.getX(), 2) + Math.pow(z - lodNode.startBlockPos.getZ(), 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.endBlockPos.getX(), 2) + Math.pow(z - lodNode.endBlockPos.getZ(), 2)));
|
||||
|
||||
int min = distances.stream().mapToInt(Integer::intValue).min().getAsInt();
|
||||
int max = distances.stream().mapToInt(Integer::intValue).max().getAsInt();
|
||||
@@ -449,10 +449,10 @@ public class LodQuadTree
|
||||
int z = playerPos.getZ();
|
||||
|
||||
List<Integer> distances = new ArrayList<>();
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.startX, 2) + Math.pow(z - lodNode.startZ, 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.startX, 2) + Math.pow(z - lodNode.endZ, 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.endX, 2) + Math.pow(z - lodNode.startZ, 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.endX, 2) + Math.pow(z - lodNode.endZ, 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.startBlockPos.getX(), 2) + Math.pow(z - lodNode.startBlockPos.getZ(), 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.startBlockPos.getX(), 2) + Math.pow(z - lodNode.endBlockPos.getZ(), 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.endBlockPos.getX(), 2) + Math.pow(z - lodNode.startBlockPos.getZ(), 2)));
|
||||
distances.add((int) Math.sqrt(Math.pow(x - lodNode.endBlockPos.getX(), 2) + Math.pow(z - lodNode.endBlockPos.getZ(), 2)));
|
||||
|
||||
int min = distances.stream().mapToInt(Integer::intValue).min().getAsInt();
|
||||
int max = distances.stream().mapToInt(Integer::intValue).max().getAsInt();
|
||||
@@ -522,10 +522,10 @@ public class LodQuadTree
|
||||
*/
|
||||
public boolean isCoordinateInQuadTree(BlockPos pos)
|
||||
{
|
||||
return (lodNode.startX * lodNode.width <= pos.getX() &&
|
||||
lodNode.startZ * lodNode.width <= pos.getZ() &&
|
||||
lodNode.endX * lodNode.width >= pos.getX() &&
|
||||
lodNode.endZ * lodNode.width >= pos.getZ());
|
||||
return (lodNode.startBlockPos.getX() * lodNode.width <= pos.getX() &&
|
||||
lodNode.startBlockPos.getZ() * lodNode.width <= pos.getZ() &&
|
||||
lodNode.endBlockPos.getX() * lodNode.width >= pos.getX() &&
|
||||
lodNode.endBlockPos.getZ() * lodNode.width >= pos.getZ());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ public class LodQuadTreeDimension
|
||||
*/
|
||||
public Boolean addNode(LodQuadTreeNode lodNode)
|
||||
{
|
||||
RegionPos regionPos = LodUtil.convertChunkPosToRegionPos(new ChunkPos(lodNode.centerX, lodNode.centerZ));
|
||||
RegionPos regionPos = LodUtil.convertChunkPosToRegionPos(new ChunkPos(lodNode.center.getX(), lodNode.center.getZ()));
|
||||
|
||||
// don't continue if the region can't be saved
|
||||
if (!regionIsInRange(regionPos.x, regionPos.z))
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Objects;
|
||||
import com.seibel.lod.enums.DistanceGenerationMode;
|
||||
import com.seibel.lod.handlers.LodQuadTreeDimensionFileHandler;
|
||||
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.gen.Heightmap;
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ import net.minecraft.world.gen.Heightmap;
|
||||
*
|
||||
* @author Leonardo Amato
|
||||
* @author James Seibel
|
||||
* @version 8-7-2021
|
||||
* @version 8-8-2021
|
||||
*/
|
||||
public class LodQuadTreeNode
|
||||
{
|
||||
@@ -87,9 +87,11 @@ public class LodQuadTreeNode
|
||||
/** detail level 0 */
|
||||
public static final short BLOCK_WIDTH = 1;
|
||||
|
||||
//this 2 values indicate the position of the LOD in the relative Level
|
||||
//this will be useful in the generation process
|
||||
// these 2 values indicate the position of the LOD in the relative Level
|
||||
// this will be useful in the generation process
|
||||
/** X position relative to the Quad tree. */
|
||||
public final int posX;
|
||||
/** Z position relative to the Quad tree */
|
||||
public final int posZ;
|
||||
|
||||
//these 4 value indicate the corner of the LOD block
|
||||
@@ -97,20 +99,17 @@ public class LodQuadTreeNode
|
||||
//the start values should always be smaller than the end values.
|
||||
//All this value could be calculated from level, posx and posz
|
||||
//so they could be removed and replaced with just a getter
|
||||
public final int startX;
|
||||
public final int startZ;
|
||||
public final int endX;
|
||||
public final int endZ;
|
||||
public final BlockPos startBlockPos;
|
||||
public final BlockPos endBlockPos;
|
||||
//these 2 value indicate the center of the LodNode in real coordinate. This
|
||||
//can be used to calculate the distance from the player
|
||||
public final int centerX;
|
||||
public final int centerZ;
|
||||
public final BlockPos center;
|
||||
|
||||
public LodDataPoint lodDataPoint;
|
||||
|
||||
//void node is used
|
||||
/** if true this node doesn't have any data */
|
||||
public boolean voidNode;
|
||||
//if dirty is true, then this node have unsaved changes
|
||||
/** if dirty is true, then this node have unsaved changes */
|
||||
public boolean dirty;
|
||||
|
||||
|
||||
@@ -122,17 +121,6 @@ public class LodQuadTreeNode
|
||||
* */
|
||||
|
||||
|
||||
/**
|
||||
* Creates and empty LodDataPoint
|
||||
* This LodDataPoint only contains the position data
|
||||
* @param detailLevel of the node
|
||||
* @param posX position x in the level
|
||||
* @param posZ position z in the level
|
||||
*/
|
||||
public LodQuadTreeNode(ChunkPos pos)
|
||||
{
|
||||
this(CHUNK_LEVEL, pos.x, pos.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and empty LodDataPoint
|
||||
@@ -150,13 +138,10 @@ public class LodQuadTreeNode
|
||||
|
||||
width = (short) Math.pow(2, detailLevel);
|
||||
|
||||
startX = posX * width;
|
||||
startZ = posZ * width;
|
||||
endX = startX + width - 1;
|
||||
endZ = startZ + width - 1;
|
||||
startBlockPos = new BlockPos(posX * width, 0, posZ * width);
|
||||
endBlockPos = new BlockPos(startBlockPos.getX() + width - 1, 0, startBlockPos.getZ() + width - 1);
|
||||
|
||||
centerX = startX + width/2;
|
||||
centerZ = startZ + width/2;
|
||||
center = new BlockPos(startBlockPos.getX() + width/2, 0, startBlockPos.getZ() + width/2);
|
||||
|
||||
lodDataPoint = new LodDataPoint();
|
||||
|
||||
@@ -214,13 +199,10 @@ public class LodQuadTreeNode
|
||||
|
||||
width = (short) Math.pow(2, detailLevel);
|
||||
|
||||
startX = posX * width;
|
||||
startZ = posZ * width;
|
||||
startBlockPos = new BlockPos(posX * width, 0, posZ * width);
|
||||
|
||||
endX = startX + width - 1;
|
||||
endZ = startZ + width - 1;
|
||||
centerX = startX + width/2;
|
||||
centerZ = startZ + width/2;
|
||||
endBlockPos = new BlockPos(startBlockPos.getX() + width - 1, 0, startBlockPos.getZ() + width - 1);
|
||||
center = new BlockPos(startBlockPos.getX() + width/2, 0, startBlockPos.getZ() + width/2);
|
||||
|
||||
this.lodDataPoint = lodDataPoint;
|
||||
this.complexity = complexity;
|
||||
@@ -279,18 +261,18 @@ public class LodQuadTreeNode
|
||||
|
||||
width = (short) Math.pow(2, detailLevel);
|
||||
|
||||
startX = posX * width;
|
||||
startZ = posZ * width;
|
||||
endX = startX + width - 1;
|
||||
endZ = startZ + width - 1;
|
||||
startBlockPos = new BlockPos(posX * width, 0, posZ * width);
|
||||
endBlockPos = new BlockPos(startBlockPos.getX() + width - 1, 0, startBlockPos.getZ() + width - 1);
|
||||
|
||||
centerX = startX + width/2;
|
||||
centerZ = startZ + width/2;
|
||||
center = new BlockPos(startBlockPos.getX() + width/2, 0, startBlockPos.getZ() + width/2);
|
||||
|
||||
dirty = false;
|
||||
dontSave = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void update(LodQuadTreeNode lodQuadTreeNode)
|
||||
{
|
||||
this.lodDataPoint = lodQuadTreeNode.lodDataPoint;
|
||||
@@ -394,7 +376,7 @@ public class LodQuadTreeNode
|
||||
+ Integer.toString(lodDataPoint.color.getGreen()) + DATA_DELIMITER
|
||||
+ Integer.toString(lodDataPoint.color.getBlue()) + DATA_DELIMITER
|
||||
+ Integer.toString(lodDataPoint.color.getAlpha()) + DATA_DELIMITER
|
||||
+ Integer.toString(voidNode ? 1 : 0) + DATA_DELIMITER;
|
||||
+ Integer.toString(voidNode ? 1 : 0);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user