change frame rate

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.
charles88
Posts: 29
Joined: Tue Nov 04, 2008 10:02 am

change frame rate

Post by charles88 »

Could anyone help me on how to change frame rate (FPS) please? I want to draw my scene for every 30 frames but do not know how to do. :)

Your help is highly appreciated, thank you.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

First off, why? Why would you only want to draw it every 30 frames? I only ask because... well it might not be sensible :lol:

Anyway basically before each time you render you can just check if the necessary amount of time has gone by using the ITimer (device->getTimer())
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

If you try to do this, then you have two choices:

1) Sit in a tight loop checking the time constantly. This will eat 100% of your CPU (or 100% of one core), so it's almost certainly pointless; you might as well be rendering rather than doing nothing except checking the time.

2) sleep() / Sleep() for a bit, or halt on a timer. Unfortunately, that will only guarantee that your main thread isn't woken for at least the specified time. In practice, you will have to sleep for much less time than you really need, then sit in a tight loop again. Even then, you might get a very long sleep, and miss a frame.

Trying to maintain any particular framerate is generally a bad idea, and should be avoided unless there's a very specific reason why you need to do it.

If you tell us why you want to do this, then perhaps we can suggest a better method.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Option 3: Turn on vsync, which will probably get you 30 or 60 FPS, depending on how fast the game can draw. (Although this does depend on how fast your monitor can refresh and is kinda moot on LCD monitors, the implementations I've seen usually cap at 30 or 60).
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

Look at the way some physics engines calculate the next frame based on specific intervals (FPS). Basically, you need to determine how many 'cpu' ticks it takes to render at say 30FPS. Then watch that number in the render loop, decrementing it every pass, keep waiting until that number goes down to zero.
Image
charles88
Posts: 29
Joined: Tue Nov 04, 2008 10:02 am

Post by charles88 »

Hi guys,

first of all thanks for all your suggestion. The reason why I want to control the frame rate is because right now I am doing some collision dectection between my model and the wall. Although my model doesn't pass through the wall, there are flickers when my model collide with it. My friend said the flickers are caused by the scene manager try to draw everything at a very high frame rate, thus suggesting me to control the frame rate in order to eliminate those flickers.

I have been looking for answer for quite some time, but still can't get it. :(
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Post by twilight17 »

Use vsync
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

charles88 wrote:Although my model doesn't pass through the wall, there are flickers when my model collide with it.
this also could be caused by node culling or too long near clipping plane of the camera...
so try to disable culling and use setNearValue() on the camera to set a smaller clipping plane... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

twilight17 wrote:Use vsync
Seconded. It's a parameter to createDevice().
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
charles88
Posts: 29
Joined: Tue Nov 04, 2008 10:02 am

Post by charles88 »

Well, can you provide me with a sample code for doing the vsync? thank you.
charles88
Posts: 29
Joined: Tue Nov 04, 2008 10:02 am

Post by charles88 »

so try to disable culling and use setNearValue() on the camera to set a smaller clipping plane...
Already tried but the flickers are still there. :(

Edit:

Anyway is this the correct code to disable culling and setNearValue()? :P sorry was not quite familiar with irrlicht. :)

Code: Select all

node->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
cam->setNearValue(10f);
Last edited by charles88 on Wed Nov 05, 2008 4:01 am, edited 1 time in total.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Uh... it's a parameter to createDevice()?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
charles88
Posts: 29
Joined: Tue Nov 04, 2008 10:02 am

Post by charles88 »

Oh, thank you rogerborg, sorry didn't notice it. :( I think I'm a complete idiot... sigh...

But it's still not working, the FPS is 60. :(

I think I will try to use multimedia timer.
charles88
Posts: 29
Joined: Tue Nov 04, 2008 10:02 am

Post by charles88 »

I've noticed the flickers reduce, is it possible to set it to smaller value? I mean 20 FPS? If so, how to do that? thanks. :)
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

what if u create a loop and check if time elapsed is XXX millisecond b4 render?

e.g.

Code: Select all

time = getsystemtimeinmillis
do {
  now = getsystemtimeinmillis
  if (now-time>33) {
    render()
    time = now
  }
} while (XXX)
use 33 millisecond for 30fps and 50millisecond for 20fps?
Post Reply