clocker: minor simplification
This commit is contained in:
parent
1490334f87
commit
71c7ac8bb9
@ -82,14 +82,14 @@ class Clocker {
|
|||||||
Clocker(std::chrono::milliseconds period): period(period) {};
|
Clocker(std::chrono::milliseconds period): period(period) {};
|
||||||
void tick() {
|
void tick() {
|
||||||
if(next_tick == std::chrono::time_point<std::chrono::steady_clock>::min()) {
|
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 {
|
} else {
|
||||||
|
next_tick += period;
|
||||||
auto duration = next_tick - std::chrono::steady_clock::now();
|
auto duration = next_tick - std::chrono::steady_clock::now();
|
||||||
if(duration >= duration.zero())
|
if(duration >= duration.zero())
|
||||||
std::this_thread::sleep_for(duration);
|
std::this_thread::sleep_for(duration);
|
||||||
else
|
else
|
||||||
std::cerr << "missed tick" << std::endl;
|
std::cerr << "missed tick" << std::endl;
|
||||||
next_tick += period;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user