I am implementing a game engine and am implementing two version of time:
- Real time
- Scaled time (for slow / fast motion effects)
Real time fully implemented and works, but I am having serious concerns with scaled time. The issue is <chrono>
header file specific. I wanted to store an std::chrono::duration<std::chrono::nanoseconds>
, but I am not sure if I do so if games built on the game engine if ran for long enough the scaled time would overflow causing chaos.
The question came when I tried to store the following:
scaledPhysicsTime
scaledPhysicsDeltaTime
For scaledPhysicsDeltaTime
I would get the real time physics delta time as a double
, multiply it by the time scale (multiplier for slow / fast motion effects) and convert the result to std::chrono::nanoseconds
. Then, the scaledPhysicsDeltaTime
I would add to scaledPhysicsTime
. Does anyone think there is a better way? Every time I begin to code it I feel like I am going about this the hard way.
Note: I am thinking of storing the time as nanoseconds
because it would store time resolution better than milliseconds
or double
. Then the user / programmer could decide which data type to request from the class.
Am I going about this the right or wrong way? Any type of insight in other directions are welcomed and thanks to everyone in advanced.