From 63867b1a372a4d1a4a4ffdec9d0862b094211a89 Mon Sep 17 00:00:00 2001 From: sapier Date: Mon, 5 Jan 2015 18:34:59 +0100 Subject: Fix memory leaks due to messed up memory handling for particles as well as their spawners --- src/particles.h | 62 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 16 deletions(-) (limited to 'src/particles.h') diff --git a/src/particles.h b/src/particles.h index 101fc49ce..d7f1147f1 100644 --- a/src/particles.h +++ b/src/particles.h @@ -28,6 +28,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "localplayer.h" #include "environment.h" +struct ClientEvent; +class ParticleManager; + class Particle : public scene::ISceneNode { public: @@ -35,7 +38,7 @@ class Particle : public scene::ISceneNode IGameDef* gamedef, scene::ISceneManager* mgr, LocalPlayer *player, - ClientEnvironment &env, + ClientEnvironment *env, v3f pos, v3f velocity, v3f acceleration, @@ -114,16 +117,18 @@ class ParticleSpawner bool collisiondetection, bool vertical, video::ITexture *texture, - u32 id); + u32 id, + ParticleManager* p_manager); ~ParticleSpawner(); - void step(float dtime, ClientEnvironment &env); + void step(float dtime, ClientEnvironment *env); bool get_expired () { return (m_amount <= 0) && m_spawntime != 0; } private: + ParticleManager* m_particlemanager; float m_time; IGameDef *m_gamedef; scene::ISceneManager *m_smgr; @@ -144,24 +149,49 @@ class ParticleSpawner std::vector m_spawntimes; bool m_collisiondetection; bool m_vertical; + }; -void allparticles_step (float dtime); -void allparticlespawners_step (float dtime, ClientEnvironment &env); +/** + * Class doing particle as well as their spawners handling + */ +class ParticleManager +{ +friend class ParticleSpawner; +public: + ParticleManager(ClientEnvironment* env); + ~ParticleManager(); + + void step (float dtime); + + void handleParticleEvent(ClientEvent *event,IGameDef *gamedef, + scene::ISceneManager* smgr, LocalPlayer *player); + + void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr, + LocalPlayer *player, v3s16 pos, const TileSpec tiles[]); -void delete_particlespawner (u32 id); -void clear_particles (); + void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr, + LocalPlayer *player, v3s16 pos, const TileSpec tiles[]); -void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr, - LocalPlayer *player, ClientEnvironment &env, v3s16 pos, - const TileSpec tiles[]); + void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr, + LocalPlayer *player, v3s16 pos, const TileSpec tiles[]); -void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr, - LocalPlayer *player, ClientEnvironment &env, v3s16 pos, - const TileSpec tiles[]); +protected: + void addParticle(Particle* toadd); -void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr, - LocalPlayer *player, ClientEnvironment &env, v3s16 pos, - const TileSpec tiles[]); +private: + + void stepParticles (float dtime); + void stepSpawners (float dtime); + + void clearAll (); + + std::vector m_particles; + std::map m_particle_spawners; + + ClientEnvironment* m_env; + JMutex m_particle_list_lock; + JMutex m_spawner_list_lock; +}; #endif -- cgit v1.2.3