timestep = scalar(ts);
long maxfps = 40;
- config.get("engine.maxfps", maxfps);
+ config.getNumber("video.maxfps", maxfps);
drawrate = 1.0 / scalar(maxfps);
printfps = false;
- config.get("engine.printfps", printfps);
+ config.get("video.printfps", printfps);
}
~engine_impl()
}
+ /**
+ * The main loop. This just calls dispatchEvents(), update(), and draw()
+ * over and over again. The timing of the update and draw are decoupled.
+ * The actual frame rate is also calculated here. This function will return
+ * with a value of 0 if the member variable running becomes true.
+ */
+
int run()
{
scalar ticksNow = ticks();
scalar nextFPSUpdate = ticksNow + 1.0;
scalar totalTime = 0.0;
+ scalar deltaTime = 0.0;
scalar accumulator = timestep;
fps = 0;
running = true;
do
{
- dispatchEvents();
-
scalar newTicks = ticks();
- accumulator += newTicks - ticksNow;
+ deltaTime = newTicks - ticksNow;
ticksNow = newTicks;
- if (accumulator >= timestep)
+ if (deltaTime >= 0.25) deltaTime = 0.25;
+ accumulator += deltaTime;
+
+ while (accumulator >= timestep)
{
+ dispatchEvents();
interface->update(totalTime, timestep);
totalTime += timestep;
accumulator -= timestep;
nextStep += timestep;
- if (ticksNow >= nextStep)
- {
- // we missed some scheduled steps, so reset the schedule
- nextStep = ticksNow + timestep;
- accumulator = 0.0;
- }
}
if (ticksNow >= nextDraw)