aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-07 21:59:12 +0200
committermakamys <makamys@outlook.com>2022-06-07 21:59:12 +0200
commit7d6ee74f2c6b591bd64532a21d3170889fa5483d (patch)
tree5cbefbeb67cb1e6694a4ea1004ddecf4e07b99e5 /src
parentfd1ad07f7e9759c43c3dae0affcaa910b06d2fb1 (diff)
downloadNeodymium-7d6ee74f2c6b591bd64532a21d3170889fa5483d.tar.gz
Neodymium-7d6ee74f2c6b591bd64532a21d3170889fa5483d.tar.bz2
Neodymium-7d6ee74f2c6b591bd64532a21d3170889fa5483d.zip
Fix meshes not getting deleted when their world renderers are deleted
Diffstat (limited to 'src')
-rw-r--r--src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java4
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRenderer.java13
2 files changed, 13 insertions, 4 deletions
diff --git a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java
index 791f24d..02b130f 100644
--- a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java
+++ b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java
@@ -144,7 +144,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer {
@Inject(method = "setDontDraw", at = @At(value = "HEAD"))
private void preSetDontDraw(CallbackInfo ci) {
if(LODMod.isActive()) {
- LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), false);
+ LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), LODRenderer.WorldRendererChange.DELETED);
}
}
@@ -170,7 +170,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer {
private void notifyIfDrawnStatusChanged() {
boolean drawn = isDrawn();
if(LODMod.isActive() && drawn != savedDrawnStatus) {
- LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), drawn);
+ LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), drawn ? LODRenderer.WorldRendererChange.VISIBLE : LODRenderer.WorldRendererChange.INVISIBLE);
}
}
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
index 7dac491..3da4603 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
@@ -448,13 +448,16 @@ public class LODRenderer {
ChunkMesh.usedRAM = 0;
}
- public void onWorldRendererChanged(WorldRenderer wr, boolean visible) {
+ public void onWorldRendererChanged(WorldRenderer wr, WorldRendererChange change) {
int x = Math.floorDiv(wr.posX, 16);
int y = Math.floorDiv(wr.posY, 16);
int z = Math.floorDiv(wr.posZ, 16);
LODChunk lodChunk = getLODChunk(x, z);
- lodChunk.hidden[y] = LODMod.hideUnderVanillaChunks ? visible : !visible;
+ lodChunk.hidden[y] = change != WorldRendererChange.VISIBLE;
+ if(change == WorldRendererChange.DELETED) {
+ removeMesh(lodChunk.chunkMeshes[y]);
+ }
lodChunkChanged(lodChunk);
}
@@ -578,6 +581,8 @@ public class LODRenderer {
}
public void removeMesh(Mesh mesh) {
+ if(mesh == null) return;
+
mem.deleteMeshFromGPU(mesh);
sentMeshes[mesh.pass].remove(mesh);
setMeshVisible(mesh, false);
@@ -707,4 +712,8 @@ public class LODRenderer {
}
}
+
+ public static enum WorldRendererChange {
+ VISIBLE, INVISIBLE, DELETED
+ }
} \ No newline at end of file