Squid::Tasks 1.0.0
C++14 coroutine-based task library for games
Time Streams

Time-stream functionality for time-sensitive awaiters. More...

Functions

template<typename tTimeFn >
tTaskTime GetTimeSince (tTaskTime in_t, tTimeFn in_timeFn)
 Helper function to elapsed time in a given time-stream.
 
tTaskTime GetGlobalTime ()
 User-defined global time-stream function (must be implemented if SQUID_ENABLE_GLOBAL_TIME is set, otherwise there will be a linker error)
 
auto GlobalTime ()
 Global time-stream function used internally by Squid::Tasks (requires SQUID_ENABLE_GLOBAL_TIME)
 
tTaskTime GetTimeSince (tTaskTime in_t)
 Helper function to elapsed time in the global time-stream (requires SQUID_ENABLE_GLOBAL_TIME)
 

Detailed Description

Time-stream functionality for time-sensitive awaiters.

Time-Streams

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.

Enabling Global Time Support

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:

NAMESPACE_SQUID_BEGIN
tTaskTime GetTime()
{
return (tTaskTime)TimeSystem::GetTime();
}
NAMESPACE_SQUID_END

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.