mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Fix parallax issues
This commit is contained in:
parent
c5262f188e
commit
cde9dbe406
@ -22,7 +22,6 @@ import com.volmit.iris.Iris;
|
|||||||
import com.volmit.iris.engine.hunk.Hunk;
|
import com.volmit.iris.engine.hunk.Hunk;
|
||||||
import com.volmit.iris.engine.object.tile.TileData;
|
import com.volmit.iris.engine.object.tile.TileData;
|
||||||
import com.volmit.iris.engine.parallel.BurstExecutor;
|
import com.volmit.iris.engine.parallel.BurstExecutor;
|
||||||
import com.volmit.iris.engine.parallel.GridLock;
|
|
||||||
import com.volmit.iris.engine.parallel.MultiBurst;
|
import com.volmit.iris.engine.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
@ -39,48 +38,13 @@ import org.bukkit.block.data.BlockData;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
// TODO: THIS IS SO SLOW
|
|
||||||
|
|
||||||
public class HunkRegionSlice<T> {
|
public class HunkRegionSlice<T> {
|
||||||
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunkSynced, new BlockDataHunkIOAdapter(), c, "blockdata");
|
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata");
|
||||||
public static final Function2<Integer, CompoundTag, HunkRegionSlice<TileData<? extends TileState>>> TILE = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunkSynced, new TileDataHunkIOAdapter(), c, "tile");
|
public static final Function2<Integer, CompoundTag, HunkRegionSlice<TileData<? extends TileState>>> TILE = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new TileDataHunkIOAdapter(), c, "tile");
|
||||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunkSynced, new StringHunkIOAdapter(), c, t);
|
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t);
|
||||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunkSynced, new BooleanHunkIOAdapter(), c, t);
|
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t);
|
||||||
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
|
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
|
||||||
private final GridLock lock;
|
|
||||||
private final HunkIOAdapter<T> adapter;
|
private final HunkIOAdapter<T> adapter;
|
||||||
private final CompoundTag compound;
|
private final CompoundTag compound;
|
||||||
private final String key;
|
private final String key;
|
||||||
@ -90,7 +54,6 @@ public class HunkRegionSlice<T> {
|
|||||||
private final int height;
|
private final int height;
|
||||||
|
|
||||||
public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key) {
|
public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key) {
|
||||||
this.lock = new GridLock(32, 32);
|
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.loadedChunks = new KMap<>();
|
this.loadedChunks = new KMap<>();
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
@ -117,7 +80,9 @@ public class HunkRegionSlice<T> {
|
|||||||
Long l = lastUse.get(i);
|
Long l = lastUse.get(i);
|
||||||
if (l == null || M.ms() - l > t) {
|
if (l == null || M.ms() - l > t) {
|
||||||
v++;
|
v++;
|
||||||
|
MultiBurst.burst.lazy(() -> {
|
||||||
unload(i.getX(), i.getZ());
|
unload(i.getX(), i.getZ());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +98,6 @@ public class HunkRegionSlice<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void save(MultiBurst burst) {
|
public synchronized void save(MultiBurst burst) {
|
||||||
BurstExecutor e = burst.burst();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (Position2 i : save.copy()) {
|
for (Position2 i : save.copy()) {
|
||||||
@ -141,16 +105,14 @@ public class HunkRegionSlice<T> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.queue(() -> save(i.getX(), i.getZ()));
|
save(i.getX(), i.getZ());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lock.withNasty(i.getX(), i.getZ(), () -> save.remove(i));
|
save.remove(i);
|
||||||
} catch (Throwable eer) {
|
} catch (Throwable eer) {
|
||||||
Iris.reportError(eer);
|
Iris.reportError(eer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e.complete();
|
|
||||||
} catch (Throwable ee) {
|
} catch (Throwable ee) {
|
||||||
Iris.reportError(ee);
|
Iris.reportError(ee);
|
||||||
}
|
}
|
||||||
@ -161,28 +123,23 @@ public class HunkRegionSlice<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delete(int x, int z) {
|
public void delete(int x, int z) {
|
||||||
lock.with(x, z, () -> compound.getValue().remove(key(x, z)));
|
compound.getValue().remove(key(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hunk<T> read(int x, int z) throws IOException {
|
public Hunk<T> read(int x, int z) throws IOException {
|
||||||
AtomicReference<IOException> e = new AtomicReference<>();
|
AtomicReference<IOException> e = new AtomicReference<>();
|
||||||
Hunk<T> xt = lock.withResult(x, z, () -> {
|
Hunk<T> xt = null;
|
||||||
|
|
||||||
Tag t = compound.getValue().get(key(x, z));
|
Tag t = compound.getValue().get(key(x, z));
|
||||||
|
|
||||||
if (!(t instanceof ByteArrayTag)) {
|
if ((t instanceof ByteArrayTag)) {
|
||||||
Iris.verbose("NOT BYTE ARRAY!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return adapter.read(factory, (ByteArrayTag) t);
|
xt = adapter.read(factory, (ByteArrayTag) t);
|
||||||
} catch (IOException xe) {
|
} catch (IOException xe) {
|
||||||
Iris.reportError(xe);
|
Iris.reportError(xe);
|
||||||
e.set(xe);
|
e.set(xe);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (xt != null) {
|
if (xt != null) {
|
||||||
return xt;
|
return xt;
|
||||||
@ -196,7 +153,7 @@ public class HunkRegionSlice<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void write(Hunk<T> hunk, int x, int z) throws IOException {
|
public void write(Hunk<T> hunk, int x, int z) throws IOException {
|
||||||
lock.withIO(x, z, () -> compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z))));
|
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int unloadAll() {
|
public synchronized int unloadAll() {
|
||||||
@ -214,7 +171,7 @@ public class HunkRegionSlice<T> {
|
|||||||
|
|
||||||
public void save(Hunk<T> region, int x, int z) {
|
public void save(Hunk<T> region, int x, int z) {
|
||||||
try {
|
try {
|
||||||
lock.withIO(x, z, () -> write(region, x, z));
|
write(region, x, z);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -222,19 +179,16 @@ public class HunkRegionSlice<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoaded(int x, int z) {
|
public boolean isLoaded(int x, int z) {
|
||||||
return lock.withResult(x, z, () -> loadedChunks.containsKey(new Position2(x, z)));
|
return loadedChunks.containsKey(new Position2(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(int x, int z) {
|
public void save(int x, int z) {
|
||||||
lock.with(x, z, () -> {
|
|
||||||
if (isLoaded(x, z)) {
|
if (isLoaded(x, z)) {
|
||||||
save(get(x, z), x, z);
|
save(get(x, z), x, z);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unload(int x, int z) {
|
public void unload(int x, int z) {
|
||||||
lock.with(x, z, () -> {
|
|
||||||
Position2 key = new Position2(x, z);
|
Position2 key = new Position2(x, z);
|
||||||
if (isLoaded(x, z)) {
|
if (isLoaded(x, z)) {
|
||||||
if (save.contains(key)) {
|
if (save.contains(key)) {
|
||||||
@ -245,11 +199,9 @@ public class HunkRegionSlice<T> {
|
|||||||
lastUse.remove(key);
|
lastUse.remove(key);
|
||||||
loadedChunks.remove(key);
|
loadedChunks.remove(key);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hunk<T> load(int x, int z) {
|
public Hunk<T> load(int x, int z) {
|
||||||
return lock.withResult(x, z, () -> {
|
|
||||||
if (isLoaded(x, z)) {
|
if (isLoaded(x, z)) {
|
||||||
return loadedChunks.get(new Position2(x, z));
|
return loadedChunks.get(new Position2(x, z));
|
||||||
}
|
}
|
||||||
@ -272,11 +224,9 @@ public class HunkRegionSlice<T> {
|
|||||||
loadedChunks.put(new Position2(x, z), v);
|
loadedChunks.put(new Position2(x, z), v);
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hunk<T> get(int x, int z) {
|
public Hunk<T> get(int x, int z) {
|
||||||
return lock.withResult(x, z, () -> {
|
|
||||||
Position2 key = new Position2(x, z);
|
Position2 key = new Position2(x, z);
|
||||||
|
|
||||||
Hunk<T> c = loadedChunks.get(key);
|
Hunk<T> c = loadedChunks.get(key);
|
||||||
@ -288,18 +238,15 @@ public class HunkRegionSlice<T> {
|
|||||||
lastUse.put(new Position2(x, z), M.ms());
|
lastUse.put(new Position2(x, z), M.ms());
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hunk<T> getR(int x, int z) {
|
public Hunk<T> getR(int x, int z) {
|
||||||
return lock.withResult(x, z, () -> get(x, z).readOnly());
|
return get(x, z).readOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hunk<T> getRW(int x, int z) {
|
public Hunk<T> getRW(int x, int z) {
|
||||||
return lock.withResult(x, z, () -> {
|
|
||||||
save.add(new Position2(x, z));
|
save.add(new Position2(x, z));
|
||||||
return get(x, z);
|
return get(x, z);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String key(int x, int z) {
|
private String key(int x, int z) {
|
||||||
|
@ -68,7 +68,7 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
private int w;
|
private int w;
|
||||||
private int d;
|
private int d;
|
||||||
private int h;
|
private int h;
|
||||||
private transient final IrisLock readLock = new IrisLock("read-conclock").setDisabled(true);
|
private transient final IrisLock readLock = new IrisLock("read-conclock");
|
||||||
private transient BlockVector center;
|
private transient BlockVector center;
|
||||||
private transient volatile boolean smartBored = false;
|
private transient volatile boolean smartBored = false;
|
||||||
private transient IrisLock lock = new IrisLock("Preloadcache");
|
private transient IrisLock lock = new IrisLock("Preloadcache");
|
||||||
|
@ -28,12 +28,14 @@ import com.volmit.iris.util.collection.KMap;
|
|||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
import com.volmit.iris.util.documentation.RegionCoordinates;
|
import com.volmit.iris.util.documentation.RegionCoordinates;
|
||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
|
import com.volmit.iris.util.plugin.Command;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import org.bukkit.block.TileState;
|
import org.bukkit.block.TileState;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL")
|
||||||
public class ParallaxWorld implements ParallaxAccess {
|
public class ParallaxWorld implements ParallaxAccess {
|
||||||
@ -234,25 +236,22 @@ public class ParallaxWorld implements ParallaxAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cleanup(long r, long c) {
|
public synchronized void cleanup(long r, long c) {
|
||||||
J.a(() -> {
|
|
||||||
try {
|
try {
|
||||||
int rr = 0;
|
int rr = 0;
|
||||||
int cc = 0;
|
|
||||||
|
|
||||||
for (ParallaxRegion i : loadedRegions.v()) {
|
for (ParallaxRegion i : loadedRegions.v()) {
|
||||||
|
burst.lazy(() -> {
|
||||||
if (i.hasBeenIdleLongerThan(r)) {
|
if (i.hasBeenIdleLongerThan(r)) {
|
||||||
rr++;
|
|
||||||
unload(i.getX(), i.getZ());
|
unload(i.getX(), i.getZ());
|
||||||
} else {
|
} else {
|
||||||
cc += i.cleanup(c);
|
i.cleanup(c);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user