Bromeon
Particles/ParticleSystem.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
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/SmartPtr/ScopedPtr.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 <vector>
00043 
00044 
00045 namespace sf
00046 {
00047 
00048     class RenderWindow;
00049     class Image;
00050 
00051 } // namespace sf
00052 
00053 
00054 namespace thor
00055 {
00056 namespace detail
00057 {
00058 
00059     struct Texture;
00060 
00061 } // namespace detail
00062 
00063 
00066 
00071 class THOR_API ParticleSystem : private NonCopyable, private Emitter::Adder
00072 {
00073     // ---------------------------------------------------------------------------------------------------------------------------
00074     // Private types
00075     private:
00076         // Container typedefs
00077         typedef std::vector<Particle>           ParticleContainer;
00078         typedef std::vector<Affector::Ptr>      AffectorContainer;
00079         typedef std::vector<Emitter::Ptr>       EmitterContainer;
00080 
00081 
00082     // ---------------------------------------------------------------------------------------------------------------------------
00083     // Public member functions
00084     public:
00088                                     ParticleSystem(const sf::Image& particleImage, 
00089                                         const sf::IntRect& particleRect);
00090         
00093         explicit                    ParticleSystem(const sf::Image& particleImage);
00094 
00097         void                        Swap(ParticleSystem& other);
00098                 
00105         void                        AddAffector(Affector::Ptr affector);
00106 
00110         void                        RemoveAffector(Affector::Ptr affector);
00111 
00115         void                        ClearAffectors();
00116 
00119         bool                        ContainsAffector(Affector::Ptr affector) const;
00120 
00124         void                        AddEmitter(Emitter::Ptr emitter);
00125 
00129         void                        RemoveEmitter(Emitter::Ptr emitter);
00130 
00134         void                        ClearEmitters();
00135         
00138         bool                        ContainsEmitter(Emitter::Ptr emitter) const;
00139 
00144         void                        Update(float dt);
00145         
00148         void                        Draw(sf::RenderWindow& target) const;
00149         
00152         void                        ClearParticles();
00153         
00157         void                        SetGlowing(bool glow);
00158         
00161         bool                        IsGlowing() const;
00162 
00163 
00164     // ---------------------------------------------------------------------------------------------------------------------------
00165     // Private member functions
00166     private:
00169         void                        AddParticle(const Particle& particle);
00170                 
00171         // Prepares OpenGL to draw the particles.
00172         void                        PushOpenGLStates(sf::RenderWindow& target) const;
00173         
00174         // Does some work to reset the OpenGL state.
00175         void                        PopOpenGLStates(sf::RenderWindow& target) const;
00176             
00177         // Updates a single particle.
00178         void                        UpdateParticle(Particle& particle, float dt);
00179 
00180         // Draws a single particle.
00181         void                        DrawParticle(const Particle& particle) const;
00182 
00183 
00184     // ---------------------------------------------------------------------------------------------------------------------------
00185     // Private variables
00186     private:
00187         ParticleContainer           mParticles;
00188         AffectorContainer           mAffectors;
00189         EmitterContainer            mEmitters;
00190 
00191         ScopedPtr<detail::Texture>  mTexture;
00192         bool                        mGlow;
00193 };
00194 
00197 THOR_GLOBAL_SWAP(ParticleSystem)
00198 
00199 
00200 
00201 } // namespace thor
00202 
00203 #endif // THOR_PARTICLESYSTEM_HPP