Tool und Oberflächen Konsolidierung angefangen

This commit is contained in:
2026-08-14 15:41:27 +02:00
parent 400a736804
commit 90599c9c7b
78 changed files with 2400 additions and 311 deletions

View File

@@ -29,6 +29,8 @@ public final class VoxelChunk {
private byte[] density;
/** Material-IDs, lazy: null = alles 0. */
private byte[] material;
/** Anzahl solider Voxel (density > 0). Wird bei jeder Änderung aktualisiert. */
private int solidCount = 0;
public volatile boolean dirty = false;
@@ -49,7 +51,11 @@ public final class VoxelChunk {
public void setDensity(int x, int y, int z, byte d) {
if (density == null) { density = new byte[SIZE*SIZE*SIZE]; Arrays.fill(density, Byte.MIN_VALUE); }
density[idx(x, y, z)] = d;
int i = idx(x, y, z);
byte old = density[i];
density[i] = d;
if (old <= 0 && d > 0) solidCount++;
else if (old > 0 && d <= 0) solidCount--;
dirty = true;
}
@@ -65,9 +71,9 @@ public final class VoxelChunk {
public boolean isSolid(int x, int y, int z) { return getDensity(x, y, z) > 0; }
public boolean isEmpty() { return density == null; }
public boolean isEmpty() { return solidCount == 0; }
public void clear() { density = null; material = null; dirty = true; }
public void clear() { density = null; material = null; solidCount = 0; dirty = true; }
/**
* Gibt die Y-Ausdehnung (in Voxel) der soliden Voxel zurück.
@@ -143,7 +149,9 @@ public final class VoxelChunk {
int i = idx(x, y, z);
int d = density[i];
if (d <= 0) continue;
density[i] = (byte) Math.max(Byte.MIN_VALUE, d - step);
byte nd = (byte) Math.max(Byte.MIN_VALUE, d - step);
density[i] = nd;
if (nd <= 0) solidCount--;
changed = true;
}
}
@@ -173,6 +181,7 @@ public final class VoxelChunk {
density[idx(x,y+1,z)] <= 0 && density[idx(x,y-1,z)] <= 0 &&
density[idx(x,y,z+1)] <= 0 && density[idx(x,y,z-1)] <= 0) {
density[idx(x, y, z)] = Byte.MIN_VALUE;
solidCount--;
changed = true;
}
}
@@ -189,6 +198,7 @@ public final class VoxelChunk {
/** Setzt das Dichte-Array direkt (für Undo/Redo). */
public void setDensityArray(byte[] d) {
this.density = d;
recomputeSolidCount();
dirty = true;
}
@@ -203,6 +213,7 @@ public final class VoxelChunk {
for (int z = 0; z < SIZE; z++)
for (int x = 0; x < SIZE; x++)
density[idx(x, y, z)] = (byte) 127;
recomputeSolidCount();
}
// ── Serialisierung ────────────────────────────────────────────────────────
@@ -242,10 +253,17 @@ public final class VoxelChunk {
in.readFully(c.material);
}
}
c.recomputeSolidCount();
c.dirty = false;
return c;
}
private void recomputeSolidCount() {
solidCount = 0;
if (density == null) return;
for (byte d : density) { if (d > 0) solidCount++; }
}
// ── Koordinaten-Hilfsmethoden ─────────────────────────────────────────────
/** Welt-Y des Voxels mit localY, ausgehend von diesem cy-Layer. */