The first bigger refactoring has been done, it concerns the design of the particle emitters. I wrote the new UniversalEmitter class, which is far more powerful than the existing emitters. As the name implies, you can set every initial particle attribute
using a functor. That is, you specify a function that is called every time a particle is emitted. For example, you can specify a random distribution for the initial position. Or set the position according to the mouse or another game object. Hereby, the predefined distributions in Math/Distributions.hpp may be of help.
thor::UniversalEmitter::Ptr emitter = thor::UniversalEmitter::create();
emitter->setEmissionRate( 20 );
emitter->setPosition( thor::Distributions::circle(center, radius) );
emitter->setRotation( thor::Distributions::uniform(0.f, 360) );
Using the aur::Distribution class template, you can also specify constants, so the syntax is still simple if you don't need the flexibility:
emitter->setColor( sf::Color::Red );
emitter->setLifetime( sf::seconds(4) );
This new design also has an impact on other parts of the library, namely:
- The complete Geometry module has been removed. For a long time, I thought about a redesign of the Zone class hierarchy. I have never liked the asymmetric treatment of initial position (determined via Zone) and initial rotation (not possible to set at all). While searching for alternatives, I came up with the distribution approach.
- Removed classes DirectionalEmitter and TargetEmitter. They are too specific, UniversalEmitter outperforms them easily in terms of flexibility.
- Turned Emitter class into a stateless interface. For custom emitters, no more attributes are dictated by the library, so you can implement whatever you want.
- Renamed emitter methods. Instead of setParticleVelocity(), it's now just setVelocity().