Author Topic: Frame rate issue  (Read 5115 times)

Offline dectar

  • byte
  • *
  • Posts: 21
    • View Profile
Frame rate issue
« on: March 03, 2011, 12:31:17 am »
Hi,

Im currently working on a simple game to try to get familiar with jpct-ae but Im having a problem with my frame rate.
It generally runs at about 55-60 frames a second but every now and then it drops to 35-40 and I can see in the logs that its being caused by java doing a garbage collection (which seems to be forced upon me). 35-40 frames a second would be sufficient for the whole game but when it goes up and down randomly it feels very glitchy - the user would definitely see the slowdown for the moments when it drops.

So does anybody know of any way to make this smoother? Perhaps a way to limit the number of frames per second to 40? Or is there a better way to control speed? At the moment the games speed is based entirely on frame rate but it would be better if i cant limit the frame rate to have those frames skipped and ensure that all objects are where they should be based on the real speed. Im not sure if im explaining this well enough but any help would be appreciated.

Many thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Frame rate issue
« Reply #1 on: March 03, 2011, 07:16:20 am »
But the game play itself is decooupled from frame rate already, isn't it? Or does this really cause a slow down in form of slower moving entities? If so, you should change that anyway. As for the garbage collection...jPCT-AE itself tries to avoid garbage where possible. However, that doesn't mean that all methods are tweaked that way. It can very well be, that less common methods still produce more garbage then they actually have to. If you could identify where most of the garbage causing the collections is created and if that it inside the engine, then maybe i can do something about it. Also take care to use the getters that take filler variables where available, i.e. don't do getTranslation() but getTranslation(fillMe) where fillMe is a always the same instance.

Offline dectar

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Frame rate issue
« Reply #2 on: March 03, 2011, 11:24:33 am »
Thanks for the response. At the moment the gameplay is, unfortunately, coupled heavily with the frame rate. The game itself involves a character that is constantly running but the way im doing it is by translating the character by a certain amount on each draw frame. I couldnt really think about the best way to decouple the characters movement from the frame rendering. I will need to put some thought into the best way to do that.

Also, thanks for the suggestion of using the getters which take filler variables. At the moment I am working mostly off returned variables so I will change these later after work.

Im sure that my issue is being caused by my own current inexperience but I will hammer on and hopefully find a good way to decouple the translation of my avatar from the frame rate.

Thanks

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: Frame rate issue
« Reply #3 on: March 03, 2011, 12:01:15 pm »
I think this might be useful for you, to keep the same speed at any framerate..
http://www.jpct.net/forum2/index.php/topic,1930.0.html
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

Offline dectar

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Frame rate issue
« Reply #4 on: March 03, 2011, 12:18:16 pm »
Thanks Kaiidyn, this is exactly what I needed to get me going.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Frame rate issue
« Reply #5 on: March 03, 2011, 12:30:07 pm »
...or have a look at the Alien Runner sources (can be found in the Alien Runner thread in the projects section), which include a more sophisticated ticker implementation.

Offline dectar

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Frame rate issue
« Reply #6 on: March 03, 2011, 12:54:54 pm »
Thanks, I will take a look at that as well. Seems pretty simple now that I see the general approach :)

Offline dectar

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Frame rate issue
« Reply #7 on: March 03, 2011, 02:26:20 pm »
Hey Egon, im looking at your Alien Runner source... great stuff! Seeing the source has answered a lot of the smaller questions I have been pondering too such as android lifecycle management and how to free up memory in better ways (i found my game crashes if i play it for too long). Many many thanks.