The following function is run consecutively:
void MyClass::handleTriggered(float dt)
{
// dt is time interval (period) between current call to this function and previous one
}
dt
is something like 0.0166026
seconds (comes from 60 frames per second).
I intend to do something every 0.25
seconds. Currently I'm using the fact that we are at 60 fps, i.e. function call occurs 60 times each second:
static long int callCount = 0;
++callCount;
// Since we are going with 60 fps, then 15 calls is 1/4 i.e. 0.25 seconds
if (callCount % 15 == 0)
// Do something every 0.25 seconds (every 15 calls)
Now I wonder how I can do it another way, with float
types rather than int
:
static float sumPeriod = 0.0;
// Total time elapsed so far
sumPeriod += dt;
if (/* How to compose the condition? */) {
// Every 0.25 seconds do something
}