diff options
Diffstat (limited to 'src/resources')
94 files changed, 609 insertions, 600 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp index feb991684..c059624c5 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -80,7 +80,7 @@ void Action::setLastFrameDelay(const int delay) noexcept2 FOR_EACH (AnimationIter, it, mAnimations) { Animation *const animation = (*it).second; - if (!animation) + if (animation == nullptr) continue; animation->setLastFrameDelay(delay); } diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp index 50397ab6a..fe702ccde 100644 --- a/src/resources/ambientlayer.cpp +++ b/src/resources/ambientlayer.cpp @@ -55,7 +55,7 @@ AmbientLayer::AmbientLayer(const std::string &name, mMask(mask), mKeepRatio(keepRatio) { - if (!mImage) + if (mImage == nullptr) return; if (keepRatio && @@ -74,7 +74,7 @@ AmbientLayer::AmbientLayer(const std::string &name, CAST_S32(mImage->mBounds.h) / defaultScreenHeight * height); - if (rescaledOverlay) + if (rescaledOverlay != nullptr) mImage = rescaledOverlay; else mImage->incRef(); @@ -86,7 +86,7 @@ AmbientLayer::AmbientLayer(const std::string &name, AmbientLayer::~AmbientLayer() { - if (mImage) + if (mImage != nullptr) { mImage->decRef(); mImage = nullptr; @@ -95,7 +95,7 @@ AmbientLayer::~AmbientLayer() void AmbientLayer::update(const int timePassed, const float dx, const float dy) { - if (!mImage) + if (mImage == nullptr) return; const float time = static_cast<float>(timePassed) / 10; @@ -126,7 +126,7 @@ void AmbientLayer::update(const int timePassed, const float dx, const float dy) void AmbientLayer::draw(Graphics *const graphics, const int x, const int y) const { - if (!mImage) + if (mImage == nullptr) return; if (imageHelper->useOpenGL() == RENDER_SOFTWARE || diff --git a/src/resources/animation/animation.cpp b/src/resources/animation/animation.cpp index ff3883c0d..4f83161de 100644 --- a/src/resources/animation/animation.cpp +++ b/src/resources/animation/animation.cpp @@ -84,7 +84,7 @@ void Animation::setLastFrameDelay(const int delay) noexcept2 for (FramesRevIter it = mFrames.rbegin(), it_end = mFrames.rend(); it != it_end; ++ it) { - if ((*it).type == FrameType::ANIMATION && (*it).image) + if ((*it).type == FrameType::ANIMATION && ((*it).image != nullptr)) { (*it).delay = delay; break; diff --git a/src/resources/animation/simpleanimation.cpp b/src/resources/animation/simpleanimation.cpp index 7f20b5eef..ed92d2b50 100644 --- a/src/resources/animation/simpleanimation.cpp +++ b/src/resources/animation/simpleanimation.cpp @@ -43,7 +43,7 @@ SimpleAnimation::SimpleAnimation(Animation *const animation) : mAnimation(animation), mAnimationTime(0), mAnimationPhase(0), - mCurrentFrame(mAnimation ? &mAnimation->mFrames[0] : nullptr), + mCurrentFrame(mAnimation != nullptr ? &mAnimation->mFrames[0] : nullptr), mInitialized(true), mImageSet(nullptr) { @@ -59,7 +59,7 @@ SimpleAnimation::SimpleAnimation(XmlNodeConstPtr animationNode, mImageSet(nullptr) { initializeAnimation(animationNode, dyePalettes); - if (mAnimation) + if (mAnimation != nullptr) mCurrentFrame = &mAnimation->mFrames[0]; else mCurrentFrame = nullptr; @@ -68,7 +68,7 @@ SimpleAnimation::SimpleAnimation(XmlNodeConstPtr animationNode, SimpleAnimation::~SimpleAnimation() { delete2(mAnimation); - if (mImageSet) + if (mImageSet != nullptr) { mImageSet->decRef(); mImageSet = nullptr; @@ -79,7 +79,7 @@ void SimpleAnimation::draw(Graphics *const graphics, const int posX, const int posY) const { FUNC_BLOCK("SimpleAnimation::draw", 1) - if (!mCurrentFrame || !mCurrentFrame->image) + if ((mCurrentFrame == nullptr) || (mCurrentFrame->image == nullptr)) return; graphics->drawImage(mCurrentFrame->image, @@ -95,7 +95,7 @@ void SimpleAnimation::reset() void SimpleAnimation::setFrame(int frame) { - if (!mAnimation) + if (mAnimation == nullptr) return; if (frame < 0) @@ -109,7 +109,7 @@ void SimpleAnimation::setFrame(int frame) bool SimpleAnimation::update(const int timePassed) { - if (!mCurrentFrame || !mAnimation || !mInitialized) + if ((mCurrentFrame == nullptr) || (mAnimation == nullptr) || !mInitialized) return false; bool updated(false); @@ -131,7 +131,7 @@ bool SimpleAnimation::update(const int timePassed) int SimpleAnimation::getLength() const { - if (!mAnimation) + if (mAnimation == nullptr) return 0; return CAST_S32(mAnimation->getLength()); @@ -139,7 +139,7 @@ int SimpleAnimation::getLength() const Image *SimpleAnimation::getCurrentImage() const { - if (mCurrentFrame) + if (mCurrentFrame != nullptr) return mCurrentFrame->image; else return nullptr; @@ -150,7 +150,7 @@ void SimpleAnimation::initializeAnimation(XmlNodeConstPtr animationNode, { mInitialized = false; - if (!animationNode) + if (animationNode == nullptr) return; std::string imagePath = XML::getProperty( @@ -165,7 +165,7 @@ void SimpleAnimation::initializeAnimation(XmlNodeConstPtr animationNode, XML::getProperty(animationNode, "width", 0), XML::getProperty(animationNode, "height", 0)); - if (!imageset) + if (imageset == nullptr) return; const int x1 = imageset->getWidth() / 2 - mapTileSize / 2; @@ -192,13 +192,13 @@ void SimpleAnimation::initializeAnimation(XmlNodeConstPtr animationNode, Image *const img = imageset->get(index); - if (!img) + if (img == nullptr) { reportAlways("No image at index %d", index); continue; } - if (mAnimation) + if (mAnimation != nullptr) mAnimation->addFrame(img, delay, offsetX, offsetY, rand); } else if (xmlNameEqual(frameNode, "sequence")) @@ -216,20 +216,20 @@ void SimpleAnimation::initializeAnimation(XmlNodeConstPtr animationNode, { Image *const img = imageset->get(start); - if (!img) + if (img == nullptr) { reportAlways("No image at index %d", start); continue; } - if (mAnimation) + if (mAnimation != nullptr) mAnimation->addFrame(img, delay, offsetX, offsetY, rand); start++; } } else if (xmlNameEqual(frameNode, "end")) { - if (mAnimation) + if (mAnimation != nullptr) mAnimation->addTerminator(rand); } } diff --git a/src/resources/atlas/atlasitem.h b/src/resources/atlas/atlasitem.h index 5d2762fb5..4da78af6e 100644 --- a/src/resources/atlas/atlasitem.h +++ b/src/resources/atlas/atlasitem.h @@ -33,8 +33,8 @@ struct AtlasItem final : public MemoryCounter name(), x(0), y(0), - width(image0 ? image0->mBounds.w : 0), - height(image0 ? image0->mBounds.h : 0) + width(image0 != nullptr ? image0->mBounds.w : 0), + height(image0 != nullptr ? image0->mBounds.h : 0) { } diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp index 8a9991714..c2da00732 100644 --- a/src/resources/atlas/atlasmanager.cpp +++ b/src/resources/atlas/atlasmanager.cpp @@ -76,7 +76,7 @@ AtlasResource *AtlasManager::loadTextureAtlas(const std::string &name, FOR_EACH (std::vector<TextureAtlas*>::iterator, it, atlases) { TextureAtlas *const atlas = *it; - if (!atlas) + if (atlas == nullptr) continue; createSDLAtlas(atlas); @@ -105,7 +105,7 @@ AtlasResource *AtlasManager::loadEmptyAtlas(const std::string &name, FOR_EACH (std::vector<TextureAtlas*>::iterator, it, atlases) { TextureAtlas *const atlas = *it; - if (!atlas) + if (atlas == nullptr) continue; atlas->atlasImage = new Image(0, @@ -132,7 +132,7 @@ void AtlasManager::loadImages(const StringVect &files, // check is image with same name already in cache // and if yes, move it to deleted set Resource *const res = ResourceManager::getTempResource(str); - if (res) + if (res != nullptr) { // increase counter because in moveToDeleted it will be decreased. res->incRef(); @@ -149,12 +149,13 @@ void AtlasManager::loadImages(const StringVect &files, } SDL_RWops *const rw = VirtFs::rwopsOpenRead(path); - if (rw) + if (rw != nullptr) { - Image *const image = d ? surfaceImageHelper->load(rw, *d) - : surfaceImageHelper->load(rw); + Image *const image = d != nullptr ? + surfaceImageHelper->load(rw, *d) : + surfaceImageHelper->load(rw); - if (image) + if (image != nullptr) { image->mIdPath = str; #ifdef DEBUG_IMAGES @@ -181,7 +182,7 @@ void AtlasManager::loadEmptyImages(const StringVect &files, // check is image with same name already in cache // and if yes, move it to deleted set Resource *const res = ResourceManager::getTempResource(str); - if (res) + if (res != nullptr) { // increase counter because in moveToDeleted it will be decreased. res->incRef(); @@ -212,7 +213,7 @@ void AtlasManager::simpleSort(const std::string &restrict name, for (it = images.begin(); it != it_end; ++ it) { const Image *const img = *it; - if (img) + if (img != nullptr) { atlas->name = std::string("atlas_").append(name).append( "_").append(img->mIdPath); @@ -223,7 +224,7 @@ void AtlasManager::simpleSort(const std::string &restrict name, for (it = images.begin(); it != it_end; ++ it) { Image *const img = *it; - if (img) + if (img != nullptr) { AtlasItem *const item = new AtlasItem(img); item->name = img->mIdPath; @@ -279,7 +280,7 @@ void AtlasManager::emptySort(const std::string &restrict name, for (it = images.begin(); it != it_end; ++ it) { const Image *const img = *it; - if (img) + if (img != nullptr) { atlas->name = std::string("atlas_").append(name).append( "_").append(img->mIdPath); @@ -290,7 +291,7 @@ void AtlasManager::emptySort(const std::string &restrict name, for (it = images.begin(); it != it_end; ++ it) { Image *const img = *it; - if (img) + if (img != nullptr) { AtlasItem *const item = new AtlasItem(img); item->name = img->mIdPath; @@ -340,7 +341,7 @@ void AtlasManager::createSDLAtlas(TextureAtlas *const atlas) // temp SDL surface for atlas SDL_Surface *const surface = MSDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32U, rmask, gmask, bmask, amask); - if (!surface) + if (surface == nullptr) { reportAlways("Error creating surface for atlas. Size: %dx%d", width, @@ -401,7 +402,7 @@ void AtlasManager::convertEmptyAtlas(TextureAtlas *const atlas) // convert surface to OpemGL image Image *const oldImage = atlas->atlasImage; - if (oldImage->mSDLSurface) + if (oldImage->mSDLSurface != nullptr) { atlas->atlasImage = imageHelper->loadSurface( atlas->atlasImage->mSDLSurface); @@ -409,7 +410,7 @@ void AtlasManager::convertEmptyAtlas(TextureAtlas *const atlas) } Image *const image = atlas->atlasImage; - if (!image) + if (image == nullptr) return; image->mIdPath = atlas->name; @@ -429,7 +430,7 @@ void AtlasManager::convertEmptyAtlas(TextureAtlas *const atlas) item->image = image->getSubImage(item->x, item->y, item->width, item->height); Image *const image2 = item->image; - if (image2) + if (image2 != nullptr) { image2->mIdPath = item->name; #ifdef DEBUG_IMAGES @@ -448,7 +449,7 @@ void AtlasManager::convertAtlas(TextureAtlas *const atlas) // convert surface to OpemGL image Image *const oldImage = atlas->atlasImage; - if (oldImage->mSDLSurface) + if (oldImage->mSDLSurface != nullptr) { atlas->atlasImage = imageHelper->loadSurface( atlas->atlasImage->mSDLSurface); @@ -456,7 +457,7 @@ void AtlasManager::convertAtlas(TextureAtlas *const atlas) } Image *const image = atlas->atlasImage; - if (!image) + if (image == nullptr) return; image->mIdPath = atlas->name; @@ -476,7 +477,7 @@ void AtlasManager::convertAtlas(TextureAtlas *const atlas) item->image = image->getSubImage(item->x, item->y, item->width, item->height); Image *const image2 = item->image; - if (image2) + if (image2 != nullptr) { image2->mIdPath = item->name; #ifdef DEBUG_IMAGES @@ -491,22 +492,22 @@ void AtlasManager::convertAtlas(TextureAtlas *const atlas) void AtlasManager::injectToResources(const AtlasResource *const resource) { - if (!resource) + if (resource == nullptr) return; FOR_EACH (std::vector<TextureAtlas*>::const_iterator, it, resource->atlases) { // add each atlas image to resources TextureAtlas *const atlas = *it; - if (atlas) + if (atlas != nullptr) { Image *const image = atlas->atlasImage; - if (image) + if (image != nullptr) ResourceManager::addResource(atlas->name, image); FOR_EACH (std::vector<AtlasItem*>::iterator, it2, atlas->items) { AtlasItem *const item = *it2; - if (!item) + if (item == nullptr) continue; // add each atlas sub image to resources ResourceManager::addResource(item->name, item->image); @@ -517,16 +518,16 @@ void AtlasManager::injectToResources(const AtlasResource *const resource) void AtlasManager::moveToDeleted(AtlasResource *const resource) { - if (!resource) + if (resource == nullptr) return; FOR_EACH (std::vector<TextureAtlas*>::iterator, it, resource->atlases) { // move each atlas image to deleted TextureAtlas *const atlas = *it; - if (atlas) + if (atlas != nullptr) { Image *const image = atlas->atlasImage; - if (image) + if (image != nullptr) { // move each atlas image to deleted ResourceManager::moveToDeleted(image); @@ -534,10 +535,10 @@ void AtlasManager::moveToDeleted(AtlasResource *const resource) FOR_EACH (std::vector<AtlasItem*>::iterator, it2, atlas->items) { AtlasItem *const item = *it2; - if (item) + if (item != nullptr) { Image *const image2 = item->image; - if (image2) + if (image2 != nullptr) { // move each atlas sub image to deleted ResourceManager::moveToDeleted(image2); diff --git a/src/resources/atlas/atlasresource.cpp b/src/resources/atlas/atlasresource.cpp index eab7c660e..51a807975 100644 --- a/src/resources/atlas/atlasresource.cpp +++ b/src/resources/atlas/atlasresource.cpp @@ -34,21 +34,21 @@ AtlasResource::~AtlasResource() FOR_EACH (std::vector<TextureAtlas*>::iterator, it, atlases) { TextureAtlas *const atlas = *it; - if (atlas) + if (atlas != nullptr) { FOR_EACH (std::vector<AtlasItem*>::iterator, it2, atlas->items) { AtlasItem *const item = *it2; - if (item) + if (item != nullptr) { Image *const image2 = item->image; - if (image2) + if (image2 != nullptr) image2->decRef(); delete item; } } Image *const image = atlas->atlasImage; - if (image) + if (image != nullptr) image->decRef(); delete atlas; } @@ -58,7 +58,7 @@ AtlasResource::~AtlasResource() void AtlasResource::incRef() { - if (!mRefCount) + if (mRefCount == 0u) AtlasManager::injectToResources(this); Resource::incRef(); } @@ -66,7 +66,7 @@ void AtlasResource::incRef() void AtlasResource::decRef() { Resource::decRef(); - if (!mRefCount) + if (mRefCount == 0u) AtlasManager::moveToDeleted(this); } diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 466a5832d..e4fe5c851 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -148,7 +148,7 @@ void BeingInfo::addSound(const ItemSoundEvent::Type event, if (mSounds.find(event) == mSounds.end()) mSounds[event] = new SoundInfoVect; - if (mSounds[event]) + if (mSounds[event] != nullptr) mSounds[event]->push_back(SoundInfo("sfx/" + filename, delay)); } @@ -162,7 +162,7 @@ const SoundInfo &BeingInfo::getSound(const ItemSoundEvent::Type event) const return emptySound; const SoundInfoVect *const vect = i->second; - if (!vect || vect->empty()) + if ((vect == nullptr) || vect->empty()) return emptySound; else return vect->at(CAST_SIZE(rand()) % vect->size()); @@ -205,7 +205,7 @@ void BeingInfo::clear() void BeingInfo::init() { - if (empty) + if (empty != nullptr) { empty->mEffectId = paths.getIntValue("effectId"); empty->mHitEffectId = paths.getIntValue("hitEffectId"); @@ -224,7 +224,7 @@ void BeingInfo::setColorsList(const std::string &name) std::string BeingInfo::getColor(const ItemColor idx) const { - if (!mColors) + if (mColors == nullptr) return std::string(); const std::map <ItemColor, ColorDB::ItemColorData>::const_iterator diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index a68e7ca7b..0b1b0e7b4 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -317,7 +317,7 @@ class BeingInfo final { mAllowDelete = b; } int getAllowDelete() const noexcept2 A_WARN_UNUSED - { return mAllowDelete; } + { return static_cast<int>(mAllowDelete); } void setQuickActionEffectId(const int n) { mQuickActionEffectId = n; } diff --git a/src/resources/db/avatardb.cpp b/src/resources/db/avatardb.cpp index eddf08b29..86c2ff5aa 100644 --- a/src/resources/db/avatardb.cpp +++ b/src/resources/db/avatardb.cpp @@ -59,7 +59,7 @@ void AvatarDB::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "avatars")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "avatars")) { logger->log("Avatars Database: Error while loading %s!", fileName.c_str()); @@ -85,7 +85,7 @@ void AvatarDB::loadXmlFile(const std::string &fileName, BeingInfo *currentInfo = nullptr; if (mAvatarInfos.find(id) != mAvatarInfos.end()) currentInfo = mAvatarInfos[id]; - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new BeingInfo; currentInfo->setName(XML::langProperty( diff --git a/src/resources/db/chardb.cpp b/src/resources/db/chardb.cpp index b0984a56f..fe87ea157 100644 --- a/src/resources/db/chardb.cpp +++ b/src/resources/db/chardb.cpp @@ -54,7 +54,7 @@ void CharDB::load() SkipError_false); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root || !xmlNameEqual(root, "chars")) + if ((root == nullptr) || !xmlNameEqual(root, "chars")) { logger->log("CharDB: Failed to parse %s.", paths.getStringValue("charCreationFile").c_str()); @@ -113,9 +113,9 @@ void CharDB::loadMinMax(XmlNodeConstPtr node, unsigned *restrict const min, unsigned *restrict const max) { - if (min) + if (min != nullptr) *min = XML::getProperty(node, "min", 1); - if (max) + if (max != nullptr) *max = XML::getProperty(node, "max", 10); } diff --git a/src/resources/db/colordb.cpp b/src/resources/db/colordb.cpp index cf377eca1..15e66bb5b 100644 --- a/src/resources/db/colordb.cpp +++ b/src/resources/db/colordb.cpp @@ -83,7 +83,7 @@ void ColorDB::loadHair(const std::string &fileName, skipError); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root || !xmlNameEqual(root, "colors")) + if ((root == nullptr) || !xmlNameEqual(root, "colors")) { logger->log("ColorDB: Failed to find hair colors file."); if (colors.find(ItemColor_zero) == colors.end()) @@ -128,7 +128,7 @@ void ColorDB::loadColorLists(const std::string &fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root) + if (root == nullptr) { delete doc; return; diff --git a/src/resources/db/commandsdb.cpp b/src/resources/db/commandsdb.cpp index 115046b1d..eec3eb7ce 100644 --- a/src/resources/db/commandsdb.cpp +++ b/src/resources/db/commandsdb.cpp @@ -64,7 +64,7 @@ void CommandsDB::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "commands")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "commands")) { logger->log("Commands Database: Error while loading %s!", fileName.c_str()); @@ -121,7 +121,7 @@ void CommandsDB::loadXmlFile(const std::string &fileName, TextCommand *cmd = nullptr; #ifdef TMWA_SUPPORT - if (skill1) + if (skill1 != 0) { cmd = new TextCommand(id, name, diff --git a/src/resources/db/deaddb.cpp b/src/resources/db/deaddb.cpp index 53a0f6e0f..bcca023eb 100644 --- a/src/resources/db/deaddb.cpp +++ b/src/resources/db/deaddb.cpp @@ -54,7 +54,7 @@ void DeadDB::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root || !xmlNameEqual(root, "messages")) + if ((root == nullptr) || !xmlNameEqual(root, "messages")) { logger->log("DeadDB: Failed to parse %s.", paths.getStringValue("deadMessagesFile").c_str()); @@ -75,9 +75,9 @@ void DeadDB::loadXmlFile(const std::string &fileName, { XmlChar *const data = reinterpret_cast<XmlChar*>( XmlNodeGetContent(node)); - if (!data) + if (data == nullptr) continue; - if (!*data) + if (*data == 0) { XmlFree(data); continue; @@ -99,7 +99,7 @@ void DeadDB::unload() std::string DeadDB::getRandomString() { const size_t sz = mMessages.size(); - if (!sz) + if (sz == 0u) return std::string(); return translator->getStr(mMessages[rand() % sz]); } diff --git a/src/resources/db/elementaldb.cpp b/src/resources/db/elementaldb.cpp index 2a626a10e..8701081a3 100644 --- a/src/resources/db/elementaldb.cpp +++ b/src/resources/db/elementaldb.cpp @@ -57,7 +57,7 @@ void ElementalDb::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtr rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "elementals")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "elementals")) { logger->log("Elemental Database: Error while loading %s!", paths.getStringValue("elementalsFile").c_str()); @@ -89,7 +89,7 @@ void ElementalDb::loadXmlFile(const std::string &fileName, logger->log("ElementalDb: Redefinition of elemental ID %d", id); currentInfo = mElementalInfos[fromInt(id + offset, BeingTypeId)]; } - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new BeingInfo; currentInfo->setBlockType(BlockType::NONE); @@ -107,7 +107,7 @@ void ElementalDb::loadXmlFile(const std::string &fileName, currentInfo->setColorsList(XML::getProperty(elementalNode, "colors", "")); - if (currentInfo->getMaxHP()) + if (currentInfo->getMaxHP() != 0) currentInfo->setStaticMaxHP(true); SpriteDisplay display; diff --git a/src/resources/db/emotedb.cpp b/src/resources/db/emotedb.cpp index 7d9e47e8b..085f81abe 100644 --- a/src/resources/db/emotedb.cpp +++ b/src/resources/db/emotedb.cpp @@ -75,7 +75,7 @@ void EmoteDB::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodePtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "emotes")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "emotes")) { logger->log("Emote Database: Error while loading %s!", fileName.c_str()); @@ -113,7 +113,7 @@ void EmoteDB::loadXmlFile(const std::string &fileName, currentInfo = mEmoteInfos[id]; else currentInfo = new EmoteInfo; - if (!currentInfo) + if (currentInfo == nullptr) continue; currentInfo->time = XML::getProperty(emoteNode, "time", 500); currentInfo->effectId = XML::getProperty(emoteNode, "effect", -1); @@ -152,7 +152,7 @@ void EmoteDB::loadSpecialXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodePtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "emotes")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "emotes")) { logger->log1("Emote Database: Error while loading" " manaplus_emotes.xml!"); @@ -186,7 +186,7 @@ void EmoteDB::loadSpecialXmlFile(const std::string &fileName, EmoteInfo *currentInfo = nullptr; if (mEmoteInfos.find(id) != mEmoteInfos.end()) currentInfo = mEmoteInfos[id]; - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new EmoteInfo; currentInfo->time = XML::getProperty(emoteNode, "time", 500); currentInfo->effectId = XML::getProperty(emoteNode, "effect", -1); @@ -226,7 +226,7 @@ void EmoteDB::unload() { FOR_EACH (EmoteInfos::const_iterator, i, mEmoteInfos) { - if (i->second) + if (i->second != nullptr) { std::list<EmoteSprite*> &sprites = i->second->sprites; while (!sprites.empty()) @@ -295,7 +295,7 @@ const EmoteInfo *EmoteDB::get2(int id, const bool allowNull) const EmoteSprite *EmoteDB::getSprite(const int id, const bool allowNull) { const EmoteInfo *const info = get(id, allowNull); - if (!info) + if (info == nullptr) return nullptr; return info->sprites.front(); diff --git a/src/resources/db/homunculusdb.cpp b/src/resources/db/homunculusdb.cpp index cf627dc01..3fdced887 100644 --- a/src/resources/db/homunculusdb.cpp +++ b/src/resources/db/homunculusdb.cpp @@ -58,7 +58,7 @@ void HomunculusDB::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtr rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "homunculuses")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "homunculuses")) { logger->log("Homunculus Database: Error while loading %s!", paths.getStringValue("homunculusesFile").c_str()); @@ -90,7 +90,7 @@ void HomunculusDB::loadXmlFile(const std::string &fileName, logger->log("HomunculusDB: Redefinition of homunculus ID %d", id); currentInfo = mHomunculusInfos[fromInt(id + offset, BeingTypeId)]; } - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new BeingInfo; currentInfo->setBlockType(BlockType::NONE); @@ -114,7 +114,7 @@ void HomunculusDB::loadXmlFile(const std::string &fileName, currentInfo->setColorsList(XML::getProperty(homunculusNode, "colors", "")); - if (currentInfo->getMaxHP()) + if (currentInfo->getMaxHP() != 0) currentInfo->setStaticMaxHP(true); SpriteDisplay display; diff --git a/src/resources/db/horsedb.cpp b/src/resources/db/horsedb.cpp index a6b395d3f..961fbca32 100644 --- a/src/resources/db/horsedb.cpp +++ b/src/resources/db/horsedb.cpp @@ -153,7 +153,7 @@ void HorseDB::loadXmlFile(const std::string &fileName, skipError); XmlNodePtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "horses")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "horses")) { logger->log("Horse Database: Error while loading %s!", fileName.c_str()); @@ -189,7 +189,7 @@ void HorseDB::loadXmlFile(const std::string &fileName, else currentInfo = new HorseInfo; - if (!currentInfo) + if (currentInfo == nullptr) continue; for_each_xml_child_node(spriteNode, horseNode) { diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 4bd68c42e..6efe6086f 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -129,7 +129,7 @@ static void readFields(std::string &effect, XmlNodeConstPtr node, const ItemFieldDb::FieldInfos &fields) { - if (!translator) + if (translator == nullptr) return; FOR_EACH (ItemFieldDb::FieldInfos::const_iterator, it, fields) @@ -249,7 +249,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "items")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "items")) { logger->log("ItemDB: Error while loading %s!", fileName.c_str()); mLoaded = true; @@ -287,7 +287,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, logger->log("ItemDB: Redefinition of item ID %d", id); itemInfo = mItemInfos[id]; } - if (!itemInfo) + if (itemInfo == nullptr) itemInfo = new ItemInfo; const std::string typeStr = XML::getProperty(node, "type", ""); @@ -375,7 +375,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, } itemInfo->setId(id); - if (name.empty() && inheritItemInfo) + if (name.empty() && (inheritItemInfo != nullptr)) name = inheritItemInfo->getName(); // TRANSLATORS: item info name itemInfo->setName(name.empty() ? _("unnamed") : name); @@ -389,12 +389,12 @@ void ItemDB::loadXmlFile(const std::string &fileName, itemInfo->setNameEn(nameEn); } - if (description.empty() && inheritItemInfo) + if (description.empty() && (inheritItemInfo != nullptr)) description = inheritItemInfo->getDescription(); itemInfo->setDescription(description); if (typeStr.empty()) { - if (inheritItemInfo) + if (inheritItemInfo != nullptr) itemInfo->setType(inheritItemInfo->getType()); else itemInfo->setType(itemTypeFromString("other")); @@ -404,12 +404,12 @@ void ItemDB::loadXmlFile(const std::string &fileName, itemInfo->setType(itemTypeFromString(typeStr)); } itemInfo->setType(itemTypeFromString(typeStr)); - if (useButton.empty() && inheritItemInfo) + if (useButton.empty() && (inheritItemInfo != nullptr)) useButton = inheritItemInfo->getUseButton(); if (useButton.empty()) useButton = useButtonFromItemType(itemInfo->getType()); itemInfo->setUseButton(useButton); - if (useButton2.empty() && inheritItemInfo) + if (useButton2.empty() && (inheritItemInfo != nullptr)) useButton2 = inheritItemInfo->getUseButton(); if (useButton2.empty()) useButton2 = useButton2FromItemType(itemInfo->getType()); @@ -419,7 +419,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, node, "sellProtected", false)); if (cardColor != -1) itemInfo->setCardColor(fromInt(cardColor, ItemColor)); - else if (inheritItemInfo) + else if (inheritItemInfo != nullptr) itemInfo->setCardColor(inheritItemInfo->getCardColor()); switch (itemInfo->getType()) @@ -462,46 +462,46 @@ void ItemDB::loadXmlFile(const std::string &fileName, } } - if (!view && inheritItemInfo) + if ((view == 0) && (inheritItemInfo != nullptr)) view = inheritItemInfo->getView(); itemInfo->setView(view); - if (!weight && inheritItemInfo) + if ((weight == 0) && (inheritItemInfo != nullptr)) weight = inheritItemInfo->getWeight(); itemInfo->setWeight(weight); - if (attackAction.empty() && inheritItemInfo) + if (attackAction.empty() && (inheritItemInfo != nullptr)) attackAction = inheritItemInfo->getAttackAction(); itemInfo->setAttackAction(attackAction); - if (skyAttackAction.empty() && inheritItemInfo) + if (skyAttackAction.empty() && (inheritItemInfo != nullptr)) skyAttackAction = inheritItemInfo->getSkyAttackAction(); itemInfo->setSkyAttackAction(skyAttackAction); - if (waterAttackAction.empty() && inheritItemInfo) + if (waterAttackAction.empty() && (inheritItemInfo != nullptr)) waterAttackAction = inheritItemInfo->getWaterAttackAction(); itemInfo->setWaterAttackAction(waterAttackAction); - if (rideAttackAction.empty() && inheritItemInfo) + if (rideAttackAction.empty() && (inheritItemInfo != nullptr)) rideAttackAction = inheritItemInfo->getRideAttackAction(); itemInfo->setRideAttackAction(rideAttackAction); - if (!attackRange && inheritItemInfo) + if ((attackRange == 0) && (inheritItemInfo != nullptr)) attackRange = inheritItemInfo->getAttackRange(); itemInfo->setAttackRange(attackRange); - if (missileParticle.empty() && inheritItemInfo) + if (missileParticle.empty() && (inheritItemInfo != nullptr)) missileParticle = inheritItemInfo->getMissileParticleFile(); itemInfo->setMissileParticleFile(missileParticle); - if (!hitEffectId && inheritItemInfo) + if ((hitEffectId == 0) && (inheritItemInfo != nullptr)) hitEffectId = inheritItemInfo->getHitEffectId(); itemInfo->setHitEffectId(hitEffectId); - if (!criticalEffectId && inheritItemInfo) + if ((criticalEffectId == 0) && (inheritItemInfo != nullptr)) criticalEffectId = inheritItemInfo->getCriticalHitEffectId(); itemInfo->setCriticalHitEffectId(criticalEffectId); - if (!missEffectId && inheritItemInfo) + if ((missEffectId == 0) && (inheritItemInfo != nullptr)) missEffectId = inheritItemInfo->getMissEffectId(); itemInfo->setMissEffectId(missEffectId); itemInfo->setDrawBefore(-1, parseSpriteName(drawBefore)); itemInfo->setDrawAfter(-1, parseSpriteName(drawAfter)); itemInfo->setDrawPriority(-1, drawPriority); - if (colors.empty() && inheritItemInfo) + if (colors.empty() && (inheritItemInfo != nullptr)) colors = inheritItemInfo->getColorsListName(); itemInfo->setColorsList(colors); - if (iconColors.empty() && inheritItemInfo) + if (iconColors.empty() && (inheritItemInfo != nullptr)) iconColors = inheritItemInfo->getIconColorsListName(); itemInfo->setIconColorsList(iconColors); itemInfo->setMaxFloorOffsetX(maxFloorOffsetX); @@ -516,7 +516,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, if (!effect.empty() && !temp.empty()) effect.append(" / "); effect.append(temp); - if (effect.empty() && inheritItemInfo) + if (effect.empty() && (inheritItemInfo != nullptr)) effect = inheritItemInfo->getEffect(); itemInfo->setEffect(effect); @@ -840,7 +840,7 @@ static int parseDirectionName(const std::string &name) static void loadSpriteRef(ItemInfo *const itemInfo, XmlNodeConstPtr node) { const std::string gender = XML::getProperty(node, "gender", "unisex"); - if (!node || !XmlHaveChildContent(node)) + if ((node == nullptr) || !XmlHaveChildContent(node)) return; const std::string filename = XmlChildContent(node); @@ -856,7 +856,7 @@ static void loadSpriteRef(ItemInfo *const itemInfo, XmlNodeConstPtr node) static void loadSoundRef(ItemInfo *const itemInfo, XmlNodeConstPtr node) { - if (!node || !XmlHaveChildContent(node)) + if ((node == nullptr) || !XmlHaveChildContent(node)) return; const std::string event = XML::getProperty(node, "event", ""); const std::string filename = XmlChildContent(node); @@ -878,7 +878,7 @@ static void loadSoundRef(ItemInfo *const itemInfo, XmlNodeConstPtr node) static void loadFloorSprite(SpriteDisplay &display, XmlNodeConstPtrConst floorNode) { - if (!floorNode) + if (floorNode == nullptr) return; for_each_xml_child_node(spriteNode, floorNode) { @@ -902,7 +902,7 @@ static void loadFloorSprite(SpriteDisplay &display, static void loadReplaceSprite(ItemInfo *const itemInfo, XmlNodeConstPtr replaceNode) { - if (!replaceNode) + if (replaceNode == nullptr) return; const std::string removeSprite = XML::getProperty( replaceNode, "sprite", ""); @@ -929,7 +929,7 @@ static void loadReplaceSprite(ItemInfo *const itemInfo, { IntMap *const mapList = itemInfo->addReplaceSprite( parseSpriteName(removeSprite), f); - if (!mapList) + if (mapList == nullptr) continue; for_each_xml_child_node(itemNode, replaceNode) { @@ -963,17 +963,17 @@ static void loadReplaceSprite(ItemInfo *const itemInfo, const int to = XML::getProperty(itemNode, "to", 1); IntMap *mapList = itemInfo->addReplaceSprite( parseSpriteName(removeSprite), SpriteDirection::DOWN); - if (mapList) + if (mapList != nullptr) (*mapList)[from] = to; mapList = itemInfo->addReplaceSprite(parseSpriteName( removeSprite), SpriteDirection::DOWNLEFT); - if (mapList) + if (mapList != nullptr) (*mapList)[from] = to; mapList = itemInfo->addReplaceSprite(parseSpriteName( removeSprite), SpriteDirection::DOWNRIGHT); - if (mapList) + if (mapList != nullptr) (*mapList)[from] = to; } } @@ -996,17 +996,17 @@ static void loadReplaceSprite(ItemInfo *const itemInfo, const int to = XML::getProperty(itemNode, "to", 1); IntMap *mapList = itemInfo->addReplaceSprite( parseSpriteName(removeSprite), SpriteDirection::UP); - if (mapList) + if (mapList != nullptr) (*mapList)[from] = to; mapList = itemInfo->addReplaceSprite(parseSpriteName( removeSprite), SpriteDirection::UPLEFT); - if (mapList) + if (mapList != nullptr) (*mapList)[from] = to; mapList = itemInfo->addReplaceSprite(parseSpriteName( removeSprite), SpriteDirection::UPRIGHT); - if (mapList) + if (mapList != nullptr) (*mapList)[from] = to; } } @@ -1016,7 +1016,7 @@ static void loadReplaceSprite(ItemInfo *const itemInfo, { IntMap *const mapList = itemInfo->addReplaceSprite( parseSpriteName(removeSprite), direction); - if (!mapList) + if (mapList == nullptr) return; for_each_xml_child_node(itemNode, replaceNode) { diff --git a/src/resources/db/itemfielddb.cpp b/src/resources/db/itemfielddb.cpp index 65020e824..8a32ccc02 100644 --- a/src/resources/db/itemfielddb.cpp +++ b/src/resources/db/itemfielddb.cpp @@ -107,7 +107,7 @@ void ItemFieldDb::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "itemfields")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "itemfields")) { logger->log("ItemFieldDb: Error while loading %s!", fileName.c_str()); diff --git a/src/resources/db/itemoptiondb.cpp b/src/resources/db/itemoptiondb.cpp index 1199e07f7..bd78f95c5 100644 --- a/src/resources/db/itemoptiondb.cpp +++ b/src/resources/db/itemoptiondb.cpp @@ -88,7 +88,7 @@ void ItemOptionDb::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "itemoptions")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "itemoptions")) { if (skipError == SkipError_true) { diff --git a/src/resources/db/languagedb.cpp b/src/resources/db/languagedb.cpp index b7e3ebc0e..a5443824e 100644 --- a/src/resources/db/languagedb.cpp +++ b/src/resources/db/languagedb.cpp @@ -52,7 +52,7 @@ void LanguageDb::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root || !xmlNameEqual(root, "languages")) + if ((root == nullptr) || !xmlNameEqual(root, "languages")) { delete doc; return; diff --git a/src/resources/db/mapdb.cpp b/src/resources/db/mapdb.cpp index d991e8273..e96f31e52 100644 --- a/src/resources/db/mapdb.cpp +++ b/src/resources/db/mapdb.cpp @@ -67,7 +67,7 @@ void MapDB::loadRemapXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root) + if (root == nullptr) { delete doc; return; @@ -101,7 +101,7 @@ void MapDB::loadRemapXmlFile(const std::string &fileName, void MapDB::readMap(XmlNodePtrConst node) { - if (!node) + if (node == nullptr) return; const std::string map = XML::getProperty(node, "name", ""); if (map.empty()) @@ -121,7 +121,7 @@ void MapDB::readMap(XmlNodePtrConst node) void MapDB::readAtlas(XmlNodePtrConst node) { - if (!node) + if (node == nullptr) return; const std::string atlas = XML::getProperty(node, "name", ""); if (atlas.empty()) @@ -154,7 +154,7 @@ void MapDB::loadInfo(const std::string &fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root) + if (root == nullptr) { delete doc; return; diff --git a/src/resources/db/mercenarydb.cpp b/src/resources/db/mercenarydb.cpp index bc1b20840..a528c7def 100644 --- a/src/resources/db/mercenarydb.cpp +++ b/src/resources/db/mercenarydb.cpp @@ -60,7 +60,7 @@ void MercenaryDB::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtr rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "mercenaries")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "mercenaries")) { logger->log("MercenaryDB: Error while loading %s!", paths.getStringValue("mercenariesFile").c_str()); @@ -92,7 +92,7 @@ void MercenaryDB::loadXmlFile(const std::string &fileName, logger->log("MercenaryDB: Redefinition of mercenary ID %d", id); currentInfo = mMercenaryInfos[fromInt(id + offset, BeingTypeId)]; } - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new BeingInfo; currentInfo->setBlockType(BlockType::NONE); @@ -111,7 +111,7 @@ void MercenaryDB::loadXmlFile(const std::string &fileName, currentInfo->setColorsList(XML::getProperty(mercenaryNode, "colors", "")); - if (currentInfo->getMaxHP()) + if (currentInfo->getMaxHP() != 0) currentInfo->setStaticMaxHP(true); SpriteDisplay display; diff --git a/src/resources/db/moddb.cpp b/src/resources/db/moddb.cpp index 7a23e255f..5932d9b19 100644 --- a/src/resources/db/moddb.cpp +++ b/src/resources/db/moddb.cpp @@ -54,7 +54,7 @@ void ModDB::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "mods")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "mods")) { logger->log("Mods Database: Error while loading %s!", fileName.c_str()); @@ -80,7 +80,7 @@ void ModDB::loadXmlFile(const std::string &fileName, ModInfo *currentInfo = nullptr; if (mModInfos.find(name) != mModInfos.end()) currentInfo = mModInfos[name]; - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new ModInfo; currentInfo->setName(name); diff --git a/src/resources/db/monsterdb.cpp b/src/resources/db/monsterdb.cpp index 1ed0caa27..44b430144 100644 --- a/src/resources/db/monsterdb.cpp +++ b/src/resources/db/monsterdb.cpp @@ -62,7 +62,7 @@ void MonsterDB::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtr rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "monsters")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "monsters")) { logger->log("Monster Database: Error while loading %s!", paths.getStringValue("monstersFile").c_str()); @@ -94,7 +94,7 @@ void MonsterDB::loadXmlFile(const std::string &fileName, logger->log("MonsterDB: Redefinition of monster ID %d", id); currentInfo = mMonsterInfos[fromInt(id + offset, BeingTypeId)]; } - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new BeingInfo; currentInfo->setBlockType(BlockType::NONE); @@ -114,7 +114,7 @@ void MonsterDB::loadXmlFile(const std::string &fileName, currentInfo->setColorsList(XML::getProperty(monsterNode, "colors", "")); - if (currentInfo->getMaxHP()) + if (currentInfo->getMaxHP() != 0) currentInfo->setStaticMaxHP(true); SpriteDisplay display; diff --git a/src/resources/db/npcdb.cpp b/src/resources/db/npcdb.cpp index 9be217819..44a0bc747 100644 --- a/src/resources/db/npcdb.cpp +++ b/src/resources/db/npcdb.cpp @@ -63,7 +63,7 @@ void NPCDB::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "npcs")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "npcs")) { logger->log("NPC Database: Error while loading %s!", paths.getStringValue("npcsFile").c_str()); @@ -99,7 +99,7 @@ void NPCDB::loadXmlFile(const std::string &fileName, logger->log("NpcDB: Redefinition of npc ID %d", toInt(id, int)); currentInfo = mNPCInfos[id]; } - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new BeingInfo; currentInfo->setTargetSelection(XML::getBoolProperty(npcNode, @@ -198,7 +198,7 @@ BeingInfo *NPCDB::get(const BeingTypeId id) BeingTypeId NPCDB::getAvatarFor(const BeingTypeId id) { const BeingInfo *const info = get(id); - if (!info) + if (info == nullptr) return BeingTypeId_zero; return info->getAvatarId(); } diff --git a/src/resources/db/npcdialogdb.cpp b/src/resources/db/npcdialogdb.cpp index 76eaea7c5..7411faca9 100644 --- a/src/resources/db/npcdialogdb.cpp +++ b/src/resources/db/npcdialogdb.cpp @@ -155,7 +155,7 @@ void NpcDialogDB::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root) + if (root == nullptr) { delete doc; return; diff --git a/src/resources/db/petdb.cpp b/src/resources/db/petdb.cpp index 5dca543a0..a47956e7f 100644 --- a/src/resources/db/petdb.cpp +++ b/src/resources/db/petdb.cpp @@ -61,7 +61,7 @@ void PETDB::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "pets")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "pets")) { logger->log("PET Database: Error while loading %s!", fileName.c_str()); @@ -95,7 +95,7 @@ void PETDB::loadXmlFile(const std::string &fileName, BeingInfo *currentInfo = nullptr; if (mPETInfos.find(id) != mPETInfos.end()) currentInfo = mPETInfos[id]; - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new BeingInfo; currentInfo->setName(XML::langProperty(petNode, diff --git a/src/resources/db/questdb.cpp b/src/resources/db/questdb.cpp index 41b3b0062..db67e5138 100644 --- a/src/resources/db/questdb.cpp +++ b/src/resources/db/questdb.cpp @@ -54,7 +54,7 @@ void QuestDb::load() static void loadQuest(const int var, XmlNodeConstPtr node) { - if (!node) + if (node == nullptr) return; QuestItem *const quest = new QuestItem; // TRANSLATORS: quests window quest name @@ -85,7 +85,7 @@ static void loadQuest(const int var, continue; XmlChar *const data = reinterpret_cast<XmlChar*>( XmlNodeGetContent(dataNode)); - if (!data) + if (data == nullptr) continue; std::string str = translator->getStr(data); XmlFree(data); @@ -181,7 +181,7 @@ void QuestDb::loadXmlFile(const std::string &fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst root = doc.rootNode(); - if (!root) + if (root == nullptr) return; for_each_xml_child_node(varNode, root) diff --git a/src/resources/db/skillunitdb.cpp b/src/resources/db/skillunitdb.cpp index cec48a4a1..b5c4592ad 100644 --- a/src/resources/db/skillunitdb.cpp +++ b/src/resources/db/skillunitdb.cpp @@ -59,7 +59,7 @@ void SkillUnitDb::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "skillunits")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "skillunits")) { logger->log("SkillUnitDb: Error while loading %s!", fileName.c_str()); @@ -94,7 +94,7 @@ void SkillUnitDb::loadXmlFile(const std::string &fileName, BeingInfo *currentInfo = nullptr; if (mSkillUnitInfos.find(id) != mSkillUnitInfos.end()) currentInfo = mSkillUnitInfos[id]; - if (!currentInfo) + if (currentInfo == nullptr) currentInfo = new BeingInfo; currentInfo->setName(XML::langProperty(skillUnitNode, diff --git a/src/resources/db/sounddb.cpp b/src/resources/db/sounddb.cpp index d58a585ee..47eb99232 100644 --- a/src/resources/db/sounddb.cpp +++ b/src/resources/db/sounddb.cpp @@ -51,7 +51,7 @@ void SoundDB::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root || !xmlNameEqual(root, "sounds")) + if ((root == nullptr) || !xmlNameEqual(root, "sounds")) { delete doc; return; @@ -70,7 +70,7 @@ void SoundDB::loadXmlFile(const std::string &fileName, { const std::string name = XML::getProperty(node, "name", ""); const int id = NotifyManager::getIndexBySound(name); - if (id) + if (id != 0) { const std::string value = XML::getProperty(node, "value", ""); mSounds[id] = value; diff --git a/src/resources/db/statdb.cpp b/src/resources/db/statdb.cpp index 12126f36a..7911009a3 100644 --- a/src/resources/db/statdb.cpp +++ b/src/resources/db/statdb.cpp @@ -175,7 +175,7 @@ void StatDb::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "stats")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "stats")) { logger->log("StatDb: Error while loading %s!", fileName.c_str()); diff --git a/src/resources/db/statuseffectdb.cpp b/src/resources/db/statuseffectdb.cpp index 58c5cf30d..d5fc96849 100644 --- a/src/resources/db/statuseffectdb.cpp +++ b/src/resources/db/statuseffectdb.cpp @@ -90,7 +90,7 @@ void StatusEffectDB::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); - if (!rootNode || !xmlNameEqual(rootNode, "status-effects")) + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "status-effects")) { logger->log("Error loading status effects file: " + fileName); return; @@ -151,9 +151,9 @@ void StatusEffectDB::loadXmlFile(const std::string &fileName, StatusEffect *endEffect = statusEffects[0][id]; const std::string name = XML::getProperty(node, "name", ""); const std::string name2 = XML::langProperty(node, "name", ""); - if (!startEffect) + if (startEffect == nullptr) startEffect = new StatusEffect; - if (!endEffect) + if (endEffect == nullptr) endEffect = new StatusEffect; startEffect->mName = name2; diff --git a/src/resources/db/textdb.cpp b/src/resources/db/textdb.cpp index 24a5f2a38..e4d0b9b65 100644 --- a/src/resources/db/textdb.cpp +++ b/src/resources/db/textdb.cpp @@ -49,7 +49,7 @@ void TextDb::loadXmlFile(const std::string &fileName, skipError); XmlNodeConstPtrConst root = doc->rootNode(); - if (!root || !xmlNameEqual(root, "texts")) + if ((root == nullptr) || !xmlNameEqual(root, "texts")) { delete doc; return; diff --git a/src/resources/db/unitsdb.cpp b/src/resources/db/unitsdb.cpp index 0437c81e4..9481406c4 100644 --- a/src/resources/db/unitsdb.cpp +++ b/src/resources/db/unitsdb.cpp @@ -193,7 +193,7 @@ void UnitsDb::loadXmlFile(const std::string &fileName, XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst root = doc.rootNode(); - if (!root || !xmlNameEqual(root, "units")) + if ((root == nullptr) || !xmlNameEqual(root, "units")) { logger->log("Error loading unit definition file: " + paths.getStringValue("unitsFile")); @@ -259,7 +259,7 @@ static std::string formatUnit(const int value, int levelAmount = CAST_S32(amount); int nextAmount = 0; - if (ul.count) + if (ul.count != 0) levelAmount /= ul.count; amount -= static_cast<double>(levelAmount * ul.count); @@ -275,7 +275,7 @@ static std::string formatUnit(const int value, pl = ul; ul = ud.levels[i]; - if (ul.count) + if (ul.count != 0) { nextAmount = levelAmount / ul.count; levelAmount %= ul.count; @@ -287,7 +287,7 @@ static std::string formatUnit(const int value, pl.separator).append(pl.symbol).append(output); } - if (!nextAmount) + if (nextAmount == 0) break; levelAmount = nextAmount; } @@ -305,7 +305,7 @@ static std::string formatUnit(const int value, ul = ud.levels[i - 1]; break; } - if (ul.count) + if (ul.count != 0) amount /= ul.count; } diff --git a/src/resources/dye/dye.cpp b/src/resources/dye/dye.cpp index b9c9e4cd8..70d2a21b1 100644 --- a/src/resources/dye/dye.cpp +++ b/src/resources/dye/dye.cpp @@ -143,9 +143,9 @@ void Dye::instantiate(std::string &restrict target, int Dye::getType() const restrict2 noexcept2 { - if (mDyePalettes[sPaleteIndex]) + if (mDyePalettes[sPaleteIndex] != nullptr) return 1; - if (mDyePalettes[aPaleteIndex]) + if (mDyePalettes[aPaleteIndex] != nullptr) return 2; return 0; } @@ -153,7 +153,7 @@ int Dye::getType() const restrict2 noexcept2 void Dye::normalDye(uint32_t *restrict pixels, const int bufSize) const restrict2 { - if (!pixels) + if (pixels == nullptr) return; #ifdef ENABLE_CILKPLUS @@ -230,7 +230,7 @@ endlabel:{} const int alpha = p & 0xff; #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - if (!alpha) + if (alpha == 0) continue; unsigned int color[3]; #if SDL_BYTEORDER == SDL_BIG_ENDIAN @@ -260,10 +260,11 @@ endlabel:{} continue; } - const unsigned int i = (color[0] != 0) | ((color[1] != 0) << 1) - | ((color[2] != 0) << 2); + const unsigned int i = static_cast<int>(color[0] != 0) | + (static_cast<int>(color[1] != 0) << 1) | + (static_cast<int>(color[2] != 0) << 2); - if (mDyePalettes[i - 1]) + if (mDyePalettes[i - 1] != nullptr) mDyePalettes[i - 1]->getColor(cmax, color); #if SDL_BYTEORDER == SDL_BIG_ENDIAN @@ -281,7 +282,7 @@ endlabel:{} void Dye::normalOGLDye(uint32_t *restrict pixels, const int bufSize) const restrict2 { - if (!pixels) + if (pixels == nullptr) return; #ifdef ENABLE_CILKPLUS @@ -357,7 +358,7 @@ endlabel:{} const int alpha = p & 0xff000000; #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - if (!alpha) + if (alpha == 0) continue; unsigned int color[3]; #if SDL_BYTEORDER == SDL_BIG_ENDIAN @@ -387,10 +388,11 @@ endlabel:{} continue; } - const unsigned int i = (color[0] != 0) | ((color[1] != 0) << 1) - | ((color[2] != 0) << 2); + const unsigned int i = static_cast<int>(color[0] != 0) | + (static_cast<int>(color[1] != 0) << 1) | + (static_cast<int>(color[2] != 0) << 2); - if (mDyePalettes[i - 1]) + if (mDyePalettes[i - 1] != nullptr) mDyePalettes[i - 1]->getColor(cmax, color); #if SDL_BYTEORDER == SDL_BIG_ENDIAN diff --git a/src/resources/dye/dyepalette.cpp b/src/resources/dye/dyepalette.cpp index 65063959b..cf1d7c205 100644 --- a/src/resources/dye/dyepalette.cpp +++ b/src/resources/dye/dyepalette.cpp @@ -97,7 +97,7 @@ DyePalette::DyePalette(const std::string &restrict description, continue; } const DyeColor *const color = PaletteDB::getColor(str); - if (color) + if (color != nullptr) { DyeColor color2 = *color; color2.value[3] = alpha; @@ -249,7 +249,7 @@ void DyePalette::initFunctions() { #ifdef SIMD_SUPPORTED const uint32_t flags = Cpu::getFlags(); - if (flags & Cpu::FEATURE_AVX2) + if ((flags & Cpu::FEATURE_AVX2) != 0u) { funcReplaceSColor = &DyePalette::replaceSColorAvx2; funcReplaceSColorAvx2 = &DyePalette::replaceSColorAvx2; @@ -267,7 +267,7 @@ void DyePalette::initFunctions() funcReplaceAOGLColorSse2 = &DyePalette::replaceAOGLColorSse2; #endif // USE_OPENGL } - else if (flags & Cpu::FEATURE_SSE2) + else if ((flags & Cpu::FEATURE_SSE2) != 0u) { funcReplaceSColor = &DyePalette::replaceSColorSse2; funcReplaceSColorAvx2 = &DyePalette::replaceSColorSse2; diff --git a/src/resources/dye/dyepalette_replaceacolor.cpp b/src/resources/dye/dyepalette_replaceacolor.cpp index 718a85853..21cd0b0c5 100644 --- a/src/resources/dye/dyepalette_replaceacolor.cpp +++ b/src/resources/dye/dyepalette_replaceacolor.cpp @@ -38,9 +38,9 @@ void DyePalette::replaceAColorDefault(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if ((sz == 0u) || (pixels == nullptr)) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; #ifdef ENABLE_CILKPLUS @@ -140,9 +140,9 @@ void DyePalette::replaceAColorSse2(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if ((sz == 0u) || (pixels == nullptr)) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; const int mod = bufSize % 4; const int bufEnd = bufSize - mod; @@ -211,9 +211,9 @@ void DyePalette::replaceAColorAvx2(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if ((sz == 0u) || (pixels == nullptr)) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; const int mod = bufSize % 8; const int bufEnd = bufSize - mod; diff --git a/src/resources/dye/dyepalette_replaceaoglcolor.cpp b/src/resources/dye/dyepalette_replaceaoglcolor.cpp index 19f74d4c7..c0225df65 100644 --- a/src/resources/dye/dyepalette_replaceaoglcolor.cpp +++ b/src/resources/dye/dyepalette_replaceaoglcolor.cpp @@ -40,9 +40,9 @@ void DyePalette::replaceAOGLColorDefault(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if (sz == 0u || pixels == nullptr) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; #ifdef ENABLE_CILKPLUS @@ -143,9 +143,9 @@ void DyePalette::replaceAOGLColorSse2(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if (sz == 0u || pixels == nullptr) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; if (bufSize >= 8) @@ -269,9 +269,9 @@ void DyePalette::replaceAOGLColorAvx2(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if (sz == 0u || pixels == nullptr) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; if (bufSize >= 8) diff --git a/src/resources/dye/dyepalette_replacescolor.cpp b/src/resources/dye/dyepalette_replacescolor.cpp index 3f14adb74..0a4206e83 100644 --- a/src/resources/dye/dyepalette_replacescolor.cpp +++ b/src/resources/dye/dyepalette_replacescolor.cpp @@ -38,9 +38,9 @@ void DyePalette::replaceSColorDefault(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if (sz == 0u || pixels == nullptr) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; #ifdef ENABLE_CILKPLUS @@ -138,9 +138,9 @@ void DyePalette::replaceSColorSse2(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if (sz == 0u || pixels == nullptr) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; const int mod = bufSize % 8; const int bufEnd = bufSize - mod; @@ -219,9 +219,9 @@ void DyePalette::replaceSColorAvx2(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if (sz == 0u || pixels == nullptr) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; const int mod = bufSize % 8; const int bufEnd = bufSize - mod; diff --git a/src/resources/dye/dyepalette_replacesoglcolor.cpp b/src/resources/dye/dyepalette_replacesoglcolor.cpp index da7cd0519..cde7fac8e 100644 --- a/src/resources/dye/dyepalette_replacesoglcolor.cpp +++ b/src/resources/dye/dyepalette_replacesoglcolor.cpp @@ -40,9 +40,9 @@ void DyePalette::replaceSOGLColorDefault(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if ((sz == 0u) || (pixels == nullptr)) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; #ifdef ENABLE_CILKPLUS @@ -143,9 +143,9 @@ void DyePalette::replaceSOGLColorSse2(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if ((sz == 0u) || (pixels == nullptr)) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; if (bufSize >= 8) @@ -271,9 +271,9 @@ void DyePalette::replaceSOGLColorAvx2(uint32_t *restrict pixels, { std::vector<DyeColor>::const_iterator it_end = mColors.end(); const size_t sz = mColors.size(); - if (!sz || !pixels) + if ((sz == 0u) || (pixels == nullptr)) return; - if (sz % 2) + if ((sz % 2) != 0u) -- it_end; if (bufSize >= 8) diff --git a/src/resources/image/image.cpp b/src/resources/image/image.cpp index 7d96cb0af..b1b23ce13 100644 --- a/src/resources/image/image.cpp +++ b/src/resources/image/image.cpp @@ -147,7 +147,7 @@ Image::Image(SDL_Surface *restrict const image, const bool hasAlphaChannel0, mBounds.x = 0; mBounds.y = 0; - if (mSDLSurface) + if (mSDLSurface != nullptr) { mBounds.w = CAST_U16(mSDLSurface->w); mBounds.h = CAST_U16(mSDLSurface->h); @@ -191,7 +191,7 @@ Image::Image(const GLuint glimage, const int width, const int height, mBounds.w = CAST_U16(width); mBounds.h = CAST_U16(height); - if (mGLImage) + if (mGLImage != 0u) { mLoaded = true; } @@ -225,7 +225,7 @@ void Image::unload() { mLoaded = false; - if (mSDLSurface) + if (mSDLSurface != nullptr) { SDLCleanCache(); // Free the image surface. @@ -244,7 +244,7 @@ void Image::unload() #endif // USE_SDL2 #ifdef USE_OPENGL - if (mGLImage) + if (mGLImage != 0u) { glDeleteTextures(1, &mGLImage); mGLImage = 0; @@ -286,12 +286,12 @@ void Image::setAlpha(const float alpha) if (alpha < 0.0F || alpha > 1.0F) return; - if (mSDLSurface) + if (mSDLSurface != nullptr) { if (mUseAlphaCache) { SDL_Surface *surface = getByAlpha(mAlpha); - if (!surface) + if (surface == nullptr) { if (mAlphaCache.size() > 100) { @@ -308,7 +308,7 @@ void Image::setAlpha(const float alpha) SDLCleanCache(); } surface = mSDLSurface; - if (surface) + if (surface != nullptr) mAlphaCache[mAlpha] = surface; } else @@ -317,7 +317,7 @@ void Image::setAlpha(const float alpha) } surface = getByAlpha(alpha); - if (surface) + if (surface != nullptr) { if (mSDLSurface == surface) logger->log("bug"); @@ -329,7 +329,7 @@ void Image::setAlpha(const float alpha) else { mSDLSurface = SDLImageHelper::SDLDuplicateSurface(mSDLSurface); - if (!mSDLSurface) + if (mSDLSurface == nullptr) return; } } @@ -368,7 +368,7 @@ void Image::setAlpha(const float alpha) const uint8_t aloss = fmt->Aloss; const uint8_t ashift = fmt->Ashift; - if (!bx && bxw == sw) + if ((bx == 0) && bxw == sw) { const int i2 = (maxHeight - 1) * sw + maxWidth - 1; for (int i = i1; i <= i2; i++) @@ -443,7 +443,7 @@ Image* Image::SDLgetScaledImage(const int width, const int height) const Image* scaledImage = nullptr; - if (mSDLSurface) + if (mSDLSurface != nullptr) { SDL_Surface *const scaledSurface = zoomSurface(mSDLSurface, static_cast<double>(width) / mBounds.w, @@ -452,7 +452,7 @@ Image* Image::SDLgetScaledImage(const int width, const int height) const // The load function takes care of the SDL<->OpenGL implementation // and about freeing the given SDL_surface*. - if (scaledSurface) + if (scaledSurface != nullptr) { scaledImage = imageHelper->loadSurface(scaledSurface); MSDL_FreeSurface(scaledSurface); @@ -508,7 +508,7 @@ int Image::calcMemoryLocal() const int sz = static_cast<int>(sizeof(Image) + sizeof(std::map<float, SDL_Surface*>)) + Resource::calcMemoryLocal(); - if (mSDLSurface) + if (mSDLSurface != nullptr) { sz += CAST_S32(mAlphaCache.size()) * memoryManager.getSurfaceSize(mSDLSurface); @@ -519,7 +519,7 @@ int Image::calcMemoryLocal() const #ifdef USE_OPENGL void Image::decRef() { - if (mGLImage && mRefCount <= 1) + if ((mGLImage != 0u) && mRefCount <= 1) OpenGLImageHelper::invalidate(mGLImage); Resource::decRef(); } diff --git a/src/resources/image/subimage.cpp b/src/resources/image/subimage.cpp index 7d936ecbf..77d0eb889 100644 --- a/src/resources/image/subimage.cpp +++ b/src/resources/image/subimage.cpp @@ -90,7 +90,7 @@ SubImage::SubImage(Image *const parent, mInternalBounds(), mParent(parent) { - if (mParent) + if (mParent != nullptr) { mParent->incRef(); mParent->SDLTerminateAlphaCache(); @@ -118,7 +118,7 @@ SubImage::SubImage(Image *const parent, mBounds.y = CAST_S16(y); mBounds.w = CAST_U16(width); mBounds.h = CAST_U16(height); - if (mParent) + if (mParent != nullptr) { mInternalBounds.x = mParent->mBounds.x; mInternalBounds.y = mParent->mBounds.y; @@ -145,7 +145,7 @@ SubImage::SubImage(Image *const parent, mInternalBounds(), mParent(parent) { - if (mParent) + if (mParent != nullptr) mParent->incRef(); // Set up the rectangle. @@ -153,7 +153,7 @@ SubImage::SubImage(Image *const parent, mBounds.y = CAST_S16(y); mBounds.w = CAST_U16(width); mBounds.h = CAST_U16(height); - if (mParent) + if (mParent != nullptr) { mInternalBounds.x = mParent->mBounds.x; mInternalBounds.y = mParent->mBounds.y; @@ -196,7 +196,7 @@ SubImage::~SubImage() #ifdef USE_OPENGL mGLImage = 0; #endif // USE_OPENGL - if (mParent) + if (mParent != nullptr) { #ifdef DEBUG_IMAGES logger->log("decref from subminage: %p, parent: %p", @@ -211,7 +211,7 @@ SubImage::~SubImage() Image *SubImage::getSubImage(const int x, const int y, const int w, const int h) { - if (mParent) + if (mParent != nullptr) return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h); else return nullptr; diff --git a/src/resources/imagehelper.cpp b/src/resources/imagehelper.cpp index 9495dde4e..1879e9a6a 100644 --- a/src/resources/imagehelper.cpp +++ b/src/resources/imagehelper.cpp @@ -46,7 +46,7 @@ RenderType ImageHelper::mUseOpenGL = RENDER_SOFTWARE; Image *ImageHelper::load(SDL_RWops *const rw) { SDL_Surface *const tmpImage = loadPng(rw); - if (!tmpImage) + if (tmpImage == nullptr) { logger->log("Error, image load failed: %s", IMG_GetError()); return nullptr; @@ -62,7 +62,7 @@ Image *ImageHelper::load(SDL_RWops *const rw, Dye const &dye) { BLOCK_START("ImageHelper::load") SDL_Surface *const tmpImage = loadPng(rw); - if (!tmpImage) + if (tmpImage == nullptr) { logger->log("Error, image load failed: %s", IMG_GetError()); BLOCK_END("ImageHelper::load") @@ -91,7 +91,7 @@ Image *ImageHelper::load(SDL_RWops *const rw, Dye const &dye) tmpImage, &rgba, SDL_SWSURFACE); MSDL_FreeSurface(tmpImage); - if (!surf) + if (surf == nullptr) return nullptr; uint32_t *const pixels = static_cast<uint32_t *>(surf->pixels); @@ -102,14 +102,14 @@ Image *ImageHelper::load(SDL_RWops *const rw, Dye const &dye) case 1: { const DyePalette *const pal = dye.getSPalete(); - if (pal) + if (pal != nullptr) DYEPALETTEP(pal, SColor)(pixels, surf->w * surf->h); break; } case 2: { const DyePalette *const pal = dye.getAPalete(); - if (pal) + if (pal != nullptr) DYEPALETTEP(pal, AColor)(pixels, surf->w * surf->h); break; } @@ -129,7 +129,7 @@ Image *ImageHelper::load(SDL_RWops *const rw, Dye const &dye) SDL_Surface* ImageHelper::convertTo32Bit(SDL_Surface *const tmpImage) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; SDL_PixelFormat RGBAFormat; RGBAFormat.palette = nullptr; @@ -174,9 +174,9 @@ SDL_Surface* ImageHelper::convertTo32Bit(SDL_Surface *const tmpImage) void ImageHelper::dumpSurfaceFormat(const SDL_Surface *const image) { - if (!image) + if (image == nullptr) return; - if (image->format) + if (image->format != nullptr) { const SDL_PixelFormat * const format = image->format; logger->log("Bytes per pixel: %d", format->BytesPerPixel); @@ -201,17 +201,17 @@ void ImageHelper::dumpSurfaceFormat(const SDL_Surface *const image) SDL_Surface *ImageHelper::loadPng(SDL_RWops *const rw) { - if (!rw) + if (rw == nullptr) return nullptr; - if (IMG_isPNG(rw)) + if (IMG_isPNG(rw) != 0) { SDL_Surface *const tmpImage = MIMG_LoadPNG_RW(rw); SDL_RWclose(rw); return tmpImage; } - if (IMG_isJPG(rw)) + if (IMG_isJPG(rw) != 0) { SDL_Surface *const tmpImage = MIMG_LoadJPG_RW(rw); SDL_RWclose(rw); diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index c2f1e532e..59a44c87f 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -39,7 +39,7 @@ ImageSet::ImageSet(Image *const img, const int width, const int height, mOffsetX(0), mOffsetY(0) { - if (img) + if (img != nullptr) { const int hAdd = height + spacing; const int wAdd = width + spacing; diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index b9287cf8a..a797e2496 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -32,7 +32,7 @@ bool ImageWriter::writePNG(SDL_Surface *const surface, const std::string &filename) { - if (!surface) + if (surface == nullptr) return false; @@ -41,14 +41,14 @@ bool ImageWriter::writePNG(SDL_Surface *const surface, png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); - if (!png_ptr) + if (png_ptr == nullptr) { reportAlways("Had trouble creating png_structp"); return false; } png_infop info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) + if (info_ptr == nullptr) { png_destroy_write_struct(&png_ptr, static_cast<png_infopp>(nullptr)); reportAlways("Could not create png_info"); @@ -63,7 +63,7 @@ bool ImageWriter::writePNG(SDL_Surface *const surface, } FILE *const fp = fopen(filename.c_str(), "wb"); - if (!fp) + if (fp == nullptr) { reportAlways("could not open file %s for writing", filename.c_str()); diff --git a/src/resources/inventory/complexinventory.cpp b/src/resources/inventory/complexinventory.cpp index 82490ac8b..065b77e49 100644 --- a/src/resources/inventory/complexinventory.cpp +++ b/src/resources/inventory/complexinventory.cpp @@ -44,7 +44,7 @@ bool ComplexInventory::addVirtualItem(const Item *const item, int index, const int amount) { - if (!item || PlayerInfo::isItemProtected(item->getId())) + if ((item == nullptr) || PlayerInfo::isItemProtected(item->getId())) return false; if (index >= 0 && index < CAST_S32(mSize)) @@ -59,7 +59,7 @@ bool ComplexInventory::addVirtualItem(const Item *const item, return false; } citem = dynamic_cast<ComplexItem*>(mItems[index]); - if (!citem) + if (citem == nullptr) { // if in inventory not complex item, converting it to complex citem = new ComplexItem(item2->getId(), item2->getType(), @@ -109,7 +109,7 @@ bool ComplexInventory::addVirtualItem(const Item *const item, return false; Item *const item2 = getItem(index); - if (item2) + if (item2 != nullptr) item2->setTag(item->getInvIndex()); return true; } @@ -133,7 +133,7 @@ void ComplexInventory::setItem(const int index, } const Item *const item1 = mItems[index]; - if (!item1 && id > 0) + if ((item1 == nullptr) && id > 0) { ComplexItem *const item = new ComplexItem(id, type, diff --git a/src/resources/inventory/inventory.cpp b/src/resources/inventory/inventory.cpp index 92f35715a..97bb255fe 100644 --- a/src/resources/inventory/inventory.cpp +++ b/src/resources/inventory/inventory.cpp @@ -49,7 +49,7 @@ namespace bool operator()(const Item *const item) const { - return item && item->mId >= 0 && item->mQuantity > 0; + return (item != nullptr) && item->mId >= 0 && item->mQuantity > 0; } typedef Item *argument_type; }; @@ -80,7 +80,7 @@ Inventory::~Inventory() Item *Inventory::getItem(const int index) const { - if (index < 0 || index >= CAST_S32(mSize) || !mItems[index] + if (index < 0 || index >= CAST_S32(mSize) || (mItems[index] == nullptr) || mItems[index]->mQuantity <= 0) { return nullptr; @@ -95,7 +95,7 @@ Item *Inventory::findItem(const int itemId, for (unsigned i = 0; i < mSize; i++) { Item *const item = mItems[i]; - if (item && item->mId == itemId) + if ((item != nullptr) && item->mId == itemId) { if (color == ItemColor_zero || item->mColor == color || @@ -156,7 +156,7 @@ void Inventory::setItem(const int index, } Item *const item1 = mItems[index]; - if (!item1 && id > 0) + if ((item1 == nullptr) && id > 0) { Item *const item = new Item(id, type, @@ -173,7 +173,7 @@ void Inventory::setItem(const int index, mUsed++; distributeSlotsChangedEvent(); } - else if (id > 0 && item1) + else if (id > 0 && (item1 != nullptr)) { item1->setId(id, color); item1->setQuantity(quantity); @@ -183,7 +183,7 @@ void Inventory::setItem(const int index, item1->setDamaged(damaged); item1->setFavorite(favorite); } - else if (item1) + else if (item1 != nullptr) { removeItemAt(index); } @@ -201,7 +201,7 @@ void Inventory::setCards(const int index, } Item *const item1 = mItems[index]; - if (item1) + if (item1 != nullptr) item1->setCards(cards, size); } @@ -215,7 +215,7 @@ void Inventory::setOptions(const int index, return; } Item *const item1 = mItems[index]; - if (item1) + if (item1 != nullptr) item1->setOptions(options); } @@ -230,14 +230,14 @@ void Inventory::removeItem(const int id) for (unsigned i = 0; i < mSize; i++) { const Item *const item = mItems[i]; - if (item && item->mId == id) + if ((item != nullptr) && item->mId == id) removeItemAt(i); } } void Inventory::removeItemAt(const int index) { - if (!mItems[index]) + if (mItems[index] == nullptr) return; delete2(mItems[index]); mUsed--; @@ -249,14 +249,14 @@ void Inventory::removeItemAt(const int index) bool Inventory::contains(const Item *const item) const { - if (!item) + if (item == nullptr) return false; const int id = item->mId; for (unsigned i = 0; i < mSize; i++) { const Item *const item1 = mItems[i]; - if (item1 && item1->mId == id) + if ((item1 != nullptr) && item1->mId == id) return true; } @@ -311,7 +311,7 @@ const Item *Inventory::findItemBySprite(std::string spritePath, for (unsigned i = 0; i < mSize; i++) { const Item *const item = mItems[i]; - if (item) + if (item != nullptr) { std::string path = item->getInfo().getSprite(gender, race); if (!path.empty()) @@ -397,7 +397,7 @@ int Inventory::findIndexByTag(const int tag) const for (unsigned i = 0; i < mSize; i++) { const Item *const item = mItems[i]; - if (item && item->mTag == tag) + if ((item != nullptr) && item->mTag == tag) return i; } @@ -408,7 +408,7 @@ bool Inventory::addVirtualItem(const Item *const item, int index, const int amount) { - if (item && !PlayerInfo::isItemProtected(item->getId())) + if ((item != nullptr) && !PlayerInfo::isItemProtected(item->getId())) { if (index >= 0 && index < CAST_S32(mSize)) { @@ -443,7 +443,7 @@ bool Inventory::addVirtualItem(const Item *const item, return false; Item *const item2 = getItem(index); - if (item2) + if (item2 != nullptr) item2->setTag(item->getInvIndex()); return true; } @@ -453,7 +453,7 @@ bool Inventory::addVirtualItem(const Item *const item, void Inventory::virtualRemove(Item *const item, const int amount) { - if (!item || item->mQuantity < amount) + if ((item == nullptr) || item->mQuantity < amount) return; const int index = item->getInvIndex(); @@ -475,7 +475,7 @@ void Inventory::restoreVirtuals() if (index < 0 || index >= sz) continue; Item *const item = mItems[index]; - if (!item) + if (item == nullptr) continue; item->mQuantity += (*it).second; } @@ -492,7 +492,7 @@ void Inventory::virtualRestore(const Item *const item, mVirtualRemove[index] -= amount; if (mVirtualRemove[index] < 0) mVirtualRemove.erase(index); - if (index < 0 || index >= CAST_S32(mSize) || !mItems[index]) + if (index < 0 || index >= CAST_S32(mSize) || (mItems[index] == nullptr)) return; mItems[index]->mQuantity += amount; } @@ -511,9 +511,9 @@ void Inventory::moveItem(const int index1, Item *const item1 = mItems[index1]; Item *const item2 = mItems[index2]; - if (item1) + if (item1 != nullptr) item1->setInvIndex(index2); - if (item2) + if (item2 != nullptr) item2->setInvIndex(index1); mItems[index1] = item2; mItems[index2] = item1; diff --git a/src/resources/item/cardslist.h b/src/resources/item/cardslist.h index f4c488404..6bc1f5e22 100644 --- a/src/resources/item/cardslist.h +++ b/src/resources/item/cardslist.h @@ -42,7 +42,7 @@ struct CardsList final explicit CardsList(const int *const cards0) { - if (cards0) + if (cards0 != nullptr) { for (int f = 0; f < maxCards; f ++) cards[f] = cards0[f]; diff --git a/src/resources/item/complexitem.cpp b/src/resources/item/complexitem.cpp index 08901a90e..047c50614 100644 --- a/src/resources/item/complexitem.cpp +++ b/src/resources/item/complexitem.cpp @@ -57,7 +57,7 @@ ComplexItem::~ComplexItem() void ComplexItem::addChild(const Item *const item, const int amount) { - if (!item) + if (item == nullptr) return; increaseQuantity(amount); Item *child = nullptr; @@ -72,7 +72,7 @@ void ComplexItem::addChild(const Item *const item, break; } } - if (child) + if (child != nullptr) { child->increaseQuantity(amount); } diff --git a/src/resources/item/item.cpp b/src/resources/item/item.cpp index c2c25a78c..897340732 100644 --- a/src/resources/item/item.cpp +++ b/src/resources/item/item.cpp @@ -78,7 +78,7 @@ Item::Item(const int id, Item::~Item() { - if (mImage) + if (mImage != nullptr) { mImage->decRef(); mImage = nullptr; @@ -97,7 +97,7 @@ void Item::setId(const int id, mEquipment = fromBool(id && CAST_S32(getInfo().getType()) >= 2, Equipm); - if (mImage) + if (mImage != nullptr) mImage->decRef(); const ItemInfo &info = getInfo(); @@ -108,7 +108,7 @@ void Item::setId(const int id, info.getDyeIconColorsString(color)); mImage = Loader::getImage(dye); - if (!mImage) + if (mImage == nullptr) { mImage = Theme::getImageFromTheme(paths.getValue("unknownItemFile", "unknown-item.png")); @@ -131,7 +131,7 @@ Image *Item::getImage(const int id, "itemIcons"), info.getDisplay().image), info.getDyeIconColorsString(color))); - if (!image) + if (image == nullptr) image = Theme::getImageFromTheme("unknown-item.png"); return image; } @@ -167,7 +167,7 @@ int Item::getCard(const int index) const void Item::setCards(const int *const cards, const int size) { - if (size < 0 || !cards) + if (size < 0 || (cards == nullptr)) return; int sz = size; if (sz > maxCards) @@ -180,7 +180,7 @@ void Item::addCard(const int card) { for (int f = 0; f < maxCards; f ++) { - if (!mCards[f]) + if (mCards[f] == 0) { mCards[f] = card; return; diff --git a/src/resources/item/shopitem.cpp b/src/resources/item/shopitem.cpp index 0c013ee89..99e0c43dd 100644 --- a/src/resources/item/shopitem.cpp +++ b/src/resources/item/shopitem.cpp @@ -102,7 +102,7 @@ void ShopItem::updateDisplayName(const int quantity) else #endif // TMWA_SUPPORT mDisplayName = std::string(getInfo().getName(mColor)); - if (mPrice) + if (mPrice != 0) { mDisplayName.append(" (").append( UnitsDb::formatCurrency(mCurrency, mPrice)).append(") "); @@ -138,7 +138,7 @@ void ShopItem::addDuplicate() int ShopItem::sellCurrentDuplicate(const int quantity) { DuplicateItem* dupl = mDuplicates.top(); - if (!dupl) + if (dupl == nullptr) return 0; const int sellCount = quantity <= dupl->quantity @@ -155,7 +155,7 @@ int ShopItem::sellCurrentDuplicate(const int quantity) void ShopItem::increaseUsedQuantity(const int amount) { - if (mShowQuantity && mQuantity) + if (mShowQuantity && (mQuantity != 0)) { if (mQuantity < mUsedQuantity + amount || mUsedQuantity + amount < 0) diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 75e166a0d..7a88a63ca 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -95,7 +95,7 @@ ItemInfo::~ItemInfo() const std::string &ItemInfo::getSprite(const GenderT gender, const BeingTypeId race) const { - if (mView) + if (mView != 0) { // Forward the request to the item defining how to view this item return ItemDB::get(mView).getSprite(gender, race); @@ -177,7 +177,7 @@ IntMap *ItemInfo::addReplaceSprite(const int sprite, SpriteToItemMap *spMap = mSpriteToItemReplaceMap[direction]; - if (!spMap) + if (spMap == nullptr) { spMap = new SpriteToItemMap; mSpriteToItemReplaceMap[direction] = spMap; @@ -224,7 +224,7 @@ void ItemInfo::setIconColorsList(const std::string &name) std::string ItemInfo::getDyeColorsString(const ItemColor color) const { - if (!mColorsList || mColorsListName.empty()) + if ((mColorsList == nullptr) || mColorsListName.empty()) return ""; const std::map <ItemColor, ColorDB::ItemColorData>::const_iterator @@ -237,7 +237,7 @@ std::string ItemInfo::getDyeColorsString(const ItemColor color) const std::string ItemInfo::getDyeIconColorsString(const ItemColor color) const { - if (!mIconColorsList || mIconColorsListName.empty()) + if ((mIconColorsList == nullptr) || mIconColorsListName.empty()) return ""; const std::map <ItemColor, ColorDB::ItemColorData>::const_iterator @@ -267,7 +267,7 @@ const std::string ItemInfo::replaceColors(std::string str, const ItemColor color) const { std::string name; - if (mColorsList && !mColorsListName.empty()) + if ((mColorsList != nullptr) && !mColorsListName.empty()) { const std::map <ItemColor, ColorDB::ItemColorData>::const_iterator it = mColorsList->find(color); @@ -295,7 +295,7 @@ const SpriteToItemMap *ItemInfo::getSpriteToItemReplaceMap(const int direction) return nullptr; const SpriteToItemMap *const spMap = mSpriteToItemReplaceMap[direction]; - if (spMap) + if (spMap != nullptr) return spMap; if (direction == SpriteDirection::UPLEFT || direction == SpriteDirection::UPRIGHT) @@ -410,7 +410,7 @@ void ItemInfo::setSprite(const std::string &animationFile, std::string ItemInfo::getColorName(const ItemColor idx) const { - if (!mColorsList) + if (mColorsList == nullptr) return std::string(); const std::map <ItemColor, ColorDB::ItemColorData>::const_iterator @@ -427,7 +427,7 @@ std::string ItemInfo::getColorName(const ItemColor idx) const std::string ItemInfo::getColor(const ItemColor idx) const { - if (!mColorsList) + if (mColorsList == nullptr) return std::string(); const std::map <ItemColor, ColorDB::ItemColorData>::const_iterator @@ -444,7 +444,7 @@ std::string ItemInfo::getColor(const ItemColor idx) const std::string ItemInfo::getIconColorName(const ItemColor idx) const { - if (!mIconColorsList) + if (mIconColorsList == nullptr) return std::string(); const std::map <ItemColor, ColorDB::ItemColorData>::const_iterator @@ -461,7 +461,7 @@ std::string ItemInfo::getIconColorName(const ItemColor idx) const std::string ItemInfo::getIconColor(const ItemColor idx) const { - if (!mIconColorsList) + if (mIconColorsList == nullptr) return std::string(); const std::map <ItemColor, ColorDB::ItemColorData>::const_iterator diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 722db5c15..502fbfbf7 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -303,12 +303,12 @@ class ItemInfo final { return mProtected; } int getColorsSize() const noexcept2 A_WARN_UNUSED - { return mColorsList ? CAST_S32(mColorsList->size()) : 0; } + { return mColorsList != nullptr ? CAST_S32(mColorsList->size()) : 0; } int getIconColorsSize() const noexcept2 A_WARN_UNUSED { - return mIconColorsList ? CAST_S32(mIconColorsList->size()) - : 0; + return mIconColorsList != nullptr ? + CAST_S32(mIconColorsList->size()) : 0; } std::string getColorName(const ItemColor idx) const; diff --git a/src/resources/loaders/atlasloader.cpp b/src/resources/loaders/atlasloader.cpp index d3e2e276f..9f7b4ab09 100644 --- a/src/resources/loaders/atlasloader.cpp +++ b/src/resources/loaders/atlasloader.cpp @@ -40,13 +40,13 @@ struct AtlasLoader final static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const AtlasLoader *const rl = static_cast<const AtlasLoader *>(v); AtlasResource *const resource = AtlasManager::loadTextureAtlas( rl->name, *rl->files); - if (!resource) + if (resource == nullptr) reportAlways("Atlas creation error: %s", rl->name.c_str()); return resource; } diff --git a/src/resources/loaders/emptyatlasloader.cpp b/src/resources/loaders/emptyatlasloader.cpp index 24c73ac21..3138c821b 100644 --- a/src/resources/loaders/emptyatlasloader.cpp +++ b/src/resources/loaders/emptyatlasloader.cpp @@ -40,14 +40,14 @@ struct EmptyAtlasLoader final static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const EmptyAtlasLoader *const rl = static_cast<const EmptyAtlasLoader *>(v); AtlasResource *const resource = AtlasManager::loadEmptyAtlas( rl->name, *rl->files); - if (!resource) + if (resource == nullptr) reportAlways("Empty atlas creation error: %s", rl->name.c_str()); return resource; } diff --git a/src/resources/loaders/imageloader.cpp b/src/resources/loaders/imageloader.cpp index 5a1830e15..c5635ef14 100644 --- a/src/resources/loaders/imageloader.cpp +++ b/src/resources/loaders/imageloader.cpp @@ -46,7 +46,7 @@ namespace static Resource *load(const void *const v) { BLOCK_START("DyedImageLoader::load") - if (!v) + if (v == nullptr) { BLOCK_END("DyedImageLoader::load") return nullptr; @@ -64,17 +64,17 @@ namespace path1 = path1.substr(0, p); } SDL_RWops *const rw = VirtFs::rwopsOpenRead(path1); - if (!rw) + if (rw == nullptr) { delete d; reportAlways("Image loading error: %s", path1.c_str()); BLOCK_END("DyedImageLoader::load") return nullptr; } - Resource *const res = d ? imageHelper->load(rw, *d) + Resource *const res = d != nullptr ? imageHelper->load(rw, *d) : imageHelper->load(rw); delete d; - if (!res) + if (res == nullptr) reportAlways("Image loading error: %s", path1.c_str()); BLOCK_END("DyedImageLoader::load") return res; diff --git a/src/resources/loaders/imagesetloader.cpp b/src/resources/loaders/imagesetloader.cpp index 342b26d9a..63b56d1fe 100644 --- a/src/resources/loaders/imagesetloader.cpp +++ b/src/resources/loaders/imagesetloader.cpp @@ -44,14 +44,14 @@ struct ImageSetLoader final static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const ImageSetLoader *const rl = static_cast<const ImageSetLoader *>(v); Image *const img = Loader::getImage(rl->path); - if (!img) + if (img == nullptr) { reportAlways("Image loading error: %s", rl->path.c_str()); return nullptr; diff --git a/src/resources/loaders/musicloader.cpp b/src/resources/loaders/musicloader.cpp index 23a994e1b..f0b67cb67 100644 --- a/src/resources/loaders/musicloader.cpp +++ b/src/resources/loaders/musicloader.cpp @@ -42,12 +42,12 @@ namespace static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const ResourceLoader *const rl = static_cast<const ResourceLoader *>(v); SDL_RWops *const rw = VirtFs::rwopsOpenRead(rl->path); - if (!rw) + if (rw == nullptr) { reportAlways("Error loading resource: %s", rl->path.c_str()); diff --git a/src/resources/loaders/rescaledloader.cpp b/src/resources/loaders/rescaledloader.cpp index c6a70f969..cea73b382 100644 --- a/src/resources/loaders/rescaledloader.cpp +++ b/src/resources/loaders/rescaledloader.cpp @@ -42,15 +42,15 @@ namespace const int height; static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const RescaledLoader *const rl = static_cast<const RescaledLoader *>(v); - if (!rl->image) + if (rl->image == nullptr) return nullptr; Image *const rescaled = rl->image->SDLgetScaledImage( rl->width, rl->height); - if (!rescaled) + if (rescaled == nullptr) { reportAlways("Rescale image failed: %s", rl->image->mIdPath.c_str()); @@ -65,7 +65,7 @@ Image *Loader::getRescaled(const Image *const image, const int width, const int height) { - if (!image) + if (image == nullptr) return nullptr; const std::string idPath = image->mIdPath + strprintf( diff --git a/src/resources/loaders/shaderloader.cpp b/src/resources/loaders/shaderloader.cpp index 5d5b70869..550be0a75 100644 --- a/src/resources/loaders/shaderloader.cpp +++ b/src/resources/loaders/shaderloader.cpp @@ -44,13 +44,13 @@ namespace static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const ShaderLoader *const rl = static_cast<const ShaderLoader *>(v); Shader *const resource = shaders.createShader(rl->type, rl->name); - if (!resource) + if (resource == nullptr) reportAlways("Shader creation error: %s", rl->name.c_str()); return resource; } diff --git a/src/resources/loaders/shaderprogramloader.cpp b/src/resources/loaders/shaderprogramloader.cpp index 2f73cb5a8..fe4a5cf50 100644 --- a/src/resources/loaders/shaderprogramloader.cpp +++ b/src/resources/loaders/shaderprogramloader.cpp @@ -45,7 +45,7 @@ namespace static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const ShaderProgramLoader *const rl @@ -54,7 +54,7 @@ namespace rl->vertex, rl->fragment, rl->isNewShader); - if (!resource) + if (resource == nullptr) reportAlways("Shader program creation error"); return resource; } diff --git a/src/resources/loaders/soundloader.cpp b/src/resources/loaders/soundloader.cpp index f5e7f1058..a84898201 100644 --- a/src/resources/loaders/soundloader.cpp +++ b/src/resources/loaders/soundloader.cpp @@ -42,12 +42,12 @@ namespace static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const ResourceLoader *const rl = static_cast<const ResourceLoader *>(v); SDL_RWops *const rw = VirtFs::rwopsOpenRead(rl->path); - if (!rw) + if (rw == nullptr) { reportAlways("Error loading resource: %s", rl->path.c_str()); @@ -56,7 +56,7 @@ namespace // Load the music data and free the RWops structure Mix_Chunk *const tmpSoundEffect = Mix_LoadWAV_RW(rw, 1); - if (tmpSoundEffect) + if (tmpSoundEffect != nullptr) { return new SoundEffect(tmpSoundEffect, rl->path); } diff --git a/src/resources/loaders/spritedefloader.cpp b/src/resources/loaders/spritedefloader.cpp index 69f182b89..2e91d759b 100644 --- a/src/resources/loaders/spritedefloader.cpp +++ b/src/resources/loaders/spritedefloader.cpp @@ -42,7 +42,7 @@ namespace const int variant; static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const SpriteDefLoader *const diff --git a/src/resources/loaders/subimageloader.cpp b/src/resources/loaders/subimageloader.cpp index f340f69c9..a4ccc2346 100644 --- a/src/resources/loaders/subimageloader.cpp +++ b/src/resources/loaders/subimageloader.cpp @@ -44,17 +44,17 @@ namespace const int height; static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const SubImageLoader *const rl = static_cast<const SubImageLoader *>(v); - if (!rl->parent) + if (rl->parent == nullptr) return nullptr; Image *const res = rl->parent->getSubImage(rl->x, rl->y, rl->width, rl->height); - if (!res) + if (res == nullptr) { reportAlways("SubImage loading error: %s", rl->parent->mSource.c_str()); @@ -70,7 +70,7 @@ Image *Loader::getSubImage(Image *const parent, const int width, const int height) { - if (!parent) + if (parent == nullptr) return nullptr; const SubImageLoader rl = { parent, x, y, width, height}; diff --git a/src/resources/loaders/subimagesetloader.cpp b/src/resources/loaders/subimagesetloader.cpp index 4aefb4c2e..ef47b164d 100644 --- a/src/resources/loaders/subimagesetloader.cpp +++ b/src/resources/loaders/subimagesetloader.cpp @@ -43,13 +43,13 @@ namespace int height; static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const SubImageSetLoader *const rl = static_cast<const SubImageSetLoader *>(v); - if (!rl->parent) + if (rl->parent == nullptr) return nullptr; ImageSet *const res = new ImageSet(rl->parent, rl->width, rl->height); @@ -62,7 +62,7 @@ ImageSet *Loader::getSubImageSet(Image *const parent, const int width, const int height) { - if (!parent) + if (parent == nullptr) return nullptr; const SubImageSetLoader rl = { parent, width, height }; diff --git a/src/resources/loaders/walklayerloader.cpp b/src/resources/loaders/walklayerloader.cpp index c5e4569c8..16be1e2ce 100644 --- a/src/resources/loaders/walklayerloader.cpp +++ b/src/resources/loaders/walklayerloader.cpp @@ -42,13 +42,13 @@ struct WalkLayerLoader final static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const WalkLayerLoader *const rl = static_cast<const WalkLayerLoader *>(v); Resource *const resource = NavigationManager::loadWalkLayer(rl->map); - if (!resource) + if (resource == nullptr) reportAlways("WalkLayer creation error"); return resource; } diff --git a/src/resources/loaders/xmlloader.cpp b/src/resources/loaders/xmlloader.cpp index 9cacd1c41..61618530e 100644 --- a/src/resources/loaders/xmlloader.cpp +++ b/src/resources/loaders/xmlloader.cpp @@ -40,7 +40,7 @@ namespace static Resource *load(const void *const v) { - if (!v) + if (v == nullptr) return nullptr; const ResourceLoader *const rl = static_cast<const ResourceLoader *>(v); diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index f0092c448..f2c8f4636 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -83,7 +83,7 @@ class ActorFunctuator final bool operator()(const Actor *const a, const Actor *const b) const { - if (!a || !b) + if ((a == nullptr) || (b == nullptr)) return false; return a->getSortPixelY() < b->getSortPixelY(); } @@ -174,7 +174,7 @@ Map::~Map() config.removeListeners(this); CHECKLISTENERS - if (mWalkLayer) + if (mWalkLayer != nullptr) { mWalkLayer->decRef(); mWalkLayer = nullptr; @@ -189,7 +189,7 @@ Map::~Map() delete2(mTempLayer); delete2(mObjects); delete_all(mMapPortals); - if (mAtlas) + if (mAtlas != nullptr) { mAtlas->decRef(); mAtlas = nullptr; @@ -244,10 +244,10 @@ void Map::initializeAmbientLayers() restrict2 Image *restrict const img = Loader::getImage( getProperty(name + "image")); - if (img) + if (img != nullptr) { int mask = atoi(getProperty(name + "mask").c_str()); - if (!mask) + if (mask == 0) mask = 1; const float parallax = getFloatProperty(name + "parallax"); mForegrounds.push_back(new AmbientLayer( @@ -275,10 +275,10 @@ void Map::initializeAmbientLayers() restrict2 Image *restrict const img = Loader::getImage( getProperty(name + "image")); - if (img) + if (img != nullptr) { int mask = atoi(getProperty(name + "mask").c_str()); - if (!mask) + if (mask == 0) mask = 1; const float parallax = getFloatProperty(name + "parallax"); @@ -303,7 +303,7 @@ void Map::initializeAmbientLayers() restrict2 void Map::addLayer(MapLayer *const layer) restrict2 { mLayers.push_back(layer); - if (layer->isFringeLayer() && !mFringeLayer) + if (layer->isFringeLayer() && (mFringeLayer == nullptr)) mFringeLayer = layer; } @@ -321,7 +321,7 @@ void Map::update(const int ticks) restrict2 FOR_EACH (TileAnimationMapCIter, iAni, mTileAnimations) { TileAnimation *restrict const tileAni = iAni->second; - if (tileAni && tileAni->update(ticks)) + if ((tileAni != nullptr) && tileAni->update(ticks)) mRedrawMap = true; } } @@ -329,7 +329,7 @@ void Map::update(const int ticks) restrict2 void Map::draw(Graphics *restrict const graphics, int scrollX, int scrollY) restrict2 { - if (!localPlayer) + if (localPlayer == nullptr) return; BLOCK_START("Map::draw") @@ -357,7 +357,7 @@ void Map::draw(Graphics *restrict const graphics, MapLayerPosition::BACKGROUND_LAYERS, mOverlayDetail); - if (mDrawLayersFlags == MapType::BLACKWHITE && userPalette) + if (mDrawLayersFlags == MapType::BLACKWHITE && (userPalette != nullptr)) { graphics->setColor(userPalette->getColorWithAlpha( UserColorId::WALKABLE_HIGHLIGHT)); @@ -395,7 +395,7 @@ void Map::draw(Graphics *restrict const graphics, if (mDrawOnlyFringe) { - if (mFringeLayer) + if (mFringeLayer != nullptr) { mFringeLayer->setSpecialLayer(mSpecialLayer); mFringeLayer->setTempLayer(mTempLayer); @@ -411,7 +411,7 @@ void Map::draw(Graphics *restrict const graphics, #ifdef USE_OPENGL if (mCachedDraw) { - if (updateFlag) + if (updateFlag != 0) { FOR_EACH (Layers::iterator, it, mDrawUnderLayers) { @@ -432,7 +432,7 @@ void Map::draw(Graphics *restrict const graphics, FOR_EACH (Layers::iterator, it, mDrawUnderLayers) (*it)->drawOGL(graphics); - if (mFringeLayer) + if (mFringeLayer != nullptr) { mFringeLayer->setSpecialLayer(mSpecialLayer); mFringeLayer->setTempLayer(mTempLayer); @@ -457,7 +457,7 @@ void Map::draw(Graphics *restrict const graphics, scrollX, scrollY); } - if (mFringeLayer) + if (mFringeLayer != nullptr) { mFringeLayer->setSpecialLayer(mSpecialLayer); mFringeLayer->setTempLayer(mTempLayer); @@ -626,14 +626,14 @@ void Map::updateAmbientLayers(const float scrollX, FOR_EACH (AmbientLayerVectorIter, i, mBackgrounds) { AmbientLayer *const layer = *i; - if (layer && (layer->mMask & mMask)) + if ((layer != nullptr) && ((layer->mMask & mMask) != 0)) layer->update(timePassed, dx, dy); } FOR_EACH (AmbientLayerVectorIter, i, mForegrounds) { AmbientLayer *const layer = *i; - if (layer && (layer->mMask & mMask)) + if ((layer != nullptr) && ((layer->mMask & mMask) != 0)) layer->update(timePassed, dx, dy); } @@ -674,7 +674,7 @@ void Map::drawAmbientLayers(Graphics *restrict const graphics, { const AmbientLayer *restrict const layer = *i; // need check mask to draw or not to draw - if (layer && (layer->mMask & mMask)) + if ((layer != nullptr) && ((layer->mMask & mMask) != 0)) (layer)->draw(graphics, graphics->mWidth, graphics->mHeight); // Detail 1: only one overlay, higher: all overlays @@ -778,7 +778,7 @@ bool Map::getWalk(const int x, const int y, return false; // Check if the tile is walkable - return !(mMetaTiles[x + y * mWidth].blockmask & blockWalkMask); + return (mMetaTiles[x + y * mWidth].blockmask & blockWalkMask) == 0; } unsigned char Map::getBlockMask(const int x, @@ -877,7 +877,7 @@ Path Map::findPath(const int startX, const int startY, // Reset starting tile's G cost to 0 MetaTile *const startTile = &mMetaTiles[startX + startY * mWidth]; - if (!startTile) + if (startTile == nullptr) { BLOCK_END("Map::findPath") return path; @@ -941,9 +941,9 @@ Path Map::findPath(const int startX, const int startY, // can be removed. It left here only for protect from // walk on wall in any case if (newTile->whichList == mOnClosedList || - ((newTile->blockmask & blockWalkMask) + (((newTile->blockmask & blockWalkMask) != 0) && !(x == destX && y == destY)) - || (newTile->blockmask & BlockMask::WALL)) + || ((newTile->blockmask & BlockMask::WALL) != 0)) { continue; } @@ -958,7 +958,7 @@ Path Map::findPath(const int startX, const int startY, dx + curWidth]; // on player abilities. - if (((t1->blockmask | t2->blockmask) & blockWalkMask)) + if (((t1->blockmask | t2->blockmask) & blockWalkMask) != 0) continue; } @@ -1096,7 +1096,7 @@ void Map::addParticleEffect(const std::string &effectFile, void Map::initializeParticleEffects() const restrict2 { BLOCK_START("Map::initializeParticleEffects") - if (!particleEngine) + if (particleEngine == nullptr) { BLOCK_END("Map::initializeParticleEffects") return; @@ -1113,7 +1113,7 @@ void Map::initializeParticleEffects() const restrict2 i->file, i->x, i->y); - if (p && + if ((p != nullptr) && i->w > 0 && i->h > 0) { @@ -1127,7 +1127,7 @@ void Map::initializeParticleEffects() const restrict2 void Map::addExtraLayer() restrict2 { BLOCK_START("Map::addExtraLayer") - if (!mSpecialLayer) + if (mSpecialLayer == nullptr) { logger->log1("No special layer"); BLOCK_END("Map::addExtraLayer") @@ -1137,7 +1137,8 @@ void Map::addExtraLayer() restrict2 "extralayer.txt"); logger->log("loading extra layer: " + mapFileName); struct stat statbuf; - if (!stat(mapFileName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode)) + if (stat(mapFileName.c_str(), &statbuf) == 0 && + S_ISREG(statbuf.st_mode)) { std::ifstream mapFile; mapFile.open(mapFileName.c_str(), std::ios::in); @@ -1201,7 +1202,7 @@ void Map::addExtraLayer() restrict2 void Map::saveExtraLayer() const restrict2 { - if (!mSpecialLayer) + if (mSpecialLayer == nullptr) { logger->log1("No special layer"); return; @@ -1210,7 +1211,7 @@ void Map::saveExtraLayer() const restrict2 "extralayer.txt"); logger->log("saving extra layer: " + mapFileName); - if (mkdir_r(getUserMapDirectory().c_str())) + if (mkdir_r(getUserMapDirectory().c_str()) != 0) { logger->log(strprintf("%s doesn't exist and can't be created! " "Exiting.", getUserMapDirectory().c_str())); @@ -1234,7 +1235,7 @@ void Map::saveExtraLayer() const restrict2 for (int y = 0; y < height; y ++) { const MapItem *restrict const item = mSpecialLayer->getTile(x, y); - if (item && item->mType != MapItemType::EMPTY + if ((item != nullptr) && item->mType != MapItemType::EMPTY && item->mType != MapItemType::HOME) { mapFile << x << " " << y << " " @@ -1257,7 +1258,7 @@ void Map::addRange(const std::string &restrict name, const int x, const int y, const int dx, const int dy) restrict2 { - if (!mObjects) + if (mObjects == nullptr) return; mObjects->addObject(name, type, x / mapTileSize, y / mapTileSize, @@ -1277,7 +1278,7 @@ void Map::addPortalTile(const std::string &restrict name, const int type, const int x, const int y) restrict2 { - if (mSpecialLayer) + if (mSpecialLayer != nullptr) { mSpecialLayer->setTile(x, y, new MapItem(type, name, x, y)); mSpecialLayer->updateCache(); @@ -1292,13 +1293,13 @@ void Map::updatePortalTile(const std::string &restrict name, const bool addNew) restrict2 { MapItem *restrict item = findPortalXY(x, y); - if (item) + if (item != nullptr) { item->mComment = name; item->setType(type); item->mX = x; item->mY = y; - if (mSpecialLayer) + if (mSpecialLayer != nullptr) { item = new MapItem(type, name, x, y); mSpecialLayer->setTile(x, y, item); @@ -1315,7 +1316,7 @@ MapItem *Map::findPortalXY(const int x, const int y) const restrict2 { FOR_EACH (std::vector<MapItem*>::const_iterator, it, mMapPortals) { - if (!*it) + if (*it == nullptr) continue; MapItem *restrict const item = *it; @@ -1338,12 +1339,12 @@ void Map::setPvpMode(const int mode) restrict2 { const int oldMode = mPvp; - if (!mode) + if (mode == 0) mPvp = 0; else mPvp |= mode; - if (mPvp != oldMode && localPlayer) + if (mPvp != oldMode && (localPlayer != nullptr)) { switch (mPvp) { @@ -1369,11 +1370,11 @@ void Map::setPvpMode(const int mode) restrict2 std::string Map::getObjectData(const unsigned x, const unsigned y, const int type) const restrict2 { - if (!mObjects) + if (mObjects == nullptr) return ""; MapObjectList *restrict const list = mObjects->getAt(x, y); - if (!list) + if (list == nullptr) return ""; std::vector<MapObject>::const_iterator it = list->objects.begin(); @@ -1400,14 +1401,14 @@ void Map::indexTilesets() restrict2 FOR_EACH (Tilesets::const_iterator, it, mTilesets) { const size_t sz = (*it)->size(); - if (!s || CAST_SIZE(s->getFirstGid()) + sSz + if ((s == nullptr) || CAST_SIZE(s->getFirstGid()) + sSz < CAST_SIZE((*it)->getFirstGid()) + sz) { s = *it; sSz = sz; } } - if (!s) + if (s == nullptr) { mIndexedTilesetsSize = 0; mIndexedTilesets = nullptr; @@ -1423,7 +1424,7 @@ void Map::indexTilesets() restrict2 FOR_EACH (Tilesets::const_iterator, it, mTilesets) { Tileset *restrict const s2 = *it; - if (s2) + if (s2 != nullptr) { const int start = s2->getFirstGid(); const int end = start + CAST_S32(s2->size()); @@ -1452,7 +1453,7 @@ void Map::reduce() restrict2 return; #else // USE_SDL2 - if (!mFringeLayer || + if ((mFringeLayer == nullptr) || mOpenGL != RENDER_SOFTWARE || !config.getBoolValue("enableMapReduce")) { @@ -1479,7 +1480,7 @@ void Map::reduce() restrict2 Image *restrict const img = layer->mTiles[x + y * layer->mWidth].image; - if (img) + if (img != nullptr) { if (img->hasAlphaChannel() && img->isAlphaCalculated()) { @@ -1505,7 +1506,7 @@ void Map::reduce() restrict2 { const uint8_t *restrict const arr = img->SDLgetAlphaChannel(); - if (!arr) + if (arr == nullptr) continue; bool bad(false); @@ -1513,7 +1514,7 @@ void Map::reduce() restrict2 int width; const SubImage *restrict const subImg = dynamic_cast<SubImage*>(img); - if (subImg) + if (subImg != nullptr) width = subImg->mInternalBounds.w; else width = img->mBounds.w; @@ -1570,7 +1571,7 @@ void Map::reduce() restrict2 const Image *restrict img = layer->mTiles[x + y * layer->mWidth].image; - if (img && !img->isAlphaVisible()) + if ((img != nullptr) && !img->isAlphaVisible()) { // removing all down tiles ++ ri; while (ri != mLayers.rend()) @@ -1585,7 +1586,7 @@ void Map::reduce() restrict2 const size_t pos = CAST_SIZE( x + y * layer2->mWidth); img = layer2->mTiles[pos].image; - if (img) + if (img != nullptr) { layer2->mTiles[pos].image = nullptr; cnt ++; @@ -1610,7 +1611,7 @@ void Map::addHeights(const MapHeights *restrict const heights) restrict2 uint8_t Map::getHeightOffset(const int x, const int y) const restrict2 { - if (!mHeights) + if (mHeights == nullptr) return 0; return mHeights->getHeight(x, y); } @@ -1628,7 +1629,7 @@ void Map::updateDrawLayersList() restrict2 for (; layers != layers_end; ++ layers) { MapLayer *const layer = *layers; - if (!(layer->mMask & mMask)) + if ((layer->mMask & mMask) == 0) continue; if (layer->isFringeLayer()) @@ -1646,7 +1647,7 @@ void Map::updateDrawLayersList() restrict2 for (; layers != layers_end; ++ layers) { MapLayer *const layer = *layers; - if (!(layer->mMask & mMask)) + if ((layer->mMask & mMask) == 0) continue; mDrawOverLayers.push_back(layer); @@ -1705,7 +1706,7 @@ void Map::setActorsFix(const int x, const int y) restrict2 { mActorFixX = x; mActorFixY = y; - if (mFringeLayer) + if (mFringeLayer != nullptr) mFringeLayer->setActorsFix(y); } @@ -1716,7 +1717,7 @@ void Map::updateConditionLayers() restrict2 FOR_EACH (LayersCIter, it, mLayers) { MapLayer *restrict const layer = *it; - if (!layer || layer->mTileCondition == -1) + if ((layer == nullptr) || layer->mTileCondition == -1) continue; layer->updateConditionTiles(mMetaTiles, mWidth, mHeight); @@ -1728,7 +1729,7 @@ void Map::preCacheLayers() restrict2 FOR_EACH (LayersCIter, it, mLayers) { MapLayer *restrict const layer = *it; - if (layer) + if (layer != nullptr) layer->updateCache(mWidth, mHeight); } } @@ -1755,7 +1756,7 @@ int Map::calcMemoryChilds(const int level) const { int sz = 0; - if (mWalkLayer) + if (mWalkLayer != nullptr) sz += mWalkLayer->calcMemory(level + 1); FOR_EACH (LayersCIter, it, mLayers) { @@ -1773,13 +1774,13 @@ int Map::calcMemoryChilds(const int level) const { sz += (*it)->calcMemory(level + 1); } - if (mSpecialLayer) + if (mSpecialLayer != nullptr) mSpecialLayer->calcMemory(level + 1); - if (mTempLayer) + if (mTempLayer != nullptr) mTempLayer->calcMemory(level + 1); - if (mObjects) + if (mObjects != nullptr) mObjects->calcMemory(level + 1); - if (mHeights) + if (mHeights != nullptr) mHeights->calcMemory(level + 1); return sz; } diff --git a/src/resources/map/mapitem.cpp b/src/resources/map/mapitem.cpp index eeca6cbf5..ce9e38fec 100644 --- a/src/resources/map/mapitem.cpp +++ b/src/resources/map/mapitem.cpp @@ -82,7 +82,7 @@ MapItem::MapItem(const int type, std::string comment, MapItem::~MapItem() { - if (mImage) + if (mImage != nullptr) { mImage->decRef(); mImage = nullptr; @@ -93,7 +93,7 @@ void MapItem::setType(const int type) { std::string name; mType = type; - if (mImage) + if (mImage != nullptr) mImage->decRef(); switch (type) @@ -130,7 +130,7 @@ void MapItem::draw(Graphics *const graphics, const int x, const int y, const int dx, const int dy) const { BLOCK_START("MapItem::draw") - if (mImage) + if (mImage != nullptr) graphics->drawImage(mImage, x, y); switch (mType) diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp index 4c6fe3a1e..2598b029c 100644 --- a/src/resources/map/maplayer.cpp +++ b/src/resources/map/maplayer.cpp @@ -316,7 +316,7 @@ void MapLayer::updateOGL(Graphics *const graphics, if (mSpecialFlag || img->mBounds.h <= mapTileSize) { - if (!lastImage || + if ((lastImage == nullptr) || lastImage->mGLImage != imgGlImage) { if (img->mBounds.w > mapTileSize) @@ -328,7 +328,7 @@ void MapLayer::updateOGL(Graphics *const graphics, } else { - if (lastImage) + if (lastImage != nullptr) imgSet[lastImage->mGLImage] = imgVert; imgVert = new ImageVertexes; imgVert->ogl.init(); @@ -387,7 +387,7 @@ void MapLayer::drawSpecialLayer(Graphics *const graphics, endX1 = 0; int x0 = startX; const MapItem *item0 = mSpecialLayer->mTiles[ptr + startX]; - if (!item0 || item0->mType == MapItemType::EMPTY) + if ((item0 == nullptr) || item0->mType == MapItemType::EMPTY) { x0 += mSpecialLayer->mCache[ptr + startX] + 1; } @@ -395,7 +395,7 @@ void MapLayer::drawSpecialLayer(Graphics *const graphics, { const int px1 = x * mapTileSize - scrollX; const MapItem *const item = mSpecialLayer->mTiles[ptr + x]; - if (item) + if (item != nullptr) { item->draw(graphics, px1, py1, mapTileSize, mapTileSize); @@ -410,7 +410,7 @@ void MapLayer::drawSpecialLayer(Graphics *const graphics, if (endX1 > specialWidth) endX1 = specialWidth; item0 = mTempLayer->mTiles[ptr + startX]; - if (!item0 || item0->mType == MapItemType::EMPTY) + if ((item0 == nullptr) || item0->mType == MapItemType::EMPTY) { x0 += mTempLayer->mCache[ptr + startX] + 1; } @@ -434,9 +434,9 @@ void MapLayer::drawFringe(Graphics *const graphics, const Actors &actors) const restrict { BLOCK_START("MapLayer::drawFringe") - if (!localPlayer || - !mSpecialLayer || - !mTempLayer) + if ((localPlayer == nullptr) || + (mSpecialLayer == nullptr) || + (mTempLayer == nullptr)) { BLOCK_END("MapLayer::drawFringe") return; @@ -684,7 +684,7 @@ void MapLayer::drawFringe(Graphics *const graphics, h += mapTileSize; } - if (userPalette) + if (userPalette != nullptr) { graphics->setColor(userPalette->getColorWithAlpha( UserColorId::ATTACK_RANGE)); @@ -783,7 +783,7 @@ void MapLayer::updateConditionTiles(const MetaTile *const metaTiles, for (int x = mX; x < width1; x ++, metaPtr ++, tilePtr ++) { if (tilePtr->image != nullptr && - (metaPtr->blockmask & mTileCondition || + (((metaPtr->blockmask & mTileCondition) != 0) || (metaPtr->blockmask == 0 && mTileCondition == BlockMask::GROUND))) { @@ -841,9 +841,9 @@ int MapLayer::calcMemoryLocal() const int MapLayer::calcMemoryChilds(const int level) const { int sz = 0; - if (mSpecialLayer) + if (mSpecialLayer != nullptr) sz += mSpecialLayer->calcMemory(level + 1); - if (mTempLayer) + if (mTempLayer != nullptr) sz += mTempLayer->calcMemory(level + 1); return sz; } diff --git a/src/resources/map/objectslayer.cpp b/src/resources/map/objectslayer.cpp index a100b2c7d..3224da0e6 100644 --- a/src/resources/map/objectslayer.cpp +++ b/src/resources/map/objectslayer.cpp @@ -48,7 +48,7 @@ void ObjectsLayer::addObject(const std::string &name, const int type, const unsigned x, const unsigned y, unsigned dx, unsigned dy) { - if (!mTiles) + if (mTiles == nullptr) return; if (x + dx > mWidth) @@ -63,7 +63,7 @@ void ObjectsLayer::addObject(const std::string &name, const int type, for (unsigned i = idx1; i < idx2; i ++) { - if (!mTiles[i]) + if (mTiles[i] == nullptr) mTiles[i] = new MapObjectList; mTiles[i]->objects.push_back(MapObject(type, name)); } diff --git a/src/resources/map/speciallayer.cpp b/src/resources/map/speciallayer.cpp index 4e826dc42..75b56be28 100644 --- a/src/resources/map/speciallayer.cpp +++ b/src/resources/map/speciallayer.cpp @@ -72,7 +72,7 @@ void SpecialLayer::setTile(const int x, const int y, MapItem *const item) const int idx = x + y * mWidth; delete mTiles[idx]; - if (item) + if (item != nullptr) item->setPos(x, y); mTiles[idx] = item; } @@ -87,7 +87,7 @@ void SpecialLayer::setTile(const int x, const int y, const int type) const int idx = x + y * mWidth; MapItem *const tile = mTiles[idx]; - if (tile) + if (tile != nullptr) { tile->setType(type); tile->setPos(x, y); @@ -105,7 +105,7 @@ void SpecialLayer::addRoad(const Path &road) { const Position &pos = (*i); MapItem *const item = getTile(pos.x, pos.y); - if (!item) + if (item == nullptr) setTile(pos.x, pos.y, new MapItem(MapItemType::ROAD)); else item->setType(MapItemType::ROAD); @@ -115,13 +115,13 @@ void SpecialLayer::addRoad(const Path &road) void SpecialLayer::clean() { - if (!mTiles) + if (mTiles == nullptr) return; for (int f = 0; f < mWidth * mHeight; f ++) { MapItem *const item = mTiles[f]; - if (item) + if (item != nullptr) item->setType(MapItemType::EMPTY); } updateCache(); @@ -148,7 +148,7 @@ void SpecialLayer::draw(Graphics *const graphics, int startX, int startY, for (int x = startX; x < endX; x ++) { const MapItem *const item = mTiles[x + y2]; - if (item) + if (item != nullptr) { item->draw(graphics, x * mapTileSize - scrollX, py, mapTileSize, mapTileSize); diff --git a/src/resources/map/tileanimation.cpp b/src/resources/map/tileanimation.cpp index 03a6ff1f4..c8ce52a70 100644 --- a/src/resources/map/tileanimation.cpp +++ b/src/resources/map/tileanimation.cpp @@ -44,7 +44,7 @@ TileAnimation::~TileAnimation() bool TileAnimation::update(const int ticks) { - if (!mAnimation) + if (mAnimation == nullptr) return false; // update animation @@ -57,7 +57,7 @@ bool TileAnimation::update(const int ticks) { FOR_EACH (TilePairVectorCIter, i, mAffected) { - if (i->first) + if (i->first != nullptr) i->first->setTile(i->second, img); } mLastImage = img; diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 3d82d0404..b795b5e0f 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -147,7 +147,7 @@ PRAGMACLANG6GCC(GCC diagnostic pop) do { - if (!strm.next_out) + if (strm.next_out == nullptr) { inflateEnd(&strm); return Z_MEM_ERROR; @@ -174,7 +174,7 @@ PRAGMACLANG6GCC(GCC diagnostic pop) { out = static_cast<unsigned char*>(realloc(out, bufferSize * 2)); - if (!out) + if (out == nullptr) { inflateEnd(&strm); return Z_MEM_ERROR; @@ -199,7 +199,7 @@ int inflateMemory(unsigned char *restrict const in, unsigned int outLength = 0; const int ret = inflateMemory(in, inLength, out, outLength); - if (ret != Z_OK || !out) + if (ret != Z_OK || (out == nullptr)) { if (ret == Z_MEM_ERROR) { @@ -233,7 +233,7 @@ void MapReader::addLayerToList(const std::string &fileName, UseVirtFs_true, skipError); XmlNodePtrConst node = doc->rootNode(); - if (!node) + if (node == nullptr) { delete doc; return; @@ -253,7 +253,7 @@ void MapReader::addLayerToList(const std::string &fileName, mKnownDocs.insert(doc); cnt ++; } - if (!cnt) + if (cnt == 0) delete doc; } @@ -274,7 +274,7 @@ Map *MapReader::readMap(const std::string &restrict filename, Map *map = nullptr; // Parse the inflated map data - if (node) + if (node != nullptr) { if (!xmlNameEqual(node, "map")) logger->log("Error: Not a map file (%s)!", realFilename.c_str()); @@ -287,7 +287,7 @@ Map *MapReader::readMap(const std::string &restrict filename, realFilename.c_str()); } - if (map) + if (map != nullptr) { map->setProperty("_filename", realFilename); map->setProperty("_realfilename", filename); @@ -328,7 +328,7 @@ static void loadReplaceLayer(const LayerInfoIterator &it, Map *MapReader::readMap(XmlNodePtrConst node, const std::string &path) { - if (!node) + if (node == nullptr) return nullptr; BLOCK_START("MapReader::readMap xml") @@ -368,7 +368,7 @@ Map *MapReader::readMap(XmlNodePtrConst node, const std::string &path) if (graphicsManager.getUseAtlases()) { const MapInfo *const info = MapDB::getMapAtlas(fileName); - if (info) + if (info != nullptr) { map->setAtlas(Loader::getAtlas( info->atlas, @@ -388,7 +388,7 @@ Map *MapReader::readMap(XmlNodePtrConst node, const std::string &path) if (xmlNameEqual(childNode, "tileset")) { Tileset *const tileset = readTileset(childNode, pathDir, map); - if (tileset) + if (tileset != nullptr) map->addTileset(tileset); } else if (xmlNameEqual(childNode, "layer")) @@ -519,7 +519,7 @@ void MapReader::readProperties(XmlNodeConstPtrConst node, Properties *const props) { BLOCK_START("MapReader::readProperties") - if (!node) + if (node == nullptr) { BLOCK_END("MapReader::readProperties") return; @@ -564,16 +564,16 @@ inline static void setTile(Map *const map, { case MapLayerType::TILES: { - Image *const img = set ? set->get(gid - set->getFirstGid()) + Image *const img = set != nullptr ? set->get(gid - set->getFirstGid()) : nullptr; - if (layer) + if (layer != nullptr) layer->setTile(x, y, img); break; } case MapLayerType::COLLISION: { - if (set) + if (set != nullptr) { if (map->getVersion() >= 1) { @@ -627,9 +627,9 @@ inline static void setTile(Map *const map, case MapLayerType::HEIGHTS: { - if (!set || !heights) + if ((set == nullptr) || (heights == nullptr)) break; - if (heights && map->getVersion() >= 2) + if ((heights != nullptr) && map->getVersion() >= 2) { heights->setHeight(x, y, CAST_U8( gid - set->getFirstGid() + 1)); @@ -637,7 +637,7 @@ inline static void setTile(Map *const map, else { Image *const img = set->get(gid - set->getFirstGid()); - if (layer) + if (layer != nullptr) layer->setTile(x, y, img); } break; @@ -658,7 +658,7 @@ bool MapReader::readBase64Layer(XmlNodeConstPtrConst childNode, int &restrict x, int &restrict y, const int w, const int h) { - if (!childNode) + if (childNode == nullptr) return false; if (!compression.empty() && compression != "gzip" @@ -677,7 +677,7 @@ bool MapReader::readBase64Layer(XmlNodeConstPtrConst childNode, unsigned char *charData = new unsigned char[len + 1]; const char *const xmlChars = XmlChildContent(childNode); const char *charStart = reinterpret_cast<const char*>(xmlChars); - if (!charStart) + if (charStart == nullptr) { delete [] charData; return false; @@ -685,7 +685,7 @@ bool MapReader::readBase64Layer(XmlNodeConstPtrConst childNode, unsigned char *charIndex = charData; - while (*charStart) + while (*charStart != 0) { if (*charStart != ' ' && *charStart != '\t' && @@ -706,7 +706,7 @@ bool MapReader::readBase64Layer(XmlNodeConstPtrConst childNode, delete [] charData; // XmlFree(const_cast<char*>(xmlChars)); - if (binData) + if (binData != nullptr) { if (compression == "gzip" || compression == "zlib") { @@ -719,7 +719,7 @@ bool MapReader::readBase64Layer(XmlNodeConstPtrConst childNode, binData = inflated; binLen = inflatedSize; - if (!inflated) + if (inflated == nullptr) { reportAlways("Error: Could not decompress layer!"); return false; @@ -744,7 +744,7 @@ bool MapReader::readBase64Layer(XmlNodeConstPtrConst childNode, if (it != tileAnimations.end()) { TileAnimation *const ani = it->second; - if (ani) + if (ani != nullptr) ani->addAffectedTile(layer, x + y * w); } @@ -794,7 +794,7 @@ bool MapReader::readCsvLayer(XmlNodeConstPtrConst childNode, int &restrict x, int &restrict y, const int w, const int h) { - if (!childNode) + if (childNode == nullptr) return false; if (!XmlHaveChildContent(childNode)) @@ -802,7 +802,7 @@ bool MapReader::readCsvLayer(XmlNodeConstPtrConst childNode, const char *const xmlChars = XmlChildContent(childNode); const char *const data = reinterpret_cast<const char*>(xmlChars); - if (!data) + if (data == nullptr) return false; std::string csv(data); @@ -826,7 +826,7 @@ bool MapReader::readCsvLayer(XmlNodeConstPtrConst childNode, if (it != tileAnimations.end()) { TileAnimation *const ani = it->second; - if (ani) + if (ani != nullptr) ani->addAffectedTile(layer, x + y * w); } @@ -870,7 +870,7 @@ bool MapReader::readCsvLayer(XmlNodeConstPtrConst childNode, void MapReader::readLayer(XmlNodeConstPtr node, Map *const map) { - if (!node) + if (node == nullptr) return; // Layers are not necessarily the same size as the map @@ -1035,7 +1035,7 @@ void MapReader::readLayer(XmlNodeConstPtr node, Map *const map) if (it != tileAnimations.end()) { TileAnimation *const ani = it->second; - if (ani) + if (ani != nullptr) ani->addAffectedTile(layer, x + y * w); } } @@ -1052,7 +1052,7 @@ void MapReader::readLayer(XmlNodeConstPtr node, Map *const map) if (y < h) std::cerr << "TOO SMALL!\n"; - if (x) + if (x != 0) std::cerr << "TOO SMALL!\n"; // There can be only one data element @@ -1065,7 +1065,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, Map *const map) { BLOCK_START("MapReader::readTileset") - if (!node) + if (node == nullptr) { BLOCK_END("MapReader::readTileset") return nullptr; @@ -1086,7 +1086,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, doc = new XML::Document(filename, UseVirtFs_true, SkipError_false); node = doc->rootNode(); - if (!node) + if (node == nullptr) { delete doc; BLOCK_END("MapReader::readTileset") @@ -1105,7 +1105,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, if (xmlNameEqual(childNode, "image")) { // ignore second other <image> tags in tileset - if (set) + if (set != nullptr) continue; const std::string source = XML::getProperty( @@ -1116,7 +1116,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, Image *const tilebmp = Loader::getImage( resolveRelativePath(pathDir, source)); - if (tilebmp) + if (tilebmp != nullptr) { set = new Tileset(tilebmp, tw, th, @@ -1192,7 +1192,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, } // create animation - if (!set || !config.getBoolValue("playMapAnimations")) + if ((set == nullptr) || !config.getBoolValue("playMapAnimations")) { delete ani; continue; @@ -1230,7 +1230,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const int duration = XML::getProperty( frameNode, "duration", 0) / 10; - if (set) + if (set != nullptr) { ani->addFrame(set->get(tileId), duration, @@ -1249,7 +1249,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, delete doc; - if (set) + if (set != nullptr) set->setProperties(props); BLOCK_END("MapReader::readTileset") return set; @@ -1306,7 +1306,7 @@ void MapReader::loadEmptyAtlas() const MapInfo *const info = MapDB::getAtlas( paths.getStringValue("emptyAtlasName")); - if (info) + if (info != nullptr) { mEmptyAtlas = Loader::getEmptyAtlas( info->atlas, @@ -1317,7 +1317,7 @@ void MapReader::loadEmptyAtlas() void MapReader::unloadEmptyAtlas() { - if (mEmptyAtlas) + if (mEmptyAtlas != nullptr) mEmptyAtlas->decRef(); } #endif // USE_OPENGL diff --git a/src/resources/memorymanager.cpp b/src/resources/memorymanager.cpp index 55d157c5f..1e4b8b378 100644 --- a/src/resources/memorymanager.cpp +++ b/src/resources/memorymanager.cpp @@ -40,7 +40,7 @@ MemoryManager::MemoryManager() int MemoryManager::getSurfaceSize(const SDL_Surface *const surface) { - if (!surface) + if (surface == nullptr) return 0; return CAST_S32(sizeof(SDL_Surface)) + CAST_S32(sizeof(SDL_PixelFormat)) + @@ -78,7 +78,7 @@ void MemoryManager::printMemory(const std::string &name, void MemoryManager::printAllMemory(ChatTab *const tab A_DYECMD_UNUSED) { - if (!logger) + if (logger == nullptr) return; #ifdef DYECMD @@ -86,7 +86,7 @@ void MemoryManager::printAllMemory(ChatTab *const tab A_DYECMD_UNUSED) #else // DYECMD int sz = ResourceManager::calcMemory(0); - if (tab) + if (tab != nullptr) { // TRANSLATORS: memory usage chat message tab->chatLog(strprintf(_("Calculated memory usage: %d"), sz), diff --git a/src/resources/mobileopenglscreenshothelper.cpp b/src/resources/mobileopenglscreenshothelper.cpp index 97312f900..3276ea07f 100644 --- a/src/resources/mobileopenglscreenshothelper.cpp +++ b/src/resources/mobileopenglscreenshothelper.cpp @@ -64,7 +64,7 @@ SDL_Surface *MobileOpenGLScreenshotHelper::getScreenshot() SDL_SWSURFACE, w, h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; // Grap the pixel buffer and write it to the SDL surface @@ -79,7 +79,7 @@ SDL_Surface *MobileOpenGLScreenshotHelper::getScreenshot() SDL_SWSURFACE, w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000); - if (!screenshot) + if (screenshot == nullptr) { MSDL_FreeSurface(tmpImage); delete [] buf; diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp index d854c0666..66c60e039 100644 --- a/src/resources/openglimagehelper.cpp +++ b/src/resources/openglimagehelper.cpp @@ -69,7 +69,7 @@ OpenGLImageHelper::~OpenGLImageHelper() Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye) { SDL_Surface *const tmpImage = loadPng(rw); - if (!tmpImage) + if (tmpImage == nullptr) { reportAlways("Error, image load failed: %s", IMG_GetError()); return nullptr; @@ -77,7 +77,7 @@ Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye) SDL_Surface *const surf = convertTo32Bit(tmpImage); MSDL_FreeSurface(tmpImage); - if (!surf) + if (surf == nullptr) return nullptr; uint32_t *pixels = static_cast<uint32_t *>(surf->pixels); @@ -88,14 +88,14 @@ Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye) case 1: { const DyePalette *const pal = dye.getSPalete(); - if (pal) + if (pal != nullptr) DYEPALETTEP(pal, SOGLColor)(pixels, surf->w * surf->h); break; } case 2: { const DyePalette *const pal = dye.getAPalete(); - if (pal) + if (pal != nullptr) DYEPALETTEP(pal, AOGLColor)(pixels, surf->w * surf->h); break; } @@ -121,11 +121,11 @@ Image *OpenGLImageHelper::createTextSurface(SDL_Surface *const tmpImage, const int width, const int height, const float alpha) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; Image *const img = glLoad(tmpImage, width, height); - if (img) + if (img != nullptr) img->setAlpha(alpha); return img; } @@ -141,7 +141,7 @@ int OpenGLImageHelper::powerOfTwo(const int input) SDL_Surface *OpenGLImageHelper::convertSurfaceNormalize(SDL_Surface *tmpImage, int width, int height) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; int realWidth = powerOfTwo(width); @@ -190,7 +190,7 @@ SDL_Surface *OpenGLImageHelper::convertSurfaceNormalize(SDL_Surface *tmpImage, tmpImage = MSDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight, 32, rmask, gmask, bmask, amask); - if (!tmpImage) + if (tmpImage == nullptr) { reportAlways("Error, image convert failed: out of memory"); return nullptr; @@ -203,7 +203,7 @@ SDL_Surface *OpenGLImageHelper::convertSurfaceNormalize(SDL_Surface *tmpImage, SDL_Surface *OpenGLImageHelper::convertSurface(SDL_Surface *tmpImage, int width, int height) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; #ifdef USE_SDL2 @@ -242,7 +242,7 @@ SDL_Surface *OpenGLImageHelper::convertSurface(SDL_Surface *tmpImage, tmpImage = MSDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask, gmask, bmask, amask); - if (!tmpImage) + if (tmpImage == nullptr) { reportAlways("Error, image convert failed: out of memory"); return nullptr; @@ -308,21 +308,21 @@ void OpenGLImageHelper::bindTexture(const GLuint texture) Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage, int width, int height) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; BLOCK_START("OpenGLImageHelper::glLoad") // Flush current error flag. graphicsManager.getLastError(); - if (!width) + if (width == 0) width = tmpImage->w; - if (!height) + if (height == 0) height = tmpImage->h; SDL_Surface *oldImage = tmpImage; tmpImage = convertSurfaceNormalize(tmpImage, width, height); - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; const int realWidth = tmpImage->w; @@ -414,7 +414,7 @@ Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage, MSDL_FreeSurface(tmpImage); GLenum error = graphicsManager.getLastError(); - if (error) + if (error != 0u) { std::string errmsg = GraphicsManager::errorToString(error); reportAlways("Error: Image GL import failed: %s (%u)", @@ -493,17 +493,17 @@ void OpenGLImageHelper::copySurfaceToImage(const Image *const image, const int x, const int y, SDL_Surface *surface) const { - if (!surface || !image) + if (surface == nullptr || image == nullptr) return; SDL_Surface *const oldSurface = surface; surface = convertSurface(surface, surface->w, surface->h); - if (!surface) + if (surface == nullptr) return; // +++ probably need combine // mglTextureSubImage2D and mglTextureSubImage2DEXT - if (mglTextureSubImage2D) + if (mglTextureSubImage2D != nullptr) { mglTextureSubImage2D(image->mGLImage, 0, diff --git a/src/resources/openglscreenshothelper.cpp b/src/resources/openglscreenshothelper.cpp index f56009da4..ef77832f6 100644 --- a/src/resources/openglscreenshothelper.cpp +++ b/src/resources/openglscreenshothelper.cpp @@ -63,7 +63,7 @@ SDL_Surface *OpenGLScreenshotHelper::getScreenshot() SDL_SWSURFACE, w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000); - if (!screenshot) + if (screenshot == nullptr) return nullptr; if (SDL_MUSTLOCK(screenshot)) diff --git a/src/resources/resourcemanager/resourcemanager.cpp b/src/resources/resourcemanager/resourcemanager.cpp index 0e77cea38..a60fea2a4 100644 --- a/src/resources/resourcemanager/resourcemanager.cpp +++ b/src/resources/resourcemanager/resourcemanager.cpp @@ -107,7 +107,7 @@ void deleteResourceManager() } #endif // DEBUG_LEAKS - if (dynamic_cast<SpriteDef*>(iter->second)) + if (dynamic_cast<SpriteDef*>(iter->second) != nullptr) { cleanUp(iter->second); const ResourceIterator toErase = iter; @@ -132,7 +132,7 @@ void deleteResourceManager() } #endif // DEBUG_LEAKS - if (dynamic_cast<ImageSet*>(iter->second)) + if (dynamic_cast<ImageSet*>(iter->second) != nullptr) { cleanUp(iter->second); const ResourceIterator toErase = iter; @@ -157,7 +157,7 @@ void deleteResourceManager() } #endif // DEBUG_LEAKS - if (iter->second) + if (iter->second != nullptr) { cleanUp(iter->second); const ResourceIterator toErase = iter; @@ -176,7 +176,7 @@ void deleteResourceManager() void cleanUp(Resource *const res) { - if (!res) + if (res == nullptr) return; const unsigned refCount = res->mRefCount; @@ -201,7 +201,7 @@ void cleanProtected() while (iter != mResources.end()) { Resource *const res = iter->second; - if (!res) + if (res == nullptr) { ++ iter; continue; @@ -234,7 +234,7 @@ bool cleanOrphans(const bool always) while (iter != mOrphanedResources.end()) { Resource *const res = iter->second; - if (!res) + if (res == nullptr) { ++iter; continue; @@ -264,15 +264,15 @@ bool cleanOrphans(const bool always) void logResource(const Resource *const res) { - if (!res) + if (res == nullptr) return; #ifdef USE_OPENGL const Image *const image = dynamic_cast<const Image *>(res); - if (image) + if (image != nullptr) { std::string src = image->mSource; const int count = image->mRefCount; - if (count) + if (count != 0) src.append(" ").append(toString(count)); logger->log("resource(%s, %u) %s", res->mIdPath.c_str(), image->getGLImage(), src.c_str()); @@ -322,7 +322,7 @@ void clearDeleted(const bool full) std::set<Resource*>::iterator resDelIter = mDeletedResources.begin(); while (resDelIter != mDeletedResources.end()) { - if (!(*resDelIter)->mRefCount) + if ((*resDelIter)->mRefCount == 0u) { status = true; Resource *res = *resDelIter; @@ -354,7 +354,7 @@ void clearDeleted(const bool full) bool addResource(const std::string &idPath, Resource *const resource) { - if (resource) + if (resource != nullptr) { resource->incRef(); resource->mIdPath = idPath; @@ -380,7 +380,7 @@ Resource *getFromCache(const std::string &filename, bool isInCache(const std::string &idPath) { const ResourceCIterator &resIter = mResources.find(idPath); - return (resIter != mResources.end() && resIter->second); + return (resIter != mResources.end() && (resIter->second != nullptr)); } Resource *getTempResource(const std::string &idPath) @@ -389,7 +389,7 @@ Resource *getTempResource(const std::string &idPath) if (resIter != mResources.end()) { Resource *const res = resIter->second; - if (resIter->second) + if (resIter->second != nullptr) return res; } return nullptr; @@ -401,7 +401,7 @@ Resource *getFromCache(const std::string &idPath) ResourceIterator resIter = mResources.find(idPath); if (resIter != mResources.end()) { - if (resIter->second) + if (resIter->second != nullptr) resIter->second->incRef(); return resIter->second; } @@ -412,7 +412,7 @@ Resource *getFromCache(const std::string &idPath) Resource *const res = resIter->second; mResources.insert(*resIter); mOrphanedResources.erase(resIter); - if (res) + if (res != nullptr) res->incRef(); return res; } @@ -425,11 +425,11 @@ Resource *get(const std::string &idPath, { #ifndef DISABLE_RESOURCE_CACHING Resource *resource = getFromCache(idPath); - if (resource) + if (resource != nullptr) return resource; resource = fun(data); - if (resource) + if (resource != nullptr) { resource->incRef(); resource->mIdPath = idPath; @@ -469,7 +469,7 @@ Resource *get(const std::string &idPath, void release(Resource *const res) { - if (!res || mDestruction) + if ((res == nullptr) || mDestruction) return; #ifndef DISABLE_RESOURCE_CACHING @@ -517,7 +517,7 @@ void release(Resource *const res) void moveToDeleted(Resource *const res) { - if (!res) + if (res == nullptr) return; bool found(false); @@ -551,7 +551,7 @@ void moveToDeleted(Resource *const res) void decRefDelete(Resource *const res) { - if (!res) + if (res == nullptr) return; const int count = res->mRefCount; @@ -596,9 +596,9 @@ void deleteInstance() while (iter != ResourceManager::mResources.end()) { const Resource *const res = iter->second; - if (res) + if (res != nullptr) { - if (res->mRefCount) + if (res->mRefCount != 0u) { logger->log(std::string("ResourceLeak: ").append( res->mIdPath).append(" (").append(toString( diff --git a/src/resources/resourcemanager/resourcemanager_unittest.cc b/src/resources/resourcemanager/resourcemanager_unittest.cc index 49599e972..801c8ae0d 100644 --- a/src/resources/resourcemanager/resourcemanager_unittest.cc +++ b/src/resources/resourcemanager/resourcemanager_unittest.cc @@ -71,7 +71,7 @@ namespace static Resource *load(const void *const v) { BLOCK_START("TestLoader::load") - if (!v) + if (v == nullptr) { BLOCK_END("TestLoader::load") return nullptr; diff --git a/src/resources/safeopenglimagehelper.cpp b/src/resources/safeopenglimagehelper.cpp index 676812d12..c1acea2f0 100644 --- a/src/resources/safeopenglimagehelper.cpp +++ b/src/resources/safeopenglimagehelper.cpp @@ -66,7 +66,7 @@ Image *SafeOpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye) { SDL_Surface *const tmpImage = loadPng(rw); - if (!tmpImage) + if (tmpImage == nullptr) { logger->log("Error, image load failed: %s", IMG_GetError()); return nullptr; @@ -74,7 +74,7 @@ Image *SafeOpenGLImageHelper::load(SDL_RWops *const rw, SDL_Surface *const surf = convertTo32Bit(tmpImage); MSDL_FreeSurface(tmpImage); - if (!surf) + if (surf == nullptr) return nullptr; uint32_t *pixels = static_cast<uint32_t *>(surf->pixels); @@ -85,14 +85,14 @@ Image *SafeOpenGLImageHelper::load(SDL_RWops *const rw, case 1: { const DyePalette *const pal = dye.getSPalete(); - if (pal) + if (pal != nullptr) DYEPALETTEP(pal, SOGLColor)(pixels, surf->w * surf->h); break; } case 2: { const DyePalette *const pal = dye.getAPalete(); - if (pal) + if (pal != nullptr) DYEPALETTEP(pal, AOGLColor)(pixels, surf->w * surf->h); break; } @@ -119,11 +119,11 @@ Image *SafeOpenGLImageHelper::createTextSurface(SDL_Surface *const tmpImage, const int height, const float alpha) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; Image *const img = glLoad(tmpImage, width, height); - if (img) + if (img != nullptr) img->setAlpha(alpha); return img; } @@ -141,7 +141,7 @@ SDL_Surface *SafeOpenGLImageHelper::convertSurfaceNormalize(SDL_Surface int width, int height) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; int realWidth = powerOfTwo(width); @@ -190,7 +190,7 @@ SDL_Surface *SafeOpenGLImageHelper::convertSurfaceNormalize(SDL_Surface tmpImage = MSDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight, 32, rmask, gmask, bmask, amask); - if (!tmpImage) + if (tmpImage == nullptr) { logger->log("Error, image convert failed: out of memory"); return nullptr; @@ -204,7 +204,7 @@ SDL_Surface *SafeOpenGLImageHelper::convertSurface(SDL_Surface *tmpImage, int width, int height) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; #ifdef USE_SDL2 @@ -243,7 +243,7 @@ SDL_Surface *SafeOpenGLImageHelper::convertSurface(SDL_Surface *tmpImage, tmpImage = MSDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask, gmask, bmask, amask); - if (!tmpImage) + if (tmpImage == nullptr) { logger->log("Error, image convert failed: out of memory"); return nullptr; @@ -308,21 +308,21 @@ Image *SafeOpenGLImageHelper::glLoad(SDL_Surface *tmpImage, int width, int height) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; BLOCK_START("SafeOpenGLImageHelper::glLoad") // Flush current error flag. graphicsManager.getLastError(); - if (!width) + if (width == 0) width = tmpImage->w; - if (!height) + if (height == 0) height = tmpImage->h; SDL_Surface *oldImage = tmpImage; tmpImage = convertSurfaceNormalize(tmpImage, width, height); - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; const int realWidth = tmpImage->w; @@ -389,7 +389,7 @@ Image *SafeOpenGLImageHelper::glLoad(SDL_Surface *tmpImage, MSDL_FreeSurface(tmpImage); GLenum error = graphicsManager.getLastError(); - if (error) + if (error != 0u) { std::string errmsg = GraphicsManager::errorToString(error); logger->log("Error: Image GL import failed: %s (%u)", @@ -469,17 +469,17 @@ void SafeOpenGLImageHelper::copySurfaceToImage(const Image *const image, const int y, SDL_Surface *surface) const { - if (!surface || !image) + if (surface == nullptr || image == nullptr) return; SDL_Surface *const oldSurface = surface; surface = convertSurface(surface, surface->w, surface->h); - if (!surface) + if (surface == nullptr) return; // +++ probably need combine // mglTextureSubImage2D and mglTextureSubImage2DEXT - if (mglTextureSubImage2D) + if (mglTextureSubImage2D != nullptr) { mglTextureSubImage2D(image->mGLImage, 0, diff --git a/src/resources/sdlgfxblitfunc.cpp b/src/resources/sdlgfxblitfunc.cpp index 2be73229c..109ddaa2e 100644 --- a/src/resources/sdlgfxblitfunc.cpp +++ b/src/resources/sdlgfxblitfunc.cpp @@ -339,7 +339,7 @@ static void _SDL_gfxBlitBlitterRGBA(SDL_gfxBlitInfo *info) const int dstskip = info->d_skip; SDL_PixelFormat *srcfmt = info->src; - while (height--) + while ((height--) != 0) { GFX_DUFFS_LOOP4( { @@ -393,7 +393,7 @@ static int _SDL_gfxBlitRGBACall(SDL_Surface *const src, /* * Set up source and destination buffer pointers, then blit */ - if (srcrect->w && srcrect->h) + if ((srcrect->w != 0u) && (srcrect->h != 0u)) { SDL_gfxBlitInfo info; @@ -444,7 +444,7 @@ int SDLgfxBlitRGBA(SDL_Surface *const src, /* * Make sure the surfaces aren't locked */ - if (!src || !dst) + if ((src == nullptr) || (dst == nullptr)) { reportAlways("SDLgfxBlitRGBA: passed a NULL surface"); return -1; @@ -468,7 +468,7 @@ int SDLgfxBlitRGBA(SDL_Surface *const src, /* * Clip the source rectangle to the source surface */ - if (srcrect) + if (srcrect != nullptr) { int maxw; int maxh; diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp index afb81d170..72afe3045 100644 --- a/src/resources/sdlimagehelper.cpp +++ b/src/resources/sdlimagehelper.cpp @@ -53,7 +53,7 @@ bool SDLImageHelper::mEnableAlphaCache = false; Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) { SDL_Surface *const tmpImage = loadPng(rw); - if (!tmpImage) + if (tmpImage == nullptr) { reportAlways("Error, image load failed: %s", IMG_GetError()); @@ -83,7 +83,7 @@ Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) SDL_Surface *const surf = MSDL_ConvertSurface( tmpImage, &rgba, SDL_SWSURFACE); MSDL_FreeSurface(tmpImage); - if (!surf) + if (surf == nullptr) return nullptr; uint32_t *pixels = static_cast<uint32_t *>(surf->pixels); @@ -94,14 +94,14 @@ Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) case 1: { const DyePalette *const pal = dye.getSPalete(); - if (pal) + if (pal != nullptr) DYEPALETTEP(pal, SColor)(pixels, surf->w * surf->h); break; } case 2: { const DyePalette *const pal = dye.getAPalete(); - if (pal) + if (pal != nullptr) DYEPALETTEP(pal, AColor)(pixels, surf->w * surf->h); break; } @@ -128,7 +128,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage, const int height A_UNUSED, const float alpha) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; bool hasAlpha = false; @@ -138,7 +138,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage, uint8_t *alphaChannel = new uint8_t[sz]; const SDL_PixelFormat *const fmt = tmpImage->format; - if (fmt->Amask) + if (fmt->Amask != 0u) { for (size_t i = 0; i < sz; ++ i) { @@ -179,7 +179,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage, alphaChannel = nullptr; } - if (!image) + if (image == nullptr) { reportAlways("Error: Image convert failed."); delete [] alphaChannel; @@ -193,7 +193,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage, SDL_Surface* SDLImageHelper::SDLDuplicateSurface(SDL_Surface *const tmpImage) { - if (!tmpImage || !tmpImage->format) + if ((tmpImage == nullptr) || (tmpImage->format == nullptr)) return nullptr; return MSDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE); @@ -201,7 +201,7 @@ SDL_Surface* SDLImageHelper::SDLDuplicateSurface(SDL_Surface *const tmpImage) Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) { - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; bool hasAlpha = false; @@ -212,7 +212,7 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) reportAlways("Non 32 bit image detected"); tmpImage = convertTo32Bit(tmpImage); - if (!tmpImage) + if (tmpImage == nullptr) return nullptr; converted = true; } @@ -223,10 +223,10 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) uint8_t *alphaChannel = new uint8_t[sz]; // Figure out whether the image uses its alpha layer - if (!tmpImage->format->palette) + if (tmpImage->format->palette == nullptr) { const SDL_PixelFormat *const fmt = tmpImage->format; - if (fmt->Amask) + if (fmt->Amask != 0u) { const uint32_t amask = fmt->Amask; const uint8_t ashift = fmt->Ashift; @@ -279,7 +279,7 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) alphaChannel = nullptr; } - if (!image) + if (image == nullptr) { reportAlways("Error: Image convert failed."); delete [] alphaChannel; @@ -308,7 +308,7 @@ void SDLImageHelper::copySurfaceToImage(const Image *const image, const int x, const int y, SDL_Surface *const surface) const { - if (!image || !surface) + if ((image == nullptr) || (surface == nullptr)) return; SDL_SetAlpha(surface, 0, SDL_ALPHA_OPAQUE); diff --git a/src/resources/sdlmusic.cpp b/src/resources/sdlmusic.cpp index ab0133588..4d604c8cb 100644 --- a/src/resources/sdlmusic.cpp +++ b/src/resources/sdlmusic.cpp @@ -48,7 +48,7 @@ SDLMusic::~SDLMusic() Mix_FreeMusic(mMusic); #ifndef USE_SDL2 #if SDL_MIXER_VERSION_ATLEAST(1, 2, 12) - if (mRw) + if (mRw != nullptr) { SDL_RWclose(mRw); mRw = nullptr; @@ -60,9 +60,9 @@ SDLMusic::~SDLMusic() bool SDLMusic::play(const int loops, const int fadeIn) { if (fadeIn > 0) - return Mix_FadeInMusicPos(mMusic, loops, fadeIn, 0.0); + return Mix_FadeInMusicPos(mMusic, loops, fadeIn, 0.0) != 0; else - return Mix_FadeInMusicPos(mMusic, loops, 0, 0.0); + return Mix_FadeInMusicPos(mMusic, loops, 0, 0.0) != 0; } int SDLMusic::calcMemoryLocal() const diff --git a/src/resources/sdlscreenshothelper.cpp b/src/resources/sdlscreenshothelper.cpp index 12256e902..2fa9f3e2d 100644 --- a/src/resources/sdlscreenshothelper.cpp +++ b/src/resources/sdlscreenshothelper.cpp @@ -47,7 +47,7 @@ void SdlScreenshotHelper::prepare() SDL_Surface *SdlScreenshotHelper::getScreenshot() { - if (!mainGraphics) + if (mainGraphics == nullptr) return nullptr; #if SDL_BYTEORDER == SDL_BIG_ENDIAN @@ -69,7 +69,7 @@ SDL_Surface *SdlScreenshotHelper::getScreenshot() rmask, gmask, bmask, amask); #ifndef USE_SDL2 - if (screenshot) + if (screenshot != nullptr) SDL_BlitSurface(mainGraphics->mWindow, nullptr, screenshot, nullptr); #endif // USE_SDL2 diff --git a/src/resources/skill/skilldata.cpp b/src/resources/skill/skilldata.cpp index 8bebf8ada..d16aefd8b 100644 --- a/src/resources/skill/skilldata.cpp +++ b/src/resources/skill/skilldata.cpp @@ -58,7 +58,7 @@ SkillData::SkillData() : SkillData::~SkillData() { - if (icon) + if (icon != nullptr) { icon->decRef(); icon = nullptr; @@ -70,7 +70,7 @@ void SkillData::setIcon(const std::string &iconPath) if (!iconPath.empty()) icon = Loader::getImage(iconPath); - if (!icon) + if (icon == nullptr) { icon = Theme::getImageFromTheme( paths.getStringValue("unknownItemFile")); diff --git a/src/resources/skill/skillinfo.cpp b/src/resources/skill/skillinfo.cpp index 7f0099a5c..8c90fbd72 100644 --- a/src/resources/skill/skillinfo.cpp +++ b/src/resources/skill/skillinfo.cpp @@ -86,7 +86,7 @@ void SkillInfo::update() if (visible == Visible_true) { visible = Visible_false; - if (model) + if (model != nullptr) model->updateVisibilities(); } return; @@ -101,7 +101,7 @@ void SkillInfo::update() } else { - if (!customSelectedLevel) + if (customSelectedLevel == 0) { // TRANSLATORS: skill level skillLevel = strprintf(_("Lvl: %d"), baseLevel); @@ -144,7 +144,7 @@ void SkillInfo::update() skillEffect.append(" ").append(toString(CAST_S32(type))); } - if (sp) + if (sp != 0) { // TRANSLATORS: skill mana skillEffect.append(strprintf(_(" / Mana: -%d"), sp)); @@ -164,11 +164,11 @@ void SkillInfo::update() skillLevelWidth = -1; - if (updateVisibility && model) + if (updateVisibility && (model != nullptr)) model->updateVisibilities(); data = getData(level); - if (!data) + if (data == nullptr) data = dataMap[0]; } 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(), |