X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fengine.cc;h=7284799343a1f144d136ac65705f94c0ff54ad67;hp=ec6faa15e9d0505c027c659aa2867ae62eb263ba;hb=838bc00015eb7f583c7cf4b3b1007697bf047da1;hpb=3e195be39157284a7f05b23a8a635adf26c10ee4 diff --git a/src/engine.cc b/src/engine.cc index ec6faa1..7284799 100644 --- a/src/engine.cc +++ b/src/engine.cc @@ -75,11 +75,11 @@ public: 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() @@ -92,6 +92,13 @@ public: } + /** + * 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(); @@ -101,6 +108,7 @@ public: scalar nextFPSUpdate = ticksNow + 1.0; scalar totalTime = 0.0; + scalar deltaTime = 0.0; scalar accumulator = timestep; fps = 0; @@ -109,26 +117,22 @@ public: 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)