In OpenTTD, we have a few different places that uses the concept of date and time.
- Windows has several counters.
The Window timing is one of the first that was changed to work based on real-time, instead of game-time, but with a twist.
The solution for this is created locally in the Window code, by tracking the
delta_msbetween calls toUpdateWindows. But instead of having the rest of the code change to show things in "real-time" values, the rest of the code still uses "ticks". Just the Window code makes sure that a tick is alwaysMILLISECONDS_PER_TICK, no matter if you fast-forward or not. There are six counter-like things in total:scroller-click: rate-limits how fast you can scroll; not influenced by fast-forward.OnHundredthTickcallback: meant to be called every 3 seconds for various of jobs in a Window (like refreshing the list); not influenced by fast-forward.OnTimeoutcallback: called when a timeout expires, which can be set per window; not influenced by fast-forward.OnRealtimeTickcallback: called with the millisecond delta from last call.OnGameTickcallback: called every game tick.highlight_timer: defines how long something is highlighted, in real-time.
- Network has several counters too, a bit all of the place.
- Chat has
remove_time, which is a real-time value (std::chrono) for when to remove / not show a chat message. ServerNetworkAdminSocketHandleruses real-time (std::chrono) to detect some timeouts (like authorization-took-too-long)ClientNetworkGameSocketHandleruses real-time (std::chrono) to detect timeouts during connecting (recent change, as it used to be game-time based too.ClientNetworkCoordinatorSocketHandleruses real-time (std::chrono) to detect timeouts during connecting.- Refresh of the server-listing is triggered by
OnRealtimeTick, so real-time, but with a twist! NetworkServer_Tickchecks if a client is lagging, based on_frame_counter, which is basically game-time but can't be paused. The lag detection is everything from "client downloading map" to actually playing the game. Some parts however do use real-time. So it is a mixed bag of different types of lag-detection.
- Chat has
- Bankrupt "do you want to take over" question (
HandleBankruptcyTakeover) is game-time based, set for 90 days. - Linkgraph is based on game-time.
- AI logic when to create a new company is based on game-time.
- Draw logic has its own way of dealing with time (as it runs on 60Hz, for example), and is uncoupled from game-time.
- Music on Windows (via DMusic) does its own thing too.
- Autosave is based on game-time.
- We have the intend to split up game-time in calendar-time and economy-time.
- These include things like Monthly callbacks, etc.
Anything not mentioned above explicitly, is in game-time of course.