clocker: minor simplification

This commit is contained in:
Sébastien Bourdeauducq 2025-01-19 18:23:09 +08:00
parent 1490334f87
commit 71c7ac8bb9

View File

@ -82,14 +82,14 @@ class Clocker {
Clocker(std::chrono::milliseconds period): period(period) {};
void tick() {
if(next_tick == std::chrono::time_point<std::chrono::steady_clock>::min()) {
next_tick = std::chrono::steady_clock::now() + period;
next_tick = std::chrono::steady_clock::now();
} else {
next_tick += period;
auto duration = next_tick - std::chrono::steady_clock::now();
if(duration >= duration.zero())
std::this_thread::sleep_for(duration);
else
std::cerr << "missed tick" << std::endl;
next_tick += period;
}
}
};