mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Lock the piss out of the parallax layer
This commit is contained in:
parent
cc95042a94
commit
229f3dc061
@ -22,6 +22,8 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.engine.hunk.Hunk;
|
||||
import com.volmit.iris.engine.object.tile.TileData;
|
||||
import com.volmit.iris.engine.parallel.GridLock;
|
||||
import com.volmit.iris.engine.parallel.HyperLock;
|
||||
import com.volmit.iris.engine.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
@ -38,12 +40,14 @@ import java.io.IOException;
|
||||
public class ParallaxWorld implements ParallaxAccess {
|
||||
private final KMap<Long, ParallaxRegion> loadedRegions;
|
||||
private final KList<Long> save;
|
||||
private final HyperLock hlock;
|
||||
private final File folder;
|
||||
private final MultiBurst burst;
|
||||
private final int height;
|
||||
|
||||
public ParallaxWorld(MultiBurst burst, int height, File folder) {
|
||||
this.height = height;
|
||||
this.hlock = new HyperLock(1024);
|
||||
this.burst = burst;
|
||||
this.folder = folder;
|
||||
save = new KList<>();
|
||||
@ -81,7 +85,7 @@ public class ParallaxWorld implements ParallaxAccess {
|
||||
|
||||
public void save(ParallaxRegion region) {
|
||||
try {
|
||||
region.save();
|
||||
hlock.withIO(region.getX(), region.getZ(), () -> region.save());
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
@ -95,13 +99,16 @@ public class ParallaxWorld implements ParallaxAccess {
|
||||
|
||||
@RegionCoordinates
|
||||
public void save(int x, int z) {
|
||||
hlock.with(x, z, () -> {
|
||||
if (isLoaded(x, z)) {
|
||||
save(getR(x, z));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@RegionCoordinates
|
||||
public int unload(int x, int z) {
|
||||
return hlock.withResult(x, z, () -> {
|
||||
long key = key(x, z);
|
||||
int v = 0;
|
||||
if (isLoaded(x, z)) {
|
||||
@ -118,10 +125,12 @@ public class ParallaxWorld implements ParallaxAccess {
|
||||
}
|
||||
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
@RegionCoordinates
|
||||
public ParallaxRegion load(int x, int z) {
|
||||
return hlock.withResult(x, z, () -> {
|
||||
if (isLoaded(x, z)) {
|
||||
return loadedRegions.get(key(x, z));
|
||||
}
|
||||
@ -130,10 +139,12 @@ public class ParallaxWorld implements ParallaxAccess {
|
||||
loadedRegions.put(key(x, z), v);
|
||||
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
@RegionCoordinates
|
||||
public ParallaxRegion getR(int x, int z) {
|
||||
return hlock.withResult(x, z, () -> {
|
||||
long key = key(x, z);
|
||||
|
||||
ParallaxRegion region = loadedRegions.get(key);
|
||||
@ -143,12 +154,15 @@ public class ParallaxWorld implements ParallaxAccess {
|
||||
}
|
||||
|
||||
return region;
|
||||
});
|
||||
}
|
||||
|
||||
@RegionCoordinates
|
||||
public ParallaxRegion getRW(int x, int z) {
|
||||
return hlock.withResult(x, z, () -> {
|
||||
save.addIfMissing(key(x, z));
|
||||
return getR(x, z);
|
||||
});
|
||||
}
|
||||
|
||||
@RegionCoordinates
|
||||
|
Loading…
x
Reference in New Issue
Block a user