Hello, Trove4j!
This commit is contained in:
@@ -4,4 +4,6 @@ version '1.0-SNAPSHOT'
|
|||||||
dependencies {
|
dependencies {
|
||||||
/* Core */
|
/* Core */
|
||||||
compile_excludeCopy project(':core')
|
compile_excludeCopy project(':core')
|
||||||
|
|
||||||
|
compile (group: 'net.sf.trove4j', name: 'trove4j', version: '3.0.3')
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,8 @@ package mc.world.anvil;
|
|||||||
|
|
||||||
import com.flowpowered.nbt.Tag;
|
import com.flowpowered.nbt.Tag;
|
||||||
import com.flowpowered.nbt.stream.NBTInputStream;
|
import com.flowpowered.nbt.stream.NBTInputStream;
|
||||||
|
import gnu.trove.list.TByteList;
|
||||||
|
import gnu.trove.list.array.TByteArrayList;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.core.world.chunk.Chunk;
|
import mc.core.world.chunk.Chunk;
|
||||||
|
|
||||||
@@ -13,19 +15,22 @@ import java.util.zip.InflaterInputStream;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RegionFile implements Closeable {
|
public class RegionFile implements Closeable {
|
||||||
|
private static final byte BYTE_TRUE = 1,
|
||||||
|
BYTE_FALSE = 0;
|
||||||
|
|
||||||
private RandomAccessFile file;
|
private RandomAccessFile file;
|
||||||
private List<Boolean> sectorFree; //TODO заменить на Trove TByteList
|
private TByteList sectorFree;
|
||||||
private final int[] offsets = new int[1024];
|
private final int[] offsets = new int[1024];
|
||||||
|
|
||||||
public RegionFile(File file) throws IOException {
|
public RegionFile(File file) throws IOException {
|
||||||
this.file = new RandomAccessFile(file, "rw");
|
this.file = new RandomAccessFile(file, "rw");
|
||||||
|
|
||||||
int sizeOfSectorFree = (int)this.file.length() / 4096;
|
int sizeOfSectorFree = (int)this.file.length() / 4096;
|
||||||
sectorFree = new ArrayList<>(sizeOfSectorFree);
|
sectorFree = new TByteArrayList(sizeOfSectorFree);
|
||||||
sectorFree.add(false);
|
sectorFree.add(BYTE_FALSE);
|
||||||
sectorFree.add(false);
|
sectorFree.add(BYTE_FALSE);
|
||||||
for (int i = 0; i < sizeOfSectorFree-2; i++) {
|
for (int i = 0; i < sizeOfSectorFree-2; i++) {
|
||||||
sectorFree.add(true);
|
sectorFree.add(BYTE_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < offsets.length; ++i) {
|
for (int i = 0; i < offsets.length; ++i) {
|
||||||
@@ -34,7 +39,7 @@ public class RegionFile implements Closeable {
|
|||||||
|
|
||||||
if (read != 0 && (read >> 8) + (read & 255) <= this.sectorFree.size()) {
|
if (read != 0 && (read >> 8) + (read & 255) <= this.sectorFree.size()) {
|
||||||
for (int j = 0; j < (read & 255); ++j) {
|
for (int j = 0; j < (read & 255); ++j) {
|
||||||
this.sectorFree.set((read >> 8) + j, false);
|
this.sectorFree.set((read >> 8) + j, BYTE_FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user