Update frequency in standardgame

I wonder how you set update frequency in standardgame. I timed it and my update() gets called aprox. every 16ms second

even if the game is just a black screen (doing nothing). I'd prefer that

my update was called as soon as possible since waiting 16ms makes the game pretty slow when that 16 ms could have been used to do something useful.

Also how do you increase the framerate to more than 60 ?

You can set the desired Framerate with getSettings() before start() is called.



StandardGame game;
game.getSettings().setFramerate(-1);
game.getSettings().setVerticalSync(true);

Thanks, just tried it and it made no difference.

Hmm suddenly it worked…thanks.

Baune said:

I wonder how you set update frequency in standardgame. I timed it and my update() gets called aprox. every 16ms second
even if the game is just a black screen (doing nothing).


Lies, all lies. :)  You must realize that the precision of System.currentTimeMillis() is only precise to 16ms on most operating systems.  If you want to test something like update performance you have to use System.nanoTime() to get any level of accuracy. Essentially, the results you're getting are in-precise up to 16ms, which is why you're getting 16ms on some updates and probably 0ms on others?

Well that might be true but after I set to -1 bla bla i get udpate time 0-4…and the game is much faster.



Is there a way to fix the render time at 60 and the update to fastest possible ?

But if thats the case I'll switch my timer to the jmonkey one.

If you setFrameRate(-1) and setVerticalSync(false) it should do updates the same way that SimpleGame does.

darkfrog said:

If you setFrameRate(-1) and setVerticalSync(false) it should do updates the same way that SimpleGame does.

It seems there's no way to avoid a pause of 5-15 ms in between calls to update (5 if I set framerate to -1, 8-15 if I set it to ex, 60).

Is there something pausing the loop somewhere ? and in case why ? I'd say a pause of 5-15 ms is an incredible long pause which could be spent in the physics engine etc.

Maybe I'm just misunderstanding something, it happens :)

This has been mentioned before, and to appease those that might question the performance of StandardGame I've just committed a new feature to make it work like SimpleGame.



Now, if you update from the repository and set the static flag:


StandardGame.THREAD_FRIENDLY = false;



It will disable the Thread.yield() that it does in the update loop. The yield is there currently to allow other threads to get some CPU time in if needed rather than being a hungry thread like SimpleGame and taking every bit of CPU to go as fast as is possible. That should give you the FPS you want, but it will sacrifice performance in all other threads.

Post you code snippet and I'll take a look.



I'm not saying yield is for OTHER processes, but rather other threads. StandardGame is primarily designed (but not limited) to be used in multi-threaded applications.  For example, if you have physics, AI, networking, etc. all running different threads the yield allows them some CPU time to do their work rather than potentially starving them their processor time.

Just one question about using

game.getSettings().setFramerate(x);

, is it normal that this setting is residual when I remove this line of code and even if I restart my computer and run the game ?

yep, the settings are set and saved in your Registry (if your in Windows)

Yield is not reliable across VM implementations and OS's. Something to double check on