diff --git a/src/main/java/com/seibel/lod/builders/bufferBuilding/LodBufferBuilder.java b/src/main/java/com/seibel/lod/builders/bufferBuilding/LodBufferBuilder.java index e886b99da..9fffc8f45 100644 --- a/src/main/java/com/seibel/lod/builders/bufferBuilding/LodBufferBuilder.java +++ b/src/main/java/com/seibel/lod/builders/bufferBuilding/LodBufferBuilder.java @@ -239,6 +239,8 @@ public class LodBufferBuilder final int xR = xRegion; final int zR = zRegion; + + //we create the Callable to use for the buffer builder creation Callable dataToRenderThread = () -> { Map adjData = new HashMap<>(); @@ -284,6 +286,8 @@ public class LodBufferBuilder short gameChunkRenderDistance = (short) (vanillaRenderedChunks.length / 2 - 1); boolean smallRenderDistance = gameChunkRenderDistance <= 4; + + for (int index = 0; index < posToRender.getNumberOfPos(); index++) { bufferIndex = Math.floorMod(index, currentBuffers.length); @@ -308,8 +312,8 @@ public class LodBufferBuilder // skip any chunks that Minecraft is going to render for (Direction direction : Box.ADJ_DIRECTIONS) { - xAdj = posX + direction.getNormal().getX(); - zAdj = posZ + direction.getNormal().getZ(); + xAdj = posX + Box.DIRECTION_NORMAL_MAP.get(direction).getX(); + zAdj = posZ + Box.DIRECTION_NORMAL_MAP.get(direction).getZ(); chunkXdist = LevelPosUtil.getChunkPos(detailLevel, xAdj) - playerChunkPos.x; chunkZdist = LevelPosUtil.getChunkPos(detailLevel, zAdj) - playerChunkPos.z; if (posToRender.contains(detailLevel, xAdj, zAdj) @@ -353,7 +357,11 @@ public class LodBufferBuilder // the thread executed successfully return true; }; + + nodeToRenderThreads.add(dataToRenderThread); + + } } // region z } // region z diff --git a/src/main/java/com/seibel/lod/builders/bufferBuilding/lodTemplates/Box.java b/src/main/java/com/seibel/lod/builders/bufferBuilding/lodTemplates/Box.java index e0e71f1d2..22843140b 100644 --- a/src/main/java/com/seibel/lod/builders/bufferBuilding/lodTemplates/Box.java +++ b/src/main/java/com/seibel/lod/builders/bufferBuilding/lodTemplates/Box.java @@ -12,6 +12,8 @@ import com.seibel.lod.wrappers.MinecraftWrapper; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.vector.Vector3i; /** * Similar to Minecraft's AxisAlignedBoundingBox. @@ -50,7 +52,9 @@ public class Box Direction.SOUTH, Direction.NORTH}; - /** TODO what does this represent? I don't understand the name */ + /** + * All the faces and vertex of a cube. This is used to extract the vertex of the column + */ @SuppressWarnings("serial") public static final Map DIRECTION_VERTEX_MAP = new HashMap() {{ @@ -87,6 +91,10 @@ public class Box }}; + /** + * This indicate which position is invariable in the DIRECTION_VERTEX_MAP. + * Is used to extract the vertex + */ @SuppressWarnings("serial") public static final Map FACE_DIRECTION = new HashMap() {{ @@ -99,17 +107,23 @@ public class Box }}; - @SuppressWarnings("serial") - public static final Map DIRECTION_NORMAL_MAP = new HashMap() + /** + * This is a map from Direction to the relative normal vector + * we are using this since i'm not sure if the getNormal create new object at every call + */ + public static final Map DIRECTION_NORMAL_MAP = new HashMap() {{ - put(Direction.UP, new int[]{0, 1, 0}); - put(Direction.DOWN, new int[]{0, -1, 0}); - put(Direction.EAST, new int[]{1, 0, 0}); - put(Direction.WEST, new int[]{-1, 0, 0}); - put(Direction.SOUTH, new int[]{0, 0, 1}); - put(Direction.NORTH, new int[]{0, 0, -1}); + put(Direction.UP, Direction.UP.getNormal()); + put(Direction.DOWN, Direction.DOWN.getNormal()); + put(Direction.EAST, Direction.EAST.getNormal()); + put(Direction.WEST, Direction.WEST.getNormal()); + put(Direction.SOUTH, Direction.SOUTH.getNormal()); + put(Direction.NORTH, Direction.NORTH.getNormal()); }}; + /** + * We use this index for all array that are going to + */ public static final Map DIRECTION_INDEX = new HashMap() {{ put(Direction.UP, 0); @@ -141,7 +155,7 @@ public class Box public Map adjDepth; /** Holds if the given direction should be culled or not */ - public Map culling; + public boolean[] culling; /** creates a empty box */ @@ -169,19 +183,15 @@ public class Box put(Direction.NORTH, new int[32]); }}; - culling = new HashMap() - {{ - put(Direction.UP, false); - put(Direction.DOWN, false); - put(Direction.EAST, false); - put(Direction.WEST, false); - put(Direction.SOUTH, false); - put(Direction.NORTH, false); - }}; + culling = new boolean[6]; } - + /** + * Set the color of the columns + * @param color color to add + * @param adjShadeDisabled this array indicate which face does not need shading + */ public void setColor(int color, boolean[] adjShadeDisabled) { this.color = color; @@ -194,6 +204,10 @@ public class Box } } + /** + * @param direction of the face of which we want to get the color + * @return color of the face + */ public int getColor(Direction direction) { if (LodConfig.CLIENT.debugging.debugMode.get() != DebugMode.SHOW_DETAIL) @@ -237,20 +251,29 @@ public class Box { if (direction == Direction.DOWN || direction == Direction.WEST || direction == Direction.NORTH) { - culling.put(direction, playerPos.get(direction.getAxis()) > getFacePos(direction) + cullingDistance); + culling[DIRECTION_INDEX.get(direction)] = playerPos.get(direction.getAxis()) > getFacePos(direction) + cullingDistance; } else if (direction == Direction.UP || direction == Direction.EAST || direction == Direction.SOUTH) { - culling.put(direction, playerPos.get(direction.getAxis()) < getFacePos(direction) - cullingDistance); + culling[DIRECTION_INDEX.get(direction)] = playerPos.get(direction.getAxis()) < getFacePos(direction) - cullingDistance; } } } + /** + * @param direction direction that we want to check if it's culled + * @return true if and only if the face of the direction is culled + */ public boolean isCulled(Direction direction) { - return culling.get(direction); + return culling[DIRECTION_INDEX.get(direction)]; } + + /** + * This method create all the shared face culling based on the adjacent data + * @param adjData data adjacent to the column we are going to render + */ public void setAdjData(Map adjData) { int height; @@ -361,11 +384,6 @@ public class Box toFinish = true; } } - //else - //{ - // // the adj data is higher than the current data - // // we continue since there could be some other data that intersect the current - //} } if(allAbove) @@ -385,6 +403,12 @@ public class Box } } + /** + * We use this method to set the various width of the column + * @param xWidth + * @param yWidth + * @param zWidth + */ public void setWidth(int xWidth, int yWidth, int zWidth) { boxWidth[X] = xWidth; @@ -392,6 +416,12 @@ public class Box boxWidth[Z] = zWidth; } + /** + * We use this method to set the various offset of the column + * @param xOffset + * @param yOffset + * @param zOffset + */ public void setOffset(int xOffset, int yOffset, int zOffset) { boxOffset[X] = xOffset; @@ -399,19 +429,17 @@ public class Box boxOffset[Z] = zOffset; } - - // TODO what does this mean? + /** + * This method return the position of a face in the axis of the face + * This is usefull for the face culling + * @param direction that we want to check + * @return position in the axis of the face + */ public int getFacePos(Direction direction) { return boxOffset[FACE_DIRECTION.get(direction)[0]] + boxWidth[FACE_DIRECTION.get(direction)[0]] * FACE_DIRECTION.get(direction)[1]; } - // TODO is this still needed? -// public int getCoord(Direction direction, int axis, int vertexIndex) -// { -// return box[OFFSET][axis] + boxWidth[axis] * DIRECTION_VERTEX_MAP.get(direction)[vertexIndex][axis]; -// } - /** * returns true if the given direction should be rendered. */ @@ -425,21 +453,35 @@ public class Box } - - - // TODO what does vertexIndex mean, is it 0-3 and represent - // the 4 vertices in the quad we send to the bufferBuilder? - + /** + * + * @param direction direction of the face we want to render + * @param vertexIndex index of the vertex of the face (0-1-2-3) + * @return position x of the relative vertex + */ public int getX(Direction direction, int vertexIndex) { return boxOffset[X] + boxWidth[X] * DIRECTION_VERTEX_MAP.get(direction)[vertexIndex][X]; } + /** + * + * @param direction direction of the face we want to render + * @param vertexIndex index of the vertex of the face (0-1-2-3) + * @return position y of the relative vertex + */ public int getY(Direction direction, int vertexIndex) { return boxOffset[Y] + boxWidth[Y] * DIRECTION_VERTEX_MAP.get(direction)[vertexIndex][Y]; } + /** + * + * @param direction direction of the face we want to render + * @param vertexIndex index of the vertex of the face (0-1-2-3) + * @param adjIndex, index of the n-th culled face of this direction + * @return position x of the relative vertex + */ public int getY(Direction direction, int vertexIndex, int adjIndex) { if (direction == Direction.DOWN || direction == Direction.UP) @@ -461,6 +503,12 @@ public class Box } } + /** + * + * @param direction direction of the face we want to render + * @param vertexIndex index of the vertex of the face (0-1-2-3) + * @return position z of the relative vertex + */ public int getZ(Direction direction, int vertexIndex) { return boxOffset[Z] + boxWidth[Z] * DIRECTION_VERTEX_MAP.get(direction)[vertexIndex][Z]; diff --git a/src/main/java/com/seibel/lod/objects/LodRegion.java b/src/main/java/com/seibel/lod/objects/LodRegion.java index a4f744196..c8fb48944 100644 --- a/src/main/java/com/seibel/lod/objects/LodRegion.java +++ b/src/main/java/com/seibel/lod/objects/LodRegion.java @@ -24,14 +24,13 @@ import com.seibel.lod.util.LodUtil; public class LodRegion { /** - * TODO what does this represent, and should it be defined here? + * Number of detail level supported by a region */ private static final byte POSSIBLE_LOD = 10; /** * Holds the lowest (least detailed) detail level in this region - * TODO is that correct? */ private byte minDetailLevel; @@ -42,7 +41,6 @@ public class LodRegion /** * the generation mode for this region - * TODO will this ever change through a region's life? */ private DistanceGenerationMode generationMode; /** diff --git a/src/main/java/com/seibel/lod/util/LodUtil.java b/src/main/java/com/seibel/lod/util/LodUtil.java index f72b02fc8..1faa87f61 100644 --- a/src/main/java/com/seibel/lod/util/LodUtil.java +++ b/src/main/java/com/seibel/lod/util/LodUtil.java @@ -506,8 +506,8 @@ public class LodUtil int tempZ; for (Direction direction : Box.ADJ_DIRECTIONS) { - tempX = x + direction.getNormal().getX(); - tempZ = z + direction.getNormal().getZ(); + tempX = x + Box.DIRECTION_NORMAL_MAP.get(direction).getX(); + tempZ = z + Box.DIRECTION_NORMAL_MAP.get(direction).getZ(); if (!(tempX < 0 || tempZ < 0 || tempX >= vanillaRenderedChunks.length || tempZ >= vanillaRenderedChunks[0].length)) { if (!vanillaRenderedChunks[tempX][tempZ])