From ecec76b081029e706390b74f06198250da43905d Mon Sep 17 00:00:00 2001 From: makamys Date: Sun, 9 May 2021 07:44:58 +0200 Subject: Improve memory tracking --- src/main/java/makamys/lodmod/renderer/LODChunk.java | 14 ++++++++++++++ src/main/java/makamys/lodmod/renderer/LODRegion.java | 2 +- src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/main/java/makamys/lodmod') diff --git a/src/main/java/makamys/lodmod/renderer/LODChunk.java b/src/main/java/makamys/lodmod/renderer/LODChunk.java index 5ee5f35..c9bdd5e 100644 --- a/src/main/java/makamys/lodmod/renderer/LODChunk.java +++ b/src/main/java/makamys/lodmod/renderer/LODChunk.java @@ -113,4 +113,18 @@ public class LODChunk { return nbt; } + public void destroy() { + for(SimpleChunkMesh scm: simpleMeshes) { + if(scm != null) { + scm.destroy(); + } + } + for(ChunkMesh cm: chunkMeshes) { + if(cm != null) { + cm.destroy(); + } + } + LODMod.renderer.setVisible(this, false); + } + } diff --git a/src/main/java/makamys/lodmod/renderer/LODRegion.java b/src/main/java/makamys/lodmod/renderer/LODRegion.java index a99c24a..df79ede 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRegion.java +++ b/src/main/java/makamys/lodmod/renderer/LODRegion.java @@ -144,7 +144,7 @@ public class LODRegion { for(int j = 0; j < 32; j++) { LODChunk chunk = data[i][j]; if(chunk != null) { - LODMod.renderer.setVisible(chunk, false); + chunk.destroy(); } } } diff --git a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java index 01291d5..581ee4a 100644 --- a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java +++ b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java @@ -180,4 +180,9 @@ public class SimpleChunkMesh extends Mesh { return (3 * 4 + 8 + 4 + 4); } + public void destroy() { + usedRAM -= buffer.limit(); + instances--; + } + } -- cgit