diff --git a/simulation_parameters/Constants.cs b/simulation_parameters/Constants.cs index 6d7de7f1b1d..f007ca1fde7 100644 --- a/simulation_parameters/Constants.cs +++ b/simulation_parameters/Constants.cs @@ -11,6 +11,12 @@ /// public static class Constants { + /// + /// Used to prevent lag causing massive simulation instability spikes (due to resource consumption etc. scaling + /// but storage not scaling) + /// + public const float SIMULATION_MAX_DELTA_TIME = 0.2f; + /// /// Default length in seconds for an in-game day. If this is changed, the placeholder values in /// NewGameSettings.tscn should also be changed. @@ -488,11 +494,6 @@ public static class Constants // TODO: remove if unused with ECS public const float MICROBE_REPRODUCTION_PROGRESS_INTERVAL = 0.05f; - /// - /// Used to prevent lag / loading causing big jumps in reproduction progress - /// - public const float MICROBE_REPRODUCTION_MAX_DELTA_FRAME = 0.2f; - /// /// Because reproduction progress is most often time limited, /// the bars can go to the reproduction ready state way too early, so this being false prevents that. @@ -1456,9 +1457,6 @@ public static class Constants private const uint FreeCompoundAmountIsLessThanUsePerSecond = (MICROBE_REPRODUCTION_FREE_COMPOUNDS < MICROBE_REPRODUCTION_MAX_COMPOUND_USE) ? 0 : -42; - private const uint ReproductionProgressIntervalLessThanMaxDelta = - (MICROBE_REPRODUCTION_PROGRESS_INTERVAL < MICROBE_REPRODUCTION_MAX_DELTA_FRAME) ? 0 : -42; - private const uint ReproductionTutorialDelaysAreSensible = (MICROBE_REPRODUCTION_TUTORIAL_DELAY + 1 < MICROBE_EDITOR_BUTTON_TUTORIAL_DELAY) ? 0 : -42; diff --git a/src/general/base_stage/WorldSimulation.cs b/src/general/base_stage/WorldSimulation.cs index 1d6cb18f0f8..53f1a23a665 100644 --- a/src/general/base_stage/WorldSimulation.cs +++ b/src/general/base_stage/WorldSimulation.cs @@ -99,6 +99,13 @@ public virtual void ProcessLogic(float delta) if (accumulatedLogicTime < minimumTimeBetweenLogicUpdates) return; + if (accumulatedLogicTime > Constants.SIMULATION_MAX_DELTA_TIME) + { + // Prevent lag spikes from messing with game logic too bad. The downside here is that at extremely low + // framerate the game will run in slow motion + accumulatedLogicTime = Constants.SIMULATION_MAX_DELTA_TIME; + } + Processing = true; OnCheckPhysicsBeforeProcessStart();