mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Fix IO
This commit is contained in:
parent
97a62752c6
commit
fc4377abaf
@ -44,6 +44,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* The mantle can store any type of data slice anywhere and manage regions & IO on it's own.
|
||||
@ -103,7 +104,7 @@ public class Mantle {
|
||||
public void flag(int x, int z, MantleFlag flag, boolean flagged)
|
||||
{
|
||||
try {
|
||||
get(x >> 5, z >> 5).get().get(x & 31, z & 31).flag(flag, flagged);
|
||||
get(x >> 5, z >> 5).get().getOrCreate(x & 31, z & 31).flag(flag, flagged);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -121,7 +122,7 @@ public class Mantle {
|
||||
}
|
||||
|
||||
try {
|
||||
get(x >> 5, z >> 5).get().get(x & 31, z & 31).iterate(type, iterator);
|
||||
get(x >> 5, z >> 5).get().getOrCreate(x & 31, z & 31).iterate(type, iterator);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -131,7 +132,7 @@ public class Mantle {
|
||||
public boolean hasFlag(int x, int z, MantleFlag flag)
|
||||
{
|
||||
try {
|
||||
get(x >> 5, z >> 5).get().get(x & 31, z & 31).isFlagged(flag);
|
||||
return get(x >> 5, z >> 5).get().getOrCreate(x & 31, z & 31).isFlagged(flag);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -297,8 +298,15 @@ public class Mantle {
|
||||
*/
|
||||
@RegionCoordinates
|
||||
private CompletableFuture<TectonicPlate> get(int x, int z) {
|
||||
return ioBurst.completeValue(() -> hyperLock.withResult(x, z, () -> {
|
||||
Long k = key(x, z);
|
||||
TectonicPlate p = loadedRegions.get(k);
|
||||
|
||||
if(p != null)
|
||||
{
|
||||
return CompletableFuture.completedFuture(p);
|
||||
}
|
||||
|
||||
return ioBurst.completeValue(() -> hyperLock.withResult(x, z, () -> {
|
||||
lastUse.put(k, M.ms());
|
||||
TectonicPlate region = loadedRegions.get(k);
|
||||
|
||||
@ -330,7 +338,7 @@ public class Mantle {
|
||||
|
||||
region = new TectonicPlate(worldHeight);
|
||||
loadedRegions.put(k, region);
|
||||
Iris.debug("Created new Tectonic Plate (Due to Load Failure) " + C.DARK_GREEN + x + " " + z);
|
||||
Iris.debug("Created new Tectonic Plate " + C.DARK_GREEN + x + " " + z);
|
||||
return region;
|
||||
}));
|
||||
}
|
||||
@ -349,4 +357,25 @@ public class Mantle {
|
||||
public static Long key(int x, int z) {
|
||||
return Cache.key(x, z);
|
||||
}
|
||||
|
||||
public void saveAll() {
|
||||
Iris.debug("Saving The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath());
|
||||
if (closed.get()) {
|
||||
throw new RuntimeException("The Mantle is closed");
|
||||
}
|
||||
|
||||
BurstExecutor b = ioBurst.burst(loadedRegions.size());
|
||||
for (Long i : loadedRegions.keySet()) {
|
||||
b.queue(() -> {
|
||||
try {
|
||||
loadedRegions.get(i).write(fileForRegion(dataFolder, i));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
b.complete();
|
||||
Iris.debug("The Mantle has Saved " + C.DARK_AQUA + dataFolder.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.mantle;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.collection.StateList;
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
@ -38,7 +39,6 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
* Mantle Chunks are fully atomic & thread safe
|
||||
*/
|
||||
public class MantleChunk {
|
||||
private static final StateList state = MantleFlag.getStateList();
|
||||
private final AtomicIntegerArray flags;
|
||||
private final AtomicReferenceArray<Matter> sections;
|
||||
|
||||
@ -51,6 +51,11 @@ public class MantleChunk {
|
||||
public MantleChunk(int sectionHeight) {
|
||||
sections = new AtomicReferenceArray<>(sectionHeight);
|
||||
flags = new AtomicIntegerArray(MantleFlag.values().length);
|
||||
|
||||
for (int i = 0; i < flags.length(); i++)
|
||||
{
|
||||
flags.set(i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,9 +70,9 @@ public class MantleChunk {
|
||||
this(sectionHeight);
|
||||
int s = din.readByte();
|
||||
|
||||
for(String i : state.getEnabled(Varint.readUnsignedVarLong(din)))
|
||||
for(int i = 0; i < flags.length(); i++)
|
||||
{
|
||||
flags.set(MantleFlag.valueOf(i).ordinal(), 1);
|
||||
flags.set(i, din.readBoolean() ? 1 : 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < s; i++) {
|
||||
@ -82,7 +87,7 @@ public class MantleChunk {
|
||||
}
|
||||
|
||||
public boolean isFlagged(MantleFlag flag) {
|
||||
return flags.get(flags.get(flag.ordinal())) == 1;
|
||||
return flags.get(flag.ordinal()) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,14 +157,11 @@ public class MantleChunk {
|
||||
*/
|
||||
public void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeByte(sections.length());
|
||||
long data = 0;
|
||||
|
||||
for (int i = 0; i < flags.length(); i++) {
|
||||
state.set(data, MantleFlag.values()[i].name(), flags.get(i) == 1);
|
||||
dos.writeBoolean(flags.get(i) == 1);
|
||||
}
|
||||
|
||||
Varint.writeUnsignedVarLong(data, dos);
|
||||
|
||||
for (int i = 0; i < sections.length(); i++) {
|
||||
if (exists(i)) {
|
||||
dos.writeBoolean(true);
|
||||
|
@ -24,6 +24,7 @@ import com.volmit.iris.util.format.C;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* Tectonic Plates are essentially representations of regions in minecraft.
|
||||
|
Loading…
x
Reference in New Issue
Block a user