aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-24 08:25:32 +0200
committermakamys <makamys@outlook.com>2022-06-24 08:25:32 +0200
commit2cd1e01bf0f6e80ff1293cacc66616ab79e2a442 (patch)
treedf91944b79153e9ead172adab74d5b423c4a197e /src/main/java/makamys
parent764b5f78e45faed5542180c1d7f48d58abd21069 (diff)
downloadNeodymium-2cd1e01bf0f6e80ff1293cacc66616ab79e2a442.tar.gz
Neodymium-2cd1e01bf0f6e80ff1293cacc66616ab79e2a442.tar.bz2
Neodymium-2cd1e01bf0f6e80ff1293cacc66616ab79e2a442.zip
Make sorting gooder
Diffstat (limited to 'src/main/java/makamys')
-rw-r--r--src/main/java/makamys/neodymium/Config.java2
-rw-r--r--src/main/java/makamys/neodymium/renderer/Mesh.java2
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java40
3 files changed, 28 insertions, 16 deletions
diff --git a/src/main/java/makamys/neodymium/Config.java b/src/main/java/makamys/neodymium/Config.java
index aa15fa6..48f46c9 100644
--- a/src/main/java/makamys/neodymium/Config.java
+++ b/src/main/java/makamys/neodymium/Config.java
@@ -46,7 +46,7 @@ public class Config {
@NeedsReload
@ConfigBoolean(cat="render", def=false, com="Store texture coordinates as shorts instead of floats. Slightly reduces memory usage and might improve performance by small amount. Might affect visuals slightly, but it's only noticable if the texture atlas is huge.")
public static boolean shortUV;
- @ConfigInt(cat="render", def=1, min=1, max=Integer.MAX_VALUE, com="Interval (in frames) between the sorting of meshes. Increasing this might improve performance, but also increase the likelyhood of graphical artifacts appearing when moving quickly.")
+ @ConfigInt(cat="render", def=1, min=1, max=Integer.MAX_VALUE, com="Interval (in frames) between the sorting of transparent meshes. Increasing this will reduce CPU usage, but also increase the likelyhood of graphical artifacts appearing when transparent chunks are loaded.")
public static int sortFrequency;
@NeedsReload
diff --git a/src/main/java/makamys/neodymium/renderer/Mesh.java b/src/main/java/makamys/neodymium/renderer/Mesh.java
index 74a1678..6db523d 100644
--- a/src/main/java/makamys/neodymium/renderer/Mesh.java
+++ b/src/main/java/makamys/neodymium/renderer/Mesh.java
@@ -22,7 +22,7 @@ public abstract class Mesh {
public abstract int getStride();
public double distSq(double x2, double y2, double z2) {
- return Util.distSq(x, y, z, x2, y2, z2);
+ return Util.distSq(x + 0.5, y + 0.5, z + 0.5, x2, y2, z2);
}
public int bufferSize() {
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index 995c835..6aa29b5 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -53,6 +53,8 @@ import net.minecraftforge.event.world.ChunkEvent;
/** The main renderer class. */
public class NeoRenderer {
+ private static final MeshDistanceComparator DISTANCE_COMPARATOR = new MeshDistanceComparator();
+
public boolean hasInited = false;
public boolean destroyPending;
public boolean reloadPending;
@@ -154,9 +156,7 @@ public class NeoRenderer {
interpYDiv = Math.floorDiv((int)Math.floor(interpY), 16);
interpZDiv = Math.floorDiv((int)Math.floor(interpZ), 16);
- if(frameCount % Config.sortFrequency == 0) {
- sort();
- }
+ sort(frameCount % 100 == 0, frameCount % Config.sortFrequency == 0);
updateMeshes();
initIndexBuffers();
@@ -184,10 +184,12 @@ public class NeoRenderer {
}
}
- private void sort() {
- Entity player = Minecraft.getMinecraft().renderViewEntity;
- for(List<Mesh> list : sentMeshes) {
- list.sort(new MeshDistanceComparator(Math.floor(player.posX / 16.0), Math.floor(player.posY / 16.0), Math.floor(player.posZ / 16.0)));
+ private void sort(boolean pass0, boolean pass1) {
+ if(pass0) {
+ sentMeshes[0].sort(DISTANCE_COMPARATOR.setOrigin(interpX, interpY, interpZ).setInverted(false));
+ }
+ if(pass1) {
+ sentMeshes[1].sort(DISTANCE_COMPARATOR.setOrigin(interpX, interpY, interpZ).setInverted(true));
}
}
@@ -805,13 +807,20 @@ public class NeoRenderer {
public static class MeshDistanceComparator implements Comparator<Mesh> {
double x, y, z;
+ boolean inverted;
- MeshDistanceComparator(double x, double y, double z){
- this.x = x;
- this.y = y;
- this.z = z;
+ public Comparator<? super Mesh> setInverted(boolean inverted) {
+ this.inverted = inverted;
+ return this;
}
-
+
+ public MeshDistanceComparator setOrigin(double x, double y, double z) {
+ this.x = x / 16.0;
+ this.y = y / 16.0;
+ this.z = z / 16.0;
+ return this;
+ }
+
@Override
public int compare(Mesh a, Mesh b) {
if(a.pass < b.pass) {
@@ -821,10 +830,13 @@ public class NeoRenderer {
} else {
double distSqA = a.distSq(x, y, z);
double distSqB = b.distSq(x, y, z);
+
+ int mult = inverted ? -1 : 1;
+
if(distSqA > distSqB) {
- return 1;
+ return 1 * mult;
} else if(distSqA < distSqB) {
- return -1;
+ return -1 * mult;
} else {
return 0;
}