better FPS... sometimes!?

I’m working on optimizing my Android OpenGL game. It started at ~18 FPS and I now have it at ~25 FPS. However, I think I may be losing my damned mind. Sometimes when I run the game on the device, as I have done a thousand times, it will run between 48 and 55 FPS, instead of the usual 25! Everything in the game is working, and the game is silky smooth! If I shutdown the game and run it again without making ANY changes, I see it runs at ~25 FPS. Does this make any sense at all!? It has happened 4 times in the past couple days. Any ideas how to figure out what kicks it into amazing FPS mode?

Well, when my phone upgraded to Android 1.5, I had the opposite, went from 30fps down to 10-15fps, but sometimes it would run fine at 30fps. After many a debugging session, I worked out it was the main screen orientation.

My game runs in landscape mode. If the main screen (the screen that kicks off the game) is also in landscape orientation, it runs at 10-15fps, however, if it is in portrait orientation, the game runs fine at 30fps. I didn’t believe this was actually happening, so I ran it over and over again, every time, without fail, it happened.

The fix was simple. Before starting the game, force the main screen into portrait layout. When the game ends, let the screen do whatever orientation it wants. Now I always get 30fps.

I tried to replicate this in a test case, but couldn’t. Funny thing is, I actually have 2 games, and it happens in both of them (although there is a lot of code reuse between my games, so I’m not ruling out it is something silly I’m doing).

Interesting. My game is also in landscape mode. I’ll take note of the screen orientation if I see it happening again. Can you tell what code you used to force the orientation?

I’ve been working all day on optimizations and now have it running at 40 to 50 FPS. This is great, though it means I may not notice the strange problem I was having.

Battery level low, or charger plugged in?

Many J2ME phones throttle the cpu to conserve power when the battery is getting low; wouldn’t be surprised if Android handsets did the same.

Force portrait before game start:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Restore default when game ends:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

You can force it in the manifest also.

One gotcha I had was handling lifecycle correctly. It’s easy to get yourself multiple threads running if you don’t start/stop things in the right places. I thought I only had 12 FPS at one point only to find it was just a duplicate thread :slight_smile:

Kev

Also surfaceDestroyed and surfaceCreated can be called at any point (although usually only if another window pops up over your game), so you need make sure you handle that properly too.