If drawing more than 125 frames per second, process the game every 10 miliseconds (100 frames per second, because that's the minimum amount of time we will be able to get away with); this avoids STK using 100% of the cpu without reason; won't really make a difference when the game is slow.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1808 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
cosmosninja 2008-05-04 00:08:49 +00:00
parent b55af274b5
commit bbb970301c

View File

@ -64,13 +64,26 @@ void GameManager::run()
bool music_on = false;
m_curr_time = SDL_GetTicks();
float dt;
while(!m_abort)
{
inputDriver->input();
m_prev_time = m_curr_time;
m_curr_time = SDL_GetTicks();
float dt = (m_curr_time - m_prev_time ) * 0.001f;
dt = m_curr_time - m_prev_time;
//This avoid wasting CPU cycles
//1000 miliseconds / 125 frames = 125 miliseconds per frame
if( dt < 8.0f)
{
//SDL_Delay has a granularity of 10ms on most platforms, so most
//likely when frames go faster than 125 frames, at times it might
//limit the frames to 100.
SDL_Delay((Uint32)(10));
dt = 10.0f;
}
dt *= 0.001f;
if (!music_on && !race_manager->raceIsActive())
{