X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FCore.cc;h=b659f9890784c2c66cdc867b91671914d0f5260c;hp=b9ad92a63a8e29e8c7f59e1e6cc310a03bca5b36;hb=76b3f4be992514a740ac03cdbdd57844142a0b4c;hpb=b714ba98cb92a1be42acba91d44fe5bfb0783a3b diff --git a/src/Moof/Core.cc b/src/Moof/Core.cc index b9ad92a..b659f98 100644 --- a/src/Moof/Core.cc +++ b/src/Moof/Core.cc @@ -70,6 +70,7 @@ public: void run() { init(); + ASSERT(video && "cannot run core without a current video context"); Scalar totalTime = 0.0; Scalar ticks = Timer::getTicks(); @@ -79,49 +80,50 @@ public: Scalar nextSecond = ticks + SCALAR(1.0); mFps = 0; - int frames = 0; + int frameCount = 0; - const int MAX_FRAMESKIP = 15; - const Scalar inverseTimestep = SCALAR(1.0) / mTimestep; + const Scalar timestep = mTimestep; + const Scalar framerate = mFramerate; - ASSERT(video && "cannot run core without a current video context"); + const int MAX_FRAMESKIP = 15; + const Scalar inverseTimestep = SCALAR(1.0) / timestep; do { - Timer::fireIfExpired(); - dispatchEvents(); + Timer::fireIfExpired(); // 1. fire timers + dispatchEvents(); // 2. dispatch events int i = 0; while (nextUpdate < Timer::getTicks() && i < MAX_FRAMESKIP) { - totalTime += mTimestep; - update(totalTime, mTimestep); + totalTime += timestep; + update(totalTime, timestep); // 3. update state - nextUpdate += mTimestep; + nextUpdate += timestep; ++i; } if (nextDraw < (ticks = Timer::getTicks())) { - ++frames; - draw((ticks + mTimestep - nextUpdate) * inverseTimestep); - video->swap(); + draw((ticks + timestep - nextUpdate) * inverseTimestep); + video->swap(); // 4. draw state - nextDraw += mFramerate; + nextDraw += framerate; + ++frameCount; - if (mShowFps && nextSecond < ticks) + if (nextSecond < Timer::getTicks()) { - mFps = frames; - frames = 0; + mFps = frameCount; + frameCount = 0; - logInfo << mFps << " fps" << std::endl; + if (mShowFps) logInfo << mFps << " fps" << std::endl; nextSecond += SCALAR(1.0); } } - // be a good citizen and give back what you don't need - Timer::sleep(0.0); + ticks = Timer::getTicks(); // 5. yield timeslice + if (ticks < nextUpdate && ticks < nextDraw) Timer::sleep(0.0); } while (!mStack.empty());