Squid::Tasks 1.0.0
C++14 coroutine-based task library for games
|
Time-stream functionality for time-sensitive awaiters. More...
Time-stream functionality for time-sensitive awaiters.
Every game project has its own method of updating and measuring game time. Most games feature multiple different "time-streams", such as "game time", "real time", "editor time", "paused time", "audio time", etc... Because of this, the Squid::Tasks library requires each time-sensitive awaiter (e.g. WaitSeconds()
, Timeout()
, etc) to be presented with a time-stream function that returns the current time in the desired time-stream. By convention, these time-streams are passed as functions into the final argument of time-sensitive awaiters.
For less-complex projects it can be desirable to default to a "global time-stream" that removes the requirement to explicitly pass a time-stream function into time-sensitive awaiters. To enable this functionality, the user must set SQUID_ENABLE_GLOBAL_TIME
in TasksConfig.h and implement a special function called Squid::GetTime(). Failure to define this function will result in a linker error.
The Squid::GetTime() function should return a floating-point value representing the number of seconds since the program started running. Here is an example Squid::GetTime() function implementation from within the main.cpp
file of a sample project:
It is recommended to save off the current time value at the start of each game frame, returning that saved value from within Squid::GetTime()
. The reason for this is that, within a single frame, you likely want all of the tasks to behave as if they are updating at the same time. By providing the same exact time value to all Tasks that are resumed within a given update, the software is more likely to behave in a stable and predictable manner.