0

I have an IOS game that uses the accelorometer. My game renders at a good rate, 60 fps, but my input from the accelerometer is lagged. For example, after I tilt the game to the left, it takes a second before the game responds. The same occurs for Touch Events, the lag is about a second at times.

My game's render loop looks like this:

procedure RenderFrame

    switch to "SpaceShips" texture

    for each bad guy
        update his location
        render to OpenGLES
    end loop

    update good guy location
    render him to OpenGLES

    switch to "Particles" texture

    for each particle
        update the location
        render to OpenGLES
    end loop

end RenderFrame

To me this sounds similar to this question:

OpenGL ES 2.0 iPhone - Rendering on background thread block main thread

Does this sound like my main thread is blocked and I would benefit from concurrency? Can I remove the block on the main thread simply by moving that entire method off to another background thread, or do I have to do a more granular rewrite of the method above to achieve concurrency? I would like to do the minimal amount of concurrency to relieve the block on the main thread if possible.

Community
  • 1
  • 1
SpecialEd
  • 473
  • 5
  • 17
  • 1
    Why don't you use Instruments and find out? – matt Feb 22 '13 at 17:49
  • Try the system trace instrument. – nielsbot Feb 22 '13 at 18:06
  • 1
    For a relatively painless means of moving your rendering actions to a background thread, you can try the GCD-based approach I suggest here: http://stackoverflow.com/questions/5944050/cadisplaylink-opengl-rendering-breaks-uiscrollview-behaviour/5956119#5956119 . I've now used this in a few different situations, and in each case it not only freed up the main thread for user interaction, but also yielded nice overall performance improvements (particularly on multicore devices). – Brad Larson Feb 22 '13 at 23:49
  • Thanks Brad, I think I understand that code you posted now. It doesn't seem too bad, but I've written my game is c++. From what I understand, I should be able to mix in objective c and c++ or do you know if its possible to make calls to GCD in c++? – SpecialEd Feb 23 '13 at 02:34
  • @SpecialEd - GCD uses a C API, and blocks work with C as long as you're using LLVM as your compiler. I know several people who use this with C++ code without any problems. It might not be as portable to other platforms (you'll need to find other solutions there), but it's an easy and performant way to move rendering onto a background thread on iOS. – Brad Larson Feb 24 '13 at 22:44

0 Answers0