Thursday, June 30, 2011

I feel the need for speed

So this will be the first Retromite development focused posting, and will sadly contain no awesome pixels. Instead I thought i'd share some findings about something we all hate. Loading Times...

Robotriot for the iPhone is making great progress, however one issue which was bothering me was the game's loading time. Due to using several large sprite sheets (2048x2048x32 bit, and 2048x1024x32 bit being common) actually loading the game was taking on average around ten seconds to start up.

This in my opinion was pretty terrible, but how can you speed up the loading of large PNG files? Well I don't have the answer to that question, I found no solution to speed up the loading of these large PNG files. What I did find however, was an alternative approach that actually saves more disk space and is loading on average 4-5x faster.

The solution to amazing loading speeds, is to abandon graphic file formats all together, and go with straight binary pixel data. If you use a format like uncompressed PVR that is written out to be Open GL compatible from the beginning, you skip the entire slow decode process, and simply load into memory the bytes, and blast them off to Open GL texture memory land. This saves a ton of loading time.

The problem of course than becomes disk space usage, as a raw uncompressed image can take a ton of space. The solution to this is to simply compress the raw image data with a fast and easy to implement compression, like gzip. Suddenly in most cases you have files that are smaller than their PNG forms, and still load much quicker, only requiring you to unzip the image into a byte array in memory and pass it off to Open GL.

We're now using this technique across the board, and our load time of 10 seconds average is down to around 2 seconds on average, we've also knocked off around 200k in disk size compared to the PNG version.

2 comments:

  1. I've recently taken a close look at PNG compression and am very surprised to hear that you received a better compression through using gzip on the raw pixels then through PNGs. The Deflate algorithm that is used by GZip is also used in PNG. But PNG also restructures the data before deflating so that deflate works better. And in all my tests it did.

    Do you have a sample of the PNGs that you used so I could reproduce your results?

    ReplyDelete
  2. Unfortunately no, these were using large 2048x2048 sheets, in 4441 and 8888 color data formats for direct deflate and upload to opengl texture memory. Content wise these were mostly 16bit level pixel art. Much of this art could have actually been done in indexed mode, if hardware supported it.

    ReplyDelete