diff options
Diffstat (limited to 'src/particlecontainer.cpp')
-rw-r--r-- | src/particlecontainer.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp index 1ed51053..63f89079 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -24,15 +24,17 @@ #include "particle.h" #include "particlecontainer.h" -ParticleContainer::ParticleContainer(ParticleContainer *parent, bool delParent) : + +ParticleContainer::ParticleContainer(ParticleContainer *parent, + bool delParent): mDelParent(delParent), mNext(parent) -{}; +{} ParticleContainer::~ParticleContainer() { clearLocally(); - if (mNext && mDelParent) + if (mDelParent) delete mNext; } @@ -51,10 +53,12 @@ void ParticleContainer::moveTo(float x, float y) // -- particle list ---------------------------------------- -ParticleList::ParticleList(ParticleContainer *parent, bool delParent) : - ParticleContainer(parent, delParent) {}; +ParticleList::ParticleList(ParticleContainer *parent, bool delParent): + ParticleContainer(parent, delParent) +{} -ParticleList::~ParticleList() {} +ParticleList::~ParticleList() +{} void ParticleList::addLocally(Particle *particle) { @@ -70,10 +74,12 @@ void ParticleList::removeLocally(Particle *particle) { for (std::list<Particle *>::iterator it = mElements.begin(); it != mElements.end(); it++) + { if (*it == particle) { (*it)->kill(); mElements.erase(it); } + } } void ParticleList::clearLocally() @@ -81,7 +87,7 @@ void ParticleList::clearLocally() for (std::list<Particle *>::iterator it = mElements.begin(); it != mElements.end(); it++) (*it)->kill(); - + mElements.clear(); } @@ -105,10 +111,12 @@ void ParticleList::moveTo(float x, float y) // -- particle vector ---------------------------------------- -ParticleVector::ParticleVector(ParticleContainer *parent, bool delParent) : - ParticleContainer(parent, delParent) {}; +ParticleVector::ParticleVector(ParticleContainer *parent, bool delParent): + ParticleContainer(parent, delParent) +{} -ParticleVector::~ParticleVector() {}; +ParticleVector::~ParticleVector() +{} void ParticleVector::setLocally(int index, Particle *particle) { @@ -119,6 +127,8 @@ void ParticleVector::setLocally(int index, Particle *particle) if (mIndexedElements.size() <= (unsigned) index) mIndexedElements.resize(index + 1, NULL); + if (particle) + particle->disableAutoDelete(); mIndexedElements[index] = particle; } @@ -148,7 +158,7 @@ void ParticleVector::moveTo(float x, float y) ParticleContainer::moveTo(x, y); for (std::vector<Particle *>::iterator it = mIndexedElements.begin(); - it != mIndexedElements.end(); it++) + it != mIndexedElements.end(); it++) { if (*it) { (*it)->moveTo(x, y); @@ -159,5 +169,6 @@ void ParticleVector::moveTo(float x, float y) *it = NULL; } } + } } |