Added generation hint persistence
This commit is contained in:
parent
06f4b4637d
commit
7a9e03f700
@ -2,9 +2,9 @@ package ru.windcorp.progressia.test;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@ -16,9 +16,11 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import ru.windcorp.progressia.common.io.ChunkIO;
|
||||
import ru.windcorp.progressia.common.state.IOContext;
|
||||
import ru.windcorp.progressia.common.world.ChunkData;
|
||||
import ru.windcorp.progressia.common.world.DecodingException;
|
||||
import ru.windcorp.progressia.common.world.WorldData;
|
||||
import ru.windcorp.progressia.server.Server;
|
||||
|
||||
public class TestWorldDiskIO {
|
||||
|
||||
@ -27,7 +29,7 @@ public class TestWorldDiskIO {
|
||||
|
||||
private static final boolean ENABLE = true;
|
||||
|
||||
public static void saveChunk(ChunkData chunk) {
|
||||
public static void saveChunk(ChunkData chunk, Server server) {
|
||||
if (!ENABLE) return;
|
||||
|
||||
try {
|
||||
@ -43,15 +45,20 @@ public class TestWorldDiskIO {
|
||||
chunk.getPosition().x, chunk.getPosition().y, chunk.getPosition().z
|
||||
));
|
||||
|
||||
try (OutputStream output = new DeflaterOutputStream(new BufferedOutputStream(Files.newOutputStream(path)))) {
|
||||
ChunkIO.save(chunk, output);
|
||||
try (DataOutputStream output = new DataOutputStream(new DeflaterOutputStream(new BufferedOutputStream(Files.newOutputStream(path))))) {
|
||||
ChunkIO.save(chunk, output, IOContext.SAVE);
|
||||
writeGenerationHint(chunk, output, server);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static ChunkData tryToLoad(Vec3i chunkPos, WorldData world) {
|
||||
private static void writeGenerationHint(ChunkData chunk, DataOutputStream output, Server server) throws IOException {
|
||||
server.getWorld().getGenerator().writeGenerationHint(output, chunk.getGenerationHint());
|
||||
}
|
||||
|
||||
public static ChunkData tryToLoad(Vec3i chunkPos, WorldData world, Server server) {
|
||||
if (!ENABLE) return null;
|
||||
|
||||
Path path = SAVE_DIR.resolve(String.format(
|
||||
@ -69,7 +76,7 @@ public class TestWorldDiskIO {
|
||||
}
|
||||
|
||||
try {
|
||||
ChunkData result = load(path, chunkPos, world);
|
||||
ChunkData result = load(path, chunkPos, world, server);
|
||||
|
||||
LOG.debug(
|
||||
"Loaded {} {} {}",
|
||||
@ -87,10 +94,16 @@ public class TestWorldDiskIO {
|
||||
}
|
||||
}
|
||||
|
||||
private static ChunkData load(Path path, Vec3i chunkPos, WorldData world) throws IOException, DecodingException {
|
||||
try (InputStream input = new InflaterInputStream(new BufferedInputStream(Files.newInputStream(path)))) {
|
||||
return ChunkIO.load(world, chunkPos, input);
|
||||
private static ChunkData load(Path path, Vec3i chunkPos, WorldData world, Server server) throws IOException, DecodingException {
|
||||
try (DataInputStream input = new DataInputStream(new InflaterInputStream(new BufferedInputStream(Files.newInputStream(path))))) {
|
||||
ChunkData chunk = ChunkIO.load(world, chunkPos, input, IOContext.SAVE);
|
||||
readGenerationHint(chunk, input, server);
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
|
||||
private static void readGenerationHint(ChunkData chunk, DataInputStream input, Server server) throws IOException, DecodingException {
|
||||
chunk.setGenerationHint(server.getWorld().getGenerator().readGenerationHint(input));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user