diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-12-27 17:17:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-12-27 17:17:23 +0300 |
commit | 291db13dde3359af019e28a55ca520ba079cfaf1 (patch) | |
tree | d33f08202fac88c54bcc3690813c7af2d0bd3d33 | |
parent | e8f23ab1a27c0b8e110c99ddb8e51aaa57c1c748 (diff) | |
download | plus-291db13dde3359af019e28a55ca520ba079cfaf1.tar.gz plus-291db13dde3359af019e28a55ca520ba079cfaf1.tar.bz2 plus-291db13dde3359af019e28a55ca520ba079cfaf1.tar.xz plus-291db13dde3359af019e28a55ca520ba079cfaf1.zip |
Add restrict keyrowrd in animatedsprite.
-rw-r--r-- | src/resources/sprite/animatedsprite.cpp | 78 | ||||
-rw-r--r-- | src/resources/sprite/animatedsprite.h | 75 |
2 files changed, 78 insertions, 75 deletions
diff --git a/src/resources/sprite/animatedsprite.cpp b/src/resources/sprite/animatedsprite.cpp index 58ee1864b..32a0cf983 100644 --- a/src/resources/sprite/animatedsprite.cpp +++ b/src/resources/sprite/animatedsprite.cpp @@ -40,7 +40,7 @@ bool AnimatedSprite::mEnableCache = false; -AnimatedSprite::AnimatedSprite(SpriteDef *const sprite) : +AnimatedSprite::AnimatedSprite(SpriteDef *restrict const sprite) : mDirection(SpriteDirection::DOWN), mLastTime(0), mFrameIndex(0), @@ -61,41 +61,45 @@ AnimatedSprite::AnimatedSprite(SpriteDef *const sprite) : mSprite->incRef(); } -AnimatedSprite *AnimatedSprite::load(const std::string &filename, +AnimatedSprite *AnimatedSprite::load(const std::string &restrict filename, const int variant) { - SpriteDef *const s = resourceManager->getSprite(filename, variant); + SpriteDef *restrict const s = resourceManager->getSprite( + filename, variant); if (!s) return nullptr; - AnimatedSprite *const as = new AnimatedSprite(s); + AnimatedSprite *restrict const as = new AnimatedSprite(s); as->play(SpriteAction::STAND); s->decRef(); return as; } -AnimatedSprite *AnimatedSprite::delayedLoad(const std::string &filename, +AnimatedSprite *AnimatedSprite::delayedLoad(const std::string &restrict + filename, const int variant) { if (!mEnableCache) return load(filename, variant); - Resource *const res = resourceManager->getFromCache(filename, variant); + Resource *restrict const res = resourceManager->getFromCache( + filename, variant); if (res) { res->decRef(); return load(filename, variant); } - AnimatedSprite *const as = new AnimatedSprite(nullptr); + AnimatedSprite *restrict const as = new AnimatedSprite(nullptr); as->play(SpriteAction::STAND); as->setDelayLoad(filename, variant); return as; } -AnimatedSprite *AnimatedSprite::clone(const AnimatedSprite *const anim) +AnimatedSprite *AnimatedSprite::clone(const AnimatedSprite *restrict const + anim) { if (!anim) return nullptr; - AnimatedSprite *const sprite = new AnimatedSprite(anim->mSprite); + AnimatedSprite *restrict const sprite = new AnimatedSprite(anim->mSprite); sprite->play(SpriteAction::STAND); return sprite; } @@ -115,7 +119,7 @@ AnimatedSprite::~AnimatedSprite() } } -bool AnimatedSprite::reset() +bool AnimatedSprite::reset() restrict2 { const bool ret = mFrameIndex !=0 || mFrameTime != 0 || @@ -132,7 +136,7 @@ bool AnimatedSprite::reset() return ret; } -bool AnimatedSprite::play(const std::string &spriteAction) +bool AnimatedSprite::play(const std::string &restrict spriteAction) restrict2 { if (!mSprite) { @@ -162,7 +166,7 @@ bool AnimatedSprite::play(const std::string &spriteAction) return false; } -bool AnimatedSprite::update(const int time) +bool AnimatedSprite::update(const int time) restrict2 { // Avoid freaking out at first frame or when tick_time overflows if (time < mLastTime || mLastTime == 0) @@ -175,8 +179,8 @@ bool AnimatedSprite::update(const int time) const unsigned int dt = time - mLastTime; mLastTime = time; - const Animation *const animation = mAnimation; - const Frame *const frame = mFrame; + const Animation *restrict const animation = mAnimation; + const Frame *restrict const frame = mFrame; if (!updateCurrentAnimation(dt)) { @@ -189,7 +193,7 @@ bool AnimatedSprite::update(const int time) return animation != mAnimation || frame != mFrame; } -bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) +bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2 { // move code from Animation::isTerminator(*mFrame) if (!mFrame || !mAnimation || (!mFrame->image @@ -230,7 +234,7 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) { for (size_t i = 0; i < mAnimation->getLength(); i ++) { - const Frame *const frame = &mAnimation->mFrames[i]; + const Frame *restrict const frame = &mAnimation->mFrames[i]; if (frame->type == Frame::LABEL && mFrame->nextAction == frame->nextAction) { @@ -299,15 +303,15 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) return true; } -void AnimatedSprite::draw(Graphics *const graphics, +void AnimatedSprite::draw(Graphics *restrict const graphics, const int posX, - const int posY) const + const int posY) const restrict2 { FUNC_BLOCK("AnimatedSprite::draw", 1) if (!mFrame || !mFrame->image) return; - Image *const image = mFrame->image; + Image *restrict const image = mFrame->image; if (image->getAlpha() != mAlpha) image->setAlpha(mAlpha); @@ -316,6 +320,7 @@ void AnimatedSprite::draw(Graphics *const graphics, } bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction) + restrict2 { if (mDirection != direction) { @@ -324,7 +329,8 @@ bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction) if (!mAction) return false; - const Animation *const animation = mAction->getAnimation(mDirection); + const Animation *restrict const animation = + mAction->getAnimation(mDirection); if (animation && animation != mAnimation && @@ -340,12 +346,7 @@ bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction) return false; } -unsigned int AnimatedSprite::getCurrentFrame() const -{ - return mFrameIndex; -} - -unsigned int AnimatedSprite::getFrameCount() const +unsigned int AnimatedSprite::getFrameCount() const restrict2 { if (mAnimation) return static_cast<unsigned int>(mAnimation->getLength()); @@ -353,7 +354,7 @@ unsigned int AnimatedSprite::getFrameCount() const return 0; } -int AnimatedSprite::getWidth() const +int AnimatedSprite::getWidth() const restrict2 { if (mFrame && mFrame->image) return mFrame->image->mBounds.w; @@ -361,7 +362,7 @@ int AnimatedSprite::getWidth() const return 0; } -int AnimatedSprite::getHeight() const +int AnimatedSprite::getHeight() const restrict2 { if (mFrame && mFrame->image) return mFrame->image->mBounds.h; @@ -369,38 +370,38 @@ int AnimatedSprite::getHeight() const return 0; } -std::string AnimatedSprite::getIdPath() const +std::string AnimatedSprite::getIdPath() const restrict2 { if (!mSprite) return ""; return mSprite->getIdPath(); } -const Image* AnimatedSprite::getImage() const +const Image* AnimatedSprite::getImage() const restrict2 { return mFrame ? mFrame->image : nullptr; } -void AnimatedSprite::setAlpha(float alpha) +void AnimatedSprite::setAlpha(float alpha) restrict2 { mAlpha = alpha; if (mFrame) { - Image *const image = mFrame->image; + Image *restrict const image = mFrame->image; if (image && image->getAlpha() != mAlpha) image->setAlpha(mAlpha); } } -const void *AnimatedSprite::getHash() const +const void *AnimatedSprite::getHash() const restrict2 { if (mFrame) return mFrame; return this; } -bool AnimatedSprite::updateNumber(const unsigned num) +bool AnimatedSprite::updateNumber(const unsigned num) restrict2 { // TODO need store num in delayed object if it exist for future usage if (!mSprite) @@ -420,8 +421,8 @@ bool AnimatedSprite::updateNumber(const unsigned num) return false; } -void AnimatedSprite::setDelayLoad(const std::string &filename, - const int variant) +void AnimatedSprite::setDelayLoad(const std::string &restrict filename, + const int variant) restrict2 { if (mDelayLoad) { @@ -432,8 +433,3 @@ void AnimatedSprite::setDelayLoad(const std::string &filename, mDelayLoad = new AnimationDelayLoad(filename, variant, this); DelayedManager::addDelayedAnimation(mDelayLoad); } - -void AnimatedSprite::clearDelayLoad() -{ - mDelayLoad = nullptr; -} diff --git a/src/resources/sprite/animatedsprite.h b/src/resources/sprite/animatedsprite.h index db21e661d..f9971cb5b 100644 --- a/src/resources/sprite/animatedsprite.h +++ b/src/resources/sprite/animatedsprite.h @@ -39,7 +39,7 @@ class AnimatedSprite final : public Sprite * Constructor. * @param sprite the sprite to animate */ - explicit AnimatedSprite(SpriteDef *const sprite); + explicit AnimatedSprite(SpriteDef *restrict const sprite); A_DELETE_COPY(AnimatedSprite) @@ -50,83 +50,90 @@ class AnimatedSprite final : public Sprite * @param filename the file of the sprite to animate * @param variant the sprite variant */ - static AnimatedSprite *load(const std::string &filename, + static AnimatedSprite *load(const std::string &restrict filename, const int variant = 0) A_WARN_UNUSED; - static AnimatedSprite *delayedLoad(const std::string &filename, + static AnimatedSprite *delayedLoad(const std::string &restrict + filename, const int variant = 0) A_WARN_UNUSED; - static AnimatedSprite *clone(const AnimatedSprite *const anim); + static AnimatedSprite *clone(const AnimatedSprite *restrict const + anim); ~AnimatedSprite(); - bool reset() override final; + bool reset() restrict2 override final; - bool play(const std::string &action) override final; + bool play(const std::string &restrict action) restrict2 override final; - bool update(const int time) override final; + bool update(const int time) restrict2 override final; - void draw(Graphics *const graphics, + void draw(Graphics *restrict const graphics, const int posX, - const int posY) const override final A_NONNULL(2); + const int posY) const restrict2 override final A_NONNULL(2); - int getWidth() const override final A_WARN_UNUSED; + int getWidth() const restrict2 override final A_WARN_UNUSED; - int getHeight() const override final A_WARN_UNUSED; + int getHeight() const restrict2 override final A_WARN_UNUSED; - const Image* getImage() const override final A_WARN_UNUSED; + const Image* getImage() const restrict2 override final A_WARN_UNUSED; bool setSpriteDirection(const SpriteDirection::Type direction) - override final; + restrict2 override final; - int getNumberOfLayers() const A_WARN_UNUSED + int getNumberOfLayers() const restrict2 A_WARN_UNUSED { return 1; } - std::string getIdPath() const A_WARN_UNUSED; + std::string getIdPath() const restrict2 A_WARN_UNUSED; - unsigned int getCurrentFrame() const override final A_WARN_UNUSED; + unsigned int getCurrentFrame() const + restrict2 override final A_WARN_UNUSED + { return mFrameIndex; } - unsigned int getFrameCount() const override final A_WARN_UNUSED; + unsigned int getFrameCount() const + restrict2 override final A_WARN_UNUSED; - void setAlpha(float alpha) override final; + void setAlpha(float alpha) restrict2 override final; - const void *getHash() const override final A_WARN_UNUSED; + const void *getHash() const restrict2 override final A_WARN_UNUSED; - bool updateNumber(const unsigned num) override final; + bool updateNumber(const unsigned num) restrict2 override final; - void clearDelayLoad(); + void clearDelayLoad() restrict2 + { mDelayLoad = nullptr; } - void setSprite(SpriteDef *const sprite) + void setSprite(SpriteDef *restrict const sprite) restrict2 { mSprite = sprite; } - bool isTerminated() const + bool isTerminated() const restrict2 { return mTerminated; } static void setEnableCache(const bool b) { mEnableCache = b; } #ifdef UNITTESTS - SpriteDef *getSprite() + SpriteDef *getSprite() restrict2 { return mSprite; } - const Frame *getFrame() const + const Frame *getFrame() const restrict2 { return mFrame; } - const Animation *getAnimation() const + const Animation *getAnimation() const restrict2 { return mAnimation; } - unsigned int getFrameIndex() const + unsigned int getFrameIndex() const restrict2 { return mFrameIndex; } - unsigned int getFrameTime() const + unsigned int getFrameTime() const restrict2 { return mFrameTime; } #endif private: - bool updateCurrentAnimation(const unsigned int dt); + bool updateCurrentAnimation(const unsigned int dt) restrict2; - void setDelayLoad(const std::string &filename, const int variant); + void setDelayLoad(const std::string &restrict filename, + const int variant) restrict2; SpriteDirection::Type mDirection; /**< The sprite direction. */ int mLastTime; /**< The last time update was called. */ @@ -134,10 +141,10 @@ class AnimatedSprite final : public Sprite unsigned int mFrameIndex; /**< The index of the current frame. */ unsigned int mFrameTime; /**< The time since start of frame. */ - SpriteDef *mSprite; /**< The sprite definition. */ - const Action *mAction; /**< The currently active action. */ - const Animation *mAnimation; /**< The currently active animation. */ - const Frame *mFrame; /**< The currently active frame. */ + SpriteDef *restrict mSprite; /**< The sprite definition. */ + const Action *restrict mAction; /**< The currently active action. */ + const Animation *restrict mAnimation; /**< The currently active animation. */ + const Frame *restrict mFrame; /**< The currently active frame. */ unsigned mNumber; unsigned mNumber1; AnimationDelayLoad *mDelayLoad; |