Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,183 +1,60 @@
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -332,6 +_,7 @@
@@ -332,6 +_,9 @@
public volatile boolean abnormalExit; // Paper - Improved watchdog support
public volatile Thread shutdownThread; // Paper - Improved watchdog support
public final io.papermc.paper.configuration.PaperConfigurations paperConfigurations; // Paper - add paper configuration files
+ public final org.galemc.gale.configuration.GaleConfigurations galeConfigurations; // Gale - Configuration - Add configuration files
+ // Gale start - Parallel world ticking
+ public org.galemc.gale.tick.GaleWorldTickExecutor galeWorldTickExecutor; // Gale - Parallel world ticking
+ // Gale end - Parallel world ticking
public boolean isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
private final Set<String> pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
@@ -576,6 +_,7 @@
@@ -576,6 +_,18 @@
Runtime.getRuntime().addShutdownHook(new org.bukkit.craftbukkit.util.ServerShutdownThread(this));
// CraftBukkit end
this.paperConfigurations = services.paper().configurations(); // Paper - add paper configuration files
+ this.galeConfigurations = services.paper().galeConfigurations(); // Gale - Configuration - Add configuration files
+ // Gale start - Parallel world ticking - Capture main thread + init executor
+ org.galemc.gale.tick.GaleThreadMarkers.captureMainServerThread();
+ {
+ org.galemc.gale.configuration.GaleGlobalConfiguration galeGlobalCfg = org.galemc.gale.configuration.GaleGlobalConfiguration.get();
+ if (galeGlobalCfg != null) {
+ org.galemc.gale.configuration.GaleGlobalConfiguration.Performance perf = galeGlobalCfg.performance;
+ if (perf != null && perf.parallelWorldTicking) {
+ this.galeWorldTickExecutor = org.galemc.gale.tick.GaleWorldTickExecutor.create(true, perf.parallelWorldTickingMaxThreads);
+ }
+ }
+ }
+ // Gale end - Parallel world ticking - Capture main thread + init executor
}

protected abstract boolean initServer() throws IOException;
@@ -1347,6 +_,11 @@

try (Profiler.Scope ignored = Profiler.use(this.createProfiler())) {
this.processPacketsAndTick(sprinting);
+ // Gale start - Speculative execution based on next tick simulation - Simulate next tick
+ org.galemc.gale.async.SimulationFlag.REAL = false;
+ this.processPacketsAndTick(true);
+ org.galemc.gale.async.SimulationFlag.REAL = true;
+ // Gale end - Speculative execution based on next tick simulation - Simulate next tick
ProfilerFiller profiler = Profiler.get();
profiler.push("nextTickWait");
this.mayHaveDelayedTasks = true;
@@ -1578,8 +_,9 @@
}

protected void tickServer(final BooleanSupplier haveTime) {
- org.spigotmc.WatchdogThread.tick(); // Spigot
+ if (org.galemc.gale.async.SimulationFlag.REAL) org.spigotmc.WatchdogThread.tick(); // Spigot // Gale - Speculative execution based on next tick simulation - Simulate next tick
long nano = Util.getNanos();
+ if (org.galemc.gale.async.SimulationFlag.REAL) { // Gale - Speculative execution based on next tick simulation - Simulate next tick
int emptyTickThreshold = this.pauseWhenEmptySeconds() * 20;
this.removeDisabledPluginsBlockingSleep(); // Paper - API to allow/disallow tick sleeping
if (emptyTickThreshold > 0) {
@@ -1618,7 +_,9 @@
new com.destroystokyo.paper.event.server.ServerTickStartEvent(this.tickCount+1).callEvent(); // Paper - Server Tick Events
this.tickCount++;
this.tickRateManager.tick();
+ } // Gale - Speculative execution based on next tick simulation - Simulate next tick
this.tickChildren(haveTime);
+ if (org.galemc.gale.async.SimulationFlag.REAL) { // Gale - Speculative execution based on next tick simulation - Simulate next tick
if (nano - this.lastServerStatus >= STATUS_EXPIRE_TIME_NANOS) {
this.lastServerStatus = nano;
this.status = this.buildServerStatus();
@@ -1668,6 +_,7 @@
this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float)tickTime / (float)TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F;
this.logTickMethodTime(nano);
profiler.pop();
+ } // Gale - Speculative execution based on next tick simulation - Simulate next tick
}

protected void processPacketsAndTick(final boolean sprinting) {
@@ -1675,7 +_,7 @@
profiler.push("tick");
this.tickFrame.start();
// Paper - improve tick loop - moved into runAllTasksAtTickStart
- this.runAllTasksAtTickStart(); // Paper - improve tick loop
+ if (org.galemc.gale.async.SimulationFlag.REAL) this.runAllTasksAtTickStart(); // Paper - improve tick loop // Gale - Speculative execution based on next tick simulation - Simulate next tick
this.tickServer(sprinting ? () -> false : this::haveTime);
// Paper start - rewrite chunk system
final Throwable crash = this.chunkSystemCrash;
@@ -1685,7 +_,7 @@
}
// Paper end - rewrite chunk system
this.tickFrame.end();
- this.recordEndOfTick(); // Paper - improve tick loop
+ if (org.galemc.gale.async.SimulationFlag.REAL) this.recordEndOfTick(); // Paper - improve tick loop // Gale - Speculative execution based on next tick simulation - Simulate next tick
profiler.pop();
}

@@ -1764,6 +_,7 @@

protected void tickChildren(final BooleanSupplier haveTime) {
ProfilerFiller profiler = Profiler.get();
+ if (org.galemc.gale.async.SimulationFlag.REAL) { // Gale - Speculative execution based on next tick simulation - Simulate next tick
this.getPlayerList().getPlayers().forEach(playerx -> playerx.connection.suspendFlushing());
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
// Paper start - optimise Folia entity scheduler
@@ -1779,10 +_,13 @@
// Paper end - Folia scheduler API
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.ADVENTURE_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.DIALOG_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
+ } // Gale - Speculative execution based on next tick simulation - Simulate next tick
profiler.push("commandFunctions");
this.getFunctions().tick();
profiler.pop();
+ boolean clocksNeedRewind = false; // Gale - Speculative execution based on next tick simulation - Simulate next tick
if (this.tickRateManager.runsNormally()) {
+ clocksNeedRewind = true; // Gale - Speculative execution based on next tick simulation - Simulate next tick
profiler.push("clocks");
// Paper start - per-world time
if (io.papermc.paper.configuration.GlobalConfiguration.get().time.affectsAllWorlds) {
@@ -1796,6 +_,7 @@
profiler.pop();
}

+ if (org.galemc.gale.async.SimulationFlag.REAL) { // Gale - Speculative execution based on next tick simulation - Simulate next tick
if (this.tickCount % 20 == 0) {
profiler.push("timeSync");
this.forceGameTimeSynchronization();
@@ -1812,7 +_,9 @@
@@ -1811,7 +_,29 @@
this.updateEffectiveRespawnData();

this.isIteratingOverLevels = true; // Paper - Throw exception on world create while being ticked
+ } // Gale - Speculative execution based on next tick simulation - Simulate next tick
+ // Gale start - Parallel world ticking - Tick different worlds on separate CPU cores
+ java.util.ArrayList<ServerLevel> gale$parallelLevels = new java.util.ArrayList<>();
+ for (ServerLevel gale$lvl : this.getAllLevels()) gale$parallelLevels.add(gale$lvl);
+ org.galemc.gale.tick.GaleWorldTickExecutor gale$exec = this.galeWorldTickExecutor;
+ final boolean gale$useParallel = gale$exec != null
+ && gale$parallelLevels.size() > 1;
+ if (gale$useParallel) {
+ for (int gale$i = 0; gale$i < gale$parallelLevels.size(); gale$i++) {
+ ServerLevel gale$level = gale$parallelLevels.get(gale$i);
+ gale$level.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
+ gale$level.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
+ gale$level.updateLagCompensationTick(); // Paper - lag compensation
+ }
+ gale$exec.tickWorldsParallel(haveTime, gale$parallelLevels);
+ }
+ // Gale end - Parallel world ticking - Tick different worlds on separate CPU cores
for (ServerLevel level : this.getAllLevels()) {
+ if (org.galemc.gale.async.SimulationFlag.REAL) { // Gale - Speculative execution based on next tick simulation - Simulate next tick
+ // Gale start - Parallel world ticking - Skip per-world sequential loop when already ran in parallel
+ if (gale$useParallel) {
+ break;
+ }
+ // Gale end - Parallel world ticking - Skip per-world sequential loop when already ran in parallel
level.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
level.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
level.updateLagCompensationTick(); // Paper - lag compensation
@@ -1820,6 +_,7 @@
profiler.push(() -> level + " " + level.dimension().identifier());
profiler.push("tick");

+ } // Gale - Speculative execution based on next tick simulation - Simulate next tick
try {
level.tick(haveTime);
} catch (Throwable t) {
@@ -1827,11 +_,14 @@
level.fillReportDetails(report);
throw new ReportedException(report);
}
+ if (org.galemc.gale.async.SimulationFlag.REAL) { // Gale - Speculative execution based on next tick simulation - Simulate next tick

profiler.pop();
profiler.pop();
level.explosionDensityCache.clear(); // Paper - Optimize explosions
+ } // Gale - Speculative execution based on next tick simulation - Simulate next tick
}
+ if (org.galemc.gale.async.SimulationFlag.REAL) { // Gale - Speculative execution based on next tick simulation - Simulate next tick
this.isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked

profiler.popPush("connection");
@@ -1860,6 +_,21 @@

profiler.pop();
this.serverActivityMonitor.tick();
+ // Gale start - Speculative execution based on next tick simulation - Simulate next tick
+ } else {
+ if (clocksNeedRewind) {
+ // Paper start - per-world time
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().time.affectsAllWorlds) {
+ this.clockManager.rewind();
+ } else {
+ for (ServerLevel level : this.getAllLevels()) {
+ level.clockManager().rewind();
+ }
+ }
+ // Paper end - per-world time
+ }
+ }
+ // Gale end - Speculative execution based on next tick simulation - Simulate next tick
}

// Paper start - per world respawn data
@@ -2032,7 +_,19 @@
new io.papermc.paper.event.world.WorldDifficultyChangeEvent(
level.getWorld(), source, org.bukkit.craftbukkit.util.CraftDifficulty.toBukkit(difficulty)
).callEvent();
- worldData.setDifficulty(worldData.isHardcore() ? Difficulty.HARD : difficulty);
+ // Gale start - Event-driven - Mob.mustDespawnBecauseOfPeacefulDifficulty
+ Difficulty oldDifficulty = worldData.getDifficulty();
+ Difficulty newDifficulty = worldData.isHardcore() ? Difficulty.HARD : difficulty;
+ if (oldDifficulty == newDifficulty) {
+ return;
+ }
+ worldData.setDifficulty(newDifficulty);
+ if ((oldDifficulty == Difficulty.PEACEFUL) != (newDifficulty == Difficulty.PEACEFUL)) {
+ for (net.minecraft.world.entity.Mob mob : level.getEntities(net.minecraft.world.level.entity.EntityTypeTest.forClass(net.minecraft.world.entity.Mob.class), _ -> true)) {
+ mob.gale$eventDriven_mustDespawnBecauseOfPeacefulDifficulty_update();
+ }
+ }
+ // Gale end - Event-driven - Mob.mustDespawnBecauseOfPeacefulDifficulty
level.setSpawnSettings(level.isSpawningMonsters());
level.players().forEach(this::sendDifficultyUpdate);
// Paper end - per level difficulty

This file was deleted.

Loading
Loading