summaryrefslogtreecommitdiff
path: root/src/resources/sprite
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-06-06 23:34:34 +0300
committerAndrei Karas <akaras@inbox.ru>2017-06-07 19:23:40 +0300
commit36ba43d6ea38062b17f7e63ef659962bfc51c64d (patch)
tree190156cb88b13a38a6d13c69ee0742cc078065a1 /src/resources/sprite
parentf1518dd8476c968a43fa57cfb06198e290a4f77a (diff)
downloadmv-36ba43d6ea38062b17f7e63ef659962bfc51c64d.tar.gz
mv-36ba43d6ea38062b17f7e63ef659962bfc51c64d.tar.bz2
mv-36ba43d6ea38062b17f7e63ef659962bfc51c64d.tar.xz
mv-36ba43d6ea38062b17f7e63ef659962bfc51c64d.zip
Fix clang-tidy check readability-implicit-bool-cast.
Diffstat (limited to 'src/resources/sprite')
-rw-r--r--src/resources/sprite/animatedsprite.cpp71
-rw-r--r--src/resources/sprite/animationdelayload.cpp6
-rw-r--r--src/resources/sprite/imagesprite.cpp6
-rw-r--r--src/resources/sprite/imagesprite.h4
-rw-r--r--src/resources/sprite/spritedef.cpp40
5 files changed, 66 insertions, 61 deletions
diff --git a/src/resources/sprite/animatedsprite.cpp b/src/resources/sprite/animatedsprite.cpp
index 7b6900510..be620a52c 100644
--- a/src/resources/sprite/animatedsprite.cpp
+++ b/src/resources/sprite/animatedsprite.cpp
@@ -63,7 +63,7 @@ AnimatedSprite::AnimatedSprite(SpriteDef *restrict const sprite) :
mAlpha = 1.0F;
// Take possession of the sprite
- if (mSprite)
+ if (mSprite != nullptr)
mSprite->incRef();
}
@@ -72,7 +72,7 @@ AnimatedSprite *AnimatedSprite::load(const std::string &restrict filename,
{
SpriteDef *restrict const s = Loader::getSprite(
filename, variant);
- if (!s)
+ if (s == nullptr)
return nullptr;
AnimatedSprite *restrict const as = new AnimatedSprite(s);
#ifdef DEBUG_ANIMATIONS
@@ -92,7 +92,7 @@ AnimatedSprite *AnimatedSprite::delayedLoad(const std::string &restrict
return load(filename, variant);
Resource *restrict const res = ResourceManager::getFromCache(
filename, variant);
- if (res)
+ if (res != nullptr)
{
res->decRef();
return load(filename, variant);
@@ -111,7 +111,7 @@ AnimatedSprite *AnimatedSprite::delayedLoad(const std::string &restrict
AnimatedSprite *AnimatedSprite::clone(const AnimatedSprite *restrict const
anim)
{
- if (!anim)
+ if (anim == nullptr)
return nullptr;
AnimatedSprite *restrict const sprite = new AnimatedSprite(anim->mSprite);
#ifdef DEBUG_ANIMATIONS
@@ -124,12 +124,12 @@ AnimatedSprite *AnimatedSprite::clone(const AnimatedSprite *restrict const
AnimatedSprite::~AnimatedSprite()
{
- if (mSprite)
+ if (mSprite != nullptr)
{
mSprite->decRef();
mSprite = nullptr;
}
- if (mDelayLoad)
+ if (mDelayLoad != nullptr)
{
mDelayLoad->clearSprite();
DelayedManager::removeDelayLoad(mDelayLoad);
@@ -147,7 +147,7 @@ bool AnimatedSprite::reset() restrict2
mFrameTime = 0;
mLastTime = 0;
- if (mAnimation)
+ if (mAnimation != nullptr)
mFrame = &mAnimation->mFrames[0];
else
mFrame = nullptr;
@@ -156,22 +156,22 @@ bool AnimatedSprite::reset() restrict2
bool AnimatedSprite::play(const std::string &restrict spriteAction) restrict2
{
- if (!mSprite)
+ if (mSprite == nullptr)
{
- if (!mDelayLoad)
+ if (mDelayLoad == nullptr)
return false;
mDelayLoad->setAction(spriteAction);
return true;
}
const Action *const action = mSprite->getAction(spriteAction, mNumber);
- if (!action)
+ if (action == nullptr)
return false;
mAction = action;
const Animation *const animation = mAction->getAnimation(mDirection);
- if (animation &&
+ if ((animation != nullptr) &&
animation != mAnimation &&
animation->getLength() > 0)
{
@@ -191,7 +191,7 @@ bool AnimatedSprite::update(const int time) restrict2
mLastTime = time;
// If not enough time has passed yet, do nothing
- if (time <= mLastTime || !mAnimation)
+ if (time <= mLastTime || (mAnimation == nullptr))
return false;
const unsigned int dt = time - mLastTime;
@@ -214,8 +214,9 @@ bool AnimatedSprite::update(const int time) restrict2
bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
{
// move code from Animation::isTerminator(*mFrame)
- if (!mFrame || !mAnimation || (!mFrame->image
- && mFrame->type == FrameType::ANIMATION))
+ if (mFrame == nullptr ||
+ mAnimation == nullptr ||
+ (mFrame->image == nullptr && mFrame->type == FrameType::ANIMATION))
{
return false;
}
@@ -245,7 +246,7 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
{
const int rand = mFrame->rand;
if (rand == 100 ||
- (rand && rand >= mrand() % 100))
+ ((rand != 0) && rand >= mrand() % 100))
{
for (size_t i = 0; i < mAnimation->getLength(); i ++)
{
@@ -278,19 +279,19 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
{
const int rand = mFrame->rand;
if (rand == 100 ||
- (rand && rand >= mrand() % 100))
+ ((rand != 0) && rand >= mrand() % 100))
{
play(mFrame->nextAction);
return true;
}
}
// copy code from Animation::isTerminator(*mFrame)
- else if (!mFrame->image &&
+ else if ((mFrame->image == nullptr) &&
mFrame->type == FrameType::ANIMATION)
{
const int rand = mFrame->rand;
if (rand == 100 ||
- (rand && rand >= mrand() % 100))
+ ((rand != 0) && rand >= mrand() % 100))
{
mAnimation = nullptr;
mFrame = nullptr;
@@ -307,13 +308,13 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
}
else
{
- if (rand && mrand() % 100 <= rand)
+ if ((rand != 0) && mrand() % 100 <= rand)
fail = false;
}
}
if (fail)
{
- if (mFrame)
+ if (mFrame != nullptr)
mFrameTime = mFrame->delay + 1;
else
mFrameTime ++;
@@ -327,7 +328,7 @@ void AnimatedSprite::draw(Graphics *restrict const graphics,
const int posY) const restrict2
{
FUNC_BLOCK("AnimatedSprite::draw", 1)
- if (!mFrame || !mFrame->image)
+ if ((mFrame == nullptr) || (mFrame->image == nullptr))
return;
Image *restrict const image = mFrame->image;
@@ -340,7 +341,7 @@ void AnimatedSprite::drawRaw(Graphics *restrict const graphics,
const int posX,
const int posY) const restrict2
{
- if (!mFrame || !mFrame->image)
+ if ((mFrame == nullptr) || (mFrame->image == nullptr))
return;
Image *restrict const image = mFrame->image;
@@ -357,13 +358,13 @@ bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction)
{
mDirection = direction;
- if (!mAction)
+ if (mAction == nullptr)
return false;
const Animation *restrict const animation =
mAction->getAnimation(mDirection);
- if (animation &&
+ if ((animation != nullptr) &&
animation != mAnimation &&
animation->getLength() > 0)
{
@@ -379,7 +380,7 @@ bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction)
unsigned int AnimatedSprite::getFrameCount() const restrict2
{
- if (mAnimation)
+ if (mAnimation != nullptr)
return CAST_U32(mAnimation->getLength());
else
return 0;
@@ -387,7 +388,7 @@ unsigned int AnimatedSprite::getFrameCount() const restrict2
int AnimatedSprite::getWidth() const restrict2
{
- if (mFrame && mFrame->image)
+ if ((mFrame != nullptr) && (mFrame->image != nullptr))
return mFrame->image->mBounds.w;
else
return 0;
@@ -395,7 +396,7 @@ int AnimatedSprite::getWidth() const restrict2
int AnimatedSprite::getHeight() const restrict2
{
- if (mFrame && mFrame->image)
+ if ((mFrame != nullptr) && (mFrame->image != nullptr))
return mFrame->image->mBounds.h;
else
return 0;
@@ -403,45 +404,45 @@ int AnimatedSprite::getHeight() const restrict2
std::string AnimatedSprite::getIdPath() const restrict2
{
- if (!mSprite)
+ if (mSprite == nullptr)
return "";
return mSprite->mIdPath;
}
const Image* AnimatedSprite::getImage() const restrict2 noexcept2
{
- return mFrame ? mFrame->image : nullptr;
+ return mFrame != nullptr ? mFrame->image : nullptr;
}
void AnimatedSprite::setAlpha(float alpha) restrict2
{
mAlpha = alpha;
- if (mFrame)
+ if (mFrame != nullptr)
{
Image *restrict const image = mFrame->image;
- if (image)
+ if (image != nullptr)
image->setAlpha(mAlpha);
}
}
const void *AnimatedSprite::getHash() const restrict2
{
- if (mFrame)
+ if (mFrame != nullptr)
return mFrame;
return this;
}
bool AnimatedSprite::updateNumber(const unsigned num) restrict2
{
- if (!mSprite)
+ if (mSprite == nullptr)
return false;
if (mNumber1 != num)
{
mNumber1 = num;
mNumber = mSprite->findNumber(num);
- if (!mNumber)
+ if (mNumber == 0u)
{
mNumber = 100;
return false;
@@ -454,7 +455,7 @@ bool AnimatedSprite::updateNumber(const unsigned num) restrict2
void AnimatedSprite::setDelayLoad(const std::string &restrict filename,
const int variant) restrict2
{
- if (mDelayLoad)
+ if (mDelayLoad != nullptr)
{
mDelayLoad->clearSprite();
DelayedManager::removeDelayLoad(mDelayLoad);
diff --git a/src/resources/sprite/animationdelayload.cpp b/src/resources/sprite/animationdelayload.cpp
index 440988252..37222d068 100644
--- a/src/resources/sprite/animationdelayload.cpp
+++ b/src/resources/sprite/animationdelayload.cpp
@@ -40,7 +40,7 @@ AnimationDelayLoad::AnimationDelayLoad(const std::string &fileName,
AnimationDelayLoad::~AnimationDelayLoad()
{
- if (mSprite)
+ if (mSprite != nullptr)
{
mSprite->clearDelayLoad();
mSprite = nullptr;
@@ -54,10 +54,10 @@ void AnimationDelayLoad::clearSprite()
void AnimationDelayLoad::load()
{
- if (mSprite)
+ if (mSprite != nullptr)
{
SpriteDef *const s = Loader::getSprite(mFileName, mVariant);
- if (!s)
+ if (s == nullptr)
return;
mSprite->setSprite(s);
mSprite->play(mAction);
diff --git a/src/resources/sprite/imagesprite.cpp b/src/resources/sprite/imagesprite.cpp
index 6867bbb01..b5aace2e1 100644
--- a/src/resources/sprite/imagesprite.cpp
+++ b/src/resources/sprite/imagesprite.cpp
@@ -28,7 +28,7 @@
ImageSprite::ImageSprite(Image *const image) :
mImage(image)
{
- if (mImage)
+ if (mImage != nullptr)
{
mAlpha = mImage->mAlpha;
mImage->incRef();
@@ -41,7 +41,7 @@ ImageSprite::ImageSprite(Image *const image) :
ImageSprite::~ImageSprite()
{
- if (mImage)
+ if (mImage != nullptr)
{
mImage->decRef();
mImage = nullptr;
@@ -52,7 +52,7 @@ void ImageSprite::draw(Graphics *const graphics,
const int posX, const int posY) const
{
FUNC_BLOCK("ImageSprite::draw", 1)
- if (!mImage)
+ if (mImage == nullptr)
return;
mImage->setAlpha(mAlpha);
diff --git a/src/resources/sprite/imagesprite.h b/src/resources/sprite/imagesprite.h
index 1b731dc00..9576933d1 100644
--- a/src/resources/sprite/imagesprite.h
+++ b/src/resources/sprite/imagesprite.h
@@ -51,10 +51,10 @@ class ImageSprite final : public Sprite
const override final A_NONNULL(2);
int getWidth() const override final A_WARN_UNUSED
- { return mImage ? mImage->getWidth() : 0; }
+ { return mImage != nullptr ? mImage->getWidth() : 0; }
int getHeight() const override final A_WARN_UNUSED
- { return mImage ? mImage->getHeight() : 0; }
+ { return mImage != nullptr ? mImage->getHeight() : 0; }
const Image* getImage() const override final A_WARN_UNUSED
{ return mImage; }
diff --git a/src/resources/sprite/spritedef.cpp b/src/resources/sprite/spritedef.cpp
index 263caebe2..8824a2ac1 100644
--- a/src/resources/sprite/spritedef.cpp
+++ b/src/resources/sprite/spritedef.cpp
@@ -54,11 +54,11 @@ const Action *SpriteDef::getAction(const std::string &action,
if (i == mActions.end() && num != 100)
i = mActions.find(100);
- if (i == mActions.end() || !(*i).second)
+ if (i == mActions.end() || ((*i).second == nullptr))
return nullptr;
const ActionMap *const actMap = (*i).second;
- if (!actMap)
+ if (actMap == nullptr)
return nullptr;
const ActionMap::const_iterator it = actMap->find(action);
@@ -97,11 +97,11 @@ SpriteDef *SpriteDef::load(const std::string &animationFile,
XML::Document *const doc = Loader::getXml(animationFile.substr(0, pos),
UseVirtFs_true,
SkipError_false);
- if (!doc)
+ if (doc == nullptr)
return nullptr;
XmlNodePtrConst rootNode = doc->rootNode();
- if (!rootNode || !xmlNameEqual(rootNode, "sprite"))
+ if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "sprite"))
{
reportAlways("Error, failed to parse sprite %s",
animationFile.c_str());
@@ -137,12 +137,12 @@ void SpriteDef::fixDeadAction()
FOR_EACH (ActionsIter, it, mActions)
{
ActionMap *const d = (*it).second;
- if (!d)
+ if (d == nullptr)
continue;
const ActionMap::iterator i = d->find(SpriteAction::DEAD);
const ActionMap::iterator i2 = d->find(SpriteAction::STAND);
// search dead action and check what it not same with stand action
- if (i != d->end() && i->second && i->second != i2->second)
+ if (i != d->end() && (i->second != nullptr) && i->second != i2->second)
(i->second)->setLastFrameDelay(0);
}
}
@@ -202,7 +202,7 @@ void SpriteDef::loadSprite(XmlNodeConstPtr spriteNode,
const std::string &palettes)
{
BLOCK_START("SpriteDef::loadSprite")
- if (!spriteNode)
+ if (spriteNode == nullptr)
{
BLOCK_END("SpriteDef::loadSprite")
return;
@@ -248,7 +248,7 @@ void SpriteDef::loadImageSet(XmlNodeConstPtr node,
ImageSet *const imageSet = Loader::getImageSet(imageSrc,
width, height);
- if (!imageSet)
+ if (imageSet == nullptr)
{
reportAlways("%s: Couldn't load imageset: %s",
mSource.c_str(),
@@ -278,7 +278,7 @@ const ImageSet *SpriteDef::getImageSet(const std::string &imageSetName) const
void SpriteDef::loadAction(XmlNodeConstPtr node,
const int variant_offset)
{
- if (!node)
+ if (node == nullptr)
return;
const std::string actionName = XML::getProperty(node, "name", "");
@@ -320,8 +320,12 @@ void SpriteDef::loadAnimation(XmlNodeConstPtr animationNode,
const ImageSet *const imageSet0,
const int variant_offset) const
{
- if (!action || !imageSet0 || !animationNode)
+ if (action == nullptr ||
+ imageSet0 == nullptr ||
+ animationNode == nullptr)
+ {
return;
+ }
const std::string directionName =
XML::getProperty(animationNode, "direction", "");
@@ -376,7 +380,7 @@ void SpriteDef::loadAnimation(XmlNodeConstPtr animationNode,
}
Image *const img = imageSet->get(index + variant_offset);
- if (!img)
+ if (img == nullptr)
{
reportAlways("%s: No image at index %d at direction '%s'",
mSource.c_str(),
@@ -434,7 +438,7 @@ void SpriteDef::loadAnimation(XmlNodeConstPtr animationNode,
{
Image *const img = imageSet->get(atoi(
str.c_str()) + variant_offset);
- if (img)
+ if (img != nullptr)
{
animation->addFrame(img, delay,
offsetX, offsetY, rand);
@@ -491,11 +495,11 @@ void SpriteDef::includeSprite(XmlNodeConstPtr includeNode, const int variant)
XML::Document *const doc = Loader::getXml(filename,
UseVirtFs_true,
SkipError_false);
- if (!doc)
+ if (doc == nullptr)
return;
XmlNodeConstPtr rootNode = doc->rootNode();
- if (!rootNode || !xmlNameEqual(rootNode, "sprite"))
+ if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "sprite"))
{
reportAlways("%s: No sprite root node in %s",
mSource.c_str(),
@@ -526,7 +530,7 @@ SpriteDef::~SpriteDef()
FOR_EACH (ImageSetIterator, i, mImageSets)
{
- if (i->second)
+ if (i->second != nullptr)
{
i->second->decRef();
i->second = nullptr;
@@ -581,7 +585,7 @@ bool SpriteDef::addSequence(const int start,
const ImageSet *const imageSet,
Animation *const animation) const
{
- if (!imageSet || !animation)
+ if ((imageSet == nullptr) || (animation == nullptr))
return true;
if (start < 0 || end < 0)
@@ -600,7 +604,7 @@ bool SpriteDef::addSequence(const int start,
{
Image *const img = imageSet->get(pos + variant_offset);
- if (!img)
+ if (img == nullptr)
{
reportAlways("%s: No image at index %d",
mSource.c_str(),
@@ -625,7 +629,7 @@ bool SpriteDef::addSequence(const int start,
{
Image *const img = imageSet->get(pos + variant_offset);
- if (!img)
+ if (img == nullptr)
{
reportAlways("%s: No image at index %d",
mSource.c_str(),