aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2021-05-08 23:24:07 +0200
committermakamys <makamys@outlook.com>2021-05-08 23:24:07 +0200
commit61f710863c52d3cb5aeeaab7600a060af49a5024 (patch)
tree6a57ac85966e6980381b799501368c4dc09ec6d4 /src/main/java/makamys
parentddc6bb4731665a70cdbe17f52367c8accb254cd1 (diff)
downloadNeodymium-61f710863c52d3cb5aeeaab7600a060af49a5024.tar.gz
Neodymium-61f710863c52d3cb5aeeaab7600a060af49a5024.tar.bz2
Neodymium-61f710863c52d3cb5aeeaab7600a060af49a5024.zip
Unload empty regions
Diffstat (limited to 'src/main/java/makamys')
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRegion.java19
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRenderer.java12
2 files changed, 28 insertions, 3 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/LODRegion.java b/src/main/java/makamys/lodmod/renderer/LODRegion.java
index 0dc49ea..2aff7a6 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRegion.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRegion.java
@@ -122,15 +122,32 @@ public class LODRegion {
return null;
}
- public void tick(Entity player) {
+ public boolean tick(Entity player) {
+ int visibleChunks = 0;
for(int i = 0; i < 32; i++) {
for(int j = 0; j < 32; j++) {
LODChunk chunk = data[i][j];
if(chunk != null) {
chunk.tick(player);
+ if(chunk.visible) {
+ visibleChunks++;
+ }
}
}
}
+ return visibleChunks > 0;
+ }
+
+ public void destroy(Path saveDir) {
+ save(saveDir);
+ for(int i = 0; i < 32; i++) {
+ for(int j = 0; j < 32; j++) {
+ LODChunk chunk = data[i][j];
+ if(chunk != null) {
+ LODMod.renderer.setVisible(chunk, false);
+ }
+ }
+ }
}
}
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
index 91c0aee..6aac74a 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
@@ -130,8 +130,16 @@ public class LODRenderer {
lastSortX = player.posX;
lastSortY = player.posY;
lastSortZ = player.posZ;
-
- loadedRegionsMap.forEach((k, v) -> v.tick(player));
+ for(Iterator<ChunkCoordIntPair> it = loadedRegionsMap.keySet().iterator(); it.hasNext();) {
+ ChunkCoordIntPair k = it.next();
+ LODRegion v = loadedRegionsMap.get(k);
+
+ if(!v.tick(player)) {
+ System.out.println("unloading " + v);
+ v.destroy(getSaveDir());
+ it.remove();
+ }
+ }
}
}
}