1 /////////////////////////////////////////////////////////////////////////////// 2 // Copyright (C) 2004-2011 by The Allacrost Project 3 // Copyright (C) 2012-2016 by Bertram (Valyria Tear) 4 // All Rights Reserved 5 // 6 // This code is licensed under the GNU GPL version 2. It is free software 7 // and you may modify it and/or redistribute it under the terms of this license. 8 // See http://www.gnu.org/copyleft/gpl.html for details. 9 /////////////////////////////////////////////////////////////////////////////// 10 11 /** *************************************************************************** 12 *** \file particle_manager.h 13 *** \author Raj Sharma, roos@allacrost.org 14 *** \author Yohann Ferreira, yohann ferreira orange fr 15 *** \brief Header file for particle manager 16 *** 17 *** The particle manager is very simple. Every time you want to draw an effect, 18 *** you call AddEffect() with a pointer to the effect definition structure. 19 *** Then every frame, call Update() and Draw() to draw all the effects. 20 *** **************************************************************************/ 21 22 #ifndef __PARTICLE_MANAGER_HEADER__ 23 #define __PARTICLE_MANAGER_HEADER__ 24 25 #include <string> 26 #include <vector> 27 #include <cstdint> 28 29 namespace vt_mode_manager 30 { 31 32 class ParticleEffect; 33 34 /*!*************************************************************************** 35 * \brief ParticleManager, used internally by video engine to store/update/draw 36 * all particle effects. 37 *****************************************************************************/ 38 39 class ParticleManager 40 { 41 public: 42 43 /*! 44 * \brief Constructor 45 */ ParticleManager()46 ParticleManager() {} 47 ~ParticleManager()48 ~ParticleManager() { 49 _Destroy(); 50 } 51 52 /*! 53 * \brief Takes control of the effect and moves it at (x,y). 54 * The effect is added to the internal std::map, _effects, and is now 55 * included in calls to Draw() and Update() 56 * \param effect the particle effect to register to the particle manager 57 * \param x x coordinate of where to add the effect 58 * \param y y coordinate of where to add the effect 59 * \return whether the effect was added 60 */ 61 bool AddParticleEffect(const std::string &effect_filename, float x, float y); 62 63 //! \brief draws all active effects 64 void Draw() const; 65 66 /*! 67 * \brief updates all active effects 68 * \param frame_time The elapsed time since last call. 69 */ 70 void Update(int32_t frame_time); 71 72 /*! 73 * \brief stops all registered effects 74 * 75 * \param kill_immediate If this is true, the effects are immediately killed. If 76 * it isn't true, then we stop the effects from emitting 77 * new particles, and allow them to live until all the active 78 * particles fizzle out. 79 */ 80 void StopAll(bool kill_immediate = false); 81 82 /*! 83 * \brief returns the total number of particles among all active registered effects 84 * \return number of particles in the effect 85 */ GetNumParticles()86 int32_t GetNumParticles() { 87 return _num_particles; 88 } 89 90 private: 91 /*! 92 * \brief destroys the system. Called by VideoEngine's destructor 93 */ 94 void _Destroy(); 95 96 /** \brief Shows graphical statistics useful for performance tweaking 97 *** This includes, for instance, the number of texture switches made during a frame. 98 **/ 99 void _DEBUG_ShowParticleStats(); 100 101 //! All the effects currently being managed. 102 std::vector<ParticleEffect *> _all_effects; 103 104 std::vector<ParticleEffect *> _active_effects; 105 106 //! Total number of particles among all the active effects. This is updated 107 //! during each call to Update(), so that when GetNumParticles() is called, 108 //! we can just return this value instead of having to calculate it 109 int32_t _num_particles; 110 }; 111 112 } // namespace vt_mode_manager 113 114 #endif // !__PARTICLE_MANAGER_HEADER 115