Pages

Showing posts with label Performance. Show all posts
Showing posts with label Performance. Show all posts

Thursday, July 22, 2010

Bullets are now implemented!

After the fireworks show here in Vancouver last night (http://www.celebration-of-light.com/), I got stumped with a bug that made all of my actors (bullets and enemies) run erratic. As I was using multi-threading in my factory to prevent a linear algorithm from blocking the UI, I've learned from the past that if you can't explain some bug after 4 hours of investigation, then it must be caused by multi-threading :) So anyway, it has been a long night last night but I finally managed to implement the bullet system in our Doodle Space Wings! I had to rewrite some sections in my Sprite Factory in order to eliminate the parts that were implemented using multi-threading as it had a critical flaw with regards to accessing critical sections of the code. Anyway, I'm happy with the new solution since even without the threading part, I still managed to meet my 60 FPS goal even when the screen was displaying 50 sprites at the same time!

I also had to redesign some of my sprites in order to make them more attractive. It's hard to do everything by yourself but I guess it's a path that every low-budget indie developers have to take. I'm learning a lot of things right now and I'm happy with the way the things are progressing despite the fact that I'm loosing more sleep :)

So next stuff on the list - collision detection, weapon drops, implementing 5 more kinds of bullets, and loosing more sleep :)

Jim

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