mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-25 21:40:08 +00:00
lazily create chunks to improve memory usage
This commit is contained in:
1 parent
17e2bdc6f7
commit
4000899d6d
2 files changed
+20
-11
No files matched your search
@@ -24,7 +24,7 @@ public final class TerraCLI {
|
|||||||
|
|
||||||
ConfigPack generate = platform.getConfigRegistry().get("OVERWORLD").orElseThrow(); // TODO: make this a cli argument
|
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();
|
world.generate();
|
||||||
|
|
||||||
@@ -32,7 +32,6 @@ public final class TerraCLI {
|
|||||||
Vector2Int pos = mcaFile.getLeft();
|
Vector2Int pos = mcaFile.getLeft();
|
||||||
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
|
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
|
||||||
LOGGER.info("Writing region ({}, {}) to {}", pos.getX(), pos.getZ(), name);
|
LOGGER.info("Writing region ({}, {}) to {}", pos.getX(), pos.getZ(), name);
|
||||||
mcaFile.getRight().cleanupPalettesAndBlockStates();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MCAUtil.write(mcaFile.getRight(), name);
|
MCAUtil.write(mcaFile.getRight(), name);
|
||||||
|
|||||||
@@ -9,31 +9,41 @@ import com.dfsek.terra.cli.world.chunk.CLIChunk;
|
|||||||
public class Region implements NBTSerializable<MCAFile> {
|
public class Region implements NBTSerializable<MCAFile> {
|
||||||
private final CLIChunk[] chunks;
|
private final CLIChunk[] chunks;
|
||||||
private final int x, z;
|
private final int x, z;
|
||||||
|
private final CLIWorld world;
|
||||||
|
|
||||||
public Region(CLIWorld world, int x, int z) {
|
public Region(CLIWorld world, int x, int z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
CLIChunk[] chunks = new CLIChunk[32 * 32];
|
this.world = world;
|
||||||
for(int cx = 0; cx < 32; cx++) {
|
this.chunks = new CLIChunk[32 * 32];;
|
||||||
for(int cz = 0; cz < 32; cz++) {
|
|
||||||
chunks[cx + cz * 32] = new CLIChunk(cx, cz, world);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.chunks = chunks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CLIChunk get(int x, int z) {
|
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
|
@Override
|
||||||
public MCAFile serialize() {
|
public MCAFile serialize() {
|
||||||
MCAFile mcaFile = new MCAFile(x, z);
|
MCAFile mcaFile = new MCAFile(x, z);
|
||||||
|
int count = 0;
|
||||||
for(int cx = 0; cx < 32; cx++) {
|
for(int cx = 0; cx < 32; cx++) {
|
||||||
for(int cz = 0; cz < 32; cz++) {
|
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;
|
return mcaFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user