Skip to content

Commit

Permalink
Cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHua269 committed Dec 28, 2024
1 parent a953ee1 commit 9c9c913
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/main/java/me/mrhua269/chlorophyll/Chlorophyll.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package me.mrhua269.chlorophyll;

import com.google.common.collect.Maps;
import com.mojang.logging.LogUtils;
import me.mrhua269.chlorophyll.impl.ChlorophyllLevelTickLoop;
import me.mrhua269.chlorophyll.utils.bridges.ITaskSchedulingLevel;
import me.mrhua269.chlorophyll.utils.TickThread;
import net.fabricmc.api.ModInitializer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import org.slf4j.Logger;

import java.util.Map;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;

public class Chlorophyll implements ModInitializer {
public static final Logger logger = LogUtils.getLogger();
private static final Map<ServerLevel, ChlorophyllLevelTickLoop> tickLoops = Maps.newConcurrentMap();

private static final AtomicInteger threadIdGenerator = new AtomicInteger();
public static final ScheduledThreadPoolExecutor workerPool = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), task -> {
final Thread wrapped = new TickThread(task, "Chlorophyll World Scheduler Thread - " + threadIdGenerator.getAndIncrement(), true);
wrapped.setPriority(8);
wrapped.setContextClassLoader(MinecraftServer.class.getClassLoader());
return wrapped;
});

public static MinecraftServer server;

public static void killAllAndAwait(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ private void processMainThreadTasks(){
}
}

while (this.ownedLevel.getChunkSource().pollTask());
for (;;) {
// Poll chunk system tasks
if (!this.ownedLevel.getChunkSource().pollTask()) {
break;
}

// Leave nothing here because we won't and should block here
}
}

private void tickConnections(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public boolean isWorldThread() {
}

@Contract(pure = true)
public static @Nullable TickThread currentThread(){
public static TickThread currentThread(){
if (Thread.currentThread() instanceof TickThread tickThread){
return tickThread;
}
Expand Down

0 comments on commit 9c9c913

Please sign in to comment.