void GameLoop::Run() { _isRunning = true; Timer timer; micro_seconds current = timer.ElapsedMicroSeconds(); micro_seconds accumulator = current; while (_isRunning) { current = timer.ElapsedMicroSeconds(); for ( int updateNumber = 0; updateNumber < MAX_CONSECUTIVE_UPDATES && accumulator < current; ++updateNumber) { accumulator += _updateDelay; InnerUpdate(_updateDelay); } // If the system is running too slow for the update to run at a consistent pace // then we need to resync the accumulator past the current time so that we can // calculate an interpolated value for the next draw call. if (accumulator < current) { micro_seconds diff = current - accumulator; micro_seconds updatesMissed = diff / _updateDelay + 1; accumulator += updatesMissed * _updateDelay; } auto interpolation = 1.0 - (double(accumulator - current) / double(_updateDelay)); InnerDraw(interpolation); } // TODO win32 system exit code //return static_cast<int>(exitCode); }