diff --git a/src/main/java/com/seibel/lod/Main.java b/src/main/java/com/seibel/lod/Main.java index 6103df2f5..639c8cbcb 100644 --- a/src/main/java/com/seibel/lod/Main.java +++ b/src/main/java/com/seibel/lod/Main.java @@ -15,10 +15,10 @@ public class Main { Map adjData = new HashMap() {{ - put(Direction.EAST, new long[]{DataPointUtil.createDataPoint(70, 50, 0, 0, 0, 0), DataPointUtil.createDataPoint(45, 30, 0, 0, 0, 0), DataPointUtil.createDataPoint(28, 25, 0, 0, 0, 0)}); - put(Direction.WEST, new long[]{DataPointUtil.createDataPoint(70, 10, 0, 0, 0, 0)}); - put(Direction.NORTH, new long[]{DataPointUtil.createDataPoint(50, 0, 0, 0, 0, 0)}); - put(Direction.SOUTH, new long[]{DataPointUtil.createDataPoint(50, 30, 0, 0, 0, 0)}); + put(Direction.EAST, new long[]{DataPointUtil.createDataPoint(40, 20, 0, 0, 0, 0)}); + put(Direction.WEST, new long[]{DataPointUtil.createDataPoint(40, 20, 0, 0, 0, 0)}); + put(Direction.NORTH, new long[]{DataPointUtil.createDataPoint(40, 20, 0, 0, 0, 0)}); + put(Direction.SOUTH, new long[]{DataPointUtil.createDataPoint(40, 20, 0, 0, 0, 0)}); }}; Box box = new Box(); diff --git a/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java b/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java index 211b34722..eafcb534b 100644 --- a/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java @@ -223,9 +223,9 @@ public class LodBufferBuilder final int zR = zRegion; Callable dataToRenderThread = () -> { - Map adjData = new HashMap<>(); - if(LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP){ + if (LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP) + { adjData.put(Direction.WEST, new long[1]); adjData.put(Direction.EAST, new long[1]); adjData.put(Direction.SOUTH, new long[1]); @@ -259,7 +259,6 @@ public class LodBufferBuilder int chunkZdist; short gameChunkRenderDistance = (short) (renderer.vanillaRenderedChunks.length / 2 - 1); //long dataPoint; - for (int index = 0; index < posToRender.getNumberOfPos(); index++) { detailLevel = posToRender.getNthDetailLevel(index); @@ -278,32 +277,32 @@ public class LodBufferBuilder // skip any chunks that Minecraft is going to render try { - for (Direction direction : Box.ADJ_DIRECTIONS) { - - xAdj = posX + direction.getNormal().getX(); zAdj = posZ + direction.getNormal().getZ(); - chunkXdist = LevelPosUtil.getChunkPos(detailLevel,xAdj) - playerChunkPos.x; - chunkZdist = LevelPosUtil.getChunkPos(detailLevel,zAdj) - playerChunkPos.z; + chunkXdist = LevelPosUtil.getChunkPos(detailLevel, xAdj) - playerChunkPos.x; + chunkZdist = LevelPosUtil.getChunkPos(detailLevel, zAdj) - playerChunkPos.z; if (gameChunkRenderDistance >= Math.abs(chunkXdist) && gameChunkRenderDistance >= Math.abs(chunkZdist)) { if (!renderer.vanillaRenderedChunks[chunkXdist + gameChunkRenderDistance + 1][chunkZdist + gameChunkRenderDistance + 1] && posToRender.contains(detailLevel, xAdj, zAdj)) { - if(LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP){ + if (LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP) + { adjData.get(direction)[0] = lodDim.getSingleData(detailLevel, xAdj, zAdj); - }else + } else { adjData.put(direction, lodDim.getData(detailLevel, xAdj, zAdj)); } - }else{ - if(LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP){ + } else + { + if (LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP) + { adjData.get(direction)[0] = DataPointUtil.createVoidDataPoint(0); - }else + } else { adjData.put(direction, null); } @@ -312,24 +311,26 @@ public class LodBufferBuilder { if (posToRender.contains(detailLevel, xAdj, zAdj)) { - if(LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP){ + if (LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP) + { adjData.get(direction)[0] = lodDim.getSingleData(detailLevel, xAdj, zAdj); - }else + } else { adjData.put(direction, lodDim.getData(detailLevel, xAdj, zAdj)); } - }else{ + } else + { - if(LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP){ + if (LodConfig.CLIENT.worldGenerator.lodQualityMode.get() == LodQualityMode.HEIGHTMAP) + { adjData.get(direction)[0] = DataPointUtil.createVoidDataPoint(0); - }else + } else { adjData.put(direction, null); } } } } - if (region.getLodQualityMode() == LodQualityMode.HEIGHTMAP) { //dataPoint = lodDim.getData(detailLevel, posX, posZ)[0]; @@ -337,7 +338,7 @@ public class LodBufferBuilder if (!DataPointUtil.isItVoid(dataPoint) && DataPointUtil.doesItExist(dataPoint)) { LodConfig.CLIENT.graphics.lodTemplate.get().template.addLodToBuffer(currentBuffer, playerBlockPosRounded, dataPoint, adjData, - detailLevel, posX, posZ, boxCache[xR][zR],renderer.previousDebugMode, renderer.lightMap); + detailLevel, posX, posZ, boxCache[xR][zR], renderer.previousDebugMode, renderer.lightMap); } } else if (region.getLodQualityMode() == LodQualityMode.MULTI_LOD) @@ -347,7 +348,7 @@ public class LodBufferBuilder if (!DataPointUtil.isItVoid(dataPoint) && DataPointUtil.doesItExist(dataPoint)) { LodConfig.CLIENT.graphics.lodTemplate.get().template.addLodToBuffer(currentBuffer, playerBlockPosRounded, dataPoint, adjData, - detailLevel, posX, posZ, boxCache[xR][zR], renderer.previousDebugMode, renderer.lightMap); + detailLevel, posX, posZ, boxCache[xR][zR], renderer.previousDebugMode, renderer.lightMap); } } } @@ -395,13 +396,11 @@ public class LodBufferBuilder // mark that the buildable buffers as ready to swap switchVbos = true; - } - catch (Exception e) + } catch (Exception e) { ClientProxy.LOGGER.warn("\"LodNodeBufferBuilder.generateLodBuffersAsync\" ran into trouble: "); e.printStackTrace(); - } - finally + } finally { // regardless of if we successfully created the buffers // we are done generating. @@ -540,8 +539,7 @@ public class LodBufferBuilder // this probably is necessary, but it makes me feel good :) GL11.glFlush(); glProxy.setGlContext(GlProxyContext.NONE); - } - catch(IllegalStateException e) + } catch (IllegalStateException e) { ClientProxy.LOGGER.error(LodBufferBuilder.class.getSimpleName() + " - UploadBuffers failed: " + e.getMessage()); e.printStackTrace(); diff --git a/src/main/java/com/seibel/lod/builders/lodTemplates/Box.java b/src/main/java/com/seibel/lod/builders/lodTemplates/Box.java index c3093b325..5466e9417 100644 --- a/src/main/java/com/seibel/lod/builders/lodTemplates/Box.java +++ b/src/main/java/com/seibel/lod/builders/lodTemplates/Box.java @@ -84,15 +84,8 @@ public class Box public int[][] box; public Map colorMap; - public Map adjData; public int color; - public Map adjHeightAndDepth = new HashMap() - {{ - put(Direction.EAST, new int[256][2]); - put(Direction.WEST, new int[256][2]); - put(Direction.SOUTH, new int[256][2]); - put(Direction.NORTH, new int[256][2]); - }}; + public Map adjHeightAndDepth; public Box() { @@ -106,6 +99,13 @@ public class Box put(Direction.SOUTH, new int[1]); put(Direction.NORTH, new int[1]); }}; + adjHeightAndDepth = new HashMap() + {{ + put(Direction.EAST, new int[256][2]); + put(Direction.WEST, new int[256][2]); + put(Direction.SOUTH, new int[256][2]); + put(Direction.NORTH, new int[256][2]); + }}; } public void setColor(int color) @@ -128,15 +128,33 @@ public class Box } } + public void reset() + { + for(int i = 0; i < box.length; i++){ + for(int j = 0; j < box[i].length; j++){ + box[i][j] = 0; + } + } + for(Direction direction : DIRECTIONS) + { + colorMap.get(direction)[0] = 0; + } + + for(Direction direction : ADJ_DIRECTIONS) + { + for(int i = 0; i < adjHeightAndDepth.get(direction).length; i++) + { + adjHeightAndDepth.get(direction)[i][0] = VOID_FACE; + adjHeightAndDepth.get(direction)[i][1] = VOID_FACE; + } + } + } public void setAdjData(Map adjData) { int height; int depth; - this.adjData = adjData; - for (Direction direction : ADJ_DIRECTIONS) { - boolean noMatch = true; long[] dataPoint = adjData.get(direction); if (dataPoint == null) { @@ -152,13 +170,13 @@ public class Box boolean toFinish = false; for (i = 0; i < dataPoint.length; i++) { - - if (DataPointUtil.isItVoid(dataPoint[i])) + long singleDataPoint = dataPoint[i]; + if (DataPointUtil.isItVoid(singleDataPoint)) { continue; } - height = DataPointUtil.getHeight(dataPoint[i]); - depth = DataPointUtil.getDepth(dataPoint[i]); + height = DataPointUtil.getHeight(singleDataPoint); + depth = DataPointUtil.getDepth(singleDataPoint); if (depth > getMaxY()) {//the adj data is higher than the current data @@ -233,7 +251,7 @@ public class Box continue; } } - if(toFinish) + if (toFinish) { adjHeightAndDepth.get(direction)[faceToDraw][1] = getMinY(); faceToDraw++; @@ -271,6 +289,11 @@ public class Box return box[OFFSET][X] + box[WIDTH][X] * DIRECTION_VERTEX_MAP.get(direction)[vertexIndex][X]; } + public int getY(Direction direction, int vertexIndex) + { + return box[OFFSET][Y] + box[WIDTH][Y] * DIRECTION_VERTEX_MAP.get(direction)[vertexIndex][Y]; + } + public int getY(Direction direction, int vertexIndex, int adjIndex) { if (direction == Direction.DOWN || direction == Direction.UP) diff --git a/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java b/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java index 9a0b64c1b..43f75fe83 100644 --- a/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java +++ b/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java @@ -51,6 +51,13 @@ public class CubicLodTemplate extends AbstractLodTemplate int color = DataPointUtil.getLightColor(data,lightMap); // add each LOD for the detail level + + if (debugging != DebugMode.OFF) + + { + color = LodUtil.DEBUG_DETAIL_LEVEL_COLORS[detailLevel].getRGB(); + } + generateBoundingBox( box, DataPointUtil.getHeight(data), @@ -63,15 +70,6 @@ public class CubicLodTemplate extends AbstractLodTemplate adjData, color); - //color = DataPointUtil.getColor(data); - - - if (debugging != DebugMode.OFF) - - { - color = LodUtil.DEBUG_DETAIL_LEVEL_COLORS[detailLevel].getRGB(); - } - if (box != null) { @@ -98,10 +96,11 @@ public class CubicLodTemplate extends AbstractLodTemplate // which only uses floats double x = -bufferCenterBlockPos.getX(); double z = -bufferCenterBlockPos.getZ(); - box.setAdjData(adjData); + box.reset(); box.setColor(color); box.set(width, height - depth, width); box.move((int) (xOffset + x), (int) (yOffset + depth), (int) (zOffset + z)); + box.setAdjData(adjData); } private void addBoundingBoxToBuffer(BufferBuilder buffer, Box box)