diff --git a/sponge/build.gradle.kts b/sponge/build.gradle.kts index a45bc9f0..43633cdd 100644 --- a/sponge/build.gradle.kts +++ b/sponge/build.gradle.kts @@ -27,7 +27,7 @@ java { sponge { injectRepositories(false) - apiVersion("12.0.0-SNAPSHOT") + apiVersion("13.0.0-SNAPSHOT") plugin(rootProject.name.lowercase()) { loader { name(PluginLoaders.JAVA_PLAIN) diff --git a/sponge/src/main/java/xyz/jpenilla/tabtps/sponge/mixin/MinecraftServerMixin.java b/sponge/src/main/java/xyz/jpenilla/tabtps/sponge/mixin/MinecraftServerMixin.java index d8d7bb32..48bc4c46 100644 --- a/sponge/src/main/java/xyz/jpenilla/tabtps/sponge/mixin/MinecraftServerMixin.java +++ b/sponge/src/main/java/xyz/jpenilla/tabtps/sponge/mixin/MinecraftServerMixin.java @@ -27,6 +27,7 @@ import java.math.RoundingMode; import java.util.function.BooleanSupplier; import net.minecraft.server.MinecraftServer; +import net.minecraft.util.profiling.ProfilerFiller; import org.checkerframework.checker.nullness.qual.NonNull; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Implements; @@ -51,34 +52,61 @@ @Mixin(MinecraftServer.class) @Implements({@Interface(iface = TickTimeService.class, prefix = "tabtps$")}) abstract class MinecraftServerMixin implements MinecraftServerAccess { + @Unique private final TickTimes tickTimes5s = new TickTimes(100); + @Unique private final TickTimes tickTimes10s = new TickTimes(200); + @Unique private final TickTimes tickTimes60s = new TickTimes(1200); - private final RollingAverage tps5s = new RollingAverage(5); + @Unique + private final RollingAverage tps15s = new RollingAverage(15); + @Unique private final RollingAverage tps1m = new RollingAverage(60); + @Unique private final RollingAverage tps5m = new RollingAverage(60 * 5); + @Unique private final RollingAverage tps15m = new RollingAverage(60 * 15); + @Unique private long previousTime; + @Unique + private boolean tickingPaused; @Shadow private int tickCount; @Shadow @Final private long[] tickTimesNanos; - @Inject(method = "tickServer", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) - public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final long tickStartTimeNanos, final long tickDurationNanos) { + @Inject( + method = "tickServer", + at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V", ordinal = 0) + ) + private void injectPause(final BooleanSupplier keepTicking, final CallbackInfo ci) { + this.tickingPaused = true; + } + + @Inject(method = "tickServer", at = @At(value = "RETURN", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD) + public void injectTick( + final BooleanSupplier keepTicking, + final CallbackInfo ci, + final long tickStartTimeNanos, + final ProfilerFiller profilerFiller, + final long tickDurationNanos + ) { this.tickTimes5s.add(this.tickCount, tickDurationNanos); this.tickTimes10s.add(this.tickCount, tickDurationNanos); this.tickTimes60s.add(this.tickCount, tickDurationNanos); if (this.tickCount % RollingAverage.SAMPLE_INTERVAL == 0) { - if (this.previousTime == 0) { - this.previousTime = tickStartTimeNanos - RollingAverage.TICK_TIME; + if (this.previousTime == 0 || this.tickingPaused) { + this.previousTime = tickStartTimeNanos - tickDurationNanos; + if (this.tickingPaused) { + this.tickingPaused = false; + } } final long diff = tickStartTimeNanos - this.previousTime; this.previousTime = tickStartTimeNanos; final BigDecimal currentTps = RollingAverage.TPS_BASE.divide(new BigDecimal(diff), 30, RoundingMode.HALF_UP); - this.tps5s.add(currentTps, diff); + this.tps15s.add(currentTps, diff); this.tps1m.add(currentTps, diff); this.tps5m.add(currentTps, diff); this.tps15m.add(currentTps, diff); @@ -91,7 +119,7 @@ public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final public double @NonNull [] tabtps$recentTps() { final double[] tps = new double[4]; - tps[0] = this.tps5s.average(); + tps[0] = this.tps15s.average(); tps[1] = this.tps1m.average(); tps[2] = this.tps5m.average(); tps[3] = this.tps15m.average();