diff --git a/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java b/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java index 486932a3b..48cd3a071 100644 --- a/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java @@ -57,7 +57,6 @@ public class LodBufferBuilder private ExecutorService mainGenThread = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName() + " - main")); /** This holds the threads used to generate buffers. */ private ExecutorService bufferBuilderThreads = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new LodThreadFactory(this.getClass().getSimpleName() + " - builder")); - //private ExecutorService bufferBuilderThreads = Executors.newFixedThreadPool(2, new LodThreadFactory(this.getClass().getSimpleName() + " - builder")); /** The buffers that are used to create LODs using far fog */ public volatile BufferBuilder[][] buildableBuffers; @@ -171,7 +170,7 @@ public class LodBufferBuilder { byte detailToRender; boolean zFix; - Set posListToRender = new HashSet<>(); + Set setOfPosToRender = new HashSet<>(); for (byte detail = detailLevel; detail <= LodUtil.REGION_DETAIL_LEVEL; detail++) { @@ -182,7 +181,7 @@ public class LodBufferBuilder detailToRender = detail; zFix = true; } - posListToRender.addAll(lodDim.getDataToRender( + setOfPosToRender.addAll(lodDim.getDataToRender( regionPos, playerBlockPosRounded.getX(), playerBlockPosRounded.getZ(), @@ -193,9 +192,9 @@ public class LodBufferBuilder } - for (LevelPos pos : posListToRender) + for (LevelPos posToRender : setOfPosToRender) { - LevelPos chunkPos = pos.convert(LodUtil.CHUNK_DETAIL_LEVEL); + LevelPos chunkPos = posToRender.convert(LodUtil.CHUNK_DETAIL_LEVEL); // skip any chunks that Minecraft is going to render if (renderer.vanillaRenderedChunks.contains(new ChunkPos(chunkPos.posX, chunkPos.posZ))) @@ -203,17 +202,37 @@ public class LodBufferBuilder continue; } - if (lodDim.doesDataExist(pos)) + if (lodDim.doesDataExist(posToRender)) { try { - int width = (int) Math.pow(2, pos.detailLevel); - LodDataPoint lodData = lodDim.getData(pos); + LodDataPoint lodData = lodDim.getData(posToRender); if (lodData != null) { - LodConfig.CLIENT.lodTemplate.get().template.addLodToBuffer(currentBuffer, lodDim, lodData, - pos.posX * width, 0, pos.posZ * width, renderer.debugging, pos.detailLevel); + /*We check for adjacent data*/ + LodDataPoint[][] adjData = new LodDataPoint[2][2]; + LevelPos adjPos; + for(int x : new int[]{0,1}){ + adjPos = new LevelPos(posToRender.detailLevel, posToRender.posX + x*2-1, posToRender.posZ); + adjData[0][x] = lodDim.getData(adjPos);/* + if(setOfPosToRender.contains(adjPos)){ + System.out.println("yup"); + adjData[0][x] = lodDim.getData(adjPos); + }*/ + } + + for(int z : new int[]{0,1}){ + adjPos = new LevelPos(posToRender.detailLevel, posToRender.posX, posToRender.posZ + z*2-1); + adjData[1][z] = lodDim.getData(adjPos);/* + if(setOfPosToRender.contains(adjPos)){ + System.out.println("yup2"); + adjData[1][z] = lodDim.getData(adjPos); + }*/ + } + + LodConfig.CLIENT.lodTemplate.get().template.addLodToBuffer(currentBuffer, playerBlockPos, lodData, adjData, + posToRender, renderer.debugging); } } catch (ArrayIndexOutOfBoundsException e) diff --git a/src/main/java/com/seibel/lod/builders/lodTemplates/AbstractLodTemplate.java b/src/main/java/com/seibel/lod/builders/lodTemplates/AbstractLodTemplate.java index aecdf2ada..264245ed1 100644 --- a/src/main/java/com/seibel/lod/builders/lodTemplates/AbstractLodTemplate.java +++ b/src/main/java/com/seibel/lod/builders/lodTemplates/AbstractLodTemplate.java @@ -18,13 +18,16 @@ package com.seibel.lod.builders.lodTemplates; import java.awt.Color; +import java.util.Set; import com.seibel.lod.enums.LodDetail; +import com.seibel.lod.objects.LevelPos; import com.seibel.lod.objects.LodDataPoint; import com.seibel.lod.objects.LodDimension; import com.seibel.lod.util.LodUtil; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.util.math.BlockPos; /** * This is the abstract class used to create different @@ -35,10 +38,8 @@ import net.minecraft.client.renderer.BufferBuilder; */ public abstract class AbstractLodTemplate { - public abstract void addLodToBuffer(BufferBuilder buffer, - LodDimension lodDim, LodDataPoint lod, - double xOffset, double yOffset, double zOffset, - boolean debugging, byte detail); + public abstract void addLodToBuffer(BufferBuilder buffer, BlockPos playerBlockPos, LodDataPoint data, LodDataPoint[][] adjData, + LevelPos levelPos, boolean debugging); /** add the given position and color to the buffer */ protected void addPosAndColor(BufferBuilder buffer, 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 8747294ed..983d58f1b 100644 --- a/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java +++ b/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java @@ -19,15 +19,15 @@ package com.seibel.lod.builders.lodTemplates; import java.awt.Color; -import com.seibel.lod.enums.LodDetail; import com.seibel.lod.enums.ShadingMode; import com.seibel.lod.handlers.LodConfig; +import com.seibel.lod.objects.LevelPos; import com.seibel.lod.objects.LodDataPoint; -import com.seibel.lod.objects.LodDimension; import com.seibel.lod.util.LodUtil; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; /** * Builds LODs as rectangular prisms. @@ -37,142 +37,263 @@ import net.minecraft.util.math.AxisAlignedBB; */ public class CubicLodTemplate extends AbstractLodTemplate { - public CubicLodTemplate() - { - } + public CubicLodTemplate() + { - @Override - public void addLodToBuffer(BufferBuilder buffer, - LodDimension lodDim, LodDataPoint lod, - double xOffset, double yOffset, double zOffset, - boolean debugging, byte detail) - { - AxisAlignedBB bbox; + } - // add each LOD for the detail level - bbox = generateBoundingBox( - lod.height, - lod.depth, - (int) Math.pow(2, detail), - xOffset, - yOffset, - zOffset); + @Override + public void addLodToBuffer(BufferBuilder buffer, BlockPos playerBlockPos, LodDataPoint data, LodDataPoint[][] adjData, + LevelPos levelPos, boolean debugging) + { + AxisAlignedBB bbox; - Color color = lod.color; - if (LodConfig.CLIENT.debugMode.get()) - { - color = LodUtil.DEBUG_DETAIL_LEVEL_COLORS[detail]; - } + int width = (int) Math.pow(2, levelPos.detailLevel); - if (bbox != null) - { - addBoundingBoxToBuffer(buffer, bbox, color); - } + // add each LOD for the detail level + bbox = generateBoundingBox( + data.height, + data.depth, + width, + levelPos.posX * width, + 0, + levelPos.posZ * width); - } + Color color = data.color; + if (LodConfig.CLIENT.debugMode.get()) + { + color = LodUtil.DEBUG_DETAIL_LEVEL_COLORS[levelPos.detailLevel]; + } - /* - * @Override public void addLodToBuffer(BufferBuilder buffer, - * LodQuadTreeDimension lodDim, LodQuadTreeNode lod, double xOffset, double - * yOffset, double zOffset, boolean debugging) { AxisAlignedBB bbox; - * - * bbox = generateBoundingBox( lod.getLodDataPoint().height, - * lod.getLodDataPoint().depth, lod.width, xOffset, yOffset, zOffset); - * - * Color color = lod.getLodDataPoint().color; - * - * if (bbox != null) { addBoundingBoxToBuffer(buffer, bbox, color); } - * - * } - */ + if (bbox != null) + { + addBoundingBoxToBuffer(buffer, bbox, color, playerBlockPos, adjData); + } - private AxisAlignedBB generateBoundingBox(int height, int depth, int width, double xOffset, double yOffset, double zOffset) - { - // don't add an LOD if it is empty - if (height == -1 && depth == -1) - return null; + } - if (depth == height) - { - // if the top and bottom points are at the same height - // render this LOD as 1 block thick - height++; - } + /* + * @Override public void addLodToBuffer(BufferBuilder buffer, + * LodQuadTreeDimension lodDim, LodQuadTreeNode lod, double xOffset, double + * yOffset, double zOffset, boolean debugging) { AxisAlignedBB bbox; + * + * bbox = generateBoundingBox( lod.getLodDataPoint().height, + * lod.getLodDataPoint().depth, lod.width, xOffset, yOffset, zOffset); + * + * Color color = lod.getLodDataPoint().color; + * + * if (bbox != null) { addBoundingBoxToBuffer(buffer, bbox, color); } + * + * } + */ - return new AxisAlignedBB(0, depth, 0, width, height, width).move(xOffset, yOffset, zOffset); - } + private AxisAlignedBB generateBoundingBox(int height, int depth, int width, double xOffset, double yOffset, double zOffset) + { + // don't add an LOD if it is empty + if (height == -1 && depth == -1) + return null; - private void addBoundingBoxToBuffer(BufferBuilder buffer, AxisAlignedBB bb, Color c) - { - Color topColor = c; - Color northSouthColor = c; - Color eastWestColor = c; - Color bottomColor = c; + if (depth == height) + { + // if the top and bottom points are at the same height + // render this LOD as 1 block thick + height++; + } - // darken the bottom and side colors if requested - if (LodConfig.CLIENT.shadingMode.get() == ShadingMode.DARKEN_SIDES) - { - // the side colors are different because - // when using fast lighting in Minecraft the north/south - // and east/west sides are different in a similar way - int northSouthDarkenAmount = 25; - int eastWestDarkenAmount = 50; - int bottomDarkenAmount = 75; + return new AxisAlignedBB(0, depth, 0, width, height, width).move(xOffset, yOffset, zOffset); + } - northSouthColor = new Color(Math.max(0, c.getRed() - northSouthDarkenAmount), Math.max(0, c.getGreen() - northSouthDarkenAmount), Math.max(0, c.getBlue() - northSouthDarkenAmount), c.getAlpha()); - eastWestColor = new Color(Math.max(0, c.getRed() - eastWestDarkenAmount), Math.max(0, c.getGreen() - eastWestDarkenAmount), Math.max(0, c.getBlue() - eastWestDarkenAmount), c.getAlpha()); - bottomColor = new Color(Math.max(0, c.getRed() - bottomDarkenAmount), Math.max(0, c.getGreen() - bottomDarkenAmount), Math.max(0, c.getBlue() - bottomDarkenAmount), c.getAlpha()); - } + private void addBoundingBoxToBuffer(BufferBuilder buffer, AxisAlignedBB bb, Color c, BlockPos playerBlockPos, LodDataPoint[][] adjData) + { + Color topColor = c; + Color northSouthColor = c; + Color eastWestColor = c; + Color bottomColor = c; - // apply the user specified saturation and brightness - float saturationMultiplier = LodConfig.CLIENT.saturationMultiplier.get().floatValue(); - float brightnessMultiplier = LodConfig.CLIENT.brightnessMultiplier.get().floatValue(); + // darken the bottom and side colors if requested + if (LodConfig.CLIENT.shadingMode.get() == ShadingMode.DARKEN_SIDES) + { + // the side colors are different because + // when using fast lighting in Minecraft the north/south + // and east/west sides are different in a similar way + int northSouthDarkenAmount = 25; + int eastWestDarkenAmount = 50; + int bottomDarkenAmount = 75; - topColor = applySaturationAndBrightnessMultipliers(topColor, saturationMultiplier, brightnessMultiplier); - northSouthColor = applySaturationAndBrightnessMultipliers(northSouthColor, saturationMultiplier, brightnessMultiplier); - bottomColor = applySaturationAndBrightnessMultipliers(bottomColor, saturationMultiplier, brightnessMultiplier); + northSouthColor = new Color(Math.max(0, c.getRed() - northSouthDarkenAmount), Math.max(0, c.getGreen() - northSouthDarkenAmount), Math.max(0, c.getBlue() - northSouthDarkenAmount), c.getAlpha()); + eastWestColor = new Color(Math.max(0, c.getRed() - eastWestDarkenAmount), Math.max(0, c.getGreen() - eastWestDarkenAmount), Math.max(0, c.getBlue() - eastWestDarkenAmount), c.getAlpha()); + bottomColor = new Color(Math.max(0, c.getRed() - bottomDarkenAmount), Math.max(0, c.getGreen() - bottomDarkenAmount), Math.max(0, c.getBlue() - bottomDarkenAmount), c.getAlpha()); + } - // top (facing up) - addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()); - // bottom (facing down) - addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()); + // apply the user specified saturation and brightness + float saturationMultiplier = LodConfig.CLIENT.saturationMultiplier.get().floatValue(); + float brightnessMultiplier = LodConfig.CLIENT.brightnessMultiplier.get().floatValue(); - // south (facing -Z) - addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); - // north (facing +Z) - addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + topColor = applySaturationAndBrightnessMultipliers(topColor, saturationMultiplier, brightnessMultiplier); + northSouthColor = applySaturationAndBrightnessMultipliers(northSouthColor, saturationMultiplier, brightnessMultiplier); + bottomColor = applySaturationAndBrightnessMultipliers(bottomColor, saturationMultiplier, brightnessMultiplier); + int minY; + int maxY; + LodDataPoint data; + /**TODO make all of this more automatic if possible*/ + if (playerBlockPos.getY() > bb.maxY) + { + // top (facing up) + addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, topColor.getRed(), topColor.getGreen(), topColor.getBlue(), topColor.getAlpha()); + } + if (playerBlockPos.getY() < bb.minY) + { + // bottom (facing down) + addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()); + } - // west (facing -X) - addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); - // east (facing +X) - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); - } + if (playerBlockPos.getZ() > bb.minZ) + { + // south (facing -Z) - @Override - public int getBufferMemoryForSingleNode(int detailLevel) - { - // (sidesOnACube * pointsInASquare * (positionPoints + colorPoints))) * - // howManyPointsPerLodChunk - return (6 * 4 * (3 + 4)); - } + data = adjData[1][1]; + if (data == null) + { + addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + } else + { + maxY = data.height; + if (maxY < bb.maxY) + { + minY = (int) Math.max(maxY, bb.minY); + addPosAndColor(buffer, bb.maxX, minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + } + minY = data.depth; + if (minY > bb.minY) + { + maxY = (int) Math.min(minY, bb.maxX); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + } + } + } + + if (playerBlockPos.getZ() < bb.maxZ) + { + data = adjData[1][0]; + // north (facing +Z) + if (data == null) + { + addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + } else + { + maxY = data.height; + if (maxY < bb.maxY) + { + minY = (int) Math.max(maxY, bb.minY); + addPosAndColor(buffer, bb.minX, minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + } + minY = data.depth; + if (minY > bb.minY) + { + maxY = (int) Math.min(minY, bb.maxX); + addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + } + } + } + + if (playerBlockPos.getX() < bb.maxX) + { + // west (facing -X) + data = adjData[0][0]; + if (data == null) + { + addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + } else + { + maxY = data.height; + if (maxY < bb.maxY) + { + minY = (int) Math.max(maxY, bb.minY); + addPosAndColor(buffer, bb.minX, minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + } + minY = data.depth; + if (minY > bb.minY) + { + maxY = (int) Math.min(minY, bb.maxX); + addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + } + } + } + + if (playerBlockPos.getX() > bb.minX) + { + // east (facing +X) + data = adjData[0][1]; + if (data == null) + { + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + } else + { + maxY = data.height; + if (maxY < bb.maxY) + { + minY = (int) Math.max(maxY, bb.minY); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + } + minY = data.depth; + if (minY > bb.minY) + { + maxY = (int) Math.min(minY, bb.maxX); + addPosAndColor(buffer, bb.maxX, maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + } + } + } + } + + @Override + public int getBufferMemoryForSingleNode(int detailLevel) + { + // (sidesOnACube * pointsInASquare * (positionPoints + colorPoints))) * + // howManyPointsPerLodChunk + return (6 * 4 * (3 + 4)); + } } diff --git a/src/main/java/com/seibel/lod/builders/lodTemplates/DynamicLodTemplate.java b/src/main/java/com/seibel/lod/builders/lodTemplates/DynamicLodTemplate.java index 1fb5b3c38..5263b5aa1 100644 --- a/src/main/java/com/seibel/lod/builders/lodTemplates/DynamicLodTemplate.java +++ b/src/main/java/com/seibel/lod/builders/lodTemplates/DynamicLodTemplate.java @@ -17,10 +17,14 @@ */ package com.seibel.lod.builders.lodTemplates; +import com.seibel.lod.objects.LevelPos; import com.seibel.lod.objects.LodDataPoint; import com.seibel.lod.objects.LodDimension; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.util.math.BlockPos; + +import java.util.Set; /** * TODO DynamicLodTemplate @@ -34,10 +38,8 @@ import net.minecraft.client.renderer.BufferBuilder; public class DynamicLodTemplate extends AbstractLodTemplate { @Override - public void addLodToBuffer(BufferBuilder buffer, - LodDimension lodDim, LodDataPoint lod, - double xOffset, double yOffset, double zOffset, - boolean debugging, byte detail) + public void addLodToBuffer(BufferBuilder buffer, BlockPos playerBlockPos, LodDataPoint data, LodDataPoint[][] adjData, + LevelPos levelPos, boolean debugging) { System.err.println("DynamicLodTemplate not implemented!"); } diff --git a/src/main/java/com/seibel/lod/builders/lodTemplates/TriangularLodTemplate.java b/src/main/java/com/seibel/lod/builders/lodTemplates/TriangularLodTemplate.java index 06f7905f0..35f542d72 100644 --- a/src/main/java/com/seibel/lod/builders/lodTemplates/TriangularLodTemplate.java +++ b/src/main/java/com/seibel/lod/builders/lodTemplates/TriangularLodTemplate.java @@ -17,10 +17,14 @@ */ package com.seibel.lod.builders.lodTemplates; +import com.seibel.lod.objects.LevelPos; import com.seibel.lod.objects.LodDataPoint; import com.seibel.lod.objects.LodDimension; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.util.math.BlockPos; + +import java.util.Set; /** * TODO #21 TriangularLodTemplate @@ -32,10 +36,8 @@ import net.minecraft.client.renderer.BufferBuilder; public class TriangularLodTemplate extends AbstractLodTemplate { @Override - public void addLodToBuffer(BufferBuilder buffer, - LodDimension lodDim, LodDataPoint lod, - double xOffset, double yOffset, double zOffset, - boolean debugging, byte detail) + public void addLodToBuffer(BufferBuilder buffer, BlockPos playerBlockPos, LodDataPoint data, LodDataPoint[][] adjData, + LevelPos levelPos, boolean debugging) { System.err.println("DynamicLodTemplate not implemented!"); } diff --git a/src/main/java/com/seibel/lod/builders/worldGeneration/LodWorldGenerator.java b/src/main/java/com/seibel/lod/builders/worldGeneration/LodWorldGenerator.java index de30c380b..4a6531b20 100644 --- a/src/main/java/com/seibel/lod/builders/worldGeneration/LodWorldGenerator.java +++ b/src/main/java/com/seibel/lod/builders/worldGeneration/LodWorldGenerator.java @@ -84,7 +84,7 @@ public class LodWorldGenerator generatorThreadRunning = true; // just in case the config is changed - maxChunkGenRequests = LodConfig.CLIENT.numberOfWorldGenerationThreads.get() * 16; + maxChunkGenRequests = LodConfig.CLIENT.numberOfWorldGenerationThreads.get() * 8; Thread generatorThread = new Thread(() -> { diff --git a/src/main/java/com/seibel/lod/objects/LodDimension.java b/src/main/java/com/seibel/lod/objects/LodDimension.java index 2f1d07a3d..4a7491394 100644 --- a/src/main/java/com/seibel/lod/objects/LodDimension.java +++ b/src/main/java/com/seibel/lod/objects/LodDimension.java @@ -534,15 +534,20 @@ public class LodDimension if (levelPos.detailLevel > LodUtil.REGION_DETAIL_LEVEL) throw new IllegalArgumentException("getLodFromCoordinates given a level of \"" + levelPos.detailLevel + "\" when \"" + LodUtil.REGION_DETAIL_LEVEL + "\" is the max."); - LodRegion region = getRegion(levelPos); - - - if (region == null) + try { + LodRegion region = getRegion(levelPos); + + if (region == null) + { + return null; + } + + return region.getData(levelPos); + + }catch (Exception e){ return null; } - - return region.getData(levelPos); } diff --git a/src/main/java/com/seibel/lod/proxy/ClientProxy.java b/src/main/java/com/seibel/lod/proxy/ClientProxy.java index e7d550f81..b1454fc61 100644 --- a/src/main/java/com/seibel/lod/proxy/ClientProxy.java +++ b/src/main/java/com/seibel/lod/proxy/ClientProxy.java @@ -157,11 +157,11 @@ public class ClientProxy LodConfig.CLIENT.distanceGenerationMode.set(DistanceGenerationMode.SURFACE); LodConfig.CLIENT.allowUnstableFeatureGeneration.set(false); - LodConfig.CLIENT.lodChunkRenderDistance.set(512); + LodConfig.CLIENT.lodChunkRenderDistance.set(256); LodConfig.CLIENT.lodDistanceCalculatorType.set(DistanceCalculatorType.LINEAR); - LodConfig.CLIENT.lodQuality.set(2); + LodConfig.CLIENT.lodQuality.set(1); LodConfig.CLIENT.allowUnstableFeatureGeneration.set(false); - LodConfig.CLIENT.numberOfWorldGenerationThreads.set(16); + LodConfig.CLIENT.numberOfWorldGenerationThreads.set(Runtime.getRuntime().availableProcessors()); // has to be set in the config file // LodConfig.CLIENT.numberOfWorldGenerationThreads.set(16); diff --git a/src/main/java/com/seibel/lod/util/DetailDistanceUtil.java b/src/main/java/com/seibel/lod/util/DetailDistanceUtil.java index e4b98372b..254bb863a 100644 --- a/src/main/java/com/seibel/lod/util/DetailDistanceUtil.java +++ b/src/main/java/com/seibel/lod/util/DetailDistanceUtil.java @@ -15,7 +15,7 @@ public class DetailDistanceUtil private static int maxDistance = LodConfig.CLIENT.lodChunkRenderDistance.get() * 16 * 2; - private static DistanceGenerationMode[] distancesGenerators = { + /*private static DistanceGenerationMode[] distancesGenerators = { DistanceGenerationMode.SURFACE, DistanceGenerationMode.SURFACE, DistanceGenerationMode.SURFACE, @@ -25,7 +25,7 @@ public class DetailDistanceUtil DistanceGenerationMode.SURFACE, DistanceGenerationMode.SURFACE, DistanceGenerationMode.SURFACE, - DistanceGenerationMode.SURFACE}; + DistanceGenerationMode.SURFACE};*/ /*private static DistanceGenerationMode[] distancesGenerators = { DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT, @@ -38,8 +38,8 @@ public class DetailDistanceUtil DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT, DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT, DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT};*/ - /*private static DistanceGenerationMode[] distancesGenerators = { - DistanceGenerationMode.FEATURES, + private static DistanceGenerationMode[] distancesGenerators = { + DistanceGenerationMode.SURFACE, DistanceGenerationMode.SURFACE, DistanceGenerationMode.SURFACE, DistanceGenerationMode.SURFACE, @@ -48,7 +48,7 @@ public class DetailDistanceUtil DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT, DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT, DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT, - DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT};*/ + DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT}; private static LodDetail[] lodDetails = { LodDetail.FULL,