aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2021-05-10 16:54:16 +0200
committermakamys <makamys@outlook.com>2021-05-10 16:54:16 +0200
commit55a677308609250e6514795ce3ef22e2f74a3c13 (patch)
tree7f315a16498ee881cf9df0ea1c0d21240e90bfda /src
parent5cac71c3aa9cb0f1f6435ad50f4098319f2217a9 (diff)
downloadNeodymium-55a677308609250e6514795ce3ef22e2f74a3c13.tar.gz
Neodymium-55a677308609250e6514795ce3ef22e2f74a3c13.tar.bz2
Neodymium-55a677308609250e6514795ce3ef22e2f74a3c13.zip
Unload regions based on distance
Diffstat (limited to 'src')
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRegion.java13
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRenderer.java16
2 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/LODRegion.java b/src/main/java/makamys/lodmod/renderer/LODRegion.java
index 0d91e22..b797531 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRegion.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRegion.java
@@ -149,4 +149,17 @@ public class LODRegion {
}
}
+ public double distanceTaxicab(Entity entity) {
+ double centerX = ((regionX * 32) + 16) * 16;
+ double centerZ = ((regionZ * 32) + 16) * 16;
+
+ return Math.max(Math.abs(centerX - entity.posX), Math.abs(centerZ - entity.posZ));
+
+ }
+
+ @Override
+ public String toString() {
+ return "LODRegion(" + regionX + ", " + regionZ + ")";
+ }
+
}
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
index 56ca600..3a0ff9d 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
@@ -159,12 +159,14 @@ public class LODRenderer {
for(int x = -renderRange; x <= renderRange; x++) {
for(int z = -renderRange; z <= renderRange; z++) {
- int chunkX = centerX + x;
- int chunkZ = centerZ + z;
-
- if(getLODChunk(chunkX, chunkZ).needsChunk) {
- newServerChunkLoadQueue.add(new ChunkCoordIntPair(chunkX, chunkZ));
- getLODChunk(chunkX, chunkZ).needsChunk = false;
+ if(x * x + z * z < renderRange * renderRange) {
+ int chunkX = centerX + x;
+ int chunkZ = centerZ + z;
+
+ if(getLODChunk(chunkX, chunkZ).needsChunk) {
+ newServerChunkLoadQueue.add(new ChunkCoordIntPair(chunkX, chunkZ));
+ getLODChunk(chunkX, chunkZ).needsChunk = false;
+ }
}
}
}
@@ -178,7 +180,7 @@ public class LODRenderer {
ChunkCoordIntPair k = it.next();
LODRegion v = loadedRegionsMap.get(k);
- if(!v.tick(player)) {
+ if(v.distanceTaxicab(player) > renderRange * 16 + 16 * 16) {
System.out.println("unloading " + v);
v.destroy(getSaveDir());
it.remove();