Shared light executor
This commit is contained in:
@@ -68,7 +68,7 @@ public abstract class MixinChunk implements IMixinChunk {
|
|||||||
private CopyOnWriteArrayList<Short> queuedBlockLightingUpdates = new CopyOnWriteArrayList<>();
|
private CopyOnWriteArrayList<Short> queuedBlockLightingUpdates = new CopyOnWriteArrayList<>();
|
||||||
private AtomicInteger pendingLightUpdates = new AtomicInteger();
|
private AtomicInteger pendingLightUpdates = new AtomicInteger();
|
||||||
private long lightUpdateTime;
|
private long lightUpdateTime;
|
||||||
private ExecutorService lightExecutorService;
|
private static ExecutorService lightExecutorService;
|
||||||
|
|
||||||
@Shadow(aliases = "m") private boolean isGapLightingUpdated;
|
@Shadow(aliases = "m") private boolean isGapLightingUpdated;
|
||||||
@Shadow(aliases = "r") private boolean ticked;
|
@Shadow(aliases = "r") private boolean ticked;
|
||||||
@@ -102,7 +102,7 @@ public abstract class MixinChunk implements IMixinChunk {
|
|||||||
|
|
||||||
@Inject(method = "<init>", at = @At("RETURN"))
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
public void onConstruct(World worldIn, int x, int z, CallbackInfo ci) {
|
public void onConstruct(World worldIn, int x, int z, CallbackInfo ci) {
|
||||||
this.lightExecutorService = ((IMixinWorldServer) worldIn).getLightingExecutor();
|
lightExecutorService = ((IMixinWorldServer) worldIn).getLightingExecutor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,7 +124,7 @@ public abstract class MixinChunk implements IMixinChunk {
|
|||||||
private void onTickHead(boolean skipRecheckGaps, CallbackInfo ci) {
|
private void onTickHead(boolean skipRecheckGaps, CallbackInfo ci) {
|
||||||
final List<Chunk> neighbors = this.getSurroundingChunks();
|
final List<Chunk> neighbors = this.getSurroundingChunks();
|
||||||
if (this.isGapLightingUpdated && this.world.worldProvider.m() && !skipRecheckGaps && !neighbors.isEmpty()) { // PAIL: hasSkyLight
|
if (this.isGapLightingUpdated && this.world.worldProvider.m() && !skipRecheckGaps && !neighbors.isEmpty()) { // PAIL: hasSkyLight
|
||||||
this.lightExecutorService.execute(() -> {
|
lightExecutorService.execute(() -> {
|
||||||
this.recheckGapsAsync(neighbors);
|
this.recheckGapsAsync(neighbors);
|
||||||
});
|
});
|
||||||
this.isGapLightingUpdated = false;
|
this.isGapLightingUpdated = false;
|
||||||
@@ -133,7 +133,7 @@ public abstract class MixinChunk implements IMixinChunk {
|
|||||||
this.ticked = true;
|
this.ticked = true;
|
||||||
|
|
||||||
if (!this.isLightPopulated && this.isTerrainPopulated && !neighbors.isEmpty()) {
|
if (!this.isLightPopulated && this.isTerrainPopulated && !neighbors.isEmpty()) {
|
||||||
this.lightExecutorService.execute(() -> {
|
lightExecutorService.execute(() -> {
|
||||||
this.checkLightAsync(neighbors);
|
this.checkLightAsync(neighbors);
|
||||||
});
|
});
|
||||||
// set to true to avoid requeuing the same task when not finished
|
// set to true to avoid requeuing the same task when not finished
|
||||||
@@ -232,7 +232,7 @@ public abstract class MixinChunk implements IMixinChunk {
|
|||||||
|
|
||||||
@Inject(method = "o()V", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "o()V", at = @At("HEAD"), cancellable = true)
|
||||||
private void checkLightHead(CallbackInfo ci) {
|
private void checkLightHead(CallbackInfo ci) {
|
||||||
if (this.world.getMinecraftServer().isStopped() || this.lightExecutorService.isShutdown()) {
|
if (this.world.getMinecraftServer().isStopped() || lightExecutorService.isShutdown()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,13 +247,13 @@ public abstract class MixinChunk implements IMixinChunk {
|
|||||||
|
|
||||||
if (Akari.isPrimaryThread()) {
|
if (Akari.isPrimaryThread()) {
|
||||||
try {
|
try {
|
||||||
this.lightExecutorService.execute(() -> {
|
lightExecutorService.execute(() -> {
|
||||||
this.checkLightAsync(neighborChunks);
|
this.checkLightAsync(neighborChunks);
|
||||||
});
|
});
|
||||||
} catch (RejectedExecutionException ex) {
|
} catch (RejectedExecutionException ex) {
|
||||||
// This could happen if ServerHangWatchdog kills the server
|
// This could happen if ServerHangWatchdog kills the server
|
||||||
// between the start of the method and the execute() call.
|
// between the start of the method and the execute() call.
|
||||||
if (!this.world.getMinecraftServer().isStopped() && !this.lightExecutorService.isShutdown()) {
|
if (!this.world.getMinecraftServer().isStopped() && !lightExecutorService.isShutdown()) {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,7 +451,7 @@ public abstract class MixinChunk implements IMixinChunk {
|
|||||||
|
|
||||||
@Inject(method = "c(III)V", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "c(III)V", at = @At("HEAD"), cancellable = true)
|
||||||
private void onRelightBlock(int x, int y, int z, CallbackInfo ci) {
|
private void onRelightBlock(int x, int y, int z, CallbackInfo ci) {
|
||||||
this.lightExecutorService.execute(() -> {
|
lightExecutorService.execute(() -> {
|
||||||
this.relightBlockAsync(x, y, z);
|
this.relightBlockAsync(x, y, z);
|
||||||
});
|
});
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ public abstract class MixinWorldServer extends MixinWorld implements IMixinWorld
|
|||||||
private static final short XZ_MASK = 0xF;
|
private static final short XZ_MASK = 0xF;
|
||||||
private static final short Y_SHORT_MASK = 0xFF;
|
private static final short Y_SHORT_MASK = 0xFF;
|
||||||
|
|
||||||
private final ExecutorService lightExecutorService = getExecutorService();
|
private static final ExecutorService lightExecutorService = getExecutorService();
|
||||||
|
|
||||||
private ExecutorService getExecutorService() {
|
private static ExecutorService getExecutorService() {
|
||||||
return AkarinGlobalConfig.asyncLightingWorkStealing ?
|
return AkarinGlobalConfig.asyncLightingWorkStealing ?
|
||||||
Executors.newFixedThreadPool(AkarinGlobalConfig.asyncLightingThreads, new ThreadFactoryBuilder().setNameFormat("Akarin Async Light Thread").build()) : Executors.newWorkStealingPool(AkarinGlobalConfig.asyncLightingThreads);
|
Executors.newFixedThreadPool(AkarinGlobalConfig.asyncLightingThreads, new ThreadFactoryBuilder().setNameFormat("Akarin Async Light Thread").build()) : Executors.newWorkStealingPool(AkarinGlobalConfig.asyncLightingThreads);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user