diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-12-27 18:37:26 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-12-27 18:37:26 +0300 |
commit | 12f2ce912aa1a7e158f06aa20396f213abdd2583 (patch) | |
tree | cd75248717e990fee8b7418df35eb5d27c195336 /src/particle | |
parent | 3605741892b995144111d4d885cf88063c3f4379 (diff) | |
download | plus-12f2ce912aa1a7e158f06aa20396f213abdd2583.tar.gz plus-12f2ce912aa1a7e158f06aa20396f213abdd2583.tar.bz2 plus-12f2ce912aa1a7e158f06aa20396f213abdd2583.tar.xz plus-12f2ce912aa1a7e158f06aa20396f213abdd2583.zip |
Add restrict keyword to particle.
Diffstat (limited to 'src/particle')
-rw-r--r-- | src/particle/animationparticle.cpp | 6 | ||||
-rw-r--r-- | src/particle/animationparticle.h | 9 | ||||
-rw-r--r-- | src/particle/imageparticle.cpp | 11 | ||||
-rw-r--r-- | src/particle/imageparticle.h | 11 | ||||
-rw-r--r-- | src/particle/particle.cpp | 74 | ||||
-rw-r--r-- | src/particle/particle.h | 96 | ||||
-rw-r--r-- | src/particle/rotationalparticle.cpp | 7 | ||||
-rw-r--r-- | src/particle/rotationalparticle.h | 9 | ||||
-rw-r--r-- | src/particle/textparticle.cpp | 14 | ||||
-rw-r--r-- | src/particle/textparticle.h | 18 |
10 files changed, 141 insertions, 114 deletions
diff --git a/src/particle/animationparticle.cpp b/src/particle/animationparticle.cpp index 919fa34e9..0d51976cb 100644 --- a/src/particle/animationparticle.cpp +++ b/src/particle/animationparticle.cpp @@ -28,14 +28,14 @@ #include "debug.h" -AnimationParticle::AnimationParticle(Animation *const animation) : +AnimationParticle::AnimationParticle(Animation *restrict const animation) : ImageParticle(nullptr), mAnimation(new SimpleAnimation(animation)) { } AnimationParticle::AnimationParticle(XmlNodePtrConst animationNode, - const std::string& dyePalettes) : + const std::string &restrict dyePalettes) : ImageParticle(nullptr), mAnimation(new SimpleAnimation(animationNode, dyePalettes)) { @@ -47,7 +47,7 @@ AnimationParticle::~AnimationParticle() mImage = nullptr; } -bool AnimationParticle::update() +bool AnimationParticle::update() restrict2 { if (mAnimation) { diff --git a/src/particle/animationparticle.h b/src/particle/animationparticle.h index e06d06774..472d91612 100644 --- a/src/particle/animationparticle.h +++ b/src/particle/animationparticle.h @@ -33,20 +33,21 @@ class SimpleAnimation; class AnimationParticle final : public ImageParticle { public: - explicit AnimationParticle(Animation *const animation); + explicit AnimationParticle(Animation *restrict const animation); explicit AnimationParticle(XmlNodePtrConst animationNode, - const std::string& dyePalettes + const std::string &restrict dyePalettes = std::string()); A_DELETE_COPY(AnimationParticle) ~AnimationParticle(); - bool update() override final; + bool update() restrict2 override final; private: - SimpleAnimation *mAnimation; /**< Used animation for this particle */ + /**< Used animation for this particle */ + SimpleAnimation *restrict mAnimation; }; #endif // PARTICLE_ANIMATIONPARTICLE_H diff --git a/src/particle/imageparticle.cpp b/src/particle/imageparticle.cpp index dbef1dd32..484bf53ae 100644 --- a/src/particle/imageparticle.cpp +++ b/src/particle/imageparticle.cpp @@ -30,7 +30,7 @@ StringIntMap ImageParticle::imageParticleCountByName; -ImageParticle::ImageParticle(Image *const image) : +ImageParticle::ImageParticle(Image *restrict const image) : Particle(), mImage(image) { @@ -38,7 +38,7 @@ ImageParticle::ImageParticle(Image *const image) : { mImage->incRef(); - const std::string &name = mImage->getIdPath(); + const std::string &restrict name = mImage->getIdPath(); StringIntMapIter it = ImageParticle::imageParticleCountByName.find(name); if (it == ImageParticle::imageParticleCountByName.end()) @@ -52,7 +52,7 @@ ImageParticle::~ImageParticle() { if (mImage) { - const std::string &name = mImage->getIdPath(); + const std::string &restrict name = mImage->getIdPath(); StringIntMapIter it = ImageParticle::imageParticleCountByName.find(name); if (it != ImageParticle::imageParticleCountByName.end()) @@ -67,8 +67,9 @@ ImageParticle::~ImageParticle() } } -void ImageParticle::draw(Graphics *const graphics, - const int offsetX, const int offsetY) const +void ImageParticle::draw(Graphics *restrict const graphics, + const int offsetX, + const int offsetY) const restrict2 { FUNC_BLOCK("ImageParticle::draw", 1) if (mAlive != ALIVE || !mImage) diff --git a/src/particle/imageparticle.h b/src/particle/imageparticle.h index b6b74362b..637004558 100644 --- a/src/particle/imageparticle.h +++ b/src/particle/imageparticle.h @@ -41,7 +41,7 @@ class ImageParticle notfinal : public Particle * @param map the map this particle appears on * @param image an Image instance, may not be NULL */ - explicit ImageParticle(Image *const image); + explicit ImageParticle(Image *restrict const image); A_DELETE_COPY(ImageParticle) @@ -53,16 +53,17 @@ class ImageParticle notfinal : public Particle /** * Draws the particle image */ - virtual void draw(Graphics *const graphics, + virtual void draw(Graphics *restrict const graphics, const int offsetX, - const int offsetY) const override final A_NONNULL(2); + const int offsetY) const + restrict2 override final A_NONNULL(2); - void setAlpha(const float alpha) override final + void setAlpha(const float alpha) restrict2 override final { mAlpha = alpha; } static StringIntMap imageParticleCountByName; protected: - Image *mImage; /**< The image used for this particle. */ + Image *restrict mImage; /**< The image used for this particle. */ }; #endif // PARTICLE_IMAGEPARTICLE_H diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp index 8fd4ecead..efde2e35e 100644 --- a/src/particle/particle.cpp +++ b/src/particle/particle.cpp @@ -87,7 +87,7 @@ Particle::~Particle() Particle::particleCount--; } -void Particle::setupEngine() +void Particle::setupEngine() restrict2 { Particle::maxCount = config.getIntValue("particleMaxCount"); Particle::fastPhysics = config.getIntValue("particleFastPhysics"); @@ -99,11 +99,12 @@ void Particle::setupEngine() logger->log1("Particle engine set up"); } -void Particle::draw(Graphics *const, const int, const int) const +void Particle::draw(Graphics *restrict const, + const int, const int) const restrict2 { } -bool Particle::update() +bool Particle::update() restrict2 { if (!mMap) return false; @@ -224,7 +225,7 @@ bool Particle::update() if ((static_cast<unsigned int>(mAlive) & mDeathEffectConditions) > 0x00 && !mDeathEffect.empty()) { - Particle *const deathEffect = particleEngine->addEffect( + Particle *restrict const deathEffect = particleEngine->addEffect( mDeathEffect, 0, 0); if (deathEffect) deathEffect->moveBy(mPos); @@ -239,7 +240,7 @@ bool Particle::update() for (ParticleIterator p = mChildParticles.begin(), p2 = mChildParticles.end(); p != p2; ) { - Particle *const particle = *p; + Particle *restrict const particle = *p; // move particle with its parent if desired if (particle->mFollow) particle->moveBy(change); @@ -261,23 +262,23 @@ bool Particle::update() return true; } -void Particle::moveBy(const Vector &change) +void Particle::moveBy(const Vector &restrict change) restrict2 { mPos += change; FOR_EACH (ParticleConstIterator, p, mChildParticles) { - Particle *const particle = *p; + Particle *restrict const particle = *p; if (particle->mFollow) particle->moveBy(change); } } -void Particle::moveTo(const float x, const float y) +void Particle::moveTo(const float x, const float y) restrict2 { moveTo(Vector(x, y, mPos.z)); } -Particle *Particle::createChild() +Particle *Particle::createChild() restrict2 { Particle *const newParticle = new Particle(); newParticle->setMap(mMap); @@ -285,9 +286,9 @@ Particle *Particle::createChild() return newParticle; } -Particle *Particle::addEffect(const std::string &particleEffectFile, +Particle *Particle::addEffect(const std::string &restrict particleEffectFile, const int pixelX, const int pixelY, - const int rotation) + const int rotation) restrict2 { Particle *newParticle = nullptr; @@ -375,8 +376,13 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, { if (xmlNameEqual(emitterNode, "emitter")) { - ParticleEmitter *const newEmitter = new ParticleEmitter( - emitterNode, newParticle, mMap, rotation, dyePalettes); + ParticleEmitter *restrict const newEmitter = + new ParticleEmitter( + emitterNode, + newParticle, + mMap, + rotation, + dyePalettes); newParticle->addEmitter(newEmitter); } else if (xmlNameEqual(emitterNode, "deatheffect")) @@ -425,15 +431,20 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, return newParticle; } -Particle *Particle::addTextSplashEffect(const std::string &text, +Particle *Particle::addTextSplashEffect(const std::string &restrict text, const int x, const int y, - const Color *const color, - Font *const font, - const bool outline) + const Color *restrict const color, + Font *restrict const font, + const bool outline) restrict2 { - Particle *const newParticle = new TextParticle(text, color, font, outline); + Particle *const newParticle = new TextParticle( + text, + color, + font, + outline); newParticle->setMap(mMap); - newParticle->moveTo(static_cast<float>(x), static_cast<float>(y)); + newParticle->moveTo(static_cast<float>(x), + static_cast<float>(y)); newParticle->setVelocity( static_cast<float>((rand() % 100) - 50) / 200.0F, // X static_cast<float>((rand() % 100) - 50) / 200.0F, // Y @@ -449,15 +460,20 @@ Particle *Particle::addTextSplashEffect(const std::string &text, return newParticle; } -Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, +Particle *Particle::addTextRiseFadeOutEffect(const std::string &restrict text, const int x, const int y, - const Color *const color, - Font *const font, - const bool outline) + const Color *restrict const color, + Font *restrict const font, + const bool outline) restrict2 { - Particle *const newParticle = new TextParticle(text, color, font, outline); + Particle *const newParticle = new TextParticle( + text, + color, + font, + outline); newParticle->setMap(mMap); - newParticle->moveTo(static_cast<float>(x), static_cast<float>(y)); + newParticle->moveTo(static_cast<float>(x), + static_cast<float>(y)); newParticle->setVelocity(0.0F, 0.0F, 0.5F); newParticle->setGravity(0.0015F); newParticle->setLifetime(300); @@ -469,7 +485,7 @@ Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, return newParticle; } -void Particle::adjustEmitterSize(const int w, const int h) +void Particle::adjustEmitterSize(const int w, const int h) restrict2 { if (mAllowSizeAdjust) { @@ -478,11 +494,11 @@ void Particle::adjustEmitterSize(const int w, const int h) } } -void Particle::prepareToDie() +void Particle::prepareToDie() restrict2 { FOR_EACH (ParticleIterator, p, mChildParticles) { - Particle *const particle = *p; + Particle *restrict const particle = *p; if (!particle) continue; particle->prepareToDie(); @@ -495,7 +511,7 @@ void Particle::prepareToDie() } } -void Particle::clear() +void Particle::clear() restrict2 { delete_all(mChildEmitters); mChildEmitters.clear(); diff --git a/src/particle/particle.h b/src/particle/particle.h index 3e396a1c0..00f5f6313 100644 --- a/src/particle/particle.h +++ b/src/particle/particle.h @@ -76,157 +76,159 @@ class Particle notfinal : public Actor /** * Deletes all child particles and emitters. */ - void clear(); + void clear() restrict2; /** * Gives a particle the properties of an engine root particle and loads * the particle-related config settings. */ - void setupEngine(); + void setupEngine() restrict2; /** * Updates particle position, returns false when the particle should * be deleted. */ - virtual bool update(); + virtual bool update() restrict2; /** * Draws the particle image. */ - virtual void draw(Graphics *const graphics, + virtual void draw(Graphics *restrict const graphics, const int offsetX, - const int offsetY) const override + const int offsetY) const restrict2 override A_CONST A_NONNULL(2); /** * Necessary for sorting with the other sprites. */ - int getPixelY() const override A_WARN_UNUSED + int getPixelY() const restrict2 override A_WARN_UNUSED { return static_cast<int>(mPos.y) - 16; } /** * Necessary for sorting with the other sprites for sorting only. */ - int getSortPixelY() const override A_WARN_UNUSED + int getSortPixelY() const restrict2 override A_WARN_UNUSED { return static_cast<int>(mPos.y) - 16; } /** * Creates a blank particle as a child of the current particle * Useful for creating target particles */ - Particle *createChild(); + Particle *createChild() restrict2; /** * Creates a child particle that hosts some emitters described in the * particleEffectFile. */ - Particle *addEffect(const std::string &particleEffectFile, + Particle *addEffect(const std::string &restrict particleEffectFile, const int pixelX, const int pixelY, - const int rotation = 0); + const int rotation = 0) restrict2; /** * Creates a standalone text particle. */ - Particle *addTextSplashEffect(const std::string &text, + Particle *addTextSplashEffect(const std::string &restrict text, const int x, const int y, - const Color *const color, - Font *const font, - const bool outline = false); + const Color *restrict const color, + Font *restrict const font, + const bool outline = false) restrict2; /** * Creates a standalone text particle. */ - Particle *addTextRiseFadeOutEffect(const std::string &text, + Particle *addTextRiseFadeOutEffect(const std::string &restrict text, const int x, const int y, - const Color *const color, - Font *const font, - const bool outline = false); + const Color *restrict const color, + Font *restrict const font, + const bool outline = false) + restrict2; /** * Adds an emitter to the particle. */ - void addEmitter(ParticleEmitter *const emitter) + void addEmitter(ParticleEmitter *const emitter) restrict2 { mChildEmitters.push_back(emitter); } /** * Sets the position in 3 dimensional space in pixels relative to map. */ - void moveTo(const Vector &pos) + void moveTo(const Vector &restrict pos) restrict2 { moveBy(pos - mPos); } /** * Sets the position in 2 dimensional space in pixels relative to map. */ - void moveTo(const float x, const float y); + void moveTo(const float x, const float y) restrict2; /** * Changes the particle position relative */ - void moveBy(const Vector &change); + void moveBy(const Vector &restrict change) restrict2; /** * Sets the time in game ticks until the particle is destroyed. */ - void setLifetime(const int lifetime) + void setLifetime(const int lifetime) restrict2 { mLifetimeLeft = lifetime; mLifetimePast = 0; } /** * Sets the age of the pixel in game ticks where the particle has * faded in completely. */ - void setFadeOut(const int fadeOut) + void setFadeOut(const int fadeOut) restrict2 { mFadeOut = fadeOut; } /** * Sets the remaining particle lifetime where the particle starts to * fade out. */ - void setFadeIn(const int fadeIn) + void setFadeIn(const int fadeIn) restrict2 { mFadeIn = fadeIn; } /** * Sets the current velocity in 3 dimensional space. */ - void setVelocity(const float x, const float y, const float z) + void setVelocity(const float x, const float y, const float z) restrict2 { mVelocity.x = x; mVelocity.y = y; mVelocity.z = z; } /** * Sets the downward acceleration. */ - void setGravity(const float gravity) + void setGravity(const float gravity) restrict2 { mGravity = gravity; } /** * Sets the ammount of random vector changes */ - void setRandomness(const int r) + void setRandomness(const int r) restrict2 { mRandomness = r; } /** * Sets the ammount of velocity particles retain after * hitting the ground. */ - void setBounce(const float bouncieness) + void setBounce(const float bouncieness) restrict2 { mBounce = bouncieness; } /** * Sets the flag if the particle is supposed to be moved by its parent */ - void setFollow(const bool follow) + void setFollow(const bool follow) restrict2 { mFollow = follow; } /** * Gets the flag if the particle is supposed to be moved by its parent */ - bool doesFollow() const A_WARN_UNUSED + bool doesFollow() const restrict2 A_WARN_UNUSED { return mFollow; } /** * Makes the particle move toward another particle with a * given acceleration and momentum */ - void setDestination(Particle *const target, - const float accel, const float moment) + void setDestination(Particle *restrict const target, + const float accel, + const float moment) restrict2 { mTarget = target; mAcceleration = accel; mMomentum = moment; } /** @@ -234,54 +236,54 @@ class Particle notfinal : public Actor * particle before it is destroyed. Does only make sense after a target * particle has been set using setDestination. */ - void setDieDistance(const float dist) + void setDieDistance(const float dist) restrict2 { mInvDieDistance = 1.0F / dist; } /** * Changes the size of the emitters so that the effect fills a * rectangle of this size */ - void adjustEmitterSize(const int w, const int h); + void adjustEmitterSize(const int w, const int h) restrict2; - void setAllowSizeAdjust(const bool adjust) + void setAllowSizeAdjust(const bool adjust) restrict2 { mAllowSizeAdjust = adjust; } - bool isAlive() const A_WARN_UNUSED + bool isAlive() const restrict2 A_WARN_UNUSED { return mAlive == ALIVE; } - void prepareToDie(); + void prepareToDie() restrict2; /** * Determines whether the particle and its children are all dead */ - bool isExtinct() const A_WARN_UNUSED + bool isExtinct() const restrict2 A_WARN_UNUSED { return !isAlive() && mChildParticles.empty(); } /** * Manually marks the particle for deletion. */ - void kill() + void kill() restrict2 { mAlive = DEAD_OTHER; mAutoDelete = true; } /** * After calling this function the particle will only request * deletion when kill() is called */ - void disableAutoDelete() + void disableAutoDelete() restrict2 { mAutoDelete = false; } /** We consider particles (at least for now) to be one layer-sprites */ - int getNumberOfLayers() const override final + int getNumberOfLayers() const restrict2 override final { return 1; } - float getAlpha() const override final + float getAlpha() const restrict2 override final { return 1.0F; } - void setAlpha(const float alpha A_UNUSED) override + void setAlpha(const float alpha A_UNUSED) restrict2 override { } - virtual void setDeathEffect(const std::string &effectFile, - const signed char conditions) + virtual void setDeathEffect(const std::string &restrict effectFile, + const signed char conditions) restrict2 { mDeathEffect = effectFile; mDeathEffectConditions = conditions; } protected: @@ -333,7 +335,7 @@ class Particle notfinal : public Actor float mMomentum; // The particle that attracts this particle - Particle *mTarget; + Particle *restrict mTarget; // Ammount of random vector change int mRandomness; diff --git a/src/particle/rotationalparticle.cpp b/src/particle/rotationalparticle.cpp index dc3206601..cee5c3c56 100644 --- a/src/particle/rotationalparticle.cpp +++ b/src/particle/rotationalparticle.cpp @@ -31,14 +31,15 @@ static const double PI = M_PI; static const float PI2 = 2 * M_PI; -RotationalParticle::RotationalParticle(Animation *const animation) : +RotationalParticle::RotationalParticle(Animation *restrict const animation) : ImageParticle(nullptr), mAnimation(new SimpleAnimation(animation)) { } RotationalParticle::RotationalParticle(const XmlNodePtr animationNode, - const std::string& dyePalettes) : + const std::string &restrict + dyePalettes) : ImageParticle(nullptr), mAnimation(new SimpleAnimation(animationNode, dyePalettes)) { @@ -50,7 +51,7 @@ RotationalParticle::~RotationalParticle() mImage = nullptr; } -bool RotationalParticle::update() +bool RotationalParticle::update() restrict2 { if (!mAnimation) return false; diff --git a/src/particle/rotationalparticle.h b/src/particle/rotationalparticle.h index 9cce18899..a3026e2b8 100644 --- a/src/particle/rotationalparticle.h +++ b/src/particle/rotationalparticle.h @@ -33,20 +33,21 @@ class SimpleAnimation; class RotationalParticle final : public ImageParticle { public: - explicit RotationalParticle(Animation *const animation); + explicit RotationalParticle(Animation *restrict const animation); explicit RotationalParticle(const XmlNodePtr animationNode, - const std::string& dyePalettes + const std::string &restrict dyePalettes = std::string()); A_DELETE_COPY(RotationalParticle) ~RotationalParticle(); - bool update() override final; + bool update() restrict2 override final; private: - SimpleAnimation *mAnimation; /**< Used animation for this particle */ + /**< Used animation for this particle */ + SimpleAnimation *restrict mAnimation; }; #endif // PARTICLE_ROTATIONALPARTICLE_H diff --git a/src/particle/textparticle.cpp b/src/particle/textparticle.cpp index 33a0c4b0c..c79b94c81 100644 --- a/src/particle/textparticle.cpp +++ b/src/particle/textparticle.cpp @@ -28,9 +28,10 @@ #include "debug.h" -TextParticle::TextParticle(const std::string &text, - const Color *const color, - Font *const font, const bool outline) : +TextParticle::TextParticle(const std::string &restrict text, + const Color *restrict const color, + Font *restrict const font, + const bool outline) : Particle(), mText(text), mTextFont(font), @@ -40,8 +41,9 @@ TextParticle::TextParticle(const std::string &text, { } -void TextParticle::draw(Graphics *const graphics, - const int offsetX, const int offsetY) const +void TextParticle::draw(Graphics *restrict const graphics, + const int offsetX, + const int offsetY) const restrict2 { if (!mColor || !mTextFont) return; @@ -77,7 +79,7 @@ void TextParticle::draw(Graphics *const graphics, graphics->setColor(color); if (mOutline) { - const Color &color2 = theme->getColor(ThemeColorId::OUTLINE, + const Color &restrict color2 = theme->getColor(ThemeColorId::OUTLINE, static_cast<int>(alpha)); mTextFont->drawString(graphics, color, color2, diff --git a/src/particle/textparticle.h b/src/particle/textparticle.h index 6858ee6a1..d80a7eb24 100644 --- a/src/particle/textparticle.h +++ b/src/particle/textparticle.h @@ -32,30 +32,32 @@ class TextParticle final : public Particle * Constructor. */ TextParticle(const std::string &text, - const Color *const color, - Font *const font, const bool outline = false); + const Color *restrict const color, + Font *restrict const font, + const bool outline = false); A_DELETE_COPY(TextParticle) /** * Draws the particle image. */ - void draw(Graphics *const graphics, + void draw(Graphics *restrict const graphics, const int offsetX, - const int offsetY) const override final A_NONNULL(2); + const int offsetY) const + restrict2 override final A_NONNULL(2); // hack to improve text visibility - int getPixelY() const override final A_WARN_UNUSED + int getPixelY() const restrict2 override final A_WARN_UNUSED { return static_cast<int>(mPos.y + mPos.z); } // hack to improve text visibility (for sorting only) - int getSortPixelY() const override final A_WARN_UNUSED + int getSortPixelY() const restrict2 override final A_WARN_UNUSED { return static_cast<int>(mPos.y + mPos.z); } private: std::string mText; /**< Text of the particle. */ - Font *mTextFont; /**< Font used for drawing the text. */ - const Color *mColor; /**< Color used for drawing the text. */ + Font *restrict mTextFont; /**< Font used for drawing the text. */ + const Color *restrict mColor; /**< Color used for drawing the text. */ int mTextWidth; bool mOutline; /**< Make the text better readable */ }; |