It’s been awhile since I last updated this, I’ve have my hands full with Vizati iPhone.

Ever since I got an IPod Touch 2G it was easier for Rita to get a sense of the screen size (although we knew to be 320×480) it’s different when you are testing on the real thing, text looks smaller, other stuff looks way too big.

Here’s a picture she took after a few adjustments.

Vizati iPhone

Initial testing

First thing I notice when testing on the device were slowdowns when the cube is fading, it had a lot of particles filling the screen and the framerate dropped down, although this only happens when each level loads and doesn’t interfere with gameplay itself I got a little frustrated.
On the simulator It slowed down a little but only on Debug and even more OpenGL on the emulator is by software.
Another issue was the sound, I’m using OpenAL + a custom OGG parser, and sound was also slow, with hiccups.

Sound
For the sound it turned out a little easier than I expected, there as nothing wrong with the parser, what would happen is that if the CPU would sometimes take longer than expected on someplace and the player would run out of data making those hiccups, since it was constantly running out of data and getting more.
I increased the buffers size and numbers, so now I have 5 buffers with 65536 bytes each. Every time a buffer is parsed I read another one and queue it.
Solved the problem immediately. Yesterday while playing the game (after 10-20m) the sound started having hiccups again, although the game was fine, so I may still have some flaw in there, must research it more.

Here’s a video where of me playing with some particles:

Primitives
I can get much more particles on screen now because my first attempt to draw primitives in OpenGLES was drawing Quads with an mapped texture. When I got that working I would just send vertex points and texture coordinates and iterate all objects I wanted to draw.
WROONGGGGGGG…..
Although this works you should always batch as much geometry (within limits of course) as you can to make it on as fewer draw calls as you can. On both OpenGL and DirectX draw calls are the slowest part.
It’s faster to draw 1000 triangles in one call than on 1 triangle per call. You get the point.
So I started by making a PrimitiveBatch, sort of what XNA has, I just pass along vertex points, texture coordinates, color refs etc.
Since it’s 2D I try to group by texture and by Z. All primitives with same texture on the same Z position can be drawn at once. You can’t draw all with same texture regardless of the Z some elements may be occluded when it was not intended, basically because it will keep drawing on top of what you have, at least for the current Buffer.

After this I got enough drawing boost to have the same amount of particles that the PC version, which is cool.

Some tips
Although I’m still kind of new at this all iPhone things I can give you a few tips, they work for everything but are particular handy on devices with lower CPU power.

  • Avoid using std::list:end(), on big lists it carries an extra burden.

If you don’t intend to add/remove anything from the list during the cycle just save that at first

   std::list::iterator b = _mylist.begin();
   std::list::iterator e = _mylist.end();
   while(b!=e)
    {
       /// Do stuff
      ++b;
    }
  • Avoid deleting stuff on loops. One example, I have a list where I stack stuff to be drawn on my PrimitiveBatch, typically when you start drawing you add everything, the lists keeps growing, you draw and then delete, and you go back to “start drawing” again. You can optimize this by never deleting and only creating on a need basis. Belize me it makes huge difference, and besides you will need to create that again so might as well not delete it and when starting over just update values. Small things like this may not be an issue on PC but on small devices every cycle counts.

Most of this stuff you may already know but there are many who don’t. I’ll try to update this more often.

So now I’ll get back to my testing to see if we get to testing and later to the app store asap =)

PS: I need iPhone/IPod Touch testers, drop me an email with your UDID if you are interested…