Class TimeManager
Deterministic time manager for multiplayer-ready simulation Uses fixed-point math and tick-based progression to ensure identical behavior across all clients
CRITICAL ARCHITECTURE REQUIREMENTS:
- Fixed-point accumulator (NO float drift)
- Real Earth calendar (365 days, no leap years for determinism)
- Tick counter for command synchronization
- Exact fraction speed multipliers
- NO Time.time dependencies (non-deterministic)
- ICalendar abstraction for custom calendars
See: Assets/Docs/Engine/time-system-architecture.md
public class TimeManager : MonoBehaviour
- Inheritance
-
objectTimeManager
Properties
Calendar
Active calendar for date formatting and validation. Default is StandardCalendar (real Earth calendar, 365 days). GAME layer can provide custom calendars via Initialize().
public ICalendar Calendar { get; }
Property Value
CurrentDay
public int CurrentDay { get; }
Property Value
- int
CurrentHour
public int CurrentHour { get; }
Property Value
- int
CurrentMonth
public int CurrentMonth { get; }
Property Value
- int
CurrentTick
public ulong CurrentTick { get; }
Property Value
- ulong
CurrentYear
public int CurrentYear { get; }
Property Value
- int
GameSpeed
public int GameSpeed { get; }
Property Value
- int
IsInitialized
public bool IsInitialized { get; }
Property Value
- bool
IsPaused
public bool IsPaused { get; }
Property Value
- bool
Methods
CalculateTotalTicks(int, int, int)
Calculate total hours between start date and current game time. Uses proper month lengths via GameTime.ToTotalHours().
public long CalculateTotalTicks(int fromYear, int fromMonth, int fromDay)
Parameters
fromYearintfromMonthintfromDayint
Returns
- long
GetAccumulator()
Get current accumulator value for save/load
public FixedPoint64 GetAccumulator()
Returns
GetCurrentGameTime()
Get current game time as struct
public GameTime GetCurrentGameTime()
Returns
GetCurrentMonthName()
Get the name of the current month from the calendar.
public string GetCurrentMonthName()
Returns
- string
GetFormattedDate()
Get formatted date string using active calendar. Example: "11 November 1444 AD"
public string GetFormattedDate()
Returns
- string
GetFormattedDateCompact()
Get compact formatted date string using active calendar. Example: "11 Nov 1444"
public string GetFormattedDateCompact()
Returns
- string
Initialize(EventBus, ProvinceSystem, ICalendar)
Initialize the time manager with event bus and optional calendar.
public void Initialize(EventBus eventBus, ProvinceSystem provinceSystem = null, ICalendar customCalendar = null)
Parameters
eventBusEventBusEvent bus for time events
provinceSystemProvinceSystemOptional province system for buffer swapping
customCalendarICalendarOptional custom calendar (default: StandardCalendar)
LoadState(ulong, int, int, int, int, int, bool, FixedPoint64)
Load complete TimeManager state from save file Restores all internal state without triggering events
public void LoadState(ulong tick, int newYear, int newMonth, int newDay, int newHour, int speedLevel, bool paused, FixedPoint64 newAccumulator)
Parameters
tickulongnewYearintnewMonthintnewDayintnewHourintspeedLevelintpausedboolnewAccumulatorFixedPoint64
PauseTime()
Pause time progression
public void PauseTime()
SetCurrentTick(ulong)
Set specific tick (for multiplayer synchronization)
public void SetCurrentTick(ulong newTick)
Parameters
newTickulong
SetGameTime(int, int, int, int)
Set specific game date (for loading saves, scenarios)
public void SetGameTime(int newYear, int newMonth, int newDay, int newHour = 0)
Parameters
newYearintnewMonthintnewDayintnewHourint
SetSpeed(int)
Set game speed (0=paused, 1+=speed multiplier)
public void SetSpeed(int multiplier)
Parameters
multiplierint
StartTime()
Start time progression
public void StartTime()
SynchronizeToTick(ulong)
Synchronize to specific tick (for multiplayer) Advances time until we reach the target tick
public void SynchronizeToTick(ulong targetTick)
Parameters
targetTickulong
TogglePause()
Toggle pause state
public void TogglePause()
Events
OnDailyTick
public event Action<int> OnDailyTick
Event Type
- Action<int>
OnHourlyTick
public event Action<int> OnHourlyTick
Event Type
- Action<int>
OnMonthlyTick
public event Action<int> OnMonthlyTick
Event Type
- Action<int>
OnPauseStateChanged
public event Action<bool> OnPauseStateChanged
Event Type
- Action<bool>
OnSpeedChanged
public event Action<int> OnSpeedChanged
Event Type
- Action<int>
OnWeeklyTick
public event Action<int> OnWeeklyTick
Event Type
- Action<int>
OnYearlyTick
public event Action<int> OnYearlyTick
Event Type
- Action<int>