aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/makamys')
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoChunk.java29
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRegion.java31
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java10
3 files changed, 40 insertions, 30 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/NeoChunk.java b/src/main/java/makamys/neodymium/renderer/NeoChunk.java
index 72957e0..e7c3cab 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoChunk.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoChunk.java
@@ -16,6 +16,7 @@ public class NeoChunk {
boolean visible;
boolean dirty;
boolean discardedMesh;
+ NeoRegion region;
SimpleChunkMesh[] simpleMeshes = new SimpleChunkMesh[2];
ChunkMesh[] chunkMeshes = new ChunkMesh[32];
@@ -24,9 +25,10 @@ public class NeoChunk {
NeoRenderer renderer = Neodymium.renderer;
- public NeoChunk(int x, int z) {
+ public NeoChunk(int x, int z, NeoRegion region) {
this.x = x;
this.z = z;
+ this.region = region;
}
/*
public LODChunk(NBTTagCompound nbt, List<String> spriteList) {
@@ -69,6 +71,8 @@ public class NeoChunk {
renderer.removeMesh(chunkMeshes[cy * 2 + i]);
chunkMeshes[cy * 2 + i].destroy();
+ } else {
+ region.meshes++;
}
chunkMeshes[cy * 2 + i] = newChunkMesh;
}
@@ -104,14 +108,18 @@ public class NeoChunk {
}
public void tick(Entity player) {
- double distSq = distSq(player);
- if(Config.disableSimpleMeshes || distSq < Math.pow((Neodymium.renderer.renderRange / 2) * 16, 2)) {
- setLOD(2);
- } else if(distSq < Math.pow((Neodymium.renderer.renderRange) * 16, 2)) {
- setLOD(1);
- } else {
- setLOD(0);
- }
+ if(Config.disableSimpleMeshes) {
+ setLOD(2);
+ } else {
+ double distSq = distSq(player);
+ if(Config.disableSimpleMeshes || distSq < Math.pow((Neodymium.renderer.renderRange / 2) * 16, 2)) {
+ setLOD(2);
+ } else if(distSq < Math.pow((Neodymium.renderer.renderRange) * 16, 2)) {
+ setLOD(1);
+ } else {
+ setLOD(0);
+ }
+ }
}
public void setLOD(int lod) {
@@ -125,6 +133,7 @@ public class NeoChunk {
if(chunkMeshes[i] != null) {
chunkMeshes[i].destroy();
chunkMeshes[i] = null;
+ region.meshes--;
discardedMesh = true;
}
}
@@ -157,11 +166,13 @@ public class NeoChunk {
for(SimpleChunkMesh scm: simpleMeshes) {
if(scm != null) {
scm.destroy();
+ region.meshes--;
}
}
for(ChunkMesh cm: chunkMeshes) {
if(cm != null) {
cm.destroy();
+ region.meshes--;
}
}
Neodymium.renderer.setVisible(this, false);
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRegion.java b/src/main/java/makamys/neodymium/renderer/NeoRegion.java
index 78bf9e7..40aaf7d 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRegion.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRegion.java
@@ -11,13 +11,17 @@ public class NeoRegion {
int regionX, regionZ;
+ public int meshes = 0;
+
+ private int emptyTicks = 0;
+
public NeoRegion(int regionX, int regionZ) {
this.regionX = regionX;
this.regionZ = regionZ;
for(int i = 0; i < 32; i++) {
for(int j = 0; j < 32; j++) {
- data[i][j] = new NeoChunk(regionX * 32 + i, regionZ * 32 + j);
+ data[i][j] = new NeoChunk(regionX * 32 + i, regionZ * 32 + j, this);
}
}
}
@@ -134,20 +138,21 @@ public class NeoRegion {
return null;
}
- public boolean tick(Entity player) {
- int visibleChunks = 0;
+ public void tick(Entity player) {
for(int i = 0; i < 32; i++) {
for(int j = 0; j < 32; j++) {
NeoChunk chunk = data[i][j];
if(chunk != null) {
chunk.tick(player);
- if(chunk.visible) {
- visibleChunks++;
- }
}
}
}
- return visibleChunks > 0;
+
+ if(meshes == 0) {
+ emptyTicks++;
+ } else {
+ emptyTicks = 0;
+ }
}
public void destroy(Path saveDir) {
@@ -175,16 +180,8 @@ public class NeoRegion {
return "LODRegion(" + regionX + ", " + regionZ + ")";
}
- public boolean isEmpty() {
- for(int i = 0; i < 32; i++) {
- for(int j = 0; j < 32; j++) {
- NeoChunk chunk = data[i][j];
- if(chunk != null && !chunk.isEmpty()) {
- return false;
- }
- }
- }
- return true;
+ public boolean shouldDelete() {
+ return emptyTicks > 100;
}
}
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index 6aa29b5..240ec49 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -18,6 +18,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -273,11 +274,11 @@ public class NeoRenderer {
lastSortX = player.posX;
lastSortY = player.posY;
lastSortZ = player.posZ;*/
- for(Iterator<ChunkCoordIntPair> it = loadedRegionsMap.keySet().iterator(); it.hasNext();) {
- ChunkCoordIntPair k = it.next();
- NeoRegion v = loadedRegionsMap.get(k);
+ for(Iterator<Entry<ChunkCoordIntPair, NeoRegion>> it = loadedRegionsMap.entrySet().iterator(); it.hasNext();) {
+ Entry<ChunkCoordIntPair, NeoRegion> kv = it.next();
+ NeoRegion v = kv.getValue();
- if(v.isEmpty()) {
+ if(v.shouldDelete()) {
v.destroy(getSaveDir());
it.remove();
} else {
@@ -570,6 +571,7 @@ public class NeoRenderer {
if(lodChunk.chunkMeshes[y] != null) {
lodChunk.chunkMeshes[y].destroy();
lodChunk.chunkMeshes[y] = null;
+ lodChunk.region.meshes--;
}
}
lodChunkChanged(lodChunk);