mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
lazily create chunks to improve memory usage
This commit is contained in:
@@ -24,7 +24,7 @@ public final class TerraCLI {
|
||||
|
||||
ConfigPack generate = platform.getConfigRegistry().get("OVERWORLD").orElseThrow(); // TODO: make this a cli argument
|
||||
|
||||
CLIWorld world = new CLIWorld(1, 2, 384, -64, generate);
|
||||
CLIWorld world = new CLIWorld(2, 2, 384, -64, generate);
|
||||
|
||||
world.generate();
|
||||
|
||||
@@ -32,7 +32,6 @@ public final class TerraCLI {
|
||||
Vector2Int pos = mcaFile.getLeft();
|
||||
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
|
||||
LOGGER.info("Writing region ({}, {}) to {}", pos.getX(), pos.getZ(), name);
|
||||
mcaFile.getRight().cleanupPalettesAndBlockStates();
|
||||
|
||||
try {
|
||||
MCAUtil.write(mcaFile.getRight(), name);
|
||||
|
||||
@@ -9,31 +9,41 @@ import com.dfsek.terra.cli.world.chunk.CLIChunk;
|
||||
public class Region implements NBTSerializable<MCAFile> {
|
||||
private final CLIChunk[] chunks;
|
||||
private final int x, z;
|
||||
private final CLIWorld world;
|
||||
|
||||
public Region(CLIWorld world, int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
CLIChunk[] chunks = new CLIChunk[32 * 32];
|
||||
for(int cx = 0; cx < 32; cx++) {
|
||||
for(int cz = 0; cz < 32; cz++) {
|
||||
chunks[cx + cz * 32] = new CLIChunk(cx, cz, world);
|
||||
}
|
||||
}
|
||||
this.chunks = chunks;
|
||||
this.world = world;
|
||||
this.chunks = new CLIChunk[32 * 32];;
|
||||
}
|
||||
|
||||
public CLIChunk get(int x, int z) {
|
||||
return chunks[x + z*32];
|
||||
int key = x + z*32;
|
||||
CLIChunk chunk = chunks[key];
|
||||
if(chunk == null) {
|
||||
chunk = new CLIChunk(x, z, world);
|
||||
chunks[key] = chunk;
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MCAFile serialize() {
|
||||
MCAFile mcaFile = new MCAFile(x, z);
|
||||
int count = 0;
|
||||
for(int cx = 0; cx < 32; cx++) {
|
||||
for(int cz = 0; cz < 32; cz++) {
|
||||
mcaFile.setChunk(cx + cz * 32, chunks[cx + cz * 32].serialize());
|
||||
CLIChunk chunk = chunks[cx + cz * 32];
|
||||
if(chunk != null) {
|
||||
count++;
|
||||
mcaFile.setChunk(cx + cz * 32, chunk.serialize());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(count > 0) {
|
||||
mcaFile.cleanupPalettesAndBlockStates();
|
||||
}
|
||||
return mcaFile;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user