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"));
}
public static void play()
{
public static void play() {
proxy.setupServer();
}

View File

@ -63,11 +63,10 @@ public class ClientProxy implements Proxy {
TestMusicPlayer.start();
//setupServer();
// setupServer();
}
public void setupServer()
{
public void setupServer() {
ServerState.startServer();
ClientState.connectToLocalServer();
}

View File

@ -65,18 +65,20 @@ public class ClientState {
setInstance(client);
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)() -> {
if (firstLoad)
{
ServerState.getInstance().getChunkManager().register((ChunksLoadStartListener) () -> {
if (firstLoad) {
GUI.addTopLayer(layer);
}});
}
});
ServerState.getInstance().getChunkManager().register((ChunksLoadFinishListener)() -> {
if (firstLoad)
{
ServerState.getInstance().getChunkManager().register((ChunksLoadFinishListener) () -> {
if (firstLoad) {
GUI.removeLayer(layer);
LayerWorld layerWorld = new LayerWorld(client);
@ -92,14 +94,12 @@ public class ClientState {
}
public static void disconnectFromLocalServer()
{
for (Layer layer : GUI.getLayers())
{
public static void disconnectFromLocalServer() {
for (Layer layer : GUI.getLayers()) {
GUI.removeLayer(layer);
}
//ServerState.getInstance().getClientManager();
// ServerState.getInstance().getClientManager();
}
private ClientState() {

View File

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

View File

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

View File

@ -66,7 +66,7 @@ class LWJGLInitializer {
GraphicsBackend.setWindowHandle(handle);
glfwMakeContextCurrent(handle);
glfwSwapInterval(0); // TODO: remove after config system is added
glfwSwapInterval(0); // TODO: remove after config system is added
}
private static void positionWindow() {

View File

@ -59,8 +59,8 @@ public abstract class BasicButton extends Component {
return false;
} else if (
e.isLeftMouseButton() ||
e.getKey() == GLFW.GLFW_KEY_SPACE ||
e.getKey() == GLFW.GLFW_KEY_ENTER
e.getKey() == GLFW.GLFW_KEY_SPACE ||
e.getKey() == GLFW.GLFW_KEY_ENTER
) {
setPressed(e.isPress());
return true;
@ -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));
}

View File

@ -105,7 +105,8 @@ public class RadioButton extends BasicButton {
addChild(group);
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 (this.group != null) {
@ -149,7 +150,8 @@ public class RadioButton extends BasicButton {
group.selectNext();
removeAction(group.listener);
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;
@ -178,7 +180,8 @@ public class RadioButton extends BasicButton {
this.checked = checked;
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 {
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<>());
private RadioButton selected = null;

View File

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

View File

@ -75,7 +75,9 @@ public abstract class BlockRenderTexturedCube
@Override
public final void getFaces(
ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace,
ChunkData chunk,
Vec3i blockInChunk,
BlockFace blockFace,
boolean inner,
Consumer<Face> output,
Vec3 offset
@ -84,7 +86,9 @@ public abstract class BlockRenderTexturedCube
}
private Face createFace(
ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace,
ChunkData chunk,
Vec3i blockInChunk,
BlockFace blockFace,
boolean inner,
Vec3 offset
) {
@ -110,7 +114,13 @@ public abstract class BlockRenderTexturedCube
if (!opaque) {
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
public final void getFaces(
ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace,
ChunkData chunk,
Vec3i blockInChunk,
BlockFace blockFace,
boolean inner,
Consumer<Face> output,
Vec3 offset
@ -68,7 +70,9 @@ public abstract class TileRenderSurface extends TileRender implements TileOptimi
}
private Face createFace(
ChunkData chunk, Vec3i blockInChunk, BlockFace blockFace,
ChunkData chunk,
Vec3i blockInChunk,
BlockFace blockFace,
boolean inner,
Vec3 offset
) {
@ -89,7 +93,7 @@ public abstract class TileRenderSurface extends TileRender implements TileOptimi
WorldRenderProgram.getDefault(),
createFace(chunk, blockInChunk, blockFace, false, Vectors.ZERO_3),
createFace(chunk, blockInChunk, blockFace, true, Vectors.ZERO_3)
createFace(chunk, blockInChunk, blockFace, true, Vectors.ZERO_3)
);
}

View File

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

View File

@ -81,24 +81,20 @@ public class ChunkManager {
}
@FunctionalInterface
public interface ChunksLoadListener
{
public interface ChunksLoadListener {
void handle(boolean starting);
}
@FunctionalInterface
private interface ChunksLoadEventListener
{
private interface ChunksLoadEventListener {
void handle();
}
public interface ChunksLoadStartListener extends ChunksLoadEventListener
{
public interface ChunksLoadStartListener extends ChunksLoadEventListener {
}
public interface ChunksLoadFinishListener extends ChunksLoadEventListener
{
public interface ChunksLoadFinishListener extends ChunksLoadEventListener {
}
@ -109,9 +105,10 @@ public class ChunkManager {
private final ChunkSet toLoad = ChunkSets.newHashSet();
private final ChunkSet toUnload = ChunkSets.newHashSet();
private Collection<ChunksLoadListener> listeners = Collections.synchronizedCollection( new ArrayList<>());
private Collection<ChunksLoadStartListener> startListeners = Collections.synchronizedCollection( new ArrayList<>());
private Collection<ChunksLoadFinishListener> finishListeners = Collections.synchronizedCollection( new ArrayList<>());
private Collection<ChunksLoadListener> listeners = Collections.synchronizedCollection(new ArrayList<>());
private Collection<ChunksLoadStartListener> startListeners = Collections.synchronizedCollection(new ArrayList<>());
private Collection<ChunksLoadFinishListener> finishListeners = Collections
.synchronizedCollection(new ArrayList<>());
// TODO replace with a normal Map managed by some sort of PlayerListener,
// weak maps are weak
@ -132,23 +129,19 @@ public class ChunkManager {
}
}
public void register(ChunksLoadListener cll)
{
public void register(ChunksLoadListener cll) {
listeners.add(cll);
}
public void register(ChunksLoadStartListener clsl)
{
public void register(ChunksLoadStartListener clsl) {
startListeners.add(clsl);
}
public void register(ChunksLoadFinishListener clfl)
{
public void register(ChunksLoadFinishListener clfl) {
finishListeners.add(clfl);
}
public void unregisterAll()
{
public void unregisterAll() {
listeners.clear();
}
@ -178,9 +171,8 @@ public class ChunkManager {
private void processQueues() {
if (toUnload.size()!=0 || toLoad.size()!=0)
{
LogManager.getLogger().info(String.valueOf(toUnload.size())+" "+String.valueOf( toLoad.size()));
if (toUnload.size() != 0 || toLoad.size() != 0) {
LogManager.getLogger().info(String.valueOf(toUnload.size()) + " " + String.valueOf(toLoad.size()));
}
listeners.forEach(l -> l.handle(false));
startListeners.forEach(sl -> sl.handle());
@ -241,7 +233,7 @@ public class ChunkManager {
{
WorldData world = getServer().getWorld().getData();
//Collection<ChunkData> chunks = world.getChunks();
// Collection<ChunkData> chunks = world.getChunks();
Collection<Vec3i> chunkPoss = new HashSet<Vec3i>();
world.forEachChunk(c -> {

View File

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

View File

@ -73,8 +73,7 @@ public class ServerThread implements Runnable {
@Override
public void run() {
try {
if (isShuttingDown)
{
if (isShuttingDown) {
getTicker().stop();
executor.shutdown();
return;
@ -90,7 +89,7 @@ public class ServerThread implements Runnable {
isShuttingDown = true;
//getTicker().stop();
// getTicker().stop();
}
public Server getServer() {

View File

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

View File

@ -75,14 +75,14 @@ public class LayerButtonTest extends MenuLayer {
}));
getContent().addChild(new Button("Menu", "Back To Menu").addAction(b -> {
//System.exit(0);
//for (Layer layer : GUI.getLayers())
//{
// GUI.removeLayer(layer);
//}
// System.exit(0);
// for (Layer layer : GUI.getLayers())
// {
// GUI.removeLayer(layer);
// }
getCloseAction().run();
//ClientState.getInstance().;
// ClientState.getInstance().;
Collection<Player> players = ServerState.getInstance().getPlayerManager().getPlayers();
players.clear();
@ -90,21 +90,23 @@ public class LayerButtonTest extends MenuLayer {
ClientState.disconnectFromLocalServer();
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);
ChunkManager cm = ServerState.getInstance().getChunkManager();
alive = true;
cm.register((ChunksLoadFinishListener)() -> {
if (alive)
{
cm.register((ChunksLoadFinishListener) () -> {
if (alive) {
GUI.removeLayer(layer);
GUI.addTopLayer(new LayerTitle("Title"));
//cm.unregisterAll();
// cm.unregisterAll();
alive = false;
//ServerState.getInstance().;
// ServerState.getInstance().;
ServerState.getInstance().shutdown("Safe Exit");
ServerState.setInstance(null);
@ -113,10 +115,9 @@ public class LayerButtonTest extends MenuLayer {
}
});
//ClientState.getInstance();
// ClientState.getInstance();
ClientState.setInstance(null);
//ServerState.getInstance().getChunkManager().unloadAll();
// ServerState.getInstance().getChunkManager().unloadAll();
}));

View File

@ -10,15 +10,15 @@ import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
public class LayerTestText extends GUILayer {
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);
getRoot().addChild(new Label(name+".Text", titleFont, value));
getRoot().addChild(new Label(name + ".Text", titleFont, value));
}
public LayerTestText(String name, String value)
{
this(name,() -> value);
public LayerTestText(String name, String value) {
this(name, () -> value);
}
}

View File

@ -14,21 +14,22 @@ import ru.windcorp.progressia.client.localization.MutableStringLocalized;
public class LayerTitle extends GUILayer {
public LayerTitle(String name) {
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);
getRoot().addChild(new Label(name+".Title", titleFont, title));
getRoot().addChild(new Label(name + ".Title", titleFont, title));
Font buttonFont = titleFont;
MutableString playText = new MutableStringLocalized("Layer"+name+".Play");
getRoot().addChild(new Button(name+".Play", new Label(name+".Play", buttonFont, playText)).addAction(b -> {
MutableString playText = new MutableStringLocalized("Layer" + name + ".Play");
getRoot().addChild(new Button(name + ".Play", new Label(name + ".Play", buttonFont, playText)).addAction(b -> {
GUI.removeLayer(this);
ProgressiaLauncher.play();}));
ProgressiaLauncher.play();
}));
MutableString quitText = new MutableStringLocalized("Layer"+name+".Quit");
getRoot().addChild(new Button(name+"Quit", new Label(name+".Quit", buttonFont, quitText)).addAction(b -> {
MutableString quitText = new MutableStringLocalized("Layer" + name + ".Quit");
getRoot().addChild(new Button(name + "Quit", new Label(name + ".Quit", buttonFont, quitText)).addAction(b -> {
System.exit(0);
}));
}

View File

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

View File

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

View File

@ -78,25 +78,29 @@ public class TestWorldDiskIO {
return loc << 1;
}
/*private static int intFromNat(int loc) // Possibly unused
{
if ((loc & 1) == 1)
return -loc >> 1;
return loc >> 1;
}*/
/*
* private static int intFromNat(int loc) // Possibly unused
* {
* if ((loc & 1) == 1)
* return -loc >> 1;
* return loc >> 1;
* }
*/
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)
{
return ((a%m)+m)%m;
private static int mod(int a, int m) {
return ((a % m) + m) % m;
}
private static Vec3i getRegionLoc(Vec3i chunkLoc)
{
return new Vec3i(mod(chunkLoc.x,regionSize.x),mod(chunkLoc.y,regionSize.y),mod(chunkLoc.z,regionSize.z));
private static Vec3i getRegionLoc(Vec3i chunkLoc) {
return new Vec3i(mod(chunkLoc.x, regionSize.x), mod(chunkLoc.y, regionSize.y), mod(chunkLoc.z, regionSize.z));
}
public static void initRegions() {
@ -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);
writeGenerationHint(chunk, output, server);
}
}
else if (currentFormat == 65536)
{
} else if (currentFormat == 65536) {
LOG.debug(
"Saving {} {} {}",
chunk.getPosition().x,
@ -220,48 +221,52 @@ public class TestWorldDiskIO {
)
);
/*if (!dosave)
{
return;
}
dosave = false;*/
/*
* if (!dosave)
* {
* return;
* }
* dosave = false;
*/
try (
RandomAccessFile output = new RandomAccessFile(path.toFile(), "rw")
) {
//LOG.debug(output.read());
if (output.read()<0)
{
// LOG.debug(output.read());
if (output.read() < 0) {
LOG.info("Making header");
output.writeChars("\0".repeat((offsetBytes+1)*chunksPerRegion));
output.writeChars("\0".repeat((offsetBytes + 1) * chunksPerRegion));
}
Vec3i pos = getRegionLoc(chunk.getPosition());
int shortOffset = (offsetBytes+1)*(pos.z+regionSize.z*(pos.y + regionSize.y*pos.x));
int fullOffset = (offsetBytes+1)*(chunksPerRegion);
int shortOffset = (offsetBytes + 1) * (pos.z + regionSize.z * (pos.y + regionSize.y * pos.x));
int fullOffset = (offsetBytes + 1) * (chunksPerRegion);
output.seek(shortOffset);
int offset = output.readInt();
int sectorLength = offset&255;
int sectorLength = offset & 255;
offset = offset >> 8;
if (sectorLength == 0)
{
if (sectorLength == 0) {
int outputLen = (int) output.length();
offset = (int) (outputLen-fullOffset)/sectorSize+1;
offset = (int) (outputLen - fullOffset) / sectorSize + 1;
output.seek(shortOffset);
output.writeInt(offset<<8);
output.writeInt(offset << 8);
output.seek(outputLen);
/*while (output.length()<fullOffset+sectorSize*offset)
{
output.write((int) (output.length()%256));
}*/
output.setLength(fullOffset+offset*sectorSize);
//output.write(200);
/*
* while (output.length()<fullOffset+sectorSize*offset)
* {
* output.write((int) (output.length()%256));
* }
*/
output.setLength(fullOffset + offset * sectorSize);
// output.write(200);
}
//int bytestoWrite = output.readInt();
//output.mark(sectorSize*sectorLength);
// int bytestoWrite = output.readInt();
// 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();
DataOutputStream trueOutput = new DataOutputStream(
new DeflaterOutputStream(
@ -271,30 +276,32 @@ public class TestWorldDiskIO {
// CountingOutputStream countOutput = new
// CountingOutputStream(trueOutput);
//LOG.info("Before: {}",output.);
//trueOutput.writeBytes("uh try this");
//counter.
// LOG.info("Before: {}",output.);
// trueOutput.writeBytes("uh try this");
// counter.
ChunkIO.save(chunk, trueOutput, IOContext.SAVE);
writeGenerationHint(chunk, trueOutput, server);
/*while (counter.getCount()%sectorSize != 0) {
counter.write(0);
}*/
LOG.info("Wrote {} bytes to {},{},{}",trueOutput.size(),chunk.getPosition().x,chunk.getPosition().y,chunk.getPosition().z);
/*
* while (counter.getCount()%sectorSize != 0) {
* counter.write(0);
* }
*/
// LOG.info("Wrote {} bytes to
// {},{},{}",trueOutput.size(),chunk.getPosition().x,chunk.getPosition().y,chunk.getPosition().z);
trueOutput.close();
byte tempData[] = tempDataStream.toByteArray();
output.seek((long) fullOffset+sectorSize*offset);
output.seek((long) fullOffset + sectorSize * offset);
output.write(tempData);
output.seek(shortOffset+offsetBytes);
output.write((int) tempData.length/sectorSize + 1);
LOG.info("Used {} sectors",(int) tempData.length/sectorSize + 1);
output.seek(shortOffset + offsetBytes);
output.write((int) tempData.length / sectorSize + 1);
// LOG.info("Used {} sectors",(int)
// tempData.length/sectorSize + 1);
output.close();
@ -348,20 +355,21 @@ public class TestWorldDiskIO {
int bfClone = bestFormat;
for (int i=0;i<4;i++)
{
bw.write(bfClone>>24);
LOG.debug(bfClone>>24);
for (int i = 0; i < 4; i++) {
bw.write(bfClone >> 24);
LOG.debug(bfClone >> 24);
bfClone = bfClone << 8;
}
/*bw.write(
new char[] {
(char) bestFormat / (256 * 256 * 256),
(char) (bestFormat % 256) / (256 * 256),
(char) (bestFormat % (256 * 256)) / (256),
(char) (bestFormat % (256 * 256 * 256)) }
);*/
/*
* bw.write(
* new char[] {
* (char) bestFormat / (256 * 256 * 256),
* (char) (bestFormat % 256) / (256 * 256),
* (char) (bestFormat % (256 * 256)) / (256),
* (char) (bestFormat % (256 * 256 * 256)) }
* );
*/
bw.close();
} catch (IOException e) {
@ -521,32 +529,33 @@ 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 (
BufferedInputStream input = new BufferedInputStream(Files.newInputStream(path))
) {
LOG.info(path.toString());
// LOG.info(path.toString());
Vec3i pos = getRegionLoc(chunkPos);
int shortOffset = (offsetBytes+1)*(pos.z+regionSize.z*(pos.y + regionSize.y*pos.x));
int fullOffset = (offsetBytes+1)*(chunksPerRegion);
int shortOffset = (offsetBytes + 1) * (pos.z + regionSize.z * (pos.y + regionSize.y * pos.x));
int fullOffset = (offsetBytes + 1) * (chunksPerRegion);
input.skipNBytes(shortOffset);
int offset = 0;
for (int i=0;i<offsetBytes;i++)
{
offset*=256;
for (int i = 0; i < offsetBytes; i++) {
offset *= 256;
offset += input.read();
}
int sectorLength = input.read();
input.skipNBytes(fullOffset-shortOffset-offsetBytes-1);
input.skipNBytes(sectorSize*offset);
input.skipNBytes(fullOffset - shortOffset - offsetBytes - 1);
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(
new InflaterInputStream(new BufferedInputStream(new ByteArrayInputStream(tempData))));
new InflaterInputStream(new BufferedInputStream(new ByteArrayInputStream(tempData)))
);
ChunkData chunk = ChunkIO.load(world, chunkPos, trueInput, IOContext.SAVE);
readGenerationHint(chunk, trueInput, server);
trueInput.close();