From c4a6dd36733fc3365d5a8913e8cdc7b4c1175c8d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 16 Mar 2016 21:21:32 +0300 Subject: Move image field from ImageParticle into Particle. --- src/particle/imageparticle.cpp | 20 ++------------------ src/particle/imageparticle.h | 3 --- src/particle/particle.cpp | 18 ++++++++++++++++++ src/particle/particle.h | 4 ++++ 4 files changed, 24 insertions(+), 21 deletions(-) (limited to 'src/particle') diff --git a/src/particle/imageparticle.cpp b/src/particle/imageparticle.cpp index e58a9e887..57fbddd93 100644 --- a/src/particle/imageparticle.cpp +++ b/src/particle/imageparticle.cpp @@ -31,11 +31,10 @@ StringIntMap ImageParticle::imageParticleCountByName; ImageParticle::ImageParticle(Image *restrict const image) : - Particle(), - mImage(image) + Particle() { mType = ParticleType::Image; - + mImage = image; if (mImage) { mImage->incRef(); @@ -52,21 +51,6 @@ ImageParticle::ImageParticle(Image *restrict const image) : ImageParticle::~ImageParticle() { - if (mImage) - { - const std::string &restrict name = mImage->getIdPath(); - StringIntMapIter it - = ImageParticle::imageParticleCountByName.find(name); - if (it != ImageParticle::imageParticleCountByName.end()) - { - int &cnt = (*it).second; - if (cnt > 0) - cnt --; - } - - mImage->decRef(); - mImage = nullptr; - } } void ImageParticle::draw(Graphics *restrict const graphics, diff --git a/src/particle/imageparticle.h b/src/particle/imageparticle.h index 0fdac0d60..78217b863 100644 --- a/src/particle/imageparticle.h +++ b/src/particle/imageparticle.h @@ -62,9 +62,6 @@ class ImageParticle notfinal : public Particle { mAlpha = alpha; } static StringIntMap imageParticleCountByName; - protected: - /**< The image used for this particle. */ - Image *restrict mImage; }; #endif // PARTICLE_IMAGEPARTICLE_H diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp index 0805aed8c..db25f3c77 100644 --- a/src/particle/particle.cpp +++ b/src/particle/particle.cpp @@ -32,6 +32,7 @@ #include "particle/rotationalparticle.h" #include "particle/textparticle.h" +#include "resources/image.h" #include "resources/resourcemanager.h" #include "resources/animation/simpleanimation.h" @@ -60,6 +61,7 @@ Particle::Particle() : mAlive(AliveStatus::ALIVE), mType(ParticleType::Normal), mAnimation(nullptr), + mImage(nullptr), mChildEmitters(), mChildParticles(), mDeathEffect(), @@ -83,6 +85,22 @@ Particle::~Particle() // Delete child emitters and child particles clear(); delete2(mAnimation); + if (mImage) + { + const std::string &restrict name = mImage->getIdPath(); + StringIntMapIter it + = ImageParticle::imageParticleCountByName.find(name); + if (it != ImageParticle::imageParticleCountByName.end()) + { + int &cnt = (*it).second; + if (cnt > 0) + cnt --; + } + + mImage->decRef(); + mImage = nullptr; + } + ParticleEngine::particleCount--; } diff --git a/src/particle/particle.h b/src/particle/particle.h index eb971ec4a..7f132c0a1 100644 --- a/src/particle/particle.h +++ b/src/particle/particle.h @@ -34,6 +34,7 @@ class Color; class Font; +class Image; class Particle; class ParticleEmitter; class SimpleAnimation; @@ -268,6 +269,9 @@ class Particle notfinal : public Actor /**< Used animation for this particle */ SimpleAnimation *restrict mAnimation; + /**< The image used for this particle. */ + Image *restrict mImage; + private: // List of child emitters. Emitters mChildEmitters; -- cgit v1.2.3-70-g09d2