Pages

Tuesday, July 20, 2010

Goal: 60 FPS

It's been a tough week. I was barely able to keep up with my schedule and the goal of having 60 FPS is not making it any easier. Our Sunday hike at Garibaldi Lake took a toll on my body - and now, I am playing through the pain. Nevertheless, after cutting back my sleeping hours to around 3 to 5 hours, I have managed to keep up with my schedule, still maintain the 60 FPS goal that I want to achieve, and most importantly, hike and bike around Vancouver! Anyway, so how do you go about keeping a high and consistent frame rate? Well, I keep the following guidelines in mind when designing our game:

1. Do not allocate a lot of things in your main game loop - especially during the draw routine
2. Try to reuse your sprite allocations as much as you can. I've implemented a sprite factory which maintains a sprite pool that can reuse sprite allocations. This ensures that dynanic memory allocations during the game loop are kept to a minimum.
3. Cache complex mathematical results.
4. Rely on O(n)-based algorithms only as a last resort. Choose O(logN) or if possible, O(1). For example, using a hash table is a lot better than using an array when you need to search for an item as it cab give you O(1) when using a very good hashing function.
5. If you have to use linear-based algorithms, sorting the array will usually yield better performance if doing search.
6. Remember the trade-off - memory vs performance - you can gain performance improvement by sacrificing some memory.
7. Do not try to reinvent the wheel. Check if the framework that you are using already supports what you are trying to do. The guys who built the framework that you are using spent a lot of time working on it and what they did is probably better than how you will be doing it.
8. Keep the texture size in check. It usually boils down to using a texture size that is a power of 2 (e.g. 512x512).

Hmm.. I guess that's my list for now - I might add some more if I learn something :)

Cheers,
Jim

No comments:

Post a Comment