Friday, April 30, 2010

Texture packing....

While Game Maker allows very simple access to sprites and drawing images, it has a side effect of bloating texture usage. From a users point of view it's done absolutely right. That is, it's very simple to use and understand. Now... enter the PSP with it's limited memory, and all of a sudden, these bloated images are an issue as there's large textures with not much in them, taking up valuable space.

So first, what do I mean by not much in them. Well, lets say a user wants to display a logo, over the top of the actual game. Now there are 2 ways of doing this; first you cut it right down to size, and use code to position it using a little trial and error, or second, you could make a full screen image, and use a painting program to position it just right. The second is far easier, so many users opt for that option, but this results in lots of empty space around the image. Now, even a few pixels space around a sprite adds up if you have hundreds of sprites, so what I've been doing in the past few days is a little smarts in our texture page packer. This looks at the image, gets rid of the surrounding space as best it can, then gets the runner to reposition the image automatically, so it's just like the original. This can seriously reduce the memory footprint of game.

So if we take an example game and apply this and a few other tricks, we can reduce the number of textures required down hugely, in this case from 28 512x512 textures to only 17 512x512s. That's a saving of almost 3Mb (DXT5) - that's a pretty meaty chunk for a platform with only 24Mb free.

Lastly, why do we pack images onto texture pages in the first place? Well, some systems (like the PSP) only want power of 2 textures, that is a texture can only be a width/height of 2,4,8,16,32,64,128,256 or 512. (512 is the maximum size on the PSP). so we can either pack them into a page, or we'd have to scale them so they were a POW2, and that makes the image look a little funny. It also helps cut down on texture swapping, and speeds up the graphics a little.

All this helps in reducing the memory footprint, and speeds up loading. When we first got something running on the PSP, the initial loading of SkyDiver took 40 seconds, which was obviously unusable. Now however, the new way we have to loading data into the game means we can now load SkyDiver in around 6 seconds, which is much better, and the smaller the file, the quicker it'll load.

All these optimisations will one day make it's way into the main Game Maker runner, which will give all users these benefits, no matter if it's on windows, mac or some new mythical platform.

No comments:

Post a Comment