From 646be6298e61079ea77738d191bdf87f42e98bef Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 4 Apr 2020 01:32:46 -0300 Subject: [PATCH] trying to flush the toileight --- .../ServerLightingProviderInterface.java | 9 ++++ ...ingProvider_scarpetChunkCreationMixin.java | 54 +++++++++++++++++++ ...hunkStorage_scarpetChunkCreationMixin.java | 15 +++--- src/main/resources/carpet.mixins.json | 1 + 4 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 src/main/java/carpet/fakes/ServerLightingProviderInterface.java create mode 100644 src/main/java/carpet/mixins/ServerLightingProvider_scarpetChunkCreationMixin.java diff --git a/src/main/java/carpet/fakes/ServerLightingProviderInterface.java b/src/main/java/carpet/fakes/ServerLightingProviderInterface.java new file mode 100644 index 00000000..42aff898 --- /dev/null +++ b/src/main/java/carpet/fakes/ServerLightingProviderInterface.java @@ -0,0 +1,9 @@ +package carpet.fakes; + +import net.minecraft.util.math.ChunkPos; + +public interface ServerLightingProviderInterface +{ + void publicUpdateChunkStatus(ChunkPos pos); + void flush(); +} diff --git a/src/main/java/carpet/mixins/ServerLightingProvider_scarpetChunkCreationMixin.java b/src/main/java/carpet/mixins/ServerLightingProvider_scarpetChunkCreationMixin.java new file mode 100644 index 00000000..1bc4795e --- /dev/null +++ b/src/main/java/carpet/mixins/ServerLightingProvider_scarpetChunkCreationMixin.java @@ -0,0 +1,54 @@ +package carpet.mixins; + +import carpet.fakes.ServerLightingProviderInterface; +import it.unimi.dsi.fastutil.objects.ObjectList; +import net.minecraft.server.world.ServerLightingProvider; +import net.minecraft.util.math.ChunkPos; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.concurrent.atomic.AtomicBoolean; + +import static java.lang.Thread.yield; + +@Mixin(ServerLightingProvider.class) +public abstract class ServerLightingProvider_scarpetChunkCreationMixin implements ServerLightingProviderInterface +{ + + @Shadow protected abstract void updateChunkStatus(ChunkPos pos); + + @Shadow private volatile int taskBatchSize; + + @Shadow public abstract void setTaskBatchSize(int taskBatchSize); + + @Shadow @Final private AtomicBoolean field_18812; + + @Shadow @Final private ObjectList pendingTasks; + + @Shadow protected abstract void runTasks(); + + @Override + public void publicUpdateChunkStatus(ChunkPos pos) + { + updateChunkStatus(pos); + } + + @Override + public void flush() + { + try + { + while (!field_18812.compareAndSet(false, true)) yield(); + if (pendingTasks.size() == 0) return; + int prevTaskBatchSize = taskBatchSize; + setTaskBatchSize(pendingTasks.size()); + runTasks(); + setTaskBatchSize(prevTaskBatchSize); + } + finally + { + this.field_18812.set(false); + } + } +} diff --git a/src/main/java/carpet/mixins/ThreadedAnvilChunkStorage_scarpetChunkCreationMixin.java b/src/main/java/carpet/mixins/ThreadedAnvilChunkStorage_scarpetChunkCreationMixin.java index bad3a35d..e5daf3dc 100644 --- a/src/main/java/carpet/mixins/ThreadedAnvilChunkStorage_scarpetChunkCreationMixin.java +++ b/src/main/java/carpet/mixins/ThreadedAnvilChunkStorage_scarpetChunkCreationMixin.java @@ -1,6 +1,7 @@ package carpet.mixins; import carpet.fakes.ChunkHolderInterface; +import carpet.fakes.ServerLightingProviderInterface; import carpet.fakes.ThreadedAnvilChunkStorageInterface; import carpet.script.utils.WorldTools; import com.mojang.datafixers.util.Either; @@ -155,7 +156,7 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem //apparently that doesn't remove them for the client this.world.unloadEntities(worldChunk); } - //this.serverLightingProvider.updateChunkStatus(chunk.getPos()); // we might need that as some point + ((ServerLightingProviderInterface)this.serverLightingProvider).publicUpdateChunkStatus(chunk.getPos()); // we might need that as some point serverLightingProvider.tick(); worldGenerationProgressListener.setChunkStatus(chunk.getPos(), (ChunkStatus) null); } @@ -175,6 +176,7 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem this.chunkHolderListDirty = true; // not needed right now mainThreadExecutor.runTasks(() -> mainThreadExecutor.getTaskCount() == 0); + ((ServerLightingProviderInterface)this.serverLightingProvider).flush(); //worldgenExecutor. // save all pending chunks / potentially only one max - ours // hopefully that would flush all chunk writes, including current chink @@ -187,10 +189,10 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem { report.put("layer_count_"+status.getId(),targetStatus.size()); long start = System.currentTimeMillis(); - if (status == ChunkStatus.LIGHT) - { - serverLightingProvider.setTaskBatchSize(targetStatus.size() + 20); - } + //if (status == ChunkStatus.LIGHT) + //{ + // serverLightingProvider.setTaskBatchSize(targetStatus.size() + 20); + //} for (ChunkPos chpos : new ArrayList<>(targetStatus.keySet())) { if (targetStatus.get(chpos) == status) @@ -201,7 +203,8 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem } if (status == ChunkStatus.LIGHT) { // default task batch size after initial generation is done - serverLightingProvider.setTaskBatchSize(5); + //serverLightingProvider.setTaskBatchSize(5); + ((ServerLightingProviderInterface)this.serverLightingProvider).flush(); } report.put("layer_time_"+status.getId(), (int) (System.currentTimeMillis()-start)); } diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 25c2356e..1ecd3f9b 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -28,6 +28,7 @@ "ThreadedAnvilChunkStorage_scarpetChunkCreationMixin", "ChunkHolder_scarpetChunkCreationMixin", + "ServerLightingProvider_scarpetChunkCreationMixin", "MobEntityMixin", "ServerWorld_unloadedEntityMixin",