From ded4b599b25ef0faa46dfd6f3dcb2d8c444a12f3 Mon Sep 17 00:00:00 2001 From: ishland Date: Thu, 12 Dec 2024 14:28:48 +0800 Subject: [PATCH 1/2] fix: add instrumentation for chunk sending --- .../MixinServerAccessibleChunkSending.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinServerAccessibleChunkSending.java b/c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinServerAccessibleChunkSending.java index 8ac950c2..38a7345e 100644 --- a/c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinServerAccessibleChunkSending.java +++ b/c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinServerAccessibleChunkSending.java @@ -1,5 +1,6 @@ package com.ishland.c2me.notickvd.mixin; +import com.ishland.c2me.base.common.threadstate.ThreadInstrumentation; import com.ishland.c2me.base.mixin.access.IThreadedAnvilChunkStorage; import com.ishland.c2me.rewrites.chunksystem.common.ChunkLoadingContext; import com.ishland.c2me.rewrites.chunksystem.common.ChunkState; @@ -7,6 +8,7 @@ import com.ishland.c2me.rewrites.chunksystem.common.NewChunkHolderVanillaInterface; import com.ishland.c2me.rewrites.chunksystem.common.NewChunkStatus; import com.ishland.c2me.rewrites.chunksystem.common.statuses.ServerAccessibleChunkSending; +import com.ishland.c2me.rewrites.chunksystem.common.threadstate.ChunkTaskWork; import com.ishland.flowsched.scheduler.Cancellable; import com.ishland.flowsched.scheduler.ItemHolder; import com.ishland.flowsched.scheduler.KeyStatusPair; @@ -65,31 +67,33 @@ private static void onCLInit(CallbackInfo ci) { @Overwrite(remap = false) public CompletionStage upgradeToThis(ChunkLoadingContext context, Cancellable cancellable) { return CompletableFuture.runAsync(() -> { - if (Config.suppressGhostMushrooms) { - final WorldChunk chunk = (WorldChunk) context.holder().getItem().get().chunk(); - ServerWorld world = ((IThreadedAnvilChunkStorage) context.tacs()).getWorld(); + try (var ignored = ThreadInstrumentation.getCurrent().begin(new ChunkTaskWork(context, (ServerAccessibleChunkSending) (Object) this, true))) { + if (Config.suppressGhostMushrooms) { + final WorldChunk chunk = (WorldChunk) context.holder().getItem().get().chunk(); + ServerWorld world = ((IThreadedAnvilChunkStorage) context.tacs()).getWorld(); - ChunkPos chunkPos = context.holder().getKey(); + ChunkPos chunkPos = context.holder().getKey(); - ShortList[] postProcessingLists = chunk.getPostProcessingLists(); - for (int i = 0; i < postProcessingLists.length; i++) { - if (postProcessingLists[i] != null) { - for (ShortListIterator iterator = postProcessingLists[i].iterator(); iterator.hasNext(); ) { - short short_ = iterator.nextShort(); - BlockPos blockPos = ProtoChunk.joinBlockPos(short_, chunk.sectionIndexToCoord(i), chunkPos); - BlockState blockState = chunk.getBlockState(blockPos); + ShortList[] postProcessingLists = chunk.getPostProcessingLists(); + for (int i = 0; i < postProcessingLists.length; i++) { + if (postProcessingLists[i] != null) { + for (ShortListIterator iterator = postProcessingLists[i].iterator(); iterator.hasNext(); ) { + short short_ = iterator.nextShort(); + BlockPos blockPos = ProtoChunk.joinBlockPos(short_, chunk.sectionIndexToCoord(i), chunkPos); + BlockState blockState = chunk.getBlockState(blockPos); - if (!(blockState.getBlock() instanceof FluidBlock)) { - BlockState blockState2 = Block.postProcessState(blockState, world, blockPos); - if (blockState2 != blockState) { - world.setBlockState(blockPos, blockState2, Block.NO_REDRAW | Block.FORCE_STATE); + if (!(blockState.getBlock() instanceof FluidBlock)) { + BlockState blockState2 = Block.postProcessState(blockState, world, blockPos); + if (blockState2 != blockState) { + world.setBlockState(blockPos, blockState2, Block.NO_REDRAW | Block.FORCE_STATE); + } } } } } } + sendChunkToPlayer(context.tacs(), context.holder()); } - sendChunkToPlayer(context.tacs(), context.holder()); }, ((IThreadedAnvilChunkStorage) context.tacs()).getMainThreadExecutor()); } From 7cc48cebf7bc13dee1fe7cb188bbb353726bb336 Mon Sep 17 00:00:00 2001 From: ishland Date: Thu, 12 Dec 2024 14:29:14 +0800 Subject: [PATCH 2/2] fix: deadlock in early postprocessing --- .../c2me/notickvd/mixin/MixinServerAccessibleChunkSending.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinServerAccessibleChunkSending.java b/c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinServerAccessibleChunkSending.java index 38a7345e..08308340 100644 --- a/c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinServerAccessibleChunkSending.java +++ b/c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinServerAccessibleChunkSending.java @@ -47,7 +47,7 @@ public class MixinServerAccessibleChunkSending { @Inject(method = "", at = @At("RETURN")) private static void onCLInit(CallbackInfo ci) { - NewChunkStatus depStatus = NewChunkStatus.fromVanillaStatus(ChunkStatus.LIGHT); + NewChunkStatus depStatus = NewChunkStatus.fromVanillaStatus(ChunkStatus.FULL); deps = new KeyStatusPair[]{ new KeyStatusPair<>(new ChunkPos(-1, -1), depStatus), new KeyStatusPair<>(new ChunkPos(-1, 0), depStatus),