|
5 | 5 | import com.ishland.c2me.base.common.scheduler.SchedulingManager; |
6 | 6 | import com.ishland.c2me.base.mixin.access.IThreadedAnvilChunkStorage; |
7 | 7 | import com.ishland.c2me.base.mixin.access.IVersionedChunkStorage; |
8 | | -import com.ishland.flowsched.scheduler.DaemonizedStatusAdvancingScheduler; |
9 | 8 | import com.ishland.flowsched.scheduler.ExceptionHandlingAction; |
10 | 9 | import com.ishland.flowsched.scheduler.ItemHolder; |
11 | 10 | import com.ishland.flowsched.scheduler.ItemStatus; |
12 | 11 | import com.ishland.flowsched.scheduler.KeyStatusPair; |
| 12 | +import com.ishland.flowsched.scheduler.StatusAdvancingScheduler; |
13 | 13 | import com.ishland.flowsched.util.Assertions; |
14 | 14 | import io.netty.util.internal.PlatformDependent; |
15 | 15 | import io.reactivex.rxjava3.core.Scheduler; |
|
21 | 21 | import net.minecraft.server.WorldGenerationProgressListener; |
22 | 22 | import net.minecraft.server.world.ChunkHolder; |
23 | 23 | import net.minecraft.server.world.ServerChunkLoadingManager; |
24 | | -import net.minecraft.util.Util; |
25 | 24 | import net.minecraft.util.collection.BoundedRegionArray; |
26 | | -import net.minecraft.util.crash.CrashException; |
27 | | -import net.minecraft.util.crash.ReportType; |
28 | 25 | import net.minecraft.util.math.ChunkPos; |
29 | 26 | import org.slf4j.Logger; |
30 | 27 | import org.slf4j.LoggerFactory; |
31 | 28 |
|
32 | | -import java.nio.file.Path; |
33 | 29 | import java.util.Queue; |
34 | 30 | import java.util.concurrent.Executor; |
35 | | -import java.util.concurrent.ThreadFactory; |
36 | 31 |
|
37 | | -public class TheChunkSystem extends DaemonizedStatusAdvancingScheduler<ChunkPos, ChunkState, ChunkLoadingContext, NewChunkHolderVanillaInterface> { |
| 32 | +public class TheChunkSystem extends StatusAdvancingScheduler<ChunkPos, ChunkState, ChunkLoadingContext, NewChunkHolderVanillaInterface> { |
38 | 33 |
|
39 | 34 | private final Logger LOGGER; |
40 | 35 |
|
41 | 36 | private final Long2IntMap managedTickets = Long2IntMaps.synchronize(new Long2IntOpenHashMap()); |
42 | 37 | private final SchedulingManager schedulingManager; |
43 | 38 | private final Executor backingBackgroundExecutor = GlobalExecutors.prioritizedScheduler.executor(15); |
44 | | - private Queue<Runnable> backgroundTaskQueue = PlatformDependent.newSpscQueue(); |
45 | | - private final Executor backgroundExecutor = command -> { |
46 | | - if (Thread.currentThread() != this.thread) { |
47 | | - command.run(); |
48 | | - } else { |
49 | | - backgroundTaskQueue.add(command); |
50 | | - } |
51 | | - }; |
52 | | - private final Scheduler backgroundScheduler = Schedulers.from(this.backgroundExecutor); |
| 39 | + private final Scheduler backgroundScheduler = Schedulers.from(this.backingBackgroundExecutor); |
53 | 40 | private final ServerChunkLoadingManager tacs; |
54 | 41 |
|
55 | | - public TheChunkSystem(ThreadFactory threadFactory, ServerChunkLoadingManager tacs) { |
56 | | - super(threadFactory, TheSpeedyObjectFactory.INSTANCE); |
| 42 | + public TheChunkSystem(ServerChunkLoadingManager tacs) { |
| 43 | + super(TheSpeedyObjectFactory.INSTANCE); |
57 | 44 | this.tacs = tacs; |
58 | 45 | this.schedulingManager = ((IVanillaChunkManager) tacs).c2me$getSchedulingManager(); |
59 | 46 | this.LOGGER = LoggerFactory.getLogger("Chunk System of %s".formatted(((IThreadedAnvilChunkStorage) tacs).getWorld().getRegistryKey().getValue())); |
60 | 47 | managedTickets.defaultReturnValue(NewChunkStatus.vanillaLevelToStatus.length - 1); |
61 | | - this.thread.start(); |
62 | 48 | } |
63 | 49 |
|
64 | 50 | @Override |
65 | 51 | protected Executor getBackgroundExecutor() { |
66 | | - return this.backgroundExecutor; |
| 52 | + return this.backingBackgroundExecutor; |
67 | 53 | } |
68 | 54 |
|
69 | 55 | @Override |
@@ -216,24 +202,4 @@ protected void onItemDowngrade(ItemHolder<ChunkPos, ChunkState, ChunkLoadingCont |
216 | 202 | public int vanillaIf$getManagedLevel(long pos) { |
217 | 203 | return this.managedTickets.get(pos); |
218 | 204 | } |
219 | | - |
220 | | - @Override |
221 | | - public boolean tick() { |
222 | | - boolean tick = super.tick(); |
223 | | - if (!this.backgroundTaskQueue.isEmpty()) { |
224 | | - Queue<Runnable> queue = this.backgroundTaskQueue; |
225 | | - this.backgroundTaskQueue = PlatformDependent.newSpscQueue(); |
226 | | - this.backingBackgroundExecutor.execute(() -> { |
227 | | - Runnable runnable; |
228 | | - while ((runnable = queue.poll()) != null) { |
229 | | - try { |
230 | | - runnable.run(); |
231 | | - } catch (Throwable t) { |
232 | | - t.printStackTrace(); |
233 | | - } |
234 | | - } |
235 | | - }); |
236 | | - } |
237 | | - return tick; |
238 | | - } |
239 | 205 | } |
0 commit comments