26 lines
437 B
C++
26 lines
437 B
C++
|
#pragma once
|
||
|
#include <chrono>
|
||
|
#include <functional>
|
||
|
|
||
|
class TickSystem {
|
||
|
private:
|
||
|
std::chrono::duration<float> timer{ 0 };
|
||
|
std::chrono::duration<float> tickRate;
|
||
|
|
||
|
public:
|
||
|
TickSystem(std::chrono::duration<float> tickRateSeconds)
|
||
|
: tickRate(tickRateSeconds) {
|
||
|
}
|
||
|
|
||
|
bool update(std::chrono::duration<float> deltaTime) {
|
||
|
timer += deltaTime;
|
||
|
|
||
|
if (timer >= tickRate) {
|
||
|
timer -= tickRate;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
};
|