diff options
author | makamys <makamys@outlook.com> | 2021-05-09 05:54:55 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2021-05-09 05:58:42 +0200 |
commit | 7720a81dac43270389b38b39ab93c9ad8950aa93 (patch) | |
tree | 867d8de5ce6ec269733bc77b9618c5791a577c9a /src | |
parent | 779c651ea0e0dfdb6d416c8eda60864229b72f93 (diff) | |
download | Neodymium-7720a81dac43270389b38b39ab93c9ad8950aa93.tar.gz Neodymium-7720a81dac43270389b38b39ab93c9ad8950aa93.tar.bz2 Neodymium-7720a81dac43270389b38b39ab93c9ad8950aa93.zip |
Sort pass 2 meshes
Diffstat (limited to 'src')
4 files changed, 34 insertions, 23 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java index 5f307df..dd41fdd 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java +++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java @@ -97,12 +97,18 @@ public class LODRenderer { } if(renderLOD) { + sort(); initIndexBuffers(); render(); } } } + private void sort() { + Entity player = (Entity)Minecraft.getMinecraft().getIntegratedServer().getConfigurationManager().playerEntityList.get(0); + sentMeshes2.sort(new MeshDistanceComparator(player.posX, player.posY, player.posZ)); + } + private void initIndexBuffers() { piFirst.limit(sentMeshes1.size() + sentMeshes2.size()); piCount.limit(sentMeshes1.size() + sentMeshes2.size()); @@ -144,7 +150,7 @@ public class LODRenderer { } } } - Collections.sort(newServerChunkLoadQueue, new ChunkCoordDistanceComparator(player)); + Collections.sort(newServerChunkLoadQueue, new ChunkCoordDistanceComparator(player.posX, player.posY, player.posZ)); setServerChunkLoadQueue(newServerChunkLoadQueue); lastSortX = player.posX; @@ -656,10 +662,12 @@ public class LODRenderer { } public static class ChunkCoordDistanceComparator implements Comparator<ChunkCoordIntPair> { - Entity player; + double x, y, z; - public ChunkCoordDistanceComparator(Entity player) { - this.player = player; + public ChunkCoordDistanceComparator(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; } @Override @@ -671,18 +679,19 @@ public class LODRenderer { int distSq(ChunkCoordIntPair p) { return (int)( - Math.pow(((p.chunkXPos * 16) - player.posX), 2) + - Math.pow(((p.chunkZPos * 16) - player.posZ), 2) + Math.pow(((p.chunkXPos * 16) - x), 2) + + Math.pow(((p.chunkZPos * 16) - z), 2) ); } } public static class MeshDistanceComparator implements Comparator<Mesh> { - - Entity player; + double x, y, z; - MeshDistanceComparator(Entity player){ - this.player = player; + MeshDistanceComparator(double x, double y, double z){ + this.x = x; + this.y = y; + this.z = z; } @Override @@ -692,8 +701,8 @@ public class LODRenderer { } else if(a.pass > b.pass) { return 1; } else { - double distSqA = a.distSq(player); - double distSqB = b.distSq(player); + double distSqA = a.distSq(x, y, z); + double distSqB = b.distSq(x, y, z); if(distSqA > distSqB) { return 1; } else if(distSqA < distSqB) { diff --git a/src/main/java/makamys/lodmod/renderer/Mesh.java b/src/main/java/makamys/lodmod/renderer/Mesh.java index 4775991..7c7e6c2 100644 --- a/src/main/java/makamys/lodmod/renderer/Mesh.java +++ b/src/main/java/makamys/lodmod/renderer/Mesh.java @@ -3,6 +3,7 @@ package makamys.lodmod.renderer; import java.nio.ByteBuffer; import java.nio.IntBuffer; +import makamys.lodmod.util.Util; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTBase; @@ -15,7 +16,11 @@ public abstract class Mesh { public int iFirst = -1, iCount = -1; public int offset = -1; public int pass; + int x, y, z; public abstract int getStride(); - public abstract double distSq(Entity player); + + public double distSq(double x2, double y2, double z2) { + return Util.distSq(x, y, z, x2, y2, z2); + } } diff --git a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java index 448ca09..01291d5 100644 --- a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java +++ b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java @@ -34,8 +34,6 @@ public class SimpleChunkMesh extends Mesh { public static int usedRAM; public static int instances; - int x, z; - public static List<SimpleChunkMesh> generateSimpleMeshes(Chunk target){ int divisions = 4; @@ -88,6 +86,7 @@ public class SimpleChunkMesh extends Mesh { public SimpleChunkMesh(int x, int z, int maxQuads, int pass) { this.x = x; + this.y = 64; this.z = z; this.pass = pass; @@ -181,12 +180,4 @@ public class SimpleChunkMesh extends Mesh { return (3 * 4 + 8 + 4 + 4); } - public double distSq(Entity player) { - int centerX = x * 16 + 8; - int centerY = 64; - int centerZ = z * 16 + 8; - - return player.getDistanceSq(centerX, centerY, centerZ); - } - } diff --git a/src/main/java/makamys/lodmod/util/Util.java b/src/main/java/makamys/lodmod/util/Util.java index 6964e9e..0a10463 100644 --- a/src/main/java/makamys/lodmod/util/Util.java +++ b/src/main/java/makamys/lodmod/util/Util.java @@ -53,4 +53,10 @@ public class Util { buffer.flip(); return dst; } + + public static double distSq(double x1, double y1, double z1, double x2, double y2, double z2) { + return Math.pow(x1 - x2, 2) + + Math.pow(y1 - y2, 2) + + Math.pow(z1 - z2, 2); + } } |