Files
Purpur/patches/server/0017-Tick-loop-config-options.patch
William Blake Galbreath 700cb27472 Update upstream
2019-06-10 19:31:06 -05:00

82 lines
4.3 KiB
Diff

From 4bbc098121fe0157622312f0ae244fb124d1db4b Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Wed, 22 May 2019 22:30:08 -0500
Subject: [PATCH] Tick loop config options
---
.../net/minecraft/server/MinecraftServer.java | 31 +++++++++++++------
.../java/net/pl3x/purpur/PurpurConfig.java | 7 +++++
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index fc57f154f..0a4d37cd4 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -865,16 +865,21 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
long start = System.nanoTime(), curTime, tickSection = start; // Paper - Further improve server tick loop
lastTick = start - TICK_TIME; // Paper
while (this.isRunning) {
- long i = ((curTime = System.nanoTime()) / (1000L * 1000L)) - this.nextTick; // Paper
-
- if (i > 5000L && this.nextTick - this.lastOverloadTime >= 30000L) { // CraftBukkit
- long j = i / 50L;
-
- if (server.getWarnOnOverload()) // CraftBukkit
- MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", i, j);
- this.nextTick += j * 50L;
- this.lastOverloadTime = this.nextTick;
+ // Purpur start - tick overload
+ curTime = System.nanoTime();
+ if (net.pl3x.purpur.PurpurConfig.enableTickOverload) {
+ long i = ((curTime) / (1000L * 1000L)) - this.nextTick; // Paper
+
+ if (i > 5000L && this.nextTick - this.lastOverloadTime >= 30000L) { // CraftBukkit
+ long j = i / 50L;
+
+ if (server.getWarnOnOverload()) // CraftBukkit
+ MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", i, j);
+ this.nextTick += j * 50L;
+ this.lastOverloadTime = this.nextTick;
+ }
}
+ // Purpur end - tick overload
if ( ++MinecraftServer.currentTick % SAMPLE_INTERVAL == 0 )
{
@@ -905,7 +910,13 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
this.a(this::canSleepForTick);
this.methodProfiler.exitEnter("nextTickWait");
this.ac = true;
- this.ab = Math.max(SystemUtils.getMonotonicMillis() + 50L, this.nextTick);
+ // Purpur start - tps catchup
+ if (net.pl3x.purpur.PurpurConfig.enableTPSCatchup) {
+ this.ab = Math.max(SystemUtils.getMonotonicMillis() + 50L, this.nextTick);
+ } else {
+ this.ab = this.nextTick = curTime / 1000000L + 50L;
+ }
+ // Purpur end - tps catchup
this.sleepForTick();
this.methodProfiler.exit();
this.methodProfiler.b();
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index 38f9d3a3a..99b7abd6d 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -103,6 +103,13 @@ public class PurpurConfig {
return config.getString(path, config.getString(path));
}
+ public static boolean enableTickOverload = false;
+ public static boolean enableTPSCatchup = false;
+ private static void tickLoopSettings() {
+ enableTickOverload = getBoolean("settings.enable-tick-overload", enableTickOverload);
+ enableTPSCatchup = getBoolean("settings.enable-tps-catchup", enableTPSCatchup);
+ }
+
public static boolean requireShiftToMount = true;
private static void requireShiftToMount() {
requireShiftToMount = getBoolean("settings.mobs.require-shift-to-mount", requireShiftToMount);
--
2.20.1