   Problems with framerate
  Been developing my game on a subpar laptop, but when I recently moved on to development on my quad core stationary, I noticed some REALLY bad shit... EVERYTHING was running at super-duper-mega-speed!Now, I have never done framerate stuff before, so I am in dire help.Here is what I do now:double t = GetSysTime();_frameTime = (t - _systemTime);_systemTime = t;And then I use _frameTime in all my drawing/updating to move things based on time.I don't really know how to fix this problem... so any help it greatly appreciated.   
  GetSysTime, I believe, returns a structure, not a double float value.What API are you using?   ;http://dewitters.koonsolo.com/gameloop.htmlthis might help.   ;  When I create a game, my GameTick function (which is called every frame) computers the time between this GameTick and the prevous GameTick. so newTime-oldTime.That's called the dt (delta time or time difference).After that, when for example, a character moves, I use x += character_speed * dt.This way the character always moves the same speed.Hope this helps,-Tigran   ;Quote:Original post by BuckeyeGetSysTime, I believe, returns a structure, not a double float value.What API are you using?Sorry, I have my own GetSysTime() function that basically calls GetTickCount() and casts the result to a double.   ;Quote:Original post by szecshttp://dewitters.koonsolo.com/gameloop.htmlthis might help.None of these produced any more positive results :(The problem is definitely due to the fact that my game loop is called X more times on this quad core computer than on my dual core laptop.My game loop looks like this:// Render scene_renderer->BeginScene();if (_activeState){CLARITY_SAFE_CALL(_activeState->GetScene()->GetCamera(), Look);_activeState->OnDraw(_frameTime);// Render UI_renderer->SetOrthoProjection();CLARITY_SAFE_CALL_ARG(_activeState->GetUI(), Draw, _frameTime);}_renderer->PresentScene();// Updatesif (_activeState){_activeState->OnInput(_input);_activeState->OnUpdate(_frameTime);CLARITY_SAFE_CALL_ARG(_activeState->GetScene()->GetCamera(), Update, _frameTime);if (_activeState->GetEvent()){HandleEvent(*(_activeState->GetEvent()));_activeState->ClearEvent();}};Quote:Original post by TigranAfter that, when for example, a character moves, I use x += character_speed * dt.This way the character always moves the same speed.Not exactly.  Your simulation depends on the size of dt.  What if your system hiccups and you get a dt of two seconds?  This'll probably place a player past a wall he should have collided with.  See fix your timestep.Quote:Original post by EldritchThe problem is definitely due to the fact that my game loop is called X more times on this quad core computer than on my dual core laptop.In that case, you'll need to regulate how many times your game is updated.  Why not update in fixed steps of 1/60th of a second?   ;Quote:Original post by _fastcallQuote:Original post by EldritchThe problem is definitely due to the fact that my game loop is called X more times on this quad core computer than on my dual core laptop.In that case, you'll need to regulate how many times your game is updated.  Why not update in fixed steps of 1/60th of a second?That sounds like something I'd want, but how would I do it? Looking at the code I posted above (my game loop), how would I make it work within those steps?   ;Quote:Original post by EldritchThat sounds like something I'd want, but how would I do it? Looking at the code I posted above (my game loop), how would I make it work within those steps?Here's a sample of what it could look like:double currentTime = getTime();double previousTime = 0;double accumulator = 0;double dt = 1 / 60.0;while ( isRunning ) {previousTime = currentTime;currentTime = getTime();double elapsed = currentTime - previousTime;for ( accumulator += elapsed; accumulator >= dt; accumulator -= dt ) {input();update( dt );}render( /* accumulator/dt */ ); // interpolation optional}Side note:  If you minimize your game and come back to it a few minutes later, elapsed/dt will be a very large number and you may notice a freeze as your simulation tries to catch up the lost time, so you might want to check for excessive elapses:if ( elapsed > maxUpdates * dt ) // If we need to do more than "maxUpdates" steps in simulationelapsed = fmod( elapsed, dt ); // Then only do one step this framefor ( accumulator += elapsed; accumulator >= dt; accumulator -= dt ) {input();update( dt );}Also note that the deWiTTERS article warns against using a floating type values to store the accumulator, as it is prone to accumulation of error.[Edited by - _fastcall on May 16, 2010 4:36:45 PM];Quote:Original post by _fastcallQuote:Original post by TigranAfter that, when for example, a character moves, I use x += character_speed * dt.This way the character always moves the same speed.Not exactly.  Your simulation depends on the size of dt.  What if your system hiccups and you get a dt of two seconds?  This'll probably place a player past a wall he should have collided with.  See fix your timestep.Thanks man, good article.