diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-07-23 02:14:30 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-07-23 02:14:30 +0300 |
commit | 6a65a4cf5b6b10839254c0c5846ec2dbfea882f8 (patch) | |
tree | cdf1dcc071ab18575defff569d33f3cbc8be0348 /src/being | |
parent | 1a5f8957c707625efbcf36722b057d5eda5a21bb (diff) | |
download | plus-6a65a4cf5b6b10839254c0c5846ec2dbfea882f8.tar.gz plus-6a65a4cf5b6b10839254c0c5846ec2dbfea882f8.tar.bz2 plus-6a65a4cf5b6b10839254c0c5846ec2dbfea882f8.tar.xz plus-6a65a4cf5b6b10839254c0c5846ec2dbfea882f8.zip |
Allow delete untracker being particle effects.
This fix some possible memory leaks.
Diffstat (limited to 'src/being')
-rw-r--r-- | src/being/actorsprite.cpp | 27 | ||||
-rw-r--r-- | src/being/actorsprite.h | 11 | ||||
-rw-r--r-- | src/being/being.cpp | 6 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 2 |
4 files changed, 37 insertions, 9 deletions
diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp index f0dfc07ec..3a9c457a4 100644 --- a/src/being/actorsprite.cpp +++ b/src/being/actorsprite.cpp @@ -33,6 +33,7 @@ #include "listeners/debugmessagelistener.h" +#include "particle/particle.h" #include "particle/particleengine.h" #include "resources/db/statuseffectdb.h" @@ -141,9 +142,29 @@ void ActorSprite::setMap(Map *const map) mMustResetParticles = true; // Reset status particles on next redraw } -void ActorSprite::controlParticle(Particle *const particle) +void ActorSprite::controlAutoParticle(Particle *const particle) { - mChildParticleEffects.addLocally(particle); + if (particle) + { + particle->setActor(mId); + mChildParticleEffects.addLocally(particle); + } +} + +void ActorSprite::controlCustomParticle(Particle *const particle) +{ + if (particle) + { + // The effect may not die without the beings permission or we segfault + particle->disableAutoDelete(); + mChildParticleEffects.addLocally(particle); + } +} + +void ActorSprite::controlParticleDeleted(Particle *const particle) +{ + if (particle) + mChildParticleEffects.removeLocally(particle); } void ActorSprite::setTargetType(const TargetCursorTypeT type) @@ -456,7 +477,7 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, FOR_EACH (StringVectCIter, itr, display.particles) { Particle *const p = particleEngine->addEffect(*itr, 0, 0); - controlParticle(p); + controlAutoParticle(p); } } diff --git a/src/being/actorsprite.h b/src/being/actorsprite.h index 6f5c020c2..c06f1c983 100644 --- a/src/being/actorsprite.h +++ b/src/being/actorsprite.h @@ -81,9 +81,14 @@ class ActorSprite notfinal : public CompoundSprite, public Actor { return BlockType::NONE; } /** - * Take control of a particle. + * Take control of a particle. Particle can be auto deleted. */ - void controlParticle(Particle *const particle); + void controlAutoParticle(Particle *const particle); + + /** + * Take control of a particle. Owner must remove particle by self. + */ + void controlCustomParticle(Particle *const particle); /** * Returns the required size of a target cursor for this being. @@ -190,6 +195,8 @@ class ActorSprite notfinal : public CompoundSprite, public Actor mChildParticleEffects.size(); } + void controlParticleDeleted(Particle *const particle); + protected: /** * A status effect block is a 16 bit mask of status effects. We assign diff --git a/src/being/being.cpp b/src/being/being.cpp index b5732b15f..0cf52c353 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -1349,7 +1349,7 @@ void Being::fireMissile(Being *restrict const victim, { target->moveBy(Vector(0.0F, 0.0F, 32.0F)); target->setLifetime(1000); - victim->controlParticle(target); + victim->controlAutoParticle(target); missile->setDestination(target, 7, 0); missile->setDieDistance(8); @@ -4849,7 +4849,7 @@ void Being::addItemParticles(const int id, FOR_EACH (StringVectCIter, itr, display.particles) { Particle *const p = particleEngine->addEffect(*itr, 0, 0); - controlParticle(p); + controlCustomParticle(p); pi->files.push_back(*itr); pi->particles.push_back(p); } @@ -4893,7 +4893,7 @@ void Being::recreateItemParticles() restrict2 { Particle *const p = particleEngine->addEffect( *str, 0, 0); - controlParticle(p); + controlCustomParticle(p); pi->particles.push_back(p); } } diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 25699f704..e065fafe4 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -2709,7 +2709,7 @@ void LocalPlayer::setTestParticle(const std::string &fileName, if (!fileName.empty()) { mTestParticle = particleEngine->addEffect(fileName, 0, 0, 0); - controlParticle(mTestParticle); + controlCustomParticle(mTestParticle); if (updateHash) mTestParticleHash = UpdaterWindow::getFileHash(mTestParticleName); } |