29 #ifndef THOR_PARTICLESYSTEM_HPP
30 #define THOR_PARTICLESYSTEM_HPP
37 #include <SFML/System/NonCopyable.hpp>
38 #include <SFML/System/Vector2.hpp>
39 #include <SFML/Graphics/Rect.hpp>
40 #include <SFML/Graphics/Drawable.hpp>
41 #include <SFML/Graphics/VertexArray.hpp>
64 class AbstractConnectionImpl;
81 template <
typename Signature>
84 Function(std::function<Signature>
function, sf::Time timeUntilRemoval)
85 :
function(std::move(
function))
86 , timeUntilRemoval(timeUntilRemoval)
92 static unsigned int nextId()
94 static unsigned int next = 0;
98 std::function<Signature>
function;
99 sf::Time timeUntilRemoval;
101 std::shared_ptr<detail::AbstractConnectionImpl> tracker;
105 typedef std::array<sf::Vertex, 4> Quad;
108 typedef Function<void(Particle&, sf::Time)> Affector;
109 typedef Function<void(EmissionInterface&, sf::Time)> Emitter;
112 typedef std::vector<Particle> ParticleContainer;
113 typedef std::vector<Affector> AffectorContainer;
114 typedef std::vector<Emitter> EmitterContainer;
137 void setTexture(
const sf::Texture& texture);
145 unsigned int addTextureRect(
const sf::IntRect& textureRect);
162 Connection addAffector(std::function<
void(
Particle&, sf::Time)> affector, sf::Time timeUntilRemoval);
166 void clearAffectors();
182 void clearEmitters();
188 void update(sf::Time dt);
192 void clearParticles();
201 virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
const;
205 virtual void emitParticle(
const Particle& particle);
208 void updateParticle(
Particle& particle, sf::Time dt);
211 void computeVertices()
const;
214 void computeQuads()
const;
215 void computeQuad(Quad& quad,
const sf::IntRect& textureRect)
const;
221 ParticleContainer mParticles;
222 AffectorContainer mAffectors;
223 EmitterContainer mEmitters;
225 const sf::Texture* mTexture;
226 std::vector<sf::IntRect> mTextureRects;
228 mutable sf::VertexArray mVertices;
229 mutable bool mNeedsVertexUpdate;
230 mutable std::vector<Quad> mQuads;
231 mutable bool mNeedsQuadUpdate;
238 #endif // THOR_PARTICLESYSTEM_HPP
Class that connects emitters with their corresponding particle system.
Definition: EmissionInterface.hpp:46
Definition: AnimationMap.hpp:42
Class thor::EmissionInterface.
Configuration header of the library.
Classes thor::Connection, thor::ScopedConnection.
Class that maintains control over a registered object.
Definition: Connection.hpp:57
Structure thor::Particle.
Definition: BigSprite.hpp:41
Class for particle systems.
Definition: ParticleSystem.hpp:75
Particle class
Definition: Particle.hpp:49