Skip to content

Commit

Permalink
Moved max simulation time per update from the reproduction system to …
Browse files Browse the repository at this point in the history
…the general world
  • Loading branch information
hhyyrylainen committed Oct 13, 2023
1 parent 19b80ec commit e8a0529
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 6 additions & 8 deletions simulation_parameters/Constants.cs
Expand Up @@ -11,6 +11,12 @@
/// </summary>
public static class Constants
{
/// <summary>
/// Used to prevent lag causing massive simulation instability spikes (due to resource consumption etc. scaling
/// but storage not scaling)
/// </summary>
public const float SIMULATION_MAX_DELTA_TIME = 0.2f;

/// <summary>
/// Default length in seconds for an in-game day. If this is changed, the placeholder values in
/// NewGameSettings.tscn should also be changed.
Expand Down Expand Up @@ -488,11 +494,6 @@ public static class Constants
// TODO: remove if unused with ECS
public const float MICROBE_REPRODUCTION_PROGRESS_INTERVAL = 0.05f;

/// <summary>
/// Used to prevent lag / loading causing big jumps in reproduction progress
/// </summary>
public const float MICROBE_REPRODUCTION_MAX_DELTA_FRAME = 0.2f;

/// <summary>
/// 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.
Expand Down Expand Up @@ -1437,9 +1438,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;

Expand Down
7 changes: 7 additions & 0 deletions src/general/base_stage/WorldSimulation.cs
Expand Up @@ -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();
Expand Down

0 comments on commit e8a0529

Please sign in to comment.