Fixing stuff

-Got rid of some annoying logging
-Format
This commit is contained in:
opfromthestart 2021-08-18 13:21:54 -04:00
parent 9c26418354
commit b7dcbb0f30
441 changed files with 1011 additions and 986 deletions

View File

@ -39,8 +39,7 @@ public class ProgressiaLauncher {
GUI.addTopLayer(new LayerTitle("Title")); GUI.addTopLayer(new LayerTitle("Title"));
} }
public static void play() public static void play() {
{
proxy.setupServer(); proxy.setupServer();
} }

View File

@ -66,8 +66,7 @@ public class ClientProxy implements Proxy {
// setupServer(); // setupServer();
} }
public void setupServer() public void setupServer() {
{
ServerState.startServer(); ServerState.startServer();
ClientState.connectToLocalServer(); ClientState.connectToLocalServer();
} }

View File

@ -65,18 +65,20 @@ public class ClientState {
setInstance(client); setInstance(client);
MutableString t = new MutableStringLocalized("LayerText.Load"); MutableString t = new MutableStringLocalized("LayerText.Load");
layer = new LayerTestText("Text",() -> {t.update(); return t.get();}); layer = new LayerTestText("Text", () -> {
t.update();
return t.get();
});
ServerState.getInstance().getChunkManager().register((ChunksLoadStartListener) () -> { ServerState.getInstance().getChunkManager().register((ChunksLoadStartListener) () -> {
if (firstLoad) if (firstLoad) {
{
GUI.addTopLayer(layer); GUI.addTopLayer(layer);
}}); }
});
ServerState.getInstance().getChunkManager().register((ChunksLoadFinishListener) () -> { ServerState.getInstance().getChunkManager().register((ChunksLoadFinishListener) () -> {
if (firstLoad) if (firstLoad) {
{
GUI.removeLayer(layer); GUI.removeLayer(layer);
LayerWorld layerWorld = new LayerWorld(client); LayerWorld layerWorld = new LayerWorld(client);
@ -92,10 +94,8 @@ public class ClientState {
} }
public static void disconnectFromLocalServer() public static void disconnectFromLocalServer() {
{ for (Layer layer : GUI.getLayers()) {
for (Layer layer : GUI.getLayers())
{
GUI.removeLayer(layer); GUI.removeLayer(layer);
} }

View File

@ -25,8 +25,6 @@ import ru.windcorp.progressia.client.audio.backend.Speaker;
public class Music public class Music
extends Sound { extends Sound {
public Music(SoundType soundType, int timeLength, float pitch, float gain) { public Music(SoundType soundType, int timeLength, float pitch, float gain) {
super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain); super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain);
} }

View File

@ -166,7 +166,8 @@ public class GraphicsBackend {
0, 0,
vidmode.width(), vidmode.width(),
vidmode.height(), vidmode.height(),
0); 0
);
isFullscreen = true; isFullscreen = true;
} }
@ -179,7 +180,8 @@ public class GraphicsBackend {
(vidmode.height() - getFrameHeight()) / 2, (vidmode.height() - getFrameHeight()) / 2,
getFrameWidth(), getFrameWidth(),
getFrameHeight(), getFrameHeight(),
0); 0
);
isFullscreen = false; isFullscreen = false;
} }

View File

@ -104,8 +104,7 @@ public abstract class BasicButton extends Component {
}); });
} }
public BasicButton(String name, String label, Font labelFont) public BasicButton(String name, String label, Font labelFont) {
{
this(name, new Label(name + ".Label", labelFont, label)); this(name, new Label(name + ".Label", labelFont, label));
} }

View File

@ -105,7 +105,8 @@ public class RadioButton extends BasicButton {
addChild(group); addChild(group);
addListener(KeyEvent.class, e -> { addListener(KeyEvent.class, e -> {
if (e.isRelease()) return false; if (e.isRelease())
return false;
if (e.getKey() == GLFW.GLFW_KEY_LEFT || e.getKey() == GLFW.GLFW_KEY_UP) { if (e.getKey() == GLFW.GLFW_KEY_LEFT || e.getKey() == GLFW.GLFW_KEY_UP) {
if (this.group != null) { if (this.group != null) {
@ -149,7 +150,8 @@ public class RadioButton extends BasicButton {
group.selectNext(); group.selectNext();
removeAction(group.listener); removeAction(group.listener);
group.buttons.remove(this); group.buttons.remove(this);
group.getSelected(); // Clear reference if this was the only button in the group group.getSelected(); // Clear reference if this was the only button
// in the group
} }
this.group = group; this.group = group;
@ -178,7 +180,8 @@ public class RadioButton extends BasicButton {
this.checked = checked; this.checked = checked;
if (group != null) { if (group != null) {
group.listener.accept(this); // Failsafe for manual invocations of setChecked() group.listener.accept(this); // Failsafe for manual invocations of
// setChecked()
} }
} }

View File

@ -26,7 +26,8 @@ import java.util.function.Consumer;
public class RadioButtonGroup { public class RadioButtonGroup {
private final Collection<Consumer<RadioButtonGroup>> actions = Collections.synchronizedCollection(new ArrayList<>()); private final Collection<Consumer<RadioButtonGroup>> actions = Collections
.synchronizedCollection(new ArrayList<>());
final List<RadioButton> buttons = Collections.synchronizedList(new ArrayList<>()); final List<RadioButton> buttons = Collections.synchronizedList(new ArrayList<>());
private RadioButton selected = null; private RadioButton selected = null;

View File

@ -51,7 +51,8 @@ public class ChunkRenderModel implements Renderable {
@Override @Override
public void render(ShapeRenderHelper renderer) { public void render(ShapeRenderHelper renderer) {
if (model == null) return; if (model == null)
return;
renderer.pushTransform().translate( renderer.pushTransform().translate(
chunk.getX() * ChunkData.BLOCKS_PER_CHUNK, chunk.getX() * ChunkData.BLOCKS_PER_CHUNK,

View File

@ -75,7 +75,9 @@ public abstract class BlockRenderTexturedCube
@Override @Override
public final void getFaces( public final void getFaces(
ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, ChunkData chunk,
Vec3i blockInChunk,
BlockFace blockFace,
boolean inner, boolean inner,
Consumer<Face> output, Consumer<Face> output,
Vec3 offset Vec3 offset
@ -84,7 +86,9 @@ public abstract class BlockRenderTexturedCube
} }
private Face createFace( private Face createFace(
ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, ChunkData chunk,
Vec3i blockInChunk,
BlockFace blockFace,
boolean inner, boolean inner,
Vec3 offset Vec3 offset
) { ) {
@ -110,7 +114,13 @@ public abstract class BlockRenderTexturedCube
if (!opaque) { if (!opaque) {
for (int i = 0; i < BLOCK_FACE_COUNT; ++i) { for (int i = 0; i < BLOCK_FACE_COUNT; ++i) {
faces[i + BLOCK_FACE_COUNT] = createFace(chunk, blockInChunk, BlockFace.getFaces().get(i), true, Vectors.ZERO_3); faces[i + BLOCK_FACE_COUNT] = createFace(
chunk,
blockInChunk,
BlockFace.getFaces().get(i),
true,
Vectors.ZERO_3
);
} }
} }

View File

@ -59,7 +59,9 @@ public abstract class TileRenderSurface extends TileRender implements TileOptimi
@Override @Override
public final void getFaces( public final void getFaces(
ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, ChunkData chunk,
Vec3i blockInChunk,
BlockFace blockFace,
boolean inner, boolean inner,
Consumer<Face> output, Consumer<Face> output,
Vec3 offset Vec3 offset
@ -68,7 +70,9 @@ public abstract class TileRenderSurface extends TileRender implements TileOptimi
} }
private Face createFace( private Face createFace(
ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace, ChunkData chunk,
Vec3i blockInChunk,
BlockFace blockFace,
boolean inner, boolean inner,
Vec3 offset Vec3 offset
) { ) {

View File

@ -95,9 +95,12 @@ public interface GenericChunk<Self extends GenericChunk<Self, B, T, TS>, B exten
default boolean isSurfaceBiC(Vec3i blockInChunk) { default boolean isSurfaceBiC(Vec3i blockInChunk) {
int hits = 0; int hits = 0;
if (Coordinates.isOnChunkBorder(blockInChunk.x)) hits++; if (Coordinates.isOnChunkBorder(blockInChunk.x))
if (Coordinates.isOnChunkBorder(blockInChunk.y)) hits++; hits++;
if (Coordinates.isOnChunkBorder(blockInChunk.z)) hits++; if (Coordinates.isOnChunkBorder(blockInChunk.y))
hits++;
if (Coordinates.isOnChunkBorder(blockInChunk.z))
hits++;
return hits >= 1; return hits >= 1;
} }
@ -117,9 +120,12 @@ public interface GenericChunk<Self extends GenericChunk<Self, B, T, TS>, B exten
default boolean isEdgeBiC(Vec3i blockInChunk) { default boolean isEdgeBiC(Vec3i blockInChunk) {
int hits = 0; int hits = 0;
if (Coordinates.isOnChunkBorder(blockInChunk.x)) hits++; if (Coordinates.isOnChunkBorder(blockInChunk.x))
if (Coordinates.isOnChunkBorder(blockInChunk.y)) hits++; hits++;
if (Coordinates.isOnChunkBorder(blockInChunk.z)) hits++; if (Coordinates.isOnChunkBorder(blockInChunk.y))
hits++;
if (Coordinates.isOnChunkBorder(blockInChunk.z))
hits++;
return hits >= 2; return hits >= 2;
} }
@ -139,9 +145,12 @@ public interface GenericChunk<Self extends GenericChunk<Self, B, T, TS>, B exten
default boolean isVertexBiC(Vec3i blockInChunk) { default boolean isVertexBiC(Vec3i blockInChunk) {
int hits = 0; int hits = 0;
if (Coordinates.isOnChunkBorder(blockInChunk.x)) hits++; if (Coordinates.isOnChunkBorder(blockInChunk.x))
if (Coordinates.isOnChunkBorder(blockInChunk.y)) hits++; hits++;
if (Coordinates.isOnChunkBorder(blockInChunk.z)) hits++; if (Coordinates.isOnChunkBorder(blockInChunk.y))
hits++;
if (Coordinates.isOnChunkBorder(blockInChunk.z))
hits++;
return hits == 3; return hits == 3;
} }

View File

@ -81,24 +81,20 @@ public class ChunkManager {
} }
@FunctionalInterface @FunctionalInterface
public interface ChunksLoadListener public interface ChunksLoadListener {
{
void handle(boolean starting); void handle(boolean starting);
} }
@FunctionalInterface @FunctionalInterface
private interface ChunksLoadEventListener private interface ChunksLoadEventListener {
{
void handle(); void handle();
} }
public interface ChunksLoadStartListener extends ChunksLoadEventListener public interface ChunksLoadStartListener extends ChunksLoadEventListener {
{
} }
public interface ChunksLoadFinishListener extends ChunksLoadEventListener public interface ChunksLoadFinishListener extends ChunksLoadEventListener {
{
} }
@ -111,7 +107,8 @@ public class ChunkManager {
private Collection<ChunksLoadListener> listeners = Collections.synchronizedCollection(new ArrayList<>()); private Collection<ChunksLoadListener> listeners = Collections.synchronizedCollection(new ArrayList<>());
private Collection<ChunksLoadStartListener> startListeners = Collections.synchronizedCollection(new ArrayList<>()); private Collection<ChunksLoadStartListener> startListeners = Collections.synchronizedCollection(new ArrayList<>());
private Collection<ChunksLoadFinishListener> finishListeners = Collections.synchronizedCollection( new ArrayList<>()); private Collection<ChunksLoadFinishListener> finishListeners = Collections
.synchronizedCollection(new ArrayList<>());
// TODO replace with a normal Map managed by some sort of PlayerListener, // TODO replace with a normal Map managed by some sort of PlayerListener,
// weak maps are weak // weak maps are weak
@ -132,23 +129,19 @@ public class ChunkManager {
} }
} }
public void register(ChunksLoadListener cll) public void register(ChunksLoadListener cll) {
{
listeners.add(cll); listeners.add(cll);
} }
public void register(ChunksLoadStartListener clsl) public void register(ChunksLoadStartListener clsl) {
{
startListeners.add(clsl); startListeners.add(clsl);
} }
public void register(ChunksLoadFinishListener clfl) public void register(ChunksLoadFinishListener clfl) {
{
finishListeners.add(clfl); finishListeners.add(clfl);
} }
public void unregisterAll() public void unregisterAll() {
{
listeners.clear(); listeners.clear();
} }
@ -178,8 +171,7 @@ public class ChunkManager {
private void processQueues() { private void processQueues() {
if (toUnload.size()!=0 || toLoad.size()!=0) if (toUnload.size() != 0 || toLoad.size() != 0) {
{
LogManager.getLogger().info(String.valueOf(toUnload.size()) + " " + String.valueOf(toLoad.size())); LogManager.getLogger().info(String.valueOf(toUnload.size()) + " " + String.valueOf(toLoad.size()));
} }
listeners.forEach(l -> l.handle(false)); listeners.forEach(l -> l.handle(false));

View File

@ -73,8 +73,7 @@ public class PlayerManager {
return player; return player;
} }
public void removePlayer(Player player) public void removePlayer(Player player) {
{
players.remove(player); players.remove(player);
} }

View File

@ -73,8 +73,7 @@ public class ServerThread implements Runnable {
@Override @Override
public void run() { public void run() {
try { try {
if (isShuttingDown) if (isShuttingDown) {
{
getTicker().stop(); getTicker().stop();
executor.shutdown(); executor.shutdown();
return; return;

View File

@ -116,7 +116,6 @@ class Ticker {
getCoordinator().crash(e, this.name); getCoordinator().crash(e, this.name);
} }
} }
private synchronized boolean sleep() { private synchronized boolean sleep() {

View File

@ -90,15 +90,17 @@ public class LayerButtonTest extends MenuLayer {
ClientState.disconnectFromLocalServer(); ClientState.disconnectFromLocalServer();
MutableString t = new MutableStringLocalized("LayerText.Save"); MutableString t = new MutableStringLocalized("LayerText.Save");
LayerTestText layer = new LayerTestText("Text",() -> {t.update(); return t.get();}); LayerTestText layer = new LayerTestText("Text", () -> {
t.update();
return t.get();
});
GUI.addTopLayer(layer); GUI.addTopLayer(layer);
ChunkManager cm = ServerState.getInstance().getChunkManager(); ChunkManager cm = ServerState.getInstance().getChunkManager();
alive = true; alive = true;
cm.register((ChunksLoadFinishListener) () -> { cm.register((ChunksLoadFinishListener) () -> {
if (alive) if (alive) {
{
GUI.removeLayer(layer); GUI.removeLayer(layer);
GUI.addTopLayer(new LayerTitle("Title")); GUI.addTopLayer(new LayerTitle("Title"));
// cm.unregisterAll(); // cm.unregisterAll();
@ -117,7 +119,6 @@ public class LayerButtonTest extends MenuLayer {
ClientState.setInstance(null); ClientState.setInstance(null);
// ServerState.getInstance().getChunkManager().unloadAll(); // ServerState.getInstance().getChunkManager().unloadAll();
})); }));
getContent().takeFocus(); getContent().takeFocus();

View File

@ -12,13 +12,13 @@ public class LayerTestText extends GUILayer {
public LayerTestText(String name, Supplier<String> value) { public LayerTestText(String name, Supplier<String> value) {
super(name, new LayoutVertical(20, 10)); super(name, new LayoutVertical(20, 10));
//MutableString title = new MutableStringLocalized("Layer"+name+".Title"); // MutableString title = new
// MutableStringLocalized("Layer"+name+".Title");
Font titleFont = new Font().deriveBold().withColor(Colors.BLACK).withAlign(0.5f); Font titleFont = new Font().deriveBold().withColor(Colors.BLACK).withAlign(0.5f);
getRoot().addChild(new Label(name + ".Text", titleFont, value)); getRoot().addChild(new Label(name + ".Text", titleFont, value));
} }
public LayerTestText(String name, String value) public LayerTestText(String name, String value) {
{
this(name, () -> value); this(name, () -> value);
} }
} }

View File

@ -25,7 +25,8 @@ public class LayerTitle extends GUILayer {
getRoot().addChild(new Button(name + ".Play", new Label(name + ".Play", buttonFont, playText)).addAction(b -> { getRoot().addChild(new Button(name + ".Play", new Label(name + ".Play", buttonFont, playText)).addAction(b -> {
GUI.removeLayer(this); GUI.removeLayer(this);
ProgressiaLauncher.play();})); ProgressiaLauncher.play();
}));
MutableString quitText = new MutableStringLocalized("Layer" + name + ".Quit"); MutableString quitText = new MutableStringLocalized("Layer" + name + ".Quit");
getRoot().addChild(new Button(name + "Quit", new Label(name + ".Quit", buttonFont, quitText)).addAction(b -> { getRoot().addChild(new Button(name + "Quit", new Label(name + ".Quit", buttonFont, quitText)).addAction(b -> {

View File

@ -141,7 +141,8 @@ public class TestMusicPlayer implements Runnable {
} }
public static void startNextNow() { public static void startNextNow() {
if (instance == null) return; if (instance == null)
return;
synchronized (instance) { synchronized (instance) {
instance.nextStart = System.currentTimeMillis(); instance.nextStart = System.currentTimeMillis();

View File

@ -91,8 +91,7 @@ public class TestPlayerControls {
private LayerTestGUI debugLayer = null; private LayerTestGUI debugLayer = null;
private Runnable updateCallback = null; private Runnable updateCallback = null;
public static void resetInstance() public static void resetInstance() {
{
INSTANCE = new TestPlayerControls(); INSTANCE = new TestPlayerControls();
} }

View File

@ -78,24 +78,28 @@ public class TestWorldDiskIO {
return loc << 1; return loc << 1;
} }
/*private static int intFromNat(int loc) // Possibly unused /*
{ * private static int intFromNat(int loc) // Possibly unused
if ((loc & 1) == 1) * {
return -loc >> 1; * if ((loc & 1) == 1)
return loc >> 1; * return -loc >> 1;
}*/ * return loc >> 1;
* }
*/
private static Vec3i getRegion(Vec3i chunkLoc) { private static Vec3i getRegion(Vec3i chunkLoc) {
return new Vec3i(natFromInt(chunkLoc.x/regionSize.x), natFromInt(chunkLoc.y/regionSize.y), natFromInt(chunkLoc.z/regionSize.z)); return new Vec3i(
natFromInt(chunkLoc.x / regionSize.x),
natFromInt(chunkLoc.y / regionSize.y),
natFromInt(chunkLoc.z / regionSize.z)
);
} }
private static int mod(int a, int m) private static int mod(int a, int m) {
{
return ((a % m) + m) % m; return ((a % m) + m) % m;
} }
private static Vec3i getRegionLoc(Vec3i chunkLoc) private static Vec3i getRegionLoc(Vec3i chunkLoc) {
{
return new Vec3i(mod(chunkLoc.x, regionSize.x), mod(chunkLoc.y, regionSize.y), mod(chunkLoc.z, regionSize.z)); return new Vec3i(mod(chunkLoc.x, regionSize.x), mod(chunkLoc.y, regionSize.y), mod(chunkLoc.z, regionSize.z));
} }
@ -130,8 +134,7 @@ public class TestWorldDiskIO {
} }
} }
private static void expand(int sectors) private static void expand(int sectors) {
{
} }
@ -197,9 +200,7 @@ public class TestWorldDiskIO {
ChunkIO.save(chunk, output, IOContext.SAVE); ChunkIO.save(chunk, output, IOContext.SAVE);
writeGenerationHint(chunk, output, server); writeGenerationHint(chunk, output, server);
} }
} } else if (currentFormat == 65536) {
else if (currentFormat == 65536)
{
LOG.debug( LOG.debug(
"Saving {} {} {}", "Saving {} {} {}",
chunk.getPosition().x, chunk.getPosition().x,
@ -220,18 +221,19 @@ public class TestWorldDiskIO {
) )
); );
/*if (!dosave) /*
{ * if (!dosave)
return; * {
} * return;
dosave = false;*/ * }
* dosave = false;
*/
try ( try (
RandomAccessFile output = new RandomAccessFile(path.toFile(), "rw") RandomAccessFile output = new RandomAccessFile(path.toFile(), "rw")
) { ) {
// LOG.debug(output.read()); // LOG.debug(output.read());
if (output.read()<0) if (output.read() < 0) {
{
LOG.info("Making header"); LOG.info("Making header");
output.writeChars("\0".repeat((offsetBytes + 1) * chunksPerRegion)); output.writeChars("\0".repeat((offsetBytes + 1) * chunksPerRegion));
} }
@ -243,17 +245,18 @@ public class TestWorldDiskIO {
int offset = output.readInt(); int offset = output.readInt();
int sectorLength = offset & 255; int sectorLength = offset & 255;
offset = offset >> 8; offset = offset >> 8;
if (sectorLength == 0) if (sectorLength == 0) {
{
int outputLen = (int) output.length(); int outputLen = (int) output.length();
offset = (int) (outputLen - fullOffset) / sectorSize + 1; offset = (int) (outputLen - fullOffset) / sectorSize + 1;
output.seek(shortOffset); output.seek(shortOffset);
output.writeInt(offset << 8); output.writeInt(offset << 8);
output.seek(outputLen); output.seek(outputLen);
/*while (output.length()<fullOffset+sectorSize*offset) /*
{ * while (output.length()<fullOffset+sectorSize*offset)
output.write((int) (output.length()%256)); * {
}*/ * output.write((int) (output.length()%256));
* }
*/
output.setLength(fullOffset + offset * sectorSize); output.setLength(fullOffset + offset * sectorSize);
// output.write(200); // output.write(200);
} }
@ -261,7 +264,9 @@ public class TestWorldDiskIO {
// int bytestoWrite = output.readInt(); // int bytestoWrite = output.readInt();
// output.mark(sectorSize*sectorLength); // output.mark(sectorSize*sectorLength);
//BufferedOutputStream counter = new BufferedOutputStream(Files.newOutputStream( SAVE_DIR.resolve(tempFile))); // BufferedOutputStream counter = new
// BufferedOutputStream(Files.newOutputStream(
// SAVE_DIR.resolve(tempFile)));
ByteArrayOutputStream tempDataStream = new ByteArrayOutputStream(); ByteArrayOutputStream tempDataStream = new ByteArrayOutputStream();
DataOutputStream trueOutput = new DataOutputStream( DataOutputStream trueOutput = new DataOutputStream(
new DeflaterOutputStream( new DeflaterOutputStream(
@ -277,13 +282,14 @@ public class TestWorldDiskIO {
ChunkIO.save(chunk, trueOutput, IOContext.SAVE); ChunkIO.save(chunk, trueOutput, IOContext.SAVE);
writeGenerationHint(chunk, trueOutput, server); writeGenerationHint(chunk, trueOutput, server);
/*while (counter.getCount()%sectorSize != 0) { /*
counter.write(0); * while (counter.getCount()%sectorSize != 0) {
}*/ * counter.write(0);
* }
*/
LOG.info("Wrote {} bytes to {},{},{}",trueOutput.size(),chunk.getPosition().x,chunk.getPosition().y,chunk.getPosition().z);
// LOG.info("Wrote {} bytes to
// {},{},{}",trueOutput.size(),chunk.getPosition().x,chunk.getPosition().y,chunk.getPosition().z);
trueOutput.close(); trueOutput.close();
@ -294,7 +300,8 @@ public class TestWorldDiskIO {
output.seek(shortOffset + offsetBytes); output.seek(shortOffset + offsetBytes);
output.write((int) tempData.length / sectorSize + 1); output.write((int) tempData.length / sectorSize + 1);
LOG.info("Used {} sectors",(int) tempData.length/sectorSize + 1); // LOG.info("Used {} sectors",(int)
// tempData.length/sectorSize + 1);
output.close(); output.close();
@ -348,20 +355,21 @@ public class TestWorldDiskIO {
int bfClone = bestFormat; int bfClone = bestFormat;
for (int i=0;i<4;i++) for (int i = 0; i < 4; i++) {
{
bw.write(bfClone >> 24); bw.write(bfClone >> 24);
LOG.debug(bfClone >> 24); LOG.debug(bfClone >> 24);
bfClone = bfClone << 8; bfClone = bfClone << 8;
} }
/*bw.write( /*
new char[] { * bw.write(
(char) bestFormat / (256 * 256 * 256), * new char[] {
(char) (bestFormat % 256) / (256 * 256), * (char) bestFormat / (256 * 256 * 256),
(char) (bestFormat % (256 * 256)) / (256), * (char) (bestFormat % 256) / (256 * 256),
(char) (bestFormat % (256 * 256 * 256)) } * (char) (bestFormat % (256 * 256)) / (256),
);*/ * (char) (bestFormat % (256 * 256 * 256)) }
* );
*/
bw.close(); bw.close();
} catch (IOException e) { } catch (IOException e) {
@ -521,19 +529,19 @@ public class TestWorldDiskIO {
} }
} }
private static ChunkData loadRegion(Path path, Vec3i chunkPos, WorldData world, Server server) throws IOException, DecodingException private static ChunkData loadRegion(Path path, Vec3i chunkPos, WorldData world, Server server)
{ throws IOException,
DecodingException {
try ( try (
BufferedInputStream input = new BufferedInputStream(Files.newInputStream(path)) BufferedInputStream input = new BufferedInputStream(Files.newInputStream(path))
) { ) {
LOG.info(path.toString()); // LOG.info(path.toString());
Vec3i pos = getRegionLoc(chunkPos); Vec3i pos = getRegionLoc(chunkPos);
int shortOffset = (offsetBytes + 1) * (pos.z + regionSize.z * (pos.y + regionSize.y * pos.x)); int shortOffset = (offsetBytes + 1) * (pos.z + regionSize.z * (pos.y + regionSize.y * pos.x));
int fullOffset = (offsetBytes + 1) * (chunksPerRegion); int fullOffset = (offsetBytes + 1) * (chunksPerRegion);
input.skipNBytes(shortOffset); input.skipNBytes(shortOffset);
int offset = 0; int offset = 0;
for (int i=0;i<offsetBytes;i++) for (int i = 0; i < offsetBytes; i++) {
{
offset *= 256; offset *= 256;
offset += input.read(); offset += input.read();
} }
@ -541,12 +549,13 @@ public class TestWorldDiskIO {
input.skipNBytes(fullOffset - shortOffset - offsetBytes - 1); input.skipNBytes(fullOffset - shortOffset - offsetBytes - 1);
input.skipNBytes(sectorSize * offset); input.skipNBytes(sectorSize * offset);
LOG.info("Read {} sectors", sectorLength); // LOG.info("Read {} sectors", sectorLength);
byte tempData[] = input.readNBytes(sectorSize * sectorLength); byte tempData[] = input.readNBytes(sectorSize * sectorLength);
DataInputStream trueInput = new DataInputStream( DataInputStream trueInput = new DataInputStream(
new InflaterInputStream(new BufferedInputStream(new ByteArrayInputStream(tempData)))); new InflaterInputStream(new BufferedInputStream(new ByteArrayInputStream(tempData)))
);
ChunkData chunk = ChunkIO.load(world, chunkPos, trueInput, IOContext.SAVE); ChunkData chunk = ChunkIO.load(world, chunkPos, trueInput, IOContext.SAVE);
readGenerationHint(chunk, trueInput, server); readGenerationHint(chunk, trueInput, server);
trueInput.close(); trueInput.close();