More Compact region files

-Sector length increased to a short, the minimum sector size is now 16
bytes
This commit is contained in:
opfromthestart 2021-08-30 10:52:56 -04:00
parent d2ffe1fe0e
commit e967a64401

View File

@ -49,9 +49,10 @@ public class Region {
// 1 MiB // 1 MiB
private static final int MAX_CHUNK_SIZE = 1024 * 1024; private static final int MAX_CHUNK_SIZE = 1024 * 1024;
private static final int SECTOR_SIZE = MAX_CHUNK_SIZE / 256; private static final int SECTORS_BYTES = Short.BYTES;
private static final int SECTOR_SIZE = MAX_CHUNK_SIZE >> (SECTORS_BYTES*8);
private static final int DEFINITION_SIZE = Integer.BYTES + 1; private static final int DEFINITION_SIZE = Integer.BYTES + Short.BYTES;
private static final int HEADER_SIZE = DEFINITION_SIZE * REGION_DIAMETER * REGION_DIAMETER * REGION_DIAMETER; private static final int HEADER_SIZE = DEFINITION_SIZE * REGION_DIAMETER * REGION_DIAMETER * REGION_DIAMETER;
@ -129,7 +130,7 @@ public class Region {
for (int i = 0; i < chunksPerRegion; i++) { for (int i = 0; i < chunksPerRegion; i++) {
int offset = file.readInt(); int offset = file.readInt();
int sectorLength = file.read(); int sectorLength = file.readShort();
if (sectorLength == 0) { if (sectorLength == 0) {
continue; continue;
} }
@ -186,8 +187,8 @@ public class Region {
file.seek(definitionOffset + Integer.BYTES); file.seek(definitionOffset + Integer.BYTES);
int sectors = buffer.length / SECTOR_SIZE + 1; int sectors = (int) buffer.length / SECTOR_SIZE + 1;
file.write(sectors); file.writeShort(sectors);
putLength(pos, sectors); putLength(pos, sectors);
} }