9#ifndef AVARA3D_UTIL_PERIODICTRIGGER_H
10#define AVARA3D_UTIL_PERIODICTRIGGER_H
39 explicit PeriodicTrigger(std::chrono::duration<double> interval,
bool deferFirstFire =
false);
50 template<
typename Function>
51 std::size_t
update(
double time, Function&& function) {
53 const auto count = dueCount(time);
55 for (std::size_t i = 0; i < count; ++i) {
56 std::invoke(function);
68 std::
size_t dueCount(
double time);
74 std::optional<
double> _nextFireTime;
75 std::optional<
double> _lastTime;
Invokes a callback at fixed intervals along a caller-supplied time line.
void reset() noexcept
Clears timing history so the next update establishes a new schedule.
std::size_t update(double time, Function &&function)
Advances the trigger to time and invokes function once for each due firing.
PeriodicTrigger(std::chrono::duration< double > interval, bool deferFirstFire=false)
Creates a trigger with interval between firings.