mirror of https://github.com/webbukkit/dynmap.git
Clean and finish x2
This commit is contained in:
parent
da05fc4675
commit
d0a791b634
|
@ -39,7 +39,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
private int snapcnt;
|
private int snapcnt;
|
||||||
private GenericChunk[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
|
private GenericChunk[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
|
||||||
private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */
|
private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */
|
||||||
private AtomicInteger loadingChunks = new AtomicInteger(0); //the amount of threads loading threads at this moment, used by async loading
|
private AtomicInteger loadingChunks = new AtomicInteger(0); //the amount of threads loading chunks at this moment, used by async loading
|
||||||
|
|
||||||
private static final BlockStep unstep[] = { BlockStep.X_MINUS, BlockStep.Y_MINUS, BlockStep.Z_MINUS,
|
private static final BlockStep unstep[] = { BlockStep.X_MINUS, BlockStep.Y_MINUS, BlockStep.Z_MINUS,
|
||||||
BlockStep.X_PLUS, BlockStep.Y_PLUS, BlockStep.Z_PLUS };
|
BlockStep.X_PLUS, BlockStep.Y_PLUS, BlockStep.Z_PLUS };
|
||||||
|
@ -924,7 +924,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readChunksAsync() {
|
public void readChunksAsync() {
|
||||||
class SimplePair {
|
class SimplePair { //pair of the chunk and the data which is readed async
|
||||||
private final Supplier<GenericChunk> supplier;
|
private final Supplier<GenericChunk> supplier;
|
||||||
private final DynmapChunk chunk;
|
private final DynmapChunk chunk;
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@ import java.util.function.Predicate;
|
||||||
* Because paper libs need java 17 we can't interact with them directly
|
* Because paper libs need java 17 we can't interact with them directly
|
||||||
*/
|
*/
|
||||||
public class AsyncChunkProvider118_2 {
|
public class AsyncChunkProvider118_2 {
|
||||||
private static final Thread ioThread;
|
private final Thread ioThread;
|
||||||
private static final Method getChunk;
|
private final Method getChunk;
|
||||||
private static final Predicate<NBTTagCompound> ifFailed;
|
private final Predicate<NBTTagCompound> ifFailed;
|
||||||
static {
|
AsyncChunkProvider118_2 () {
|
||||||
try {
|
try {
|
||||||
Predicate<NBTTagCompound> ifFailed1 = null;
|
Predicate<NBTTagCompound> ifFailed1 = null;
|
||||||
Method getChunk1 = null;
|
Method getChunk1 = null;
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.util.function.Supplier;
|
||||||
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
|
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
|
||||||
*/
|
*/
|
||||||
public class MapChunkCache118_2 extends GenericMapChunkCache {
|
public class MapChunkCache118_2 extends GenericMapChunkCache {
|
||||||
private final AsyncChunkProvider118_2 provider = BukkitVersionHelper.helper.isUnsafeAsync() ? null : new AsyncChunkProvider118_2();
|
private static final AsyncChunkProvider118_2 provider = BukkitVersionHelper.helper.isUnsafeAsync() ? null : new AsyncChunkProvider118_2();
|
||||||
private World w;
|
private World w;
|
||||||
/**
|
/**
|
||||||
* Construct empty cache
|
* Construct empty cache
|
||||||
|
@ -52,9 +52,8 @@ public class MapChunkCache118_2 extends GenericMapChunkCache {
|
||||||
NBTTagCompound compound = nbt.join();
|
NBTTagCompound compound = nbt.join();
|
||||||
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
|
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
|
||||||
};
|
};
|
||||||
} catch (InvocationTargetException | IllegalAccessException e) {
|
} catch (InvocationTargetException | IllegalAccessException ignored) {
|
||||||
e.printStackTrace();
|
return () -> null;
|
||||||
return () -> loadChunk(chunk);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +62,12 @@ public class MapChunkCache118_2 extends GenericMapChunkCache {
|
||||||
if (!cw.isChunkLoaded(chunk.x, chunk.z)) return () -> null;
|
if (!cw.isChunkLoaded(chunk.x, chunk.z)) return () -> null;
|
||||||
Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z); //already safe async on vanilla
|
Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z); //already safe async on vanilla
|
||||||
if ((c == null) || c.o) return () -> null; // c.loaded
|
if ((c == null) || c.o) return () -> null; // c.loaded
|
||||||
if (async) { //idk why, but paper uses this only sync, so I won't be smarter
|
if (async) { //the data of the chunk may change while we write, better to write it sync
|
||||||
CompletableFuture<NBTTagCompound> nbt = CompletableFuture.supplyAsync(() -> ChunkRegionLoader.a(cw.getHandle(), c), ((CraftServer) Bukkit.getServer()).getServer());
|
CompletableFuture<NBTTagCompound> nbt = CompletableFuture.supplyAsync(() -> ChunkRegionLoader.a(cw.getHandle(), c), ((CraftServer) Bukkit.getServer()).getServer());
|
||||||
return () -> parseChunkFromNBT(new NBT.NBTCompound(nbt.join()));
|
return () -> {
|
||||||
|
NBTTagCompound compound = nbt.join();
|
||||||
|
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
NBTTagCompound nbt = ChunkRegionLoader.a(cw.getHandle(), c);
|
NBTTagCompound nbt = ChunkRegionLoader.a(cw.getHandle(), c);
|
||||||
GenericChunk genericChunk;
|
GenericChunk genericChunk;
|
||||||
|
|
|
@ -482,7 +482,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||||
boolean rslt = permissions.hasOfflinePermission(player, perm);
|
boolean rslt = permissions.hasOfflinePermission(player, perm);
|
||||||
return rslt;
|
return rslt;
|
||||||
}
|
}
|
||||||
private final Object[] lock = {};
|
|
||||||
/**
|
/**
|
||||||
* Render processor helper - used by code running on render threads to request chunk snapshot cache from server/sync thread
|
* Render processor helper - used by code running on render threads to request chunk snapshot cache from server/sync thread
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue