Game Time System - UO-DFM/SimCityOttawa-Documentation GitHub Wiki

Overview

Game time is an integral system in the game used to simulate the passage of time at an accelerated rate to reflect the real experience of working as a physician while also ensuring engaging and meaningful gameplay. Game time runs primarily on an event based design where other game systems can subscribe to events triggered on minute, day, month, etc passed events. Game time is controlled almost entirely in Time Manager.

Important Design Notes

  • Time is based on device clock and not synced with the cloud
  • In game time is paused ever month to allow for rescheduling of work shifts

Game Time Event System

A game event listener can be used to subscribe to game time events in order to execute specific functionality based on the passage of time. Time manager controls the follow events used by other game managers to control the flow of the game:

  • OnMinuteChanged
  • OnDayChanged
  • OnWeekChanged
  • OnMonthChanged
  • OnYearChanged
  • OnTimeJump

Controlling Game Time

Game time can be paused and resumed by other managers to control the passage of time (eg. time paused to complete schedule creation each month). This is done through the following public methods:

  • PauseTime
  • ResumeTime

Real Time to Game Time

Game time is controlled during active gameplay in the update loop. There is a scaling factor used to convert real time into game time. The game will only update the in game time if it has been instantiated and time is not paused. Each update that the game is not paused and is initialized, the delta time is added to a counter. Once this counter exceeds the "seconds to in game minutes" scaling factor, the counter is reset and the game time is advanced by a minute. This ensures a consistent timer across variable frame rates.

Offline Time Calculation

The game save information along with system time are used to calculate the amount of in game time passed while offline. A DateTime variable is recorded when the game is saved to keep track of the real time that the player stopped playing the game. When they resume the game, this value is compared to the current time. The new game time is calculated by multiplying the timespan that the player was offline in seconds by the scaling factor and adding it to the in game time that they quit. If the new date is after the end of the month, the time is instead fast forwarded to the end of that month. When fast forwarding the in game time to any date, a time jump event is raised for other game systems to subscribe to. This allows other systems to update their values according to the amount of time that has passed without raising each individual minute, day, week, etc changed event.