No Stable Frame Rate - with Demo

I’m still having trouble getting a really stable smooth framerate on Android devices and I wondered if anyone has got it right? I’m using Android 1.5 with OpenGLES. I use two threads - logic thread and render thread (part of GLSurfaceView). I render with RENDER_ON_DIRTY. Essentially logic loop is:

  • calculateWhenTheFrameShouldEnd
  • doLogic
  • requestRender
  • waitTilTheFrameShouldEnd

Render, doesn’t do anything exciting, just splatting a few quads to the screen.

While this runs pretty smoothly it still glitches regularly. I’ve observed this behavior in any GL based animation game that I’ve tried (including the ones here). They run ok, but it doesn’t feel really smooth. To illustrate I knocked a silly game together the last few nights:

http://www.cokeandcode.com/applets/defend/tapattack.png

Applet: http://www.cokeandcode.com/applets/defend/

Android: http://www.cokeandcode.com/applets/defend/defend-2.apk

While it’s just about playable (from a game play point of view) the jitters are still fairly evident. The game creates zero garbage outside of the Android SDK and the logic going is really pretty simple.

Bit confused, not sure why it should be bad, has anyone got a simple example of something that runs really smoothly on the handset and uses GL?

Kev

I don’t use GLSurfaceView. I manage the GL thread myself and use EGLContext.getEGL(). Then in the GL thread I use a wait and the game loop calls notify (this is mostly likely how RENDER_ON_DIRTY works).

So I have 3 threads:

  • Game loop
  • GL thread
  • EDT

The game loop thread will spend a lot of time sleeping (as I only target 30fps). I think this allows other processes to run in the background and gives a more stable frame rate.

I read somewhere that the next version of Android will stop widgets and other background processes from hogging the CPU.

Yeah, it’s the same thing. I get the same behaviour in Craig’s Race too… most of the time it’s smooth then jitter.

Kev

The 1.5 Android SDK generates garbage. This is ridiculous IMO, but true. There is a thread on their newsgroup somewhere about it. Connect up DDMS using the batch file, not Eclipse, and you can watch the memory allocations in both your code, if any, and the SDK. The SDK causes garbage collection about every 20 seconds on my G1, probably depending on how much OpenGL stuff you are doing. Maybe they’ll fix it at some point!? Haven’t tried 1.6.

FWIW, I use a modified (ie completely gutted) version of GLSurfaceView. There are two threads, the Android UI thread (where events come in) and the GL thread. I run my event listeners (onTouch, etc) on the GL thread to keep things sane. I don’t use the request render stuff, I just try to render at 60fps. Hopefully soon I’ll post my code.

Yeah, I took a look at GLSurfaceView after you mentioned it before. I’m using a hacked down version (simplifing and running events nicely). Still no luck.

FWIW, in SingSong when it’s scrolling along the music/lyrics I see the same thing… just slight jitters that make draw your attention.

On another note, the demo above also shows how the touch screen isn’t quite responsive enough for action games.

Interesting the SDK causes a lot of garbage… bit of a pain in the bum that. I’ve tried frame smoothing also and still no real luck. It almost feels like the timing isn’t quite right.

Kev

Re-reading my post I realize I wasn’t as explicit as I meant to be. It is the OpenGL stuff in the SDK that generates garbage, so there is nothing we can do if we want to use OpenGL. I haven’t tried frame smoothing, I just considered it good enough as I had a lot of other things that needed attention.

I don’t have any issues with Craig’s Race, could it be other processes on the device?, have you tried a scene with no widgets?, tried killing other processes?. Just a thought. Might be totally the wrong path, but it’s a thought :).

Endolf

I’ve tried lots of things :slight_smile: It’s more likely that if you’re just focused on playing the game you don’t notice the slight hiccups - but if you just want it scrolling you’ll see slight blips - not enough to worry about probably but enough to make it not look quite perfect :wink:

Kev