From e313a034103d5f2f3b229c26c095e1e0741fd59f Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 5 Aug 2021 20:40:12 -0500 Subject: [PATCH] Fix/improve rendering again --- build.gradle | 10 ++++--- .../lod/{objects => }/QuadTreeImage.java | 30 +++++++++++++------ .../lod/builders/LodNodeBufferBuilder.java | 13 ++++---- .../java/com/seibel/lod/util/LodUtil.java | 26 +++++++--------- 4 files changed, 46 insertions(+), 33 deletions(-) rename src/main/java/com/seibel/lod/{objects => }/QuadTreeImage.java (96%) diff --git a/build.gradle b/build.gradle index 985fa034c..cde1459f8 100644 --- a/build.gradle +++ b/build.gradle @@ -132,17 +132,19 @@ dependencies { // The userdev artifact is a special name and will get all sorts of transformations applied to it. minecraft 'net.minecraftforge:forge:1.16.5-36.1.0' - implementation ('com.github.KaptainWutax:BiomeUtils:-SNAPSHOT'){ + implementation ('com.github.KaptainWutax:BiomeUtils:1.0.0'){ transitive = false } implementation ('com.github.KaptainWutax:SeedUtils:-SNAPSHOT'){ transitive = false } - implementation ('com.github.KaptainWutax:MCUtils:-SNAPSHOT'){ + implementation ('com.github.KaptainWutax:MCUtils:1.0.0'){ transitive = false } - // not working - implementation ('com.github.KaptainWutax:NoiseUtils:-SNAPSHOT'){ + implementation ('com.github.KaptainWutax:NoiseUtils:1.0.0'){ + transitive = false + } + implementation ('com.github.KaptainWutax:MathUtils:-SNAPSHOT'){ transitive = false } diff --git a/src/main/java/com/seibel/lod/objects/QuadTreeImage.java b/src/main/java/com/seibel/lod/QuadTreeImage.java similarity index 96% rename from src/main/java/com/seibel/lod/objects/QuadTreeImage.java rename to src/main/java/com/seibel/lod/QuadTreeImage.java index 8d61f2449..7217048f1 100644 --- a/src/main/java/com/seibel/lod/objects/QuadTreeImage.java +++ b/src/main/java/com/seibel/lod/QuadTreeImage.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.seibel.lod.objects; +package com.seibel.lod; import java.awt.BasicStroke; import java.awt.Color; @@ -30,6 +30,7 @@ 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; @@ -39,6 +40,9 @@ import javax.swing.SwingUtilities; import javax.swing.Timer; 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.util.BiomeColorsUtils; import kaptainwutax.biomeutils.source.OverworldBiomeSource; @@ -51,18 +55,21 @@ public class QuadTreeImage extends JPanel private static final int PREF_H = PREF_W; private List drawables = new ArrayList<>(); - public QuadTreeImage() { + public QuadTreeImage() + { setBackground(Color.white); } - public void addMyDrawable(MyDrawable myDrawable) { + public void addMyDrawable(MyDrawable myDrawable) + { drawables.add(myDrawable); repaint(); } @Override // make it bigger - public Dimension getPreferredSize() { + public Dimension getPreferredSize() + { if (isPreferredSizeSet()) { return super.getPreferredSize(); } @@ -70,7 +77,8 @@ public class QuadTreeImage extends JPanel } @Override - protected void paintComponent(Graphics g) { + protected void paintComponent(Graphics g) + { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, @@ -80,12 +88,14 @@ public class QuadTreeImage extends JPanel } } - public void clearAll() { + public void clearAll() + { drawables.clear(); repaint(); } - private static void createAndShowGui() { + private static void createAndShowGui() + { final QuadTreeImage quadTreeImage = new QuadTreeImage(); @@ -106,7 +116,8 @@ public class QuadTreeImage extends JPanel //SIMULATING A PLAYER MOVING, int[] playerXs = {0, 100, 200, 300, 400, 1000}; int[] playerZs = {0, 100, 200, 300, 400, 500}; - for (int pos = 0; pos < 1; pos++) { + for (int pos = 0; pos < 1; pos++) + { int playerX = 0 + playerXs[pos]; //2097152 int playerZ = 0 + playerZs[pos]/2; @@ -266,7 +277,8 @@ public class QuadTreeImage extends JPanel }).start(); } - public static void main(String[] args) { + public static void main(String[] args) + { /* LodQuadTreeDimension dim2 = new LodQuadTreeDimension(null, null, 1); dim2.move(10000000,10000000); diff --git a/src/main/java/com/seibel/lod/builders/LodNodeBufferBuilder.java b/src/main/java/com/seibel/lod/builders/LodNodeBufferBuilder.java index 3e96fb274..38ae18595 100644 --- a/src/main/java/com/seibel/lod/builders/LodNodeBufferBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodNodeBufferBuilder.java @@ -29,7 +29,6 @@ import com.seibel.lod.handlers.LodConfig; import com.seibel.lod.objects.LodQuadTreeDimension; import com.seibel.lod.objects.LodQuadTreeNode; import com.seibel.lod.objects.NearFarBuffer; -import com.seibel.lod.proxy.ClientProxy; import com.seibel.lod.render.LodNodeRenderer; import com.seibel.lod.util.LodUtil; @@ -174,9 +173,11 @@ public class LodNodeBufferBuilder // set where this square will be drawn in the world double xOffset = (LodQuadTreeNode.CHUNK_WIDTH * i) + // offset by the number of LOD blocks - startX; // offset so the center LOD block is centered underneath the player - double yOffset = 0; - double zOffset = (LodQuadTreeNode.CHUNK_WIDTH * j) + startZ; + startX + // offset so the center LOD block is centered underneath the player + 8; // I'm not sure what this is correcting exactly but with it the chunks line up. + // 8 works for LODs the size of chunks + double yOffset = 1; + double zOffset = (LodQuadTreeNode.CHUNK_WIDTH * j) + startZ + 8; LodQuadTreeNode lod = lodDim.getLodFromCoordinates(chunkX, chunkZ, LodQuadTreeNode.CHUNK_LEVEL); @@ -189,6 +190,7 @@ public class LodNodeBufferBuilder ChunkPos pos = new ChunkPos(chunkX, chunkZ); + // alternate determining logic that // can be used for debugging // if (chunksToGen == null) // { @@ -272,6 +274,7 @@ public class LodNodeBufferBuilder chunkGenIndex++; } } + } // lod null and can generate more chunks // don't render this null/empty chunk @@ -294,7 +297,7 @@ public class LodNodeBufferBuilder } } - ClientProxy.LOGGER.info(numberOfChunksWaitingToGenerate.get()); + //ClientProxy.LOGGER.info(numberOfChunksWaitingToGenerate.get()); // issue #19 // TODO add a way for a server side mod to generate chunks requested here diff --git a/src/main/java/com/seibel/lod/util/LodUtil.java b/src/main/java/com/seibel/lod/util/LodUtil.java index 12b3764b5..b4797ae1f 100644 --- a/src/main/java/com/seibel/lod/util/LodUtil.java +++ b/src/main/java/com/seibel/lod/util/LodUtil.java @@ -20,7 +20,6 @@ package com.seibel.lod.util; import java.awt.Color; import java.io.File; -import com.seibel.lod.objects.LodQuadTreeNode; import com.seibel.lod.objects.RegionPos; import net.minecraft.client.Minecraft; @@ -96,21 +95,18 @@ public class LodUtil public static RegionPos convertChunkPosToRegionPos(ChunkPos pos) { RegionPos rPos = new RegionPos(); -// rPos.x = pos.x / 512; -// rPos.z = pos.z / 512; -// -// // prevent issues if X/Z is negative and less than 16 -// if (pos.x < 0) -// { -// rPos.x = (Math.abs(rPos.x) * -1) - 1; -// } -// if (pos.z < 0) -// { -// rPos.z = (Math.abs(rPos.z) * -1) - 1; -// } + rPos.x = pos.x / 512; + rPos.z = pos.z / 512; - rPos.x = (Math.floorDiv(pos.x, (int) (512/Math.pow(LodQuadTreeNode.CHUNK_LEVEL,2)))); - rPos.z = (Math.floorDiv(pos.z, (int) (512/Math.pow(LodQuadTreeNode.CHUNK_LEVEL,2)))); + // prevent issues if X/Z is negative and less than 16 + if (pos.x < 0) + { + rPos.x = (Math.abs(rPos.x) * -1) - 1; + } + if (pos.z < 0) + { + rPos.z = (Math.abs(rPos.z) * -1) - 1; + } return rPos; }