tickspeed server - client separation.

This commit is contained in:
gnembon committed 2023-05-14 23:36:55 +02:00
1 parent 755ec1daa8
commit e0a3060339
21 files changed
+505 -237

No files matched your search

@@ -34,7 +34,7 @@ public class BoundTickingBlockEntity_tickMixin<T extends BlockEntity>
))
private void checkProcessBEs(BlockEntityTicker<T> blockEntityTicker, Level world, BlockPos pos, BlockState state, T blockEntity)
{
if (TickSpeed.process_entities) blockEntityTicker.tick(world, pos, state, blockEntity);
if (TickSpeed.process_entities()) blockEntityTicker.tick(world, pos, state, blockEntity);
}
@Inject(method = "tick()V", at = @At("RETURN"))
@@ -18,6 +18,6 @@ public class DistanceManager_tickMixin
{
// pausing expiry of tickets
// that will prevent also chunks from unloading, so require a deep frozen state
if (!TickSpeed.process_entities && TickSpeed.deeplyFrozen()) ticketTickCounter--;
if (!TickSpeed.process_entities() && TickSpeed.deeplyFrozen()) ticketTickCounter--;
}
}
@@ -25,7 +25,7 @@ public class LevelRenderer_pausedShakeMixin
private float changeTickPhase(float previous)
{
initial = previous;
if (!TickSpeed.process_entities)
if (!TickSpeed.process_entitiesClient())
return ((MinecraftClientInferface)minecraft).getPausedTickDelta();
return previous;
}
@@ -86,8 +86,18 @@ public abstract class Level_tickMixin implements LevelInterface
@Inject(method = "guardEntityTick", at = @At("HEAD"), cancellable = true)
private void startEntity(Consumer<Entity> consumer_1, Entity e, CallbackInfo ci)
{
if (!(TickSpeed.process_entities || (e instanceof Player) || (TickSpeed.is_superHot && isClientSide && e.getControllingPassenger() instanceof Player)))
ci.cancel();
// this shows that probably tick speed controller needs to be accessible through level referring to servers on server and client on clientLevel
if (isClientSide) {
if (!(TickSpeed.process_entitiesClient() || (e instanceof Player) || TickSpeed.isIs_superHotClient() && e.getControllingPassenger() instanceof Player))
{
ci.cancel();
}
} else {
if (!(TickSpeed.gTRM().map(trm -> trm.process_entities).orElse(true) || (e instanceof Player)))
{
ci.cancel();
}
}
entitySection = CarpetProfiler.start_entity_section((Level) (Object) this, e, CarpetProfiler.TYPE.ENTITY);
}
@@ -26,9 +26,15 @@ public class MinecraftMixin
@Inject(at = @At("HEAD"), method = "tick")
private void onClientTick(CallbackInfo info) {
if (this.level != null) {
if (CarpetServer.minecraft_server == null)
TickSpeed.tick();
if (!TickSpeed.process_entities)
TickSpeed.tickClient();
if (CarpetServer.minecraft_server == null) // remote client only ? no - now any client
{
} else {
// hmm, server should tick, rgiht?
//TickSpeed.tick();
}
if (!TickSpeed.process_entitiesClient())
CarpetClient.shapes.renewShapes();
}
}
@@ -89,7 +89,7 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantBlockableEve
))
public void tickTasks(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
if (!TickSpeed.process_entities)
if (!TickSpeed.process_entities())
return;
TICK.onTick((MinecraftServer) (Object) this);
NETHER_TICK.onTick((MinecraftServer) (Object) this);
@@ -1,5 +1,7 @@
package carpet.mixins;
import carpet.fakes.MinecraftServerInterface;
import carpet.helpers.TickRateManager;
import carpet.helpers.TickSpeed;
import carpet.patches.CopyProfilerResult;
import carpet.utils.CarpetProfiler;
@@ -25,7 +27,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.function.BooleanSupplier;
@Mixin(value = MinecraftServer.class, priority = Integer.MAX_VALUE - 10)
public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableEventLoop<TickTask>
public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableEventLoop<TickTask> implements MinecraftServerInterface
{
@Shadow private volatile boolean running;
@@ -67,6 +69,20 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
private float carpetMsptAccum = 0.0f;
private TickRateManager tickRateManager;
@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(CallbackInfo ci)
{
tickRateManager = new TickRateManager((MinecraftServer)(Object)this);
}
@Override
public TickRateManager getTickRateManager()
{
return tickRateManager;
}
/**
* To ensure compatibility with other mods we should allow milliseconds
*/
@@ -95,32 +111,33 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
}
long msThisTick = 0L;
long long_1 = 0L;
if (TickSpeed.time_warp_start_time != 0 && TickSpeed.continueWarp())
float mspt = tickRateManager.mspt;
if (tickRateManager.time_warp_start_time != 0 && TickSpeed.continueWarp())
{
//making sure server won't flop after the warp or if the warp is interrupted
this.nextTickTime = this.lastOverloadWarning = Util.getMillis();
carpetMsptAccum = TickSpeed.mspt;
carpetMsptAccum = mspt;
}
else
{
if (Math.abs(carpetMsptAccum - TickSpeed.mspt) > 1.0f)
if (Math.abs(carpetMsptAccum - mspt) > 1.0f)
{
// Tickrate changed. Ensure that we use the correct value.
carpetMsptAccum = TickSpeed.mspt;
carpetMsptAccum = mspt;
}
msThisTick = (long)carpetMsptAccum; // regular tick
carpetMsptAccum += TickSpeed.mspt - msThisTick;
carpetMsptAccum += mspt - msThisTick;
long_1 = Util.getMillis() - this.nextTickTime;
}
//end tick deciding
//smoothed out delay to include mcpt component. With 50L gives defaults.
if (long_1 > /*2000L*/1000L+20*TickSpeed.mspt && this.nextTickTime - this.lastOverloadWarning >= /*15000L*/10000L+100*TickSpeed.mspt)
if (long_1 > /*2000L*/1000L+20*mspt && this.nextTickTime - this.lastOverloadWarning >= /*15000L*/10000L+100*mspt)
{
long long_2 = (long)(long_1 / TickSpeed.mspt);//50L;
long long_2 = (long)(long_1 / mspt);//50L;
LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", long_1, long_2);
this.nextTickTime += (long)(long_2 * TickSpeed.mspt);//50L;
this.nextTickTime += (long)(long_2 * mspt);//50L;
this.lastOverloadWarning = this.nextTickTime;
}
@@ -134,9 +151,9 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
//this.startMonitor(tickDurationMonitor);
this.startMetricsRecordingTick();
this.profiler.push("tick");
this.tickServer(TickSpeed.time_warp_start_time != 0 ? ()->true : this::haveTime);
this.tickServer(TickSpeed.gTRM().map(trm -> trm.time_warp_start_time).orElse(0L) != 0 ? ()->true : this::haveTime);
this.profiler.popPush("nextTickWait");
if (TickSpeed.time_warp_start_time != 0) // clearing all hanging tasks no matter what when warping
if (TickSpeed.gTRM().map(trm -> trm.time_warp_start_time).orElse(0L) != 0) // clearing all hanging tasks no matter what when warping
{
while(this.runEveryTask()) {Thread.yield();}
}
@@ -12,6 +12,7 @@ public abstract class PlayerTabOverlayMixin implements PlayerListHudInterface
@Shadow private Component header;
@Override
public boolean hasFooterOrHeader()
{
return footer != null || header != null;
@@ -78,7 +78,7 @@ public abstract class ServerChunkCache_tickMixin
private boolean skipChunkTicking(ServerLevel serverWorld)
{
boolean debug = serverWorld.isDebug();
if (!TickSpeed.process_entities)
if (!TickSpeed.process_entities())
{
// simplified chunk tick iteration assuming world is frozen otherwise as suggested by Hadron67
// to be kept in sync with the original injection source
@@ -16,7 +16,7 @@ public class ServerFunctionManager_tickMixin
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
private void beforeDatapacks(CallbackInfo ci)
{
if (!TickSpeed.process_entities) ci.cancel();
if (!TickSpeed.process_entities()) ci.cancel();
else
currentSection = CarpetProfiler.start_section(null, "Datapacks", CarpetProfiler.TYPE.GENERAL);
}
@@ -159,13 +159,13 @@ public abstract class ServerLevel_tickMixin extends Level
))
private void tickWorldBorder(WorldBorder worldBorder)
{
if (TickSpeed.process_entities) worldBorder.tick();
if (TickSpeed.process_entities()) worldBorder.tick();
}
@Inject(method = "advanceWeatherCycle", cancellable = true, at = @At("HEAD"))
private void tickWeather(CallbackInfo ci)
{
if (!TickSpeed.process_entities) ci.cancel();
if (!TickSpeed.process_entities()) ci.cancel();
}
@Redirect(method = "tick", at = @At(
@@ -174,7 +174,7 @@ public abstract class ServerLevel_tickMixin extends Level
))
private void tickTimeConditionally(ServerLevel serverWorld)
{
if (TickSpeed.process_entities) tickTime();
if (TickSpeed.process_entities()) tickTime();
}
@Redirect(method = "tick", at = @At(
@@ -183,7 +183,7 @@ public abstract class ServerLevel_tickMixin extends Level
))
private boolean tickPendingBlocks(ServerLevel serverWorld)
{
if (!TickSpeed.process_entities) return true;
if (!TickSpeed.process_entities()) return true;
return serverWorld.isDebug(); // isDebug()
}
@@ -193,7 +193,7 @@ public abstract class ServerLevel_tickMixin extends Level
))
private void tickConditionally(Raids raidManager)
{
if (TickSpeed.process_entities) raidManager.tick();
if (TickSpeed.process_entities()) raidManager.tick();
}
@Redirect(method = "tick", at = @At(
@@ -202,6 +202,6 @@ public abstract class ServerLevel_tickMixin extends Level
))
private void tickConditionally(ServerLevel serverWorld)
{
if (TickSpeed.process_entities) runBlockEvents();
if (TickSpeed.process_entities()) runBlockEvents();
}
}
@@ -14,9 +14,9 @@ public class Timer_tickSpeedMixin {
target = "Lnet/minecraft/client/Timer;msPerTick:F"
))
private float adjustTickSpeed(Timer counter) {
if (CarpetSettings.smoothClientAnimations && TickSpeed.process_entities)
if (CarpetSettings.smoothClientAnimations && TickSpeed.process_entitiesClient())
{
return Math.max(50.0f, TickSpeed.mspt);
return Math.max(50.0f, TickSpeed.msptClient());
}
return 50f;
}