Removed warnings and formatted code

This commit is contained in:
OLEGSHA 2021-09-10 23:31:14 +03:00
parent e0f6a08740
commit e2308b825d
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A
4 changed files with 103 additions and 133 deletions

View File

@ -18,7 +18,6 @@
package ru.windcorp.progressia;
import ru.windcorp.progressia.client.ClientProxy;
import ru.windcorp.progressia.client.graphics.GUI;
import ru.windcorp.progressia.common.util.crash.CrashReports;
import ru.windcorp.progressia.common.util.crash.analyzers.OutOfMemoryAnalyzer;
@ -28,17 +27,21 @@ import ru.windcorp.progressia.test.LayerTitle;
public class ProgressiaLauncher {
public static String[] arguments;
private static ClientProxy proxy;
private static Proxy proxy;
public static void launch(String[] args, ClientProxy inProxy) {
public static void launch(String[] args, Proxy proxy) {
arguments = args.clone();
setupCrashReports();
inProxy.initialize();
proxy = inProxy;
proxy.initialize();
ProgressiaLauncher.proxy = proxy;
GUI.addTopLayer(new LayerTitle("Title"));
}
public static Proxy getProxy() {
return proxy;
}
private static void setupCrashReports() {
// Context providers
CrashReports.registerProvider(new OSContextProvider());

View File

@ -88,13 +88,11 @@ public class Region {
offsets.put(pos, offset);
}
public AtomicBoolean isClosed()
{
public AtomicBoolean isClosed() {
return isClosed;
}
public AtomicBoolean isUsing()
{
public AtomicBoolean isUsing() {
return isUsing;
}
@ -129,8 +127,6 @@ public class Region {
return arrayStream.toByteArray();
}
public DefaultChunkData load(Vec3i chunkPos, DefaultWorldData world, Server server)
throws IOException,
DecodingException {

View File

@ -13,9 +13,9 @@ import org.apache.logging.log4j.LogManager;
import glm.vec._3.i.Vec3i;
import ru.windcorp.progressia.common.world.generic.ChunkMap;
/**Backend for the .progressia_region file.
/**
* Backend for the .progressia_region file.
* Use similarly to a file object
*
*/
public class RegionFile {
// 4 MiB
@ -26,8 +26,7 @@ public class RegionFile {
final byte endBytes[] = new byte[SECTOR_SIZE];
public static enum SectorType
{
public static enum SectorType {
Ending(0), // Just an empty block
Data(1), // has a byte counting up in position 1, and then
PartitionLink(2),
@ -35,8 +34,7 @@ public class RegionFile {
private final byte data;
SectorType(int i)
{
SectorType(int i) {
this.data = (byte) i;
}
@ -48,8 +46,7 @@ public class RegionFile {
private final RandomAccessFile file;
public RegionFile(RandomAccessFile inFile)
{
public RegionFile(RandomAccessFile inFile) {
file = inFile;
}
@ -82,10 +79,8 @@ public class RegionFile {
boolean shouldEnd = false;
byte counter = 0;
while (!shouldEnd)
{
if (offset > maxUsed)
{
while (!shouldEnd) {
if (offset > maxUsed) {
maxUsed = offset;
}
@ -96,21 +91,16 @@ public class RegionFile {
file.seek(HEADER_SIZE + SECTOR_SIZE * offset);
byte type = file.readByte();
if (type == SectorType.Data.data)
{
if (type == SectorType.Data.data) {
byte fileCounter = file.readByte();
if (fileCounter != counter)
{
if (fileCounter != counter) {
throw new IOException("An unexpected block was found");
}
counter++;
offset++;
}
else if (type == SectorType.Ending.data) {
} else if (type == SectorType.Ending.data) {
shouldEnd = true;
}
else if (type == SectorType.PartitionLink.data)
{
} else if (type == SectorType.PartitionLink.data) {
offset = file.readInt();
}
@ -119,11 +109,9 @@ public class RegionFile {
LogManager.getLogger("Region").debug("Efficiency of {}", (double) used.size() / maxUsed);
}
public void makeHeader() throws IOException
{
public void makeHeader() throws IOException {
file.seek(0);
for (int i=0;i<HEADER_SIZE;i++)
{
for (int i = 0; i < HEADER_SIZE; i++) {
file.write(0);
}
}
@ -134,8 +122,7 @@ public class RegionFile {
byte tempBuffer[] = new byte[SECTOR_SIZE];
byte counter = 0;
boolean isDone = false;
while (!isDone)
{
while (!isDone) {
if (file.length() > HEADER_SIZE + SECTOR_SIZE * (dataOffset + 1)) {
file.seek(HEADER_SIZE + SECTOR_SIZE * (dataOffset + 1));
byte header = file.readByte();
@ -155,21 +142,18 @@ public class RegionFile {
tempBuffer[0] = 1;
tempBuffer[1] = counter;
counter++;
for (int i=0;i<(SECTOR_SIZE-SECTOR_HEADER_SIZE-1);i++)
{
if (loc*(SECTOR_SIZE-SECTOR_HEADER_SIZE-1) + i<buffer.length)
{
for (int i = 0; i < (SECTOR_SIZE - SECTOR_HEADER_SIZE - 1); i++) {
if (loc * (SECTOR_SIZE - SECTOR_HEADER_SIZE - 1) + i < buffer.length) {
tempBuffer[i + SECTOR_HEADER_SIZE + 1] = buffer[loc * (SECTOR_SIZE - SECTOR_HEADER_SIZE - 1) + i];
}
else
{
} else {
isDone = true;
break;
}
}
loc++;
if (file.getFilePointer() < 256)
LogManager.getLogger("Region").debug("at {}, ({},{},{}), {}", file.getFilePointer(),pos.x,pos.y,pos.z, dataOffset);
LogManager.getLogger("Region")
.debug("at {}, ({},{},{}), {}", file.getFilePointer(), pos.x, pos.y, pos.z, dataOffset);
file.seek(HEADER_SIZE + SECTOR_SIZE * dataOffset);
dataOffset++;
file.write(tempBuffer);
@ -192,8 +176,7 @@ public class RegionFile {
return dataOffset;
}
private int allocateEmptySector() throws IOException
{
private int allocateEmptySector() throws IOException {
int outputLen = (int) file.length();
int dataOffset = (int) Math.ceil((double) (outputLen - HEADER_SIZE) / SECTOR_SIZE);
@ -212,48 +195,41 @@ public class RegionFile {
boolean reachedEnd = false;
byte counter = 0;
while (!reachedEnd)
{
while (!reachedEnd) {
int bytesRead = file.read(tempBuffer, 0, SECTOR_SIZE);
if (bytesRead<0)
{
if (bytesRead < 0) {
reachedEnd = true;
continue;
}
if (tempBuffer[0] == SectorType.Data.data)
{
if (tempBuffer[1] != counter)
{
throw new IOException("Sectors were read out of order\nExpected chunk number "+Byte.toString(counter)+" but encountered number " + Byte.toString(tempBuffer[1]));
if (tempBuffer[0] == SectorType.Data.data) {
if (tempBuffer[1] != counter) {
throw new IOException(
"Sectors were read out of order\nExpected chunk number " + Byte.toString(counter)
+ " but encountered number " + Byte.toString(tempBuffer[1])
);
}
counter++;
if (buffer.length - bufferPos < SECTOR_SIZE-SECTOR_HEADER_SIZE-1)
{
if (buffer.length - bufferPos < SECTOR_SIZE - SECTOR_HEADER_SIZE - 1) {
byte newBuffer[] = new byte[buffer.length + SECTOR_SIZE * 16];
for (int i=0;i<buffer.length;i++) // TODO dedicated copy, java-y at least
for (int i = 0; i < buffer.length; i++) // TODO dedicated
// copy, java-y at
// least
{
newBuffer[i] = buffer[i];
}
buffer = newBuffer;
}
for (int i=0;i<SECTOR_SIZE-SECTOR_HEADER_SIZE-1;i++)
{
for (int i = 0; i < SECTOR_SIZE - SECTOR_HEADER_SIZE - 1; i++) {
buffer[bufferPos + i] = tempBuffer[i + 2];
}
bufferPos += SECTOR_SIZE - SECTOR_HEADER_SIZE - 1;
}
else if (tempBuffer[0] == SectorType.Ending.data)
{
} else if (tempBuffer[0] == SectorType.Ending.data) {
reachedEnd = true;
}
else if (tempBuffer[0] == SectorType.PartitionLink.data)
{
} else if (tempBuffer[0] == SectorType.PartitionLink.data) {
ByteBuffer intBuffer = ByteBuffer.wrap(tempBuffer);
int newOffset = intBuffer.getInt(1);
file.seek(HEADER_SIZE + SECTOR_SIZE * newOffset);
}
else
{
} else {
throw new IOException("Invalid sector ID.");
}
}

View File

@ -232,23 +232,18 @@ public class TestWorldDiskIO implements WorldContainer {
ChunkMap<AtomicBoolean> isCloseds = ChunkMaps.newHashMap();
ChunkMap<AtomicBoolean> isUsings = ChunkMaps.newHashMap();
for (Vec3i region : regions.keys())
{
for (Vec3i region : regions.keys()) {
isCloseds.put(region, regions.get(region).isClosed());
isUsings.put(region, regions.get(region).isUsing());
}
boolean stillOpen = true;
while (stillOpen)
{
while (stillOpen) {
stillOpen = false;
for (Vec3i region : regions.keys()) {
if (!isCloseds.get(region).get() && !isUsings.get(region).get())
{
if (!isCloseds.get(region).get() && !isUsings.get(region).get()) {
regions.get(region).close();
}
else if (isUsings.get(region).get())
{
} else if (isUsings.get(region).get()) {
stillOpen = false;
}
}