Some fixes and improvements to internal queuing (#1715)

* the set array given in NMSAdapter should have get data written to it
 - Fixes #1664
 - May fix #1700

* Having target size >= 2* parallel threads allows for adjacent chunks to be loaded with issues

* "empty" chunk section doesn't need to be localised to the chunk and may be static

* Switch to slightly more performant stream method for testing for non-empty sections

* Implement lock into ChunkHolder preventing any modification to occur whilst the edit is being applied to the world
 (when ChunkHolder is called)

* Add config note about target-size

* set ordinal equal to air if both set and get are `__reserved__`

* Add note to checkAndWaitOnCalledLock method of its use

* Don't print exception and throw

* Switch to a wrapped StampedLock allowing reentrant behaviour
 - StampedLock is not reentrent
 - Allow unlock from a different thread only if it provides the correct stamp
 - This stamp can only be retrieved by the thread owning the lock

* Avoid some "doubling-up" of using checkAndWaitOnCalledLock

* Unbloat `checkAndWaitOnCalledLock`

* Add since tags
This commit is contained in:
Jordan
2022-06-05 19:52:28 +01:00
committed by GitHub
parent 8228b798e5
commit 198c6b7800
8 changed files with 238 additions and 28 deletions

View File

@ -4,11 +4,15 @@ import com.fastasyncworldedit.core.FAWEPlatformAdapterImpl;
import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.util.MathMan;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.function.Function;
public class NMSAdapter implements FAWEPlatformAdapterImpl {
private static final Logger LOGGER = LogManager.getLogger();
public static int createPalette(
int[] blockToPalette,
int[] paletteToBlock,
@ -79,14 +83,20 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
if (getArr == null) {
getArr = get.apply(layer);
}
ordinal = getArr[i];
switch (ordinal) {
// write to set array as this should be a copied array, and will be important when the changes are written
// to the GET chunk cached by FAWE
set[i] = switch (ordinal = getArr[i]) {
case BlockTypesCache.ReservedIDs.__RESERVED__ -> {
ordinal = BlockTypesCache.ReservedIDs.AIR;
nonAir--;
yield (ordinal = BlockTypesCache.ReservedIDs.AIR);
}
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--;
}
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR,
BlockTypesCache.ReservedIDs.VOID_AIR -> {
nonAir--;
yield ordinal;
}
default -> ordinal;
};
}
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--;
}
@ -109,12 +119,8 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
if (getArr == null) {
getArr = get.apply(layer);
}
if ((ordinal = getArr[i]) == BlockTypesCache.ReservedIDs.__RESERVED__) {
ordinal = BlockTypesCache.ReservedIDs.AIR;
}
LOGGER.error("Empty (__RESERVED__) ordinal given where not expected, default to air.");
ordinal = BlockTypesCache.ReservedIDs.AIR;
}
int palette = blockToPalette[ordinal];
blocksCopy[i] = palette;