aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/makamys/lodmod/renderer/ChunkMesh.java9
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODChunk.java4
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRenderer.java64
-rw-r--r--src/main/java/makamys/lodmod/renderer/Mesh.java3
-rw-r--r--src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java21
5 files changed, 96 insertions, 5 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
index 9d6241f..8fac2db 100644
--- a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
+++ b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
@@ -27,6 +27,7 @@ import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
+import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByteArray;
import net.minecraft.nbt.NBTTagCompound;
@@ -350,6 +351,14 @@ public class ChunkMesh extends Mesh {
return ((IWorldRenderer)wr).getChunkMeshes();
}
+ public double distSq(Entity player) {
+ int centerX = x * 16 + 8;
+ int centerY = y * 16 + 8;
+ int centerZ = z * 16 + 8;
+
+ return player.getDistanceSq(centerX, centerY, centerZ);
+ }
+
public static class Flags {
boolean hasTexture;
boolean hasBrightness;
diff --git a/src/main/java/makamys/lodmod/renderer/LODChunk.java b/src/main/java/makamys/lodmod/renderer/LODChunk.java
index 0688d22..557b37e 100644
--- a/src/main/java/makamys/lodmod/renderer/LODChunk.java
+++ b/src/main/java/makamys/lodmod/renderer/LODChunk.java
@@ -39,6 +39,7 @@ public class LODChunk {
byte[] data = chunkMeshesCompound.getByteArray(key);
chunkMeshes[keyInt] = new ChunkMesh(x, keyInt / 2, z, new ChunkMesh.Flags(true, true, true, false), data.length / (2 + 4 * (3 + 2 + 2 + 4)), data, spriteList);
+ chunkMeshes[keyInt].pass = keyInt % 2;
}
}
@@ -63,6 +64,9 @@ public class LODChunk {
for(int i = 0; i < newChunkMeshes.size(); i++) {
chunkMeshes[cy * 2 + i] = newChunkMeshes.get(i);
+ if(newChunkMeshes.get(i) != null) {
+ chunkMeshes[cy * 2 + i].pass = i;
+ }
}
}
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
index 8bfe85d..f8dd200 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
@@ -79,6 +79,8 @@ public class LODRenderer {
public int renderRange = 48;
+ private boolean freezeMeshes;
+
public LODRenderer(){
hasInited = init();
}
@@ -156,12 +158,36 @@ public class LODRenderer {
if(Keyboard.isKeyDown(Keyboard.KEY_V) && !wasDown[Keyboard.KEY_V]) {
renderWorld = !renderWorld;
}
+ if(Keyboard.isKeyDown(Keyboard.KEY_G) && !wasDown[Keyboard.KEY_G]) {
+ //LODChunk chunk = getLODChunk(9, -18);
+ //setMeshVisible(chunk.chunkMeshes[7], false, true);
+ //freezeMeshes = false;
+ resort();
+ //chunk.chunkMeshes[7].quadCount = 256;
+ //setMeshVisible(chunk.chunkMeshes[7], true, true);
+ }
for(int i = 0; i < 256; i++) {
wasDown[i] = Keyboard.isKeyDown(i);
}
}
+ private void resort() {
+ List<Mesh> visibleMeshes = new ArrayList<>();
+ for(Mesh mesh : sentMeshes) {
+ if(mesh.visible) {
+ setMeshVisible(mesh, false);
+ visibleMeshes.add(mesh);
+ }
+ }
+
+ Entity player = (Entity)Minecraft.getMinecraft().getIntegratedServer().getConfigurationManager().playerEntityList.get(0);
+ visibleMeshes.sort(new MeshDistanceComparator(player));
+ for(Mesh mesh : visibleMeshes) {
+ setMeshVisible(mesh, true);
+ }
+ }
+
private void runGC() {
nextMeshOffset = 0;
nextTri = 0;
@@ -212,7 +238,8 @@ public class LODRenderer {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glDisable(GL11.GL_TEXTURE_2D);
- GL11.glDisable(GL11.GL_BLEND);
+ GL11.glEnable(GL11.GL_BLEND);
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
glUseProgram(shaderProgram);
@@ -531,7 +558,11 @@ public class LODRenderer {
private int nextMesh;
protected void setMeshVisible(Mesh mesh, boolean visible) {
- if(mesh == null) return;
+ setMeshVisible(mesh, visible, false);
+ }
+
+ protected void setMeshVisible(Mesh mesh, boolean visible, boolean force) {
+ if((!force && freezeMeshes) || mesh == null) return;
if(mesh.visible != visible) {
if(!visible) {
@@ -671,4 +702,33 @@ public class LODRenderer {
);
}
}
+
+ public static class MeshDistanceComparator implements Comparator<Mesh> {
+
+ Entity player;
+
+ MeshDistanceComparator(Entity player){
+ this.player = player;
+ }
+
+ @Override
+ public int compare(Mesh a, Mesh b) {
+ if(a.pass < b.pass) {
+ return -1;
+ } else if(a.pass > b.pass) {
+ return 1;
+ } else {
+ double distSqA = a.distSq(player);
+ double distSqB = b.distSq(player);
+ if(distSqA > distSqB) {
+ return 1;
+ } else if(distSqA < distSqB) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+ }
+
+ }
}
diff --git a/src/main/java/makamys/lodmod/renderer/Mesh.java b/src/main/java/makamys/lodmod/renderer/Mesh.java
index 0f429ec..4775991 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 net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTBase;
public abstract class Mesh {
@@ -13,6 +14,8 @@ public abstract class Mesh {
public boolean pendingGPUDelete;
public int iFirst = -1, iCount = -1;
public int offset = -1;
+ public int pass;
public abstract int getStride();
+ public abstract double distSq(Entity player);
}
diff --git a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
index 9cdbea8..448ca09 100644
--- a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
+++ b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
@@ -21,6 +21,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
+import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.IIcon;
import net.minecraft.world.chunk.Chunk;
@@ -33,11 +34,13 @@ 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;
- SimpleChunkMesh pass1 = new SimpleChunkMesh(divisions * divisions * 25);
- SimpleChunkMesh pass2 = new SimpleChunkMesh(divisions * divisions * 25);
+ SimpleChunkMesh pass1 = new SimpleChunkMesh(target.xPosition, target.zPosition, divisions * divisions * 25, 0);
+ SimpleChunkMesh pass2 = new SimpleChunkMesh(target.xPosition, target.zPosition, divisions * divisions * 25, 1);
for(int divX = 0; divX < divisions; divX++) {
for(int divZ = 0; divZ < divisions; divZ++) {
@@ -83,7 +86,11 @@ public class SimpleChunkMesh extends Mesh {
return Arrays.asList(new SimpleChunkMesh[] {pass1.quadCount != 0 ? pass1 : null, pass2.quadCount != 0 ? pass2 : null});
}
- public SimpleChunkMesh(int maxQuads) {
+ public SimpleChunkMesh(int x, int z, int maxQuads, int pass) {
+ this.x = x;
+ this.z = z;
+ this.pass = pass;
+
buffer = BufferUtils.createByteBuffer(4 * 6 * 7 * maxQuads);
vertices = buffer.asFloatBuffer();
}
@@ -174,4 +181,12 @@ 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);
+ }
+
}