Skip to content

Commit

Permalink
Update for AsyncWorldTimeComp, some renames
Browse files Browse the repository at this point in the history
Some changes that originally were made for `MultiplayerWorldComp` were properly moved to `AsyncWorldTimeComp`.

Some names were changed to be clearer to what it does or is. `IsPaused` property was renamed to `IsForcePaused`. `TimePauseSlowdownInfo` enum was renamed to `ForcedTickRate`.
  • Loading branch information
SokyranTheDragon committed Aug 26, 2024
1 parent 1665972 commit 322cacb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
16 changes: 10 additions & 6 deletions Source/Client/AsyncTime/AsyncWorldTimeComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ public class AsyncWorldTimeComp : IExposable, ITickable

public float TickRateMultiplier(TimeSpeed speed)
{
if (Multiplayer.GameComp.asyncTime)
{
var enforcePause = Multiplayer.WorldComp.sessionManager.IsAnySessionCurrentlyPausing(null);
if (IsForcePaused)
return 0f;

if (enforcePause)
return 0f;
}
// Could just skip, as it currently can not be true unless a mod makes a Harmony patch.
if (IsForceSlowdown)
return speed == TimeSpeed.Paused ? 0 : 1;

return speed switch
{
Expand All @@ -44,6 +43,11 @@ public float TickRateMultiplier(TimeSpeed speed)
};
}

public bool IsForcePaused => Multiplayer.GameComp.asyncTime &&
Multiplayer.WorldComp.sessionManager.IsAnySessionCurrentlyPausing(null);

public bool IsForceSlowdown => false;

// Run at the speed of the fastest map or at chosen speed if there are no maps
public TimeSpeed DesiredTimeSpeed => !Find.Maps.Any() ?
timeSpeedInt :
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/AsyncTime/ITickable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface ITickable

void ExecuteCmd(ScheduledCommand cmd);

bool IsPaused { get; }
bool IsForcePaused { get; }

bool IsForceSlowdown { get; }
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Client/AsyncTime/TimeControlUI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using HarmonyLib;
Expand Down Expand Up @@ -106,11 +106,11 @@ private static void DoTimeControlsGUI(Rect timerRect)
rect.x += rect.width;
}

ForcedTickRateInfo info = Tickable.GetForcedSpeedInfo();
ForcedTickRate info = Tickable.GetForcedSpeedInfo();

if (info == ForcedTickRateInfo.Paused) // Completely paused
if (info == ForcedTickRate.Paused) // Completely paused
Widgets.DrawLineHorizontal(rect.width, rect.height / 2f, rect.width * 3f);
else if (info == ForcedTickRateInfo.Slowdown) // Slowed down
else if (info == ForcedTickRate.Slowdown) // Slowed down
Widgets.DrawLineHorizontal(rect.width * 2f, rect.height / 2f, rect.width * 2f);

Widgets.EndGroup();
Expand Down
30 changes: 15 additions & 15 deletions Source/Client/Patches/TickPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,37 +288,37 @@ public static float ActualRateMultiplier(this ITickable tickable, TimeSpeed spee
return rate;
}

public static TimePauseSlowdownInfo IsPausedOrSlowedDown(this ITickable tickable)
public static ForcedTickRate GetForcedSpeedInfo(this ITickable tickable)
{
if (Multiplayer.GameComp.asyncTime)
{
if (tickable.IsPaused)
return TimePauseSlowdownInfo.Paused;
if (tickable.IsForcePaused)
return ForcedTickRate.Paused;
if (tickable.IsForceSlowdown)
return TimePauseSlowdownInfo.Slowdown;
return TimePauseSlowdownInfo.Normal;
return ForcedTickRate.Slowdown;
return ForcedTickRate.Normal;
}

if (Multiplayer.WorldComp.IsPaused)
return TimePauseSlowdownInfo.Paused;
if (Multiplayer.AsyncWorldTime.IsForcePaused)
return ForcedTickRate.Paused;

// Could just use false, as it currently can not be force slowed down.
// If we keep this, some mods may potentially use force slowdown on world.
var isForceSlowdown = Multiplayer.WorldComp.IsForceSlowdown;
// Could just use false as default, as it currently can
// not be true unless a mod makes a Harmony patch.
var isForceSlowdown = Multiplayer.AsyncWorldTime.IsForceSlowdown;

foreach (var map in Find.Maps)
{
var comp = map.AsyncTime();

if (comp.IsPaused)
return TimePauseSlowdownInfo.Paused;
if (comp.IsForcePaused)
return ForcedTickRate.Paused;
if (!isForceSlowdown)
isForceSlowdown = comp.IsForceSlowdown;
}

if (isForceSlowdown)
return TimePauseSlowdownInfo.Slowdown;
return TimePauseSlowdownInfo.Normal;
return ForcedTickRate.Slowdown;
return ForcedTickRate.Normal;
}

public static void ClearSimulating()
Expand Down Expand Up @@ -362,5 +362,5 @@ public class SimulatingData
public string simTextKey;
}

public enum TimePauseSlowdownInfo { Normal, Paused, Slowdown, }
public enum ForcedTickRate { Normal, Paused, Slowdown, }
}

0 comments on commit 322cacb

Please sign in to comment.