The most basic timing facility is the Timer.
Its role is to keep track of the delta time between two updates.
using ddge::time;
auto check_time(Resource<Timer> timer) -> void
{
auto delta = timer->delta();
auto time_of_last_update = timer->current();
}It can also be reset and updated.
using ddge::time;
auto check_time(Resource<Timer> timer) -> void
{
auto last_time = timer->current();
auto current_time = Timer::Clock::now();
// delta gets set to `current_time - last_time`
timer->update(current_time);
// delta gets set to zero
timer->reset(current_time);
}Some systems need to be updated at fixed intervals.
This may be 2 or 60 times a second, or whatever custom time that fits best.
One iteration of a game loop may take from a couple of microseconds to milliseconds, meaning that a fixed system update should be called 0 or more times per iteration.
To measure how many times a system should get called at a given timepoint, it is recommended to use a FixedTimer resource.
FixedTimer is very similar to Timer, but it makes sure that you get the exact number of ticks that happened within the last update.
Because of how common fixed systems are, there is a dedicated scheduling primitive for scheduling fixed updates.
using namespace ddge::measurement::symbols;
namespace sch = ddge::scheduler;
using DisplayTimer = ddge::time::FixedTimer<std::chrono::microseconds, 16'667>;
constexpr auto render =
sch::at_fixed_rate<DisplayTimer>(
sch::start_as(clear_window)
.then(draw)
.then(display)
);|
Warning
|
Don’t nest multiple |