Skip to content

Commit

Permalink
add ChiyogamiLib
Browse files Browse the repository at this point in the history
  • Loading branch information
bea4dev committed Sep 26, 2024
1 parent 438292e commit ae0f77b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Notes

API
------
APIは未公開です
[ChiyogamiLib](https://github.com/bea4dev/ChiyogamiLib/tree/master)

How to build
------
Expand All @@ -35,4 +35,4 @@ For developer

このサーバーはワールドにそれぞれ専用のスレッドを割り当て、楽観的に同期を取りつつ動作します。

イベントの発火処理にはデフォルトで排他制御が設けられますが、ワールド間での順序関係は保証されないため注意が必要です。
イベントの発火処理にはデフォルトで排他制御が設けられますが、ワールド間での順序関係は保証されないため注意が必要です。
19 changes: 19 additions & 0 deletions patches/api/0004-fix-world-task-scheduler.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: bea4dev <[email protected]>
Date: Thu, 26 Sep 2024 20:46:07 +0900
Subject: [PATCH] fix world task scheduler


diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index d826babe9466d21b4eaf72061a22b77293298baa..a715347104038d8a1a8befa5cc7d70cdb41cf150 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -65,7 +65,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
* @param runnable Tasks in runnable.
* @param delay Delay in executing a task.
*/
- default void scheduleTask(Runnable runnable, long delay){scheduleTask(runnable, 0, delay);}
+ default void scheduleTask(Runnable runnable, long delay){scheduleTask(runnable, delay, 0);}

/**
* Schedules a task to the thread executing this world.
19 changes: 19 additions & 0 deletions patches/server/0020-fix-world-task-scheduler.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: bea4dev <[email protected]>
Date: Thu, 26 Sep 2024 20:46:07 +0900
Subject: [PATCH] fix world task scheduler


diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 5d08442e7c18a0be7eb66c017e5bce846eb5eaaa..dcb686420f489f5d46d78bad65e8be3d4aa77301 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -2473,7 +2473,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {

// Chiyogami start - thread
@Override
- public void scheduleTask(Runnable runnable, long period, long delay) {
+ public void scheduleTask(Runnable runnable, long delay, long period) {
if (runnable instanceof world.chiyogami.thread.WorldThreadRunnable) {
world.chiyogami.thread.WorldThread worldThread = this.getHandle().worldThread;
worldThread.scheduleWorldThreadRunnable((world.chiyogami.thread.WorldThreadRunnable) runnable);
80 changes: 80 additions & 0 deletions patches/server/0021-add-ChiyogamiLib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: bea4dev <[email protected]>
Date: Fri, 27 Sep 2024 00:14:33 +0900
Subject: [PATCH] add ChiyogamiLib


diff --git a/build.gradle.kts b/build.gradle.kts
index 2326cdcef7bdac0b201370624c9bab70965039a0..2b5cda32b8ee062818e7a413ebffbd1286606c65 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -11,7 +11,11 @@ configurations.named(log4jPlugins.compileClasspathConfigurationName) {
extendsFrom(configurations.compileClasspath.get())
}
val alsoShade: Configuration by configurations.creating
-
+// Chiyogami start - add ChiyogamiLib
+repositories {
+ maven("https://jitpack.io")
+}
+// Chiyogami end
dependencies {
implementation(project(":chiyogami-api")) // Chiyogami
// Paper start
@@ -65,6 +69,9 @@ dependencies {
implementation("me.lucko:spark-api:0.1-20240720.200737-2")
implementation("me.lucko:spark-paper:1.10.84-20240720.204128-1")
// Paper end - spark
+ // Chiyogami start - add ChiyogamiLib
+ implementation("com.github.bea4dev:ChiyogamiLib:7ed1df4960")
+ // Chiyogami end
}

paperweight {
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 835bd0fad47b437dd51f9b8386d0764b92cc99bd..aa18bb012dc8839bd5634910a27c1efd99aaa9cf 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1653,6 +1653,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.profiler.pop();
org.spigotmc.WatchdogThread.tick(); // Spigot
co.aikar.timings.TimingsManager.FULL_SERVER_TICK.stopTiming(); // Paper
+ world.chiyogami.chiyogamilib.monitor.PerformanceMonitor.setFullServerTickNanoTime(System.nanoTime() - i); // Chiyogami - add ChiyogamiLib
}

private void logTickMethodTime(long tickStartTime) {
@@ -1780,6 +1781,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

this.isIteratingOverLevels = true; // Paper - Throw exception on world create while being ticked
Iterator iterator = this.getAllLevels().iterator(); // Paper - Throw exception on world create while being ticked; move down
+ long allWorldServerStartTimeNano = System.nanoTime(); // Chiyogami - add ChiyogamiLib
while (iterator.hasNext()) {
ServerLevel worldserver = (ServerLevel) iterator.next();
// Chiyogami start - world threading
@@ -1788,6 +1790,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
worldThread.setWorldTickRunnable(() -> {
worldserver.thread = Thread.currentThread();
// Chiyogami end
+ // Chiyogami start - add ChiyogamiLib
+ world.chiyogami.chiyogamilib.WorldThreads.worldThreadMap.put(worldserver.getWorld(), Thread.currentThread());
+ world.chiyogami.chiyogamilib.scheduler.WorldThreadRunnable.worldThreadHeartBeat(worldserver.getWorld(), currentTick);
+ long worldServerStartTimeNano = System.nanoTime();
+ // Chiyogami end
worldserver.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = worldserver.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper - Perf: Optimize Hoppers
@@ -1822,10 +1829,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.profiler.pop();
this.profiler.pop();
worldserver.explosionDensityCache.clear(); // Paper - Optimize explosions
+ // Chiyogami start - add ChiyogamiLib
+ world.chiyogami.chiyogamilib.monitor.PerformanceMonitor.getWorldTickNanoTimeMap().put(worldserver.getWorld(), System.nanoTime() - worldServerStartTimeNano);
+ // Chiyogami end
});} // Chiyogami - world threading
}
world.chiyogami.thread.WorldThreadPool.doTick(this.levels.values()); // Chiyogami - world threading
this.isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
+ world.chiyogami.chiyogamilib.monitor.PerformanceMonitor.setAllWorldTickNanoTime(System.nanoTime() - allWorldServerStartTimeNano); // Chiyogami - add ChiyogamiLib

this.profiler.popPush("connection");
MinecraftTimings.connectionTimer.startTiming(); // Spigot // Paper

0 comments on commit ae0f77b

Please sign in to comment.