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.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@ -16,9 +16,11 @@ import org.apache.logging.log4j.Logger;
|
|||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import glm.vec._3.i.Vec3i;
|
||||||
import ru.windcorp.progressia.common.io.ChunkIO;
|
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.ChunkData;
|
||||||
import ru.windcorp.progressia.common.world.DecodingException;
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
|
import ru.windcorp.progressia.server.Server;
|
||||||
|
|
||||||
public class TestWorldDiskIO {
|
public class TestWorldDiskIO {
|
||||||
|
|
||||||
@ -27,7 +29,7 @@ public class TestWorldDiskIO {
|
|||||||
|
|
||||||
private static final boolean ENABLE = true;
|
private static final boolean ENABLE = true;
|
||||||
|
|
||||||
public static void saveChunk(ChunkData chunk) {
|
public static void saveChunk(ChunkData chunk, Server server) {
|
||||||
if (!ENABLE) return;
|
if (!ENABLE) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -43,15 +45,20 @@ public class TestWorldDiskIO {
|
|||||||
chunk.getPosition().x, chunk.getPosition().y, chunk.getPosition().z
|
chunk.getPosition().x, chunk.getPosition().y, chunk.getPosition().z
|
||||||
));
|
));
|
||||||
|
|
||||||
try (OutputStream output = new DeflaterOutputStream(new BufferedOutputStream(Files.newOutputStream(path)))) {
|
try (DataOutputStream output = new DataOutputStream(new DeflaterOutputStream(new BufferedOutputStream(Files.newOutputStream(path))))) {
|
||||||
ChunkIO.save(chunk, output);
|
ChunkIO.save(chunk, output, IOContext.SAVE);
|
||||||
|
writeGenerationHint(chunk, output, server);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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;
|
if (!ENABLE) return null;
|
||||||
|
|
||||||
Path path = SAVE_DIR.resolve(String.format(
|
Path path = SAVE_DIR.resolve(String.format(
|
||||||
@ -69,7 +76,7 @@ public class TestWorldDiskIO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ChunkData result = load(path, chunkPos, world);
|
ChunkData result = load(path, chunkPos, world, server);
|
||||||
|
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
"Loaded {} {} {}",
|
"Loaded {} {} {}",
|
||||||
@ -87,10 +94,16 @@ public class TestWorldDiskIO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ChunkData load(Path path, Vec3i chunkPos, WorldData world) throws IOException, DecodingException {
|
private static ChunkData load(Path path, Vec3i chunkPos, WorldData world, Server server) throws IOException, DecodingException {
|
||||||
try (InputStream input = new InflaterInputStream(new BufferedInputStream(Files.newInputStream(path)))) {
|
try (DataInputStream input = new DataInputStream(new InflaterInputStream(new BufferedInputStream(Files.newInputStream(path))))) {
|
||||||
return ChunkIO.load(world, chunkPos, input);
|
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