Limiting The FPS

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Unforgivable.Course
Posts: 46
Joined: Tue Feb 07, 2006 6:28 pm

Limiting The FPS

Post by Unforgivable.Course »

hi

i'm here again with a new problem !!
i'm sure that you know all games FPS(frame per second) must be limited for executing games in every graphical card with a constant speed . how can i do it in irrlicht ?? i found getFPS() function but isn't there any other function for limiting the FPS .

Help me please . thanks
Get Ready For an Amazing Journey Into the World of Game Development
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

this isn't a new, or an advanced help question.
you can use Sleep() from windows.h if you want to limit the fps, but what happens if your pc can't manage 60fps? you want your simulation to be the same no matter how many frames per-sec you're getting-
http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=68133

i'm moving this multi-dupe newbie question to beginners help
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
stef_
Posts: 53
Joined: Tue Apr 18, 2006 9:39 pm
Contact:

Post by stef_ »

recording to me the simplest way for having the same framerate on all pc is
to sleep (period_ms - elapsed_ms), and period_ms is your fixed time for each loop.

There is a good example in this post:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=42343

I put the code here because it's very clean.

Code: Select all

   void run()
   {
      u32 start, end, elapsed, frame = 10; // 10 millisec per frame = 100 hz

      while(videoDevice->run())
      {
         start = videoDevice->getTimer()->getTime();

         videoDriver->beginScene(true, true, video::SColor(0,87,133,157));

         sceneManager->drawAll();

         gameController->onRenderFrame();

         videoDriver->endScene();
      
         end = videoDevice->getTimer()->getTime();
         elapsed = end-start;

         if(elapsed < frame)
         {
            #ifdef LINUX
            usleep(1000* (frame - elapsed));
            #endif
            #ifdef WINDOWS
            Sleep(frame - elapsed);
            #endif
         }

      }

      videoDevice->drop();
   } 
Unforgivable.Course
Posts: 46
Joined: Tue Feb 07, 2006 6:28 pm

Post by Unforgivable.Course »

thanks guys , it's very useful for me .
Get Ready For an Amazing Journey Into the World of Game Development
pwierz
Posts: 59
Joined: Sun Aug 20, 2006 3:32 pm

Post by pwierz »

Has anyone had any difficulty with the above posted method? I need to limit my framerate to 60Hz. But in the code timer->getTime() only seems to increment by 2ms. So I can only get my frame rate to 55Hz or 62Hz. Any suggestions? Is there a higher fidelity timer? (I'm on a 2.4GHz machine, so it's not a slow clock problem)
Warchief
Posts: 204
Joined: Tue Nov 22, 2005 10:58 am

Post by Warchief »

Well, once again, take a look at

Main Loop with Fixed Time Steps, by Javier Arevalo:
http://www.iguanademos.com/Jare/Article ... ew=FixLoop
Post Reply