Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00028
00029 #ifndef THOR_PARTICLESYSTEM_HPP
00030 #define THOR_PARTICLESYSTEM_HPP
00031
00032 #include <Thor/Particles/ParticleInterfaces.hpp>
00033 #include <Thor/Particles/Particle.hpp>
00034 #include <Thor/Resources/ResourcePtr.hpp>
00035 #include <Thor/Tools/NonCopyable.hpp>
00036 #include <Thor/Detail/Swap.hpp>
00037 #include <Thor/Config.hpp>
00038
00039 #include <SFML/Graphics/Rect.hpp>
00040 #include <SFML/System/Vector2.hpp>
00041
00042 #include THOR_TR1_HEADER(functional)
00043 #include <vector>
00044 #include <utility>
00045
00046
00047 namespace sf
00048 {
00049
00050 class RenderWindow;
00051 class Image;
00052 class Texture;
00053
00054 }
00055
00056
00057 namespace thor
00058 {
00059
00062
00067 class THOR_API ParticleSystem : private NonCopyable, private Emitter::Adder
00068 {
00069
00070
00071 private:
00072
00073 typedef std::vector< Particle > ParticleContainer;
00074 typedef std::vector< std::pair<Affector::Ptr, sf::Time> > AffectorContainer;
00075 typedef std::vector< std::pair<Emitter::Ptr, sf::Time> > EmitterContainer;
00076
00077
00078
00079
00080 public:
00083 explicit ParticleSystem(ResourcePtr<const sf::Texture> texture);
00084
00088 ParticleSystem(ResourcePtr<const sf::Texture> texture, const sf::IntRect& textureRect);
00089
00092 void Swap(ParticleSystem& other);
00093
00100 void AddAffector(Affector::Ptr affector);
00101
00109 void AddAffector(Affector::Ptr affector, sf::Time timeUntilRemoval);
00110
00114 void RemoveAffector(Affector::Ptr affector);
00115
00119 void ClearAffectors();
00120
00123 bool ContainsAffector(Affector::Ptr affector) const;
00124
00128 void AddEmitter(Emitter::Ptr emitter);
00129
00134 void AddEmitter(Emitter::Ptr emitter, sf::Time timeUntilRemoval);
00135
00139 void RemoveEmitter(Emitter::Ptr emitter);
00140
00144 void ClearEmitters();
00145
00148 bool ContainsEmitter(Emitter::Ptr emitter) const;
00149
00154 void Update(sf::Time dt);
00155
00158 void Draw(sf::RenderWindow& target) const;
00159
00162 void ClearParticles();
00163
00167 void SetGlowing(bool glow);
00168
00171 bool IsGlowing() const;
00172
00173
00174
00175
00176 private:
00179 virtual void AddParticle(const Particle& particle);
00180
00181
00182 void PushOpenGLStates(sf::RenderWindow& target) const;
00183
00184
00185 void PopOpenGLStates() const;
00186
00187
00188 void UpdateParticle(Particle& particle, sf::Time dt);
00189
00190
00191 void DrawParticle(const Particle& particle) const;
00192
00193
00194
00195
00196 private:
00197 ParticleContainer mParticles;
00198 AffectorContainer mAffectors;
00199 EmitterContainer mEmitters;
00200
00201 ResourcePtr<const sf::Texture> mTexture;
00202 sf::Vector2f mTexCoordsBegin;
00203 sf::Vector2f mTexCoordsEnd;
00204 sf::Vector2f mHalfSize;
00205 bool mGlow;
00206 };
00207
00210 THOR_GLOBAL_SWAP(ParticleSystem)
00211
00212
00213
00214 }
00215
00216 #endif // THOR_PARTICLESYSTEM_HPP