diff options
Diffstat (limited to 'src/particle')
-rw-r--r-- | src/particle/imageparticle.cpp | 8 | ||||
-rw-r--r-- | src/particle/particle.cpp | 36 | ||||
-rw-r--r-- | src/particle/particlecontainer.cpp | 4 | ||||
-rw-r--r-- | src/particle/particleemitter.cpp | 32 | ||||
-rw-r--r-- | src/particle/particleemitterprop.h | 2 | ||||
-rw-r--r-- | src/particle/particleengine.cpp | 18 | ||||
-rw-r--r-- | src/particle/particlelist.cpp | 2 | ||||
-rw-r--r-- | src/particle/particlevector.cpp | 8 | ||||
-rw-r--r-- | src/particle/textparticle.cpp | 6 |
9 files changed, 60 insertions, 56 deletions
diff --git a/src/particle/imageparticle.cpp b/src/particle/imageparticle.cpp index a8b5cd1ae..7e4a6105a 100644 --- a/src/particle/imageparticle.cpp +++ b/src/particle/imageparticle.cpp @@ -35,7 +35,7 @@ ImageParticle::ImageParticle(Image *restrict const image) : { mType = ParticleType::Image; mImage = image; - if (mImage) + if (mImage != nullptr) { mImage->incRef(); @@ -54,7 +54,7 @@ void ImageParticle::draw(Graphics *restrict const graphics, const int offsetY) const restrict2 { FUNC_BLOCK("ImageParticle::draw", 1) - if (mAlive != AliveStatus::ALIVE || !mImage) + if (mAlive != AliveStatus::ALIVE || (mImage == nullptr)) return; const int w = mImage->mBounds.w; @@ -75,13 +75,13 @@ void ImageParticle::draw(Graphics *restrict const graphics, float alphafactor = mAlpha; - if (mFadeOut && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) + if ((mFadeOut != 0) && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) { alphafactor *= static_cast<float>(mLifetimeLeft) / static_cast<float>(mFadeOut); } - if (mFadeIn && mLifetimePast < mFadeIn) + if ((mFadeIn != 0) && mLifetimePast < mFadeIn) { alphafactor *= static_cast<float>(mLifetimePast) / static_cast<float>(mFadeIn); diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp index a1ca0b265..419105cbd 100644 --- a/src/particle/particle.cpp +++ b/src/particle/particle.cpp @@ -88,16 +88,16 @@ Particle::Particle() : Particle::~Particle() { if (mActor != BeingId_zero && - actorManager) + (actorManager != nullptr)) { ActorSprite *const actor = actorManager->findActor(mActor); - if (actor) + if (actor != nullptr) actor->controlParticleDeleted(this); } // Delete child emitters and child particles clear(); delete2(mAnimation); - if (mImage) + if (mImage != nullptr) { if (mType == ParticleType::Image) { @@ -129,7 +129,7 @@ void Particle::updateSelf() restrict2 if (A_LIKELY(mMomentum != 1.0F)) mVelocity *= mMomentum; - if (mTarget && mAcceleration != 0.0F) + if ((mTarget != nullptr) && mAcceleration != 0.0F) { Vector dist = mPos - mTarget->mPos; dist.x *= SIN45; @@ -142,7 +142,7 @@ void Particle::updateSelf() restrict2 dist.x * dist.x + dist.y * dist.y + dist.z * dist.z); break; case 2: - if (!dist.x) + if (dist.x == 0.0f) { invHypotenuse = 0; break; @@ -158,7 +158,7 @@ void Particle::updateSelf() restrict2 break; } - if (invHypotenuse) + if (invHypotenuse != 0.0f) { if (mInvDieDistance > 0.0F && invHypotenuse > mInvDieDistance) mAlive = AliveStatus::DEAD_IMPACT; @@ -210,7 +210,7 @@ void Particle::updateSelf() restrict2 } // Update child emitters - if (ParticleEngine::emitterSkip && + if ((ParticleEngine::emitterSkip != 0) && (mLifetimePast - 1) % ParticleEngine::emitterSkip == 0) { FOR_EACH (EmitterConstIterator, e, mChildEmitters) @@ -239,7 +239,7 @@ void Particle::updateSelf() restrict2 { Particle *restrict const deathEffect = particleEngine->addEffect( mDeathEffect, 0, 0); - if (deathEffect) + if (deathEffect != nullptr) deathEffect->moveBy(mPos); } mAlive = AliveStatus::DEAD_LONG_AGO; @@ -262,7 +262,7 @@ bool Particle::update() restrict2 } else { - if (mAnimation) + if (mAnimation != nullptr) { if (mType == ParticleType::Animation) { @@ -273,7 +273,7 @@ bool Particle::update() restrict2 { // TODO: cache velocities to avoid spamming atan2() const int size = mAnimation->getLength(); - if (!size) + if (size == 0) return false; float rad = static_cast<float>(atan2(mVelocity.x, @@ -415,11 +415,11 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile, XML::Document *doc = Loader::getXml(particleEffectFile.substr(0, pos), UseVirtFs_true, SkipError_false); - if (!doc) + if (doc == nullptr) return nullptr; XmlNodeConstPtrConst rootNode = doc->rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "effect")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "effect")) { logger->log("Error loading particle: %s", particleEffectFile.c_str()); doc->decRef(); @@ -437,20 +437,22 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile, XmlNodePtr node; // Animation - if ((node = XML::findFirstChildByName(effectChildNode, "animation"))) + if ((node = XML::findFirstChildByName(effectChildNode, "animation")) != + nullptr) { newParticle = new AnimationParticle(node, dyePalettes); newParticle->setMap(mMap); } // Rotational else if ((node = XML::findFirstChildByName( - effectChildNode, "rotation"))) + effectChildNode, "rotation")) != nullptr) { newParticle = new RotationalParticle(node, dyePalettes); newParticle->setMap(mMap); } // Image - else if ((node = XML::findFirstChildByName(effectChildNode, "image"))) + else if ((node = XML::findFirstChildByName(effectChildNode, + "image")) != nullptr) { std::string imageSrc; if (XmlHaveChildContent(node)) @@ -505,7 +507,7 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile, else if (xmlNameEqual(emitterNode, "deatheffect")) { std::string deathEffect; - if (node && XmlHaveChildContent(node)) + if ((node != nullptr) && XmlHaveChildContent(node)) deathEffect = XmlChildContent(emitterNode); char deathEffectConditions = 0x00; @@ -560,7 +562,7 @@ void Particle::prepareToDie() restrict2 FOR_EACH (ParticleIterator, p, mChildParticles) { Particle *restrict const particle = *p; - if (!particle) + if (particle == nullptr) continue; particle->prepareToDie(); if (particle->isAlive() && diff --git a/src/particle/particlecontainer.cpp b/src/particle/particlecontainer.cpp index c6c469436..b69cd091d 100644 --- a/src/particle/particlecontainer.cpp +++ b/src/particle/particlecontainer.cpp @@ -44,12 +44,12 @@ ParticleContainer::~ParticleContainer() void ParticleContainer::clear() { clearLocally(); - if (mNext) + if (mNext != nullptr) mNext->clear(); } void ParticleContainer::moveTo(const float x, const float y) { - if (mNext) + if (mNext != nullptr) mNext->moveTo(x, y); } diff --git a/src/particle/particleemitter.cpp b/src/particle/particleemitter.cpp index 1c9293063..c200d787d 100644 --- a/src/particle/particleemitter.cpp +++ b/src/particle/particleemitter.cpp @@ -87,7 +87,7 @@ ParticleEmitter::ParticleEmitter(XmlNodeConstPtrConst emitterNode, mOutputPause.set(0); mParticleAlpha.set(1.0F); - if (!emitterNode) + if (emitterNode == nullptr) return; for_each_xml_child_node(propertyNode, emitterNode) { @@ -119,7 +119,7 @@ ParticleEmitter::ParticleEmitter(XmlNodeConstPtrConst emitterNode, std::string image = XML::getProperty( propertyNode, "value", ""); // Don't leak when multiple images are defined - if (!image.empty() && !mParticleImage) + if (!image.empty() && (mParticleImage == nullptr)) { if (!dyePalettes.empty()) Dye::instantiate(image, dyePalettes); @@ -131,12 +131,12 @@ ParticleEmitter::ParticleEmitter(XmlNodeConstPtrConst emitterNode, std::string image = XML::getProperty( propertyNode, "value", ""); // Don't leak when multiple images are defined - if (!image.empty() && !mParticleImage) + if (!image.empty() && (mParticleImage == nullptr)) { if (!dyePalettes.empty()) Dye::instantiate(image, dyePalettes); Image *img = Loader::getImage(image); - if (img) + if (img != nullptr) { mParticleImage = Loader::getSubImage(img, XML::getProperty(propertyNode, "x", 0), @@ -254,15 +254,15 @@ ParticleEmitter::ParticleEmitter(XmlNodeConstPtrConst emitterNode, || xmlNameEqual(propertyNode, "animation")) { ImageSet *const imageset = getImageSet(propertyNode); - if (!imageset) + if (imageset == nullptr) { logger->log1("Error: no valid imageset"); continue; } mTempSets.push_back(imageset); - Animation &animation = (xmlNameEqual(propertyNode, "rotation")) ? - mParticleRotation : mParticleAnimation; + Animation &animation = (xmlNameEqual(propertyNode, "rotation")) != + 0 ? mParticleRotation : mParticleAnimation; // Get animation frames for_each_xml_child_node(frameNode, propertyNode) @@ -288,7 +288,7 @@ ParticleEmitter::ParticleEmitter(XmlNodeConstPtrConst emitterNode, Image *const img = imageset->get(index); - if (!img) + if (img == nullptr) { logger->log("No image at index %d", index); continue; @@ -311,7 +311,7 @@ ParticleEmitter::ParticleEmitter(XmlNodeConstPtrConst emitterNode, while (end >= start) { Image *const img = imageset->get(start); - if (!img) + if (img == nullptr) { logger->log("No image at index %d", start); continue; @@ -376,14 +376,14 @@ ImageSet *ParticleEmitter::getImageSet(XmlNodePtrConst node) { Image *const img = Loader::getImage(XML::getProperty( node, "imageset", "")); - if (!img) + if (img == nullptr) return nullptr; Image *const img2 = Loader::getSubImage(img, subX, XML::getProperty(node, "subY", 0), XML::getProperty(node, "subWidth", 0), XML::getProperty(node, "subHeight", 0)); - if (!img2) + if (img2 == nullptr) { img->decRef(); return nullptr; @@ -438,13 +438,13 @@ ParticleEmitter & ParticleEmitter::operator=(const ParticleEmitter &o) FOR_EACH (ImageSetVectorCIter, i, mTempSets) { - if (*i) + if (*i != nullptr) (*i)->incRef(); } mOutputPauseLeft = 0; - if (mParticleImage) + if (mParticleImage != nullptr) mParticleImage->incRef(); return *this; @@ -454,12 +454,12 @@ ParticleEmitter::~ParticleEmitter() { FOR_EACH (ImageSetVectorCIter, i, mTempSets) { - if (*i) + if (*i != nullptr) (*i)->decRef(); } mTempSets.clear(); - if (mParticleImage) + if (mParticleImage != nullptr) { mParticleImage->decRef(); mParticleImage = nullptr; @@ -525,7 +525,7 @@ void ParticleEmitter::createParticles(const int tick, break; Particle *newParticle = nullptr; - if (mParticleImage) + if (mParticleImage != nullptr) { const std::string &name = mParticleImage->mIdPath; if (ImageParticle::imageParticleCountByName.find(name) == diff --git a/src/particle/particleemitterprop.h b/src/particle/particleemitterprop.h index 0bc35ae14..da7d0ac5b 100644 --- a/src/particle/particleemitterprop.h +++ b/src/particle/particleemitterprop.h @@ -62,7 +62,7 @@ template <typename T> struct ParticleEmitterProp final changeFunc = func; changeAmplitude = amplitude; changePeriod = period; - if (!changePeriod) + if (changePeriod == 0) changePeriod = 1; changePhase = phase; } diff --git a/src/particle/particleengine.cpp b/src/particle/particleengine.cpp index 2ac1d7166..51620a11e 100644 --- a/src/particle/particleengine.cpp +++ b/src/particle/particleengine.cpp @@ -70,7 +70,7 @@ void ParticleEngine::setupEngine() restrict2 ParticleEngine::fastPhysics = config.getIntValue("particleFastPhysics"); ParticleEngine::emitterSkip = config.getIntValue("particleEmitterSkip") + 1; - if (!ParticleEngine::emitterSkip) + if (ParticleEngine::emitterSkip == 0) ParticleEngine::emitterSkip = 1; ParticleEngine::enabled = config.getBoolValue("particleeffects"); logger->log1("Particle engine set up"); @@ -78,7 +78,7 @@ void ParticleEngine::setupEngine() restrict2 bool ParticleEngine::update() restrict2 { - if (mChildParticles.empty() || !mMap) + if (mChildParticles.empty() || (mMap == nullptr)) return true; // Update child particles @@ -139,12 +139,12 @@ Particle *ParticleEngine::addEffect(const std::string &restrict particleEffectFile.substr(0, pos), UseVirtFs_true, SkipError_false); - if (!doc) + if (doc == nullptr) return nullptr; XmlNodeConstPtrConst rootNode = doc->rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "effect")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "effect")) { logger->log("Error loading particle: %s", particleEffectFile.c_str()); doc->decRef(); @@ -162,20 +162,22 @@ Particle *ParticleEngine::addEffect(const std::string &restrict XmlNodePtr node; // Animation - if ((node = XML::findFirstChildByName(effectChildNode, "animation"))) + if ((node = XML::findFirstChildByName(effectChildNode, "animation")) != + nullptr) { newParticle = new AnimationParticle(node, dyePalettes); newParticle->setMap(mMap); } // Rotational else if ((node = XML::findFirstChildByName( - effectChildNode, "rotation"))) + effectChildNode, "rotation")) != nullptr) { newParticle = new RotationalParticle(node, dyePalettes); newParticle->setMap(mMap); } // Image - else if ((node = XML::findFirstChildByName(effectChildNode, "image"))) + else if ((node = XML::findFirstChildByName(effectChildNode, + "image")) != nullptr) { std::string imageSrc; if (XmlHaveChildContent(node)) @@ -230,7 +232,7 @@ Particle *ParticleEngine::addEffect(const std::string &restrict else if (xmlNameEqual(emitterNode, "deatheffect")) { std::string deathEffect; - if (node && XmlHaveChildContent(node)) + if ((node != nullptr) && XmlHaveChildContent(node)) deathEffect = XmlChildContent(emitterNode); char deathEffectConditions = 0x00; diff --git a/src/particle/particlelist.cpp b/src/particle/particlelist.cpp index e254da1be..d854a1da2 100644 --- a/src/particle/particlelist.cpp +++ b/src/particle/particlelist.cpp @@ -42,7 +42,7 @@ ParticleList::~ParticleList() void ParticleList::addLocally(Particle *const particle) { - if (particle) + if (particle != nullptr) { mElements.push_back(particle); mSize ++; diff --git a/src/particle/particlevector.cpp b/src/particle/particlevector.cpp index aa7ce828a..ba8c0a0a7 100644 --- a/src/particle/particlevector.cpp +++ b/src/particle/particlevector.cpp @@ -44,7 +44,7 @@ void ParticleVector::setLocally(const int index, Particle *const particle) if (mIndexedElements.size() <= CAST_SIZE(index)) mIndexedElements.resize(index + 1, nullptr); - if (particle) + if (particle != nullptr) particle->disableAutoDelete(); mIndexedElements[index] = particle; } @@ -58,7 +58,7 @@ void ParticleVector::delLocally(const int index) return; Particle *const p = mIndexedElements[index]; - if (p) + if (p != nullptr) { mIndexedElements[index] = nullptr; p->kill(); @@ -83,7 +83,7 @@ void ParticleVector::moveTo(const float x, const float y) it != mIndexedElements.end(); ++it) { Particle *const p = *it; - if (p) + if (p != nullptr) { p->moveTo(x, y); @@ -102,7 +102,7 @@ size_t ParticleVector::usedSize() const for (std::vector<Particle *>::const_iterator it = mIndexedElements.begin(); it != mIndexedElements.end(); ++it) { - if (*it) + if (*it != nullptr) cnt ++; } return cnt; diff --git a/src/particle/textparticle.cpp b/src/particle/textparticle.cpp index 84eb4f8ef..cf4da05f4 100644 --- a/src/particle/textparticle.cpp +++ b/src/particle/textparticle.cpp @@ -38,7 +38,7 @@ TextParticle::TextParticle(const std::string &restrict text, mText(text), mTextFont(font), mColor(color), - mTextWidth(mTextFont ? mTextFont->getWidth(mText) / 2 : 1), + mTextWidth(mTextFont != nullptr ? mTextFont->getWidth(mText) / 2 : 1), mOutline(outline) { mType = ParticleType::Text; @@ -61,13 +61,13 @@ void TextParticle::draw(Graphics *restrict const graphics, float alpha = mAlpha * 255.0F; - if (mFadeOut && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) + if ((mFadeOut != 0) && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) { alpha *= static_cast<float>(mLifetimeLeft) / static_cast<float>(mFadeOut); } - if (mFadeIn && mLifetimePast < mFadeIn) + if ((mFadeIn != 0) && mLifetimePast < mFadeIn) { alpha *= static_cast<float>(mLifetimePast) / static_cast<float>(mFadeIn); |