Pixelate:Issue 14/An Allegro Implementation of an Extensible Particle System
From Allegro Wiki
| An Allegro Implementation of an Extensible Particle System | |
| Original author: | Chris Barry (aka 23yrold3yrold) |
|---|---|
| Website: | |
| zip: | tgs.zip |
An Allegro Implementation of an Extensible Particle System
This is an article detailing an Allegro implementation of a particle system relying heavily on templates. The article this code is based on resides right here.
The high concept here is this: when one wants an extensible class system, one generally goes to inheritance and polymorphism. But when you're dealing with potentially thousands of particles, the cost of virtual function calls adds up fast. With a template system however, all the code can get compiled inline. Templates are a standard part of the C++ language which allow you to create functions or (in this case) classes for use with any object types, so you don't have to write the same function/class over and over to handle a half dozen types. This lets us use one single template class for a generic particle system, yet this one system can accomidate many different types of particles. Hopefully you have at least a little experience with templates; if not, I refer you to your C++ text of choice.
I'll leave the details to the original article. The purpose of this, besides making you aware of the ideas in the original article, is to show you how one might go about implementing these ideas using Allegro. I don't go quite as crazy with the templates, but that's more a matter of taste. I'm including two source files, one with the original ideas and another that's stripped down (more to my personal preferences). Also included is a bitmap image the program needs, just to give one of the particles some variety.
Hopefully this system can be useful to you.
