summaryrefslogtreecommitdiff
path: root/src/particles.h
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2015-01-05 18:34:59 +0100
committersapier <Sapier at GMX dot net>2015-01-09 15:23:49 +0100
commit63867b1a372a4d1a4a4ffdec9d0862b094211a89 (patch)
tree677bcba3907e937c408e975a64f8232aad4f14fc /src/particles.h
parente201620ee1051545ed7856fb18f805c67adccc85 (diff)
downloadminetest-63867b1a372a4d1a4a4ffdec9d0862b094211a89.tar.gz
minetest-63867b1a372a4d1a4a4ffdec9d0862b094211a89.tar.bz2
minetest-63867b1a372a4d1a4a4ffdec9d0862b094211a89.zip
Fix memory leaks due to messed up memory handling for particles as well as their spawners
Diffstat (limited to 'src/particles.h')
-rw-r--r--src/particles.h62
1 files changed, 46 insertions, 16 deletions
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<float> 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<Particle*> m_particles;
+ std::map<u32, ParticleSpawner*> m_particle_spawners;
+
+ ClientEnvironment* m_env;
+ JMutex m_particle_list_lock;
+ JMutex m_spawner_list_lock;
+};
#endif