fixed framerate, how?

Hi,
i was wondering what should be a good way for fixing the frames per second to the desired framerate (?)

tks!
c

You can, of course, slow down the frame rate to a desired constant fps. You would do this by putting:

clock-mode limited
clock-frame-rate 20

or whatever fps you wanted, in your Config.prc. There are lots of good reasons for running at a constant frame rate, rather than at Pandaā€™s default, which is to run as fast as it can go.

This wonā€™t work to make your frame rate faster, though; for instance, putting ā€œclock-frame-rate 100ā€ wonā€™t make your game suddenly run at 100 fps. If you want to improve your frame rate, you have to optimize your code to do less work per frame.

David

1 Like

of course, the panda still cannot do miracles :slight_smile:
thatā€™s exactly the config commands i was looking for, thanks a lot!
c

Not exactly on topic but hopefully someone watching this thread can help me.

Iā€™m fine with Panda3D grabbing lots of CPU when the scene is actually changing. In many of my applications (visualizations rather than games) the scene will be static most of the time, with most changes being due to the user navigating the scene with the mouse.

What seems to make sense to me is to increase the max frame rate while the mouse navigation is occurring, but then to drop down to some low frame rate otherwise. Is this something that can be done? All of the frame rate stuff Iā€™ve seen mentioned involves the Config.prc which suggests to me that it can only be set once at startup.

actually in that case you donā€™t use run, but a just call each frame when you want to render it (based off mouse move or window redraw events).
When window updates just call

taskMgr.step()

Ok, thanks Iā€™ll give that a try. Will I need to implement all the mouse navigation stuff myself though?

Actually, I have a better idea. Why not create a task that calculates how much the mouse has moved, then calls time.sleep(t) where t is, say, 0.04 if the mouse hasnā€™t moved, and 0 when the mouse moves.

another method i cant think of is add some sleep time inbetween the tasks.
I think its base.setSleep(.1) for sleeping 1/10 of a second. Or you can to call time.sleep(.1) yourself when there is no events.

Making calls to sleep is a simple and easy way to slow down your applicationā€™s use of CPU, though it doesnā€™t tend to result in a very steady frame rate.

You can also change the clock frame rate at runtime. Just use globalClock.setFrameRate(). To put it in limited mode, either use clock-mode limited in your Config.prc file as described above, or at runtime use globalClock.setMode(ClockObject.MLimited).

David

@drwr: Thanks, I gave that a try and it does work, though with a bit of a quirk, at first. The CPU utilization when not navigating the scene is indeed reduced (how much itā€™s reduced depends on how low I force the frame rate to be). The problem initially was that now Panda would only give me mouse events every 1/5th of a second, and this resulted in jerkyness when the user starts to do mouse navigation.

But what I ended up doing and works pretty well is this:

First, set up a task every frame that does this:

  • when the mouse is outside the window (base.mouseWatcherNode.hasMouse() returns false), set the FPS very low, e.g. 1 FPS, and also disable mouse navigation (base.disableMouse())
  • when the mouse is inside the window, set the FPS to a ā€˜mediumā€™ value (e.g. 30 FPS), and re-enable mouse navigation.

Also, set up mouse event response as follows:

  • on mouse down, set the FPS very high (e.g. 1000) for best speed of interactive mouse navigation
  • on mouse up, set the FPS back to the ā€˜mediumā€™ value (i.e. 30 FPS).

Just to give a very unscientific idea of performance:

FPS = 1 (mouse outside 3D window): CPU usage ~ 7%
FPS = 30 (mouse inside 3D window): CPU usage ~ 61%
FPS = 1000 (navigating with mouse): CPU usage ~ 86%*

  • actually 100% of ā€˜availableā€™ CPU; if I add the next couple of tasks listed by ā€˜topā€™ itā€™s close to 100%.

Thanks to all for the help and ideas.

iā€™ve just found out, that setting the clock-mode and clock-frame-rate as mentioned by drwr doesnā€™t work when set as described here. setting the same through config file works fine

pro-rsoft gave me this and it works just fine for changing a running programā€™s framerate:

from pandac.PandaModules import ClockObject
FPS = 30
globalClock = ClockObject.getGlobalClock()
globalClock.setMode(ClockObject.MLimited)
globalClock.setFrameRate(FPS)

cheers

1 Like