Clean and finish x2

This commit is contained in:
mastermc05 2022-04-01 15:16:57 +03:00
parent da05fc4675
commit d0a791b634
4 changed files with 14 additions and 13 deletions

View File

@ -39,7 +39,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
private int snapcnt;
private GenericChunk[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
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,
BlockStep.X_PLUS, BlockStep.Y_PLUS, BlockStep.Z_PLUS };
@ -924,7 +924,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
}
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 DynmapChunk chunk;

View File

@ -16,10 +16,10 @@ import java.util.function.Predicate;
* Because paper libs need java 17 we can't interact with them directly
*/
public class AsyncChunkProvider118_2 {
private static final Thread ioThread;
private static final Method getChunk;
private static final Predicate<NBTTagCompound> ifFailed;
static {
private final Thread ioThread;
private final Method getChunk;
private final Predicate<NBTTagCompound> ifFailed;
AsyncChunkProvider118_2 () {
try {
Predicate<NBTTagCompound> ifFailed1 = null;
Method getChunk1 = null;

View File

@ -26,7 +26,7 @@ import java.util.function.Supplier;
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
*/
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;
/**
* Construct empty cache
@ -52,9 +52,8 @@ public class MapChunkCache118_2 extends GenericMapChunkCache {
NBTTagCompound compound = nbt.join();
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
};
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
return () -> loadChunk(chunk);
} catch (InvocationTargetException | IllegalAccessException ignored) {
return () -> null;
}
}
@ -63,9 +62,12 @@ public class MapChunkCache118_2 extends GenericMapChunkCache {
if (!cw.isChunkLoaded(chunk.x, chunk.z)) return () -> null;
Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z); //already safe async on vanilla
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());
return () -> parseChunkFromNBT(new NBT.NBTCompound(nbt.join()));
return () -> {
NBTTagCompound compound = nbt.join();
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
};
} else {
NBTTagCompound nbt = ChunkRegionLoader.a(cw.getHandle(), c);
GenericChunk genericChunk;

View File

@ -482,7 +482,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
boolean rslt = permissions.hasOfflinePermission(player, perm);
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
*/