diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-26 16:21:43 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-29 14:18:06 +0100 |
commit | e7c285e3423ddd660447f6a6fc6bbae25f99f386 (patch) | |
tree | 1d700f09a5e96a2a0d390af30581097bdec0bf77 /src | |
parent | e1a7c1d0ca30c2c4a293ffbff6b9c51c881d23e3 (diff) | |
download | mana-e7c285e3423ddd660447f6a6fc6bbae25f99f386.tar.gz mana-e7c285e3423ddd660447f6a6fc6bbae25f99f386.tar.bz2 mana-e7c285e3423ddd660447f6a6fc6bbae25f99f386.tar.xz mana-e7c285e3423ddd660447f6a6fc6bbae25f99f386.zip |
Apply C++11 fixits
modernize-loop-convert
modernize-deprecated-headers
Diffstat (limited to 'src')
70 files changed, 409 insertions, 542 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 58ffa6e7..ab220d45 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -112,12 +112,11 @@ void ActorSprite::logic() if (mMustResetParticles) { mMustResetParticles = false; - for (auto it = mStatusEffects.begin(); - it != mStatusEffects.end(); it++) + for (int statusEffect : mStatusEffects) { - const StatusEffect *effect = StatusEffect::getStatusEffect(*it, true); + const StatusEffect *effect = StatusEffect::getStatusEffect(statusEffect, true); if (effect && effect->particleEffectIsPersistent()) - updateStatusEffect(*it, true); + updateStatusEffect(statusEffect, true); } } diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 88823d34..0ecc731d 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -24,12 +24,7 @@ #include "game.h" #include "localplayer.h" -#include "utils/dtor.h" - -#include <cassert> - -#define for_actors ActorSpritesConstIterator it, it_end; \ -for (it = mActors.begin(), it_end = mActors.end() ; it != it_end; it++) +#include <algorithm> class FindBeingFunctor { @@ -63,13 +58,11 @@ class PlayerNamesLister : public AutoCompleteLister { names.clear(); - const ActorSprites &mActors = actorSpriteManager->getAll(); - for_actors - { - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + for (auto actor : actorSpriteManager->getAll()) { + if (actor->getType() == ActorSprite::FLOOR_ITEM) continue; - auto *being = static_cast<Being*>(*it); + auto *being = static_cast<Being *>(actor); if (being->getType() == Being::PLAYER && being->getName() != "") names.push_back(being->getName()); } @@ -82,16 +75,15 @@ class PlayerNPCNamesLister : public AutoCompleteLister { names.clear(); - const ActorSprites &mActors = actorSpriteManager->getAll(); - for_actors + for (auto actor : actorSpriteManager->getAll()) { - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + if (actor->getType() == ActorSprite::FLOOR_ITEM) continue; - auto *being = static_cast<Being*>(*it); - if ((being->getType() == Being::PLAYER - || being->getType() == Being::NPC) - && being->getName() != "") + auto *being = static_cast<Being *>(actor); + if ((being->getType() == Being::PLAYER || + being->getType() == Being::NPC) && + being->getName() != "") names.push_back(being->getName()); } } @@ -155,12 +147,9 @@ void ActorSpriteManager::scheduleDelete(ActorSprite *actor) Being *ActorSpriteManager::findBeing(int id) const { - for_actors - { - ActorSprite *actor = *it; - if (actor->getId() == id && - actor->getType() != ActorSprite::FLOOR_ITEM) - return static_cast<Being*>(actor); + for (auto actor : mActors) { + if (actor->getId() == id && actor->getType() != ActorSprite::FLOOR_ITEM) + return static_cast<Being *>(actor); } return nullptr; @@ -189,12 +178,12 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y) const Being *closest = nullptr; int closestDist = 0; - for_actors + for (auto actor : mActors) { - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + if (actor->getType() == ActorSprite::FLOOR_ITEM) continue; - auto *being = static_cast<Being*>(*it); + auto *being = static_cast<Being *>(actor); const int halfWidth = std::max(16, being->getWidth() / 2); const int height = std::max(32, being->getHeight()); @@ -206,14 +195,11 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y) const const int dist = std::max(std::abs(bottom - halfHeight - y), std::abs(being->getPixelX() - x)); - if ((being->isAlive() && - being != local_player && + if ((being->isAlive() && being != local_player && being->getPixelX() - halfWidth <= x && - being->getPixelX() + halfWidth >= x && - bottom - height <= y && + being->getPixelX() + halfWidth >= x && bottom - height <= y && bottom >= y) && - (!closest || closestDist > dist)) - { + (!closest || closestDist > dist)) { closest = being; closestDist = dist; } @@ -224,13 +210,10 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y) const FloorItem *ActorSpriteManager::findItem(int id) const { - for_actors + for (auto actor : mActors) { - if ((*it)->getId() == id && - (*it)->getType() == ActorSprite::FLOOR_ITEM) - { - return static_cast<FloorItem*>(*it); - } + if (actor->getId() == id && actor->getType() == ActorSprite::FLOOR_ITEM) + return static_cast<FloorItem *>(actor); } return nullptr; @@ -240,14 +223,14 @@ FloorItem *ActorSpriteManager::findItem(int x, int y, int maxDist) const { FloorItem *item = nullptr; int smallestDist = 0; - for_actors + for (auto actor : mActors) { - int dist = std::max(std::abs((*it)->getTileX() - x), - std::abs((*it)->getTileY() - y)); - if (((*it)->getType() == ActorSprite::FLOOR_ITEM) && - ((!item && dist <= maxDist) || dist < smallestDist)) + int dist = std::max(std::abs(actor->getTileX() - x), + std::abs(actor->getTileY() - y)); + if ((actor->getType() == ActorSprite::FLOOR_ITEM) && + ((!item && dist <= maxDist) || dist < smallestDist)) { - item = static_cast<FloorItem*>(*it); + item = static_cast<FloorItem *>(actor); smallestDist = dist; } } @@ -258,14 +241,14 @@ FloorItem *ActorSpriteManager::findItem(int x, int y, int maxDist) const Being *ActorSpriteManager::findBeingByName(const std::string &name, ActorSprite::Type type) const { - for_actors + for (auto actor : mActors) { - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + if (actor->getType() == ActorSprite::FLOOR_ITEM) continue; - auto *being = static_cast<Being*>(*it); + auto *being = static_cast<Being *>(actor); if (being->getName() == name && - (type == ActorSprite::UNKNOWN || type == being->getType())) + (type == ActorSprite::UNKNOWN || type == being->getType())) return being; } return nullptr; @@ -278,14 +261,13 @@ const ActorSprites &ActorSpriteManager::getAll() const void ActorSpriteManager::logic() { - for_actors - (*it)->logic(); + for (auto actor : mActors) + actor->logic(); - for (it = mDeleteActors.begin(), it_end = mDeleteActors.end(); - it != it_end; ++it) + for (auto actor : mDeleteActors) { - mActors.erase(*it); - delete *it; + mActors.erase(actor); + delete actor; } mDeleteActors.clear(); @@ -296,8 +278,8 @@ void ActorSpriteManager::clear() if (local_player) mActors.erase(local_player); - for_actors - delete *it; + for (auto actor : mActors) + delete actor; mActors.clear(); mDeleteActors.clear(); @@ -319,18 +301,18 @@ Being *ActorSpriteManager::findNearestLivingBeing(int x, int y, const int maxDist = maxTileDist * game->getCurrentTileWidth(); - for_actors + for (auto actor : mActors) { - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + if (actor->getType() == ActorSprite::FLOOR_ITEM) continue; - auto *being = static_cast<Being*>(*it); + auto *being = static_cast<Being *>(actor); const Vector &pos = being->getPosition(); - int d = abs(((int) pos.x) - x) + abs(((int) pos.y) - y); + int d = abs(((int)pos.x) - x) + abs(((int)pos.y) - y); - if ((being->getType() == type || type == ActorSprite::UNKNOWN) - && (d < dist || !closestBeing) // it is closer - && being->isAlive() // no dead beings + if ((being->getType() == type || type == ActorSprite::UNKNOWN) && + (d < dist || !closestBeing) // it is closer + && being->isAlive() // no dead beings && being != excluded) { dist = d; @@ -350,15 +332,9 @@ Being *ActorSpriteManager::findNearestLivingBeing(Being *aroundBeing, aroundBeing); } -bool ActorSpriteManager::hasActorSprite(ActorSprite *actor) const +bool ActorSpriteManager::hasActorSprite(ActorSprite *someActor) const { - for_actors - { - if (actor == *it) - return true; - } - - return false; + return mActors.find(someActor) != mActors.end(); } AutoCompleteLister *ActorSpriteManager::getPlayerNameLister() @@ -373,12 +349,12 @@ AutoCompleteLister *ActorSpriteManager::getPlayerNPCNameLister() void ActorSpriteManager::updatePlayerNames() { - for_actors + for (auto actor : mActors) { - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + if (actor->getType() == ActorSprite::FLOOR_ITEM) continue; - auto *being = static_cast<Being*>(*it); + auto *being = static_cast<Being *>(actor); if (being->getType() == ActorSprite::PLAYER && being->getName() != "") being->updateName(); } diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h index de674a78..daba3356 100644 --- a/src/actorspritemanager.h +++ b/src/actorspritemanager.h @@ -32,8 +32,6 @@ class LocalPlayer; class Map; using ActorSprites = std::set<ActorSprite *>; -using ActorSpritesIterator = ActorSprites::iterator; -using ActorSpritesConstIterator = ActorSprites::const_iterator; class ActorSpriteManager { @@ -143,9 +141,9 @@ class ActorSpriteManager * Returns true if the given ActorSprite is in the manager's list, * false otherwise. * - * \param actor the ActorSprite to search for + * \param someActor the ActorSprite to search for */ - bool hasActorSprite(ActorSprite *actor) const; + bool hasActorSprite(ActorSprite *someActor) const; /** * Performs ActorSprite logic and deletes ActorSprite scheduled to be diff --git a/src/channelmanager.cpp b/src/channelmanager.cpp index 3e285889..7f13143f 100644 --- a/src/channelmanager.cpp +++ b/src/channelmanager.cpp @@ -38,12 +38,8 @@ ChannelManager::~ChannelManager() Channel *ChannelManager::findById(int id) const { Channel *channel = nullptr; - for (auto itr = mChannels.begin(), - end = mChannels.end(); - itr != end; - itr++) + for (auto c : mChannels) { - Channel *c = (*itr); if (c->getId() == id) { channel = c; @@ -58,12 +54,8 @@ Channel *ChannelManager::findByName(const std::string &name) const Channel *channel = nullptr; if (!name.empty()) { - for (auto itr = mChannels.begin(), - end = mChannels.end(); - itr != end; - itr++) + for (auto c : mChannels) { - Channel *c = (*itr); if (c->getName() == name) { channel = c; diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index 90abedc9..e126b0ef 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -126,15 +126,15 @@ std::string ChatLogger::getDateString() const std::string ChatLogger::secureName(std::string &name) const { - for (unsigned int f = 0; f < name.length(); f ++) + for (char & f : name) { - if (name[f] < '0' && name[f] > '9' && name[f] < 'a' && name[f] > 'z' - && name[f] < 'A' && name[f] > 'Z' - && name[f] != '-' && name[f] != '+' && name[f] != '=' - && name[f] != '.' && name[f] != ','&& name[f] != ')' - && name[f] != '(' && name[f] != '[' && name[f] != ')') + if (f < '0' && f > '9' && f < 'a' && f > 'z' + && f < 'A' && f > 'Z' + && f != '-' && f != '+' && f != '=' + && f != '.' && f != ','&& f != ')' + && f != '(' && f != '[' && f != ')') { - name[f] = '_'; + f = '_'; } } return name; diff --git a/src/configuration.cpp b/src/configuration.cpp index 34febf22..74104ec6 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -286,14 +286,13 @@ void Configuration::init(const std::string &filename, bool useResManager) void ConfigurationObject::writeToXML(xmlTextWriterPtr writer) { - for (Options::const_iterator i = mOptions.begin(), i_end = mOptions.end(); - i != i_end; ++i) + for (const auto &option : mOptions) { xmlTextWriterStartElement(writer, BAD_CAST "option"); xmlTextWriterWriteAttribute(writer, - BAD_CAST "name", BAD_CAST i->first.c_str()); + BAD_CAST "name", BAD_CAST option.first.c_str()); xmlTextWriterWriteAttribute(writer, - BAD_CAST "value", BAD_CAST i->second.c_str()); + BAD_CAST "value", BAD_CAST option.second.c_str()); xmlTextWriterEndElement(writer); } @@ -306,11 +305,10 @@ void ConfigurationObject::writeToXML(xmlTextWriterPtr writer) xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST name); // Recurse on all elements - for (auto - elt_it = it->second.begin(); elt_it != it->second.end(); elt_it++) + for (auto element : it->second) { xmlTextWriterStartElement(writer, BAD_CAST name); - (*elt_it)->writeToXML(writer); + element->writeToXML(writer); xmlTextWriterEndElement(writer); } diff --git a/src/defaults.cpp b/src/defaults.cpp index 99b9d6a0..1c9cb7aa 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -24,7 +24,7 @@ #include "graphics.h" #include "client.h" -#include <stdlib.h> +#include <cstdlib> VariableData* createData(int defData) { diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp index 4fd7d7e6..5de0b872 100644 --- a/src/effectmanager.cpp +++ b/src/effectmanager.cpp @@ -67,19 +67,19 @@ EffectManager::~EffectManager() bool EffectManager::trigger(int id, Being* being, int rotation) { bool rValue = false; - for (auto i = mEffects.begin(); i != mEffects.end(); ++i) + for (auto &effect : mEffects) { - if ((*i).id == id) + if (effect.id == id) { rValue = true; - if (!(*i).GFX.empty()) + if (!effect.GFX.empty()) { Particle *selfFX; - selfFX = particleEngine->addEffect((*i).GFX, 0, 0, rotation); + selfFX = particleEngine->addEffect(effect.GFX, 0, 0, rotation); being->controlParticle(selfFX); } - if (!(*i).SFX.empty()) - sound.playSfx((*i).SFX); + if (!effect.SFX.empty()) + sound.playSfx(effect.SFX); break; } } @@ -89,15 +89,15 @@ bool EffectManager::trigger(int id, Being* being, int rotation) bool EffectManager::trigger(int id, int x, int y, int rotation) { bool rValue = false; - for (auto i = mEffects.begin(); i != mEffects.end(); ++i) + for (auto &effect : mEffects) { - if ((*i).id == id) + if (effect.id == id) { rValue = true; - if (!(*i).GFX.empty()) - particleEngine->addEffect((*i).GFX, x, y, rotation); - if (!(*i).SFX.empty()) - sound.playSfx((*i).SFX); + if (!effect.GFX.empty()) + particleEngine->addEffect(effect.GFX, x, y, rotation); + if (!effect.SFX.empty()) + sound.playSfx(effect.SFX); break; } } diff --git a/src/graphics.cpp b/src/graphics.cpp index b3f3050e..6f488cc1 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -28,6 +28,15 @@ #include <guichan/exception.hpp> +void ImageRect::setAlpha(float alpha) +{ + for (auto img : grid) + { + img->setAlpha(alpha); + } +} + + Graphics::~Graphics() { _endDraw(); diff --git a/src/graphics.h b/src/graphics.h index 6239bd23..24483078 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -67,6 +67,8 @@ public: }; Image *grid[9]; + + void setAlpha(float alpha); }; /** diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index e4d5f371..46f28fe8 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -318,8 +318,8 @@ void CharSelectDialog::setLocked(bool locked) if (mChangeEmailButton) mChangeEmailButton->setEnabled(!locked); - for (int i = 0; i < (int)mCharacterEntries.size(); ++i) - mCharacterEntries[i]->setActive(!mLocked); + for (auto &characterEntry : mCharacterEntries) + characterEntry->setActive(!mLocked); } bool CharSelectDialog::selectByName(const std::string &name, diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 1ae2fcbd..e1bbed5f 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -278,10 +278,9 @@ void ChatWindow::removeAllWhispers() tabs.push_back(iter->second); } - for (auto it = tabs.begin(); - it != tabs.end(); ++it) + for (auto &tab : tabs) { - delete *it; + delete tab; } mWhispers.clear(); @@ -295,20 +294,18 @@ void ChatWindow::chatInput(const std::string &msg) void ChatWindow::doPresent() { - const ActorSprites &actors = actorSpriteManager->getAll(); std::string response = ""; int playercount = 0; - for (auto it = actors.begin(), it_end = actors.end(); - it != it_end; it++) + for (auto actor : actorSpriteManager->getAll()) { - if ((*it)->getType() == ActorSprite::PLAYER) + if (actor->getType() == ActorSprite::PLAYER) { if (!response.empty()) { response += ", "; } - response += static_cast<Being*>(*it)->getName(); + response += static_cast<Being*>(actor)->getName(); ++playercount; } } diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index 077f3091..35e65bd6 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -102,8 +102,8 @@ void HelpWindow::loadFile(const std::string &file) std::vector<std::string> lines = resman->loadTextFile(helpPath + file + ".txt"); - for (unsigned int i = 0; i < lines.size(); ++i) + for (const auto &line : lines) { - mBrowserBox->addRow(lines[i]); + mBrowserBox->addRow(line); } } diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index f096e5ca..3b3dfcd3 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -198,9 +198,8 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage) { const std::vector<std::string> &effect = item.getEffect(); std::string temp = ""; - for (auto it = effect.begin(), - it_end = effect.end(); it != it_end; ++it) - temp += temp.empty() ? *it : "\n" + *it; + for (const auto &it : effect) + temp += temp.empty() ? it : "\n" + it; mItemEffect->setTextWrapped(temp, ITEMPOPUP_WRAP_WIDTH); } mItemWeight->setTextWrapped(strprintf(_("Weight: %s"), diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 1682b972..388a032a 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -190,15 +190,12 @@ void Minimap::draw(gcn::Graphics *graphics) drawImage(mMapImage, mapOriginX, mapOriginY); } - const ActorSprites &actors = actorSpriteManager->getAll(); - - for (auto it = actors.begin(), it_end = actors.end(); - it != it_end; it++) + for (auto actor : actorSpriteManager->getAll()) { - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + if (actor->getType() == ActorSprite::FLOOR_ITEM) continue; - const Being *being = static_cast<Being*>(*it); + const Being *being = static_cast<Being*>(actor); if (!being->isAlive()) continue; diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp index 3cd97a6d..29718ed6 100644 --- a/src/gui/ministatuswindow.cpp +++ b/src/gui/ministatuswindow.cpp @@ -110,12 +110,12 @@ void MiniStatusWindow::drawIcons(Graphics *graphics) { // Draw icons int icon_x = mXpBar->getX() + mXpBar->getWidth() + 14; - for (unsigned int i = 0; i < mIcons.size(); i++) + for (auto &icon : mIcons) { - if (mIcons[i]) + if (icon) { - mIcons[i]->draw(graphics, icon_x, 3); - icon_x += 2 + mIcons[i]->getWidth(); + icon->draw(graphics, icon_x, 3); + icon_x += 2 + icon->getWidth(); } } } @@ -223,9 +223,9 @@ void MiniStatusWindow::logic() } */ - for (unsigned int i = 0; i < mIcons.size(); i++) - if (mIcons[i]) - mIcons[i]->update(tick_time * 10); + for (auto &icon : mIcons) + if (icon) + icon->update(tick_time * 10); } void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 23ba75ee..aee78b29 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -30,7 +30,7 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include <math.h> +#include <cmath> static const double PI = 3.14159265; const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0); @@ -60,15 +60,14 @@ Palette::~Palette() mInstances.erase(this); } -const gcn::Color& Palette::getColor(char c, bool &valid) +const gcn::Color &Palette::getColor(char c, bool &valid) { - for (Colors::const_iterator col = mColors.begin(), - colEnd = mColors.end(); col != colEnd; ++col) + for (const auto &color : mColors) { - if (col->ch == c) + if (color.ch == c) { valid = true; - return col->color; + return color.color; } } valid = false; @@ -97,35 +96,35 @@ void Palette::advanceGradient() int advance = get_elapsed_time(mRainbowTime) / 5; double startColVal, destColVal; - for (size_t i = 0; i < mGradVector.size(); i++) + for (auto &elem : mGradVector) { - delay = mGradVector[i]->delay; + delay = elem->delay; - if (mGradVector[i]->grad == PULSE) + if (elem->grad == PULSE) delay = delay / 20; - numOfColors = (mGradVector[i]->grad == SPECTRUM ? 6 : - mGradVector[i]->grad == PULSE ? 127 : + numOfColors = (elem->grad == SPECTRUM ? 6 : + elem->grad == PULSE ? 127 : RAINBOW_COLOR_COUNT); - mGradVector[i]->gradientIndex = - (mGradVector[i]->gradientIndex + advance) % + elem->gradientIndex = + (elem->gradientIndex + advance) % (delay * numOfColors); - pos = mGradVector[i]->gradientIndex % delay; - colIndex = mGradVector[i]->gradientIndex / delay; + pos = elem->gradientIndex % delay; + colIndex = elem->gradientIndex / delay; - if (mGradVector[i]->grad == PULSE) + if (elem->grad == PULSE) { colVal = (int) (255.0 * sin(PI * colIndex / numOfColors)); - const gcn::Color &col = mGradVector[i]->testColor; + const gcn::Color &col = elem->testColor; - mGradVector[i]->color.r = ((colVal * col.r) / 255) % (col.r + 1); - mGradVector[i]->color.g = ((colVal * col.g) / 255) % (col.g + 1); - mGradVector[i]->color.b = ((colVal * col.b) / 255) % (col.b + 1); + elem->color.r = ((colVal * col.r) / 255) % (col.r + 1); + elem->color.g = ((colVal * col.g) / 255) % (col.g + 1); + elem->color.b = ((colVal * col.b) / 255) % (col.b + 1); } - if (mGradVector[i]->grad == SPECTRUM) + if (elem->grad == SPECTRUM) { if (colIndex % 2) { // falling curve @@ -137,17 +136,17 @@ void Palette::advanceGradient() 1) / 2); } - mGradVector[i]->color.r = + elem->color.r = (colIndex == 0 || colIndex == 5) ? 255 : (colIndex == 1 || colIndex == 4) ? colVal : 0; - mGradVector[i]->color.g = + elem->color.g = (colIndex == 1 || colIndex == 2) ? 255 : (colIndex == 0 || colIndex == 3) ? colVal : 0; - mGradVector[i]->color.b = + elem->color.b = (colIndex == 3 || colIndex == 4) ? 255 : (colIndex == 2 || colIndex == 5) ? colVal : 0; } - else if (mGradVector[i]->grad == RAINBOW) + else if (elem->grad == RAINBOW) { const gcn::Color &startCol = RAINBOW_COLORS[colIndex]; const gcn::Color &destCol = @@ -156,13 +155,13 @@ void Palette::advanceGradient() startColVal = (cos(PI * pos / delay) + 1) / 2; destColVal = 1 - startColVal; - mGradVector[i]->color.r =(int)(startColVal * startCol.r + + elem->color.r =(int)(startColVal * startCol.r + destColVal * destCol.r); - mGradVector[i]->color.g =(int)(startColVal * startCol.g + + elem->color.g =(int)(startColVal * startCol.g + destColVal * destCol.g); - mGradVector[i]->color.b =(int)(startColVal * startCol.b + + elem->color.b =(int)(startColVal * startCol.b + destColVal * destCol.b); } } diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index 4262f9cc..4afbd419 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -34,7 +34,7 @@ #include "utils/gettext.h" -#include <assert.h> +#include <cassert> QuitDialog::QuitDialog(QuitDialog** pointerToMe): Window(_("Quit"), true, nullptr), mMyPointer(pointerToMe) diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index f0016322..6a7f6ab5 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -523,15 +523,14 @@ void ServerDialog::loadServers() // Add the server to the local list if it's not already present bool found = false; int i = 0; - for (auto it = mServers.begin(); it != mServers.end(); - ++it) + for (auto &s : mServers) { - if (*it == server) + if (s == server) { // Use the name listed in the server list - (*it).name = server.name; - (*it).version = server.version; - (*it).description = server.description; + s.name = server.name; + s.version = server.version; + s.description = server.description; mServersListModel->setVersionString(i, version); found = true; break; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index daced0fa..357f1921 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -77,10 +77,8 @@ Setup::Setup(): mTabs.push_back(new Setup_Colors); mTabs.push_back(new Setup_Players); - for (auto i = mTabs.begin(), i_end = mTabs.end(); - i != i_end; ++i) + for (auto tab : mTabs) { - SetupTab *tab = *i; panel->addTab(tab->getName(), tab); } @@ -119,10 +117,9 @@ void Setup::action(const gcn::ActionEvent &event) if (!statusWindow) return; - for (auto it = mWindowsToReset.begin(); - it != mWindowsToReset.end(); it++) + for (auto &window : mWindowsToReset) { - (*it)->resetToDefaultSize(); + window->resetToDefaultSize(); } } } diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index a3b0ef53..6a77e229 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -135,9 +135,8 @@ public: mPlayers = player_relations.getPlayers(); // set up widgets - for (unsigned int r = 0; r < mPlayers->size(); ++r) + for (const auto &name : *mPlayers) { - std::string name = (*mPlayers)[r]; gcn::Widget *widget = new Label(name); mWidgets.push_back(widget); diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 09bde167..7f42b016 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -275,9 +275,9 @@ void SkillDialog::update() PlayerInfo::getAttribute(SKILL_POINTS))); mPointsLabel->adjustSize(); - for (auto it = mSkills.begin(); it != mSkills.end(); it++) + for (auto &skill : mSkills) { - (*it).second->update(); + skill.second->update(); } } @@ -431,11 +431,11 @@ void SkillModel::updateVisibilities() { mVisibleSkills.clear(); - for (auto it = mSkills.begin(); it != mSkills.end(); it++) + for (auto &skill : mSkills) { - if ((*it)->visible) + if (skill->visible) { - mVisibleSkills.push_back((*it)); + mVisibleSkills.push_back(skill); } } } diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index d114d6e3..194e6afe 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -49,9 +49,6 @@ #define SPECIALS_WIDTH 200 #define SPECIALS_HEIGHT 32 -class SpecialEntry; - - class SpecialEntry : public Container { public: @@ -127,10 +124,9 @@ void SpecialsWindow::draw(gcn::Graphics *graphics) bool foundNew = false; unsigned int found = 0; // number of entries in specialData which match mEntries - for (auto it = specialData.begin(); - it != specialData.end(); ++it) + for (auto &special : specialData) { - auto e = mEntries.find(it->first); + auto e = mEntries.find(special.first); if (e == mEntries.end()) { // found a new special - abort update and rebuild from scratch @@ -140,7 +136,7 @@ void SpecialsWindow::draw(gcn::Graphics *graphics) else { // update progress bar of special - e->second->update(it->second.currentMana, it->second.neededMana); + e->second->update(special.second.currentMana, special.second.neededMana); found++; } } @@ -158,25 +154,24 @@ void SpecialsWindow::rebuild(const std::map<int, Special> &specialData) mEntries.clear(); int vPos = 0; //vertical position of next placed element - for (auto it = specialData.begin(); - it != specialData.end(); ++it) + for (auto special : specialData) { - logger->log("Updating special GUI for %d", it->first); + logger->log("Updating special GUI for %d", special.first); - SpecialInfo *info = SpecialDB::get(it->first); + SpecialInfo *info = SpecialDB::get(special.first); if (info) { - info->rechargeCurrent = it->second.currentMana; - info->rechargeNeeded = it->second.neededMana; + info->rechargeCurrent = special.second.currentMana; + info->rechargeNeeded = special.second.neededMana; auto* entry = new SpecialEntry(info); entry->setPosition(0, vPos); vPos += entry->getHeight() + 3; add(entry); - mEntries[it->first] = entry; + mEntries[special.first] = entry; } else { - logger->log("Warning: No info available of special %d", it->first); + logger->log("Warning: No info available of special %d", special.first); } } } diff --git a/src/gui/specialswindow.h b/src/gui/specialswindow.h index 1da05c5c..c945fd4b 100644 --- a/src/gui/specialswindow.h +++ b/src/gui/specialswindow.h @@ -31,7 +31,7 @@ #include <map> -struct SpecialEntry; +class SpecialEntry; class SpecialsWindow : public Window, public gcn::ActionListener { diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index eee832ec..c2486b89 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -301,9 +301,9 @@ void StatusWindow::event(Event::Channel channel, void StatusWindow::updateAttrs() { - for (auto it = mAttrs.begin(); it != mAttrs.end(); it++) + for (auto &attr : mAttrs) { - it->second->update(); + attr.second->update(); } } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 3fb11d2c..456196ce 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -238,25 +238,21 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) } // Draw player names, speech, and emotion sprite as needed - const ActorSprites &actors = actorSpriteManager->getAll(); - for (auto it = actors.begin(), it_end = actors.end(); - it != it_end; it++) + for (auto actor : actorSpriteManager->getAll()) { - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + if (actor->getType() == ActorSprite::FLOOR_ITEM) continue; - auto *b = static_cast<Being*>(*it); - b->drawSpeech((int) mPixelViewX, (int) mPixelViewY); + auto *being = static_cast<Being*>(actor); + being->drawSpeech((int) mPixelViewX, (int) mPixelViewY); } if (mDebugFlags & Map::DEBUG_BEING_IDS) { graphics->setColor(gcn::Color(255, 0, 255, 255)); - ActorSpritesConstIterator it, it_end; - const ActorSprites &actors = actorSpriteManager->getAll(); - for (it = actors.begin(), it_end = actors.end(); it != it_end; ++it) + for (auto actor : actorSpriteManager->getAll()) { - auto *being = dynamic_cast<Being*>(*it); + auto *being = dynamic_cast<Being*>(actor); if (!being) continue; @@ -382,11 +378,9 @@ void Viewport::_drawDebugPath(Graphics *graphics) } // Draw the path debug information for every beings. - ActorSpritesConstIterator it, it_end; - const ActorSprites &actors = actorSpriteManager->getAll(); - for (it = actors.begin(), it_end = actors.end(); it != it_end; it++) + for (auto actor : actorSpriteManager->getAll()) { - auto *being = dynamic_cast<Being*>(*it); + auto *being = dynamic_cast<Being*>(actor); if (!being) continue; @@ -428,16 +422,16 @@ void Viewport::_drawPath(Graphics *graphics, const Path &path, { graphics->setColor(color); - for (auto i = path.begin(); i != path.end(); ++i) + for (auto pos : path) { - int squareX = i->x - (int) mPixelViewX; - int squareY = i->y - (int) mPixelViewY; + int squareX = pos.x - (int) mPixelViewX; + int squareY = pos.y - (int) mPixelViewY; graphics->fillRectangle(gcn::Rectangle(squareX - 4, squareY - 4, 8, 8)); graphics->drawText( - toString(mMap->getMetaTile(i->x / mMap->getTileWidth(), - i->y / mMap->getTileHeight())->Gcost), + toString(mMap->getMetaTile(pos.x / mMap->getTileWidth(), + pos.y / mMap->getTileHeight())->Gcost), squareX + 4, squareY + 12, gcn::Graphics::CENTER); } } diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index d5b853b2..2fe3b5b1 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -185,9 +185,8 @@ void BrowserBox::addRow(const std::string &row) int tildeWidth = font->getWidth(tilde); int x = 0; - for (auto i = mTextRows.begin(); i != mTextRows.end(); i++) + for (auto row : mTextRows) { - std::string row = *i; for (unsigned int j = 0; j < row.size(); ++j) { std::string character = row.substr(j, 1); @@ -316,11 +315,8 @@ void BrowserBox::draw(gcn::Graphics *graphics) } } - for (auto i = mLineParts.begin(); - i != mLineParts.end(); - i ++) + for (auto &part : mLineParts) { - const LinePart &part = *i; if (part.getY() + 50 < mYStart) continue; if (part.getY() > yEnd) @@ -385,9 +381,8 @@ int BrowserBox::calcHeight() mLineParts.clear(); - for (auto i = mTextRows.begin(); i != mTextRows.end(); i++) + for (auto row : mTextRows) { - const std::string row = *(i); bool wrapped = false; x = 0; diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index fb0d4cbe..b2a395e9 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -205,8 +205,7 @@ void Button::updateAlpha() mAlpha = alpha; for (int mode = 0; mode < BUTTON_COUNT; ++mode) { - for (int a = 0; a < 9; ++a) - mButton[mode].grid[a]->setAlpha(mAlpha); + mButton[mode].setAlpha(mAlpha); } } } diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 101afaef..81a0ea46 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -80,11 +80,12 @@ DropDown::DropDown(gcn::ListModel *listModel): gridx[x] + 1, gridy[y + 1] - gridy[y] + 1); - skin.grid[a]->setAlpha(mAlpha); a++; } } + skin.setAlpha(mAlpha); + boxBorder->decRef(); } @@ -122,10 +123,7 @@ void DropDown::updateAlpha() buttons[1][0]->setAlpha(mAlpha); buttons[1][1]->setAlpha(mAlpha); - for (int a = 0; a < 9; a++) - { - skin.grid[a]->setAlpha(mAlpha); - } + skin.setAlpha(mAlpha); } } diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp index bf34c4c7..0110c534 100644 --- a/src/gui/widgets/flowcontainer.cpp +++ b/src/gui/widgets/flowcontainer.cpp @@ -57,10 +57,10 @@ void FlowContainer::widgetResized(const gcn::Event &event) int i = 0; height = 0; - for (auto it = mWidgets.begin(); it != mWidgets.end(); it++) + for (auto &widget : mWidgets) { int x = i % mGridWidth * mBoxWidth; - (*it)->setPosition(x, height); + widget->setPosition(x, height); i++; diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index ac8488e0..3659baa1 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -71,15 +71,12 @@ void LayoutCell::computeSizes() { assert(mType == ARRAY); - for (auto - i = mArray->mCells.begin(), i_end = mArray->mCells.end(); - i != i_end; ++i) + for (auto &row : mArray->mCells) { - for (auto - j = i->begin(), j_end = i->end(); j != j_end; ++j) + for (auto cell : row) { - LayoutCell *cell = *j; - if (cell && cell->mType == ARRAY) cell->computeSizes(); + if (cell && cell->mType == ARRAY) + cell->computeSizes(); } } @@ -93,13 +90,11 @@ LayoutArray::LayoutArray(): mSpacing(4) LayoutArray::~LayoutArray() { - for (auto - i = mCells.begin(), i_end = mCells.end(); i != i_end; ++i) + for (auto &row : mCells) { - for (auto - j = i->begin(), j_end = i->end(); j != j_end; ++j) + for (auto &cell : row) { - delete *j; + delete cell; } } } @@ -133,10 +128,9 @@ void LayoutArray::resizeGrid(int w, int h) mSizes[0].resize(w, Layout::AUTO_DEF); } - for (auto - i = mCells.begin(), i_end = mCells.end(); i != i_end; ++i) + for (auto &row : mCells) { - i->resize(w, nullptr); + row.resize(w, nullptr); } } diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index 1d3325ee..0d63ddf2 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -56,11 +56,12 @@ PlayerBox::PlayerBox(const Being *being): bggridx[x], bggridy[y], bggridx[x + 1] - bggridx[x] + 1, bggridy[y + 1] - bggridy[y] + 1); - background.grid[a]->setAlpha(config.getFloatValue("guialpha")); a++; } } + background.setAlpha(config.getFloatValue("guialpha")); + textbox->decRef(); } @@ -92,10 +93,7 @@ void PlayerBox::draw(gcn::Graphics *graphics) if (config.getFloatValue("guialpha") != mAlpha) { - for (int a = 0; a < 9; a++) - { - background.grid[a]->setAlpha(config.getFloatValue("guialpha")); - } + background.setAlpha(config.getFloatValue("guialpha")); } } diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index 4695f5ab..9397d59e 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -71,10 +71,7 @@ ProgressBar::ProgressBar(float progress, mBorder.grid[7] = dBorders->getSubImage(4, 15, 3, 4); mBorder.grid[8] = dBorders->getSubImage(7, 15, 4, 4); - for (int i = 0; i < 9; i++) - { - mBorder.grid[i]->setAlpha(mAlpha); - } + mBorder.setAlpha(mAlpha); dBorders->decRef(); } @@ -129,12 +126,8 @@ void ProgressBar::updateAlpha() if (mAlpha != alpha) { mAlpha = alpha; - for (int i = 0; i < 9; i++) - { - mBorder.grid[i]->setAlpha(mAlpha); - } + mBorder.setAlpha(mAlpha); } - } void ProgressBar::draw(gcn::Graphics *graphics) diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index c95adeaa..f4d8007a 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -107,10 +107,10 @@ void ScrollArea::init() bggridx[x], bggridy[y], bggridx[x + 1] - bggridx[x] + 1, bggridy[y + 1] - bggridy[y] + 1); - background.grid[a]->setAlpha(config.getFloatValue("guialpha")); a++; } } + background.setAlpha(config.getFloatValue("guialpha")); textbox->decRef(); @@ -134,12 +134,13 @@ void ScrollArea::init() vsgridx[x], vsgridy[y], vsgridx[x + 1] - vsgridx[x], vsgridy[y + 1] - vsgridy[y]); - vMarker.grid[a]->setAlpha(config.getFloatValue("guialpha")); - vMarkerHi.grid[a]->setAlpha(config.getFloatValue("guialpha")); a++; } } + vMarker.setAlpha(config.getFloatValue("guialpha")); + vMarkerHi.setAlpha(config.getFloatValue("guialpha")); + vscroll->decRef(); vscrollHi->decRef(); @@ -218,12 +219,10 @@ void ScrollArea::updateAlpha() if (alpha != mAlpha) { mAlpha = alpha; - for (int a = 0; a < 9; a++) - { - background.grid[a]->setAlpha(mAlpha); - vMarker.grid[a]->setAlpha(mAlpha); - vMarkerHi.grid[a]->setAlpha(mAlpha); - } + + background.setAlpha(mAlpha); + vMarker.setAlpha(mAlpha); + vMarkerHi.setAlpha(mAlpha); } } diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index c8ed2141..15a10d33 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -74,9 +74,9 @@ Tab::~Tab() if (mInstances == 0) { - for (int mode = 0; mode < TAB_COUNT; mode++) + for (auto &imgRect : tabImg) { - std::for_each(tabImg[mode].grid, tabImg[mode].grid + 9, dtor<Image*>()); + std::for_each(imgRect.grid, imgRect.grid + 9, dtor<Image*>()); } } } @@ -106,10 +106,10 @@ void Tab::init() data[mode].gridX[x], data[mode].gridY[y], data[mode].gridX[x + 1] - data[mode].gridX[x] + 1, data[mode].gridY[y + 1] - data[mode].gridY[y] + 1); - tabImg[mode].grid[a]->setAlpha(mAlpha); a++; } } + tabImg[mode].setAlpha(mAlpha); tab[mode]->decRef(); } } @@ -126,12 +126,10 @@ void Tab::updateAlpha() if (alpha != mAlpha) { mAlpha = alpha; - for (int a = 0; a < 9; a++) + + for (auto &t : tabImg) { - for (int t = 0; t < TAB_COUNT; t++) - { - tabImg[t].grid[a]->setAlpha(mAlpha); - } + t.setAlpha(mAlpha); } } } diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index cd2c0f03..1fdd276f 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -214,10 +214,9 @@ void TabbedArea::widgetResized(const gcn::Event &event) void TabbedArea::updateTabsWidth() { mTabsWidth = 0; - for (TabContainer::const_iterator itr = mTabs.begin(), itr_end = mTabs.end(); - itr != itr_end; ++itr) + for (const auto &tab : mTabs) { - mTabsWidth += (*itr).first->getWidth(); + mTabsWidth += tab.first->getWidth(); } updateVisibleTabsWidth(); } @@ -234,11 +233,11 @@ void TabbedArea::updateVisibleTabsWidth() void TabbedArea::adjustTabPositions() { int maxTabHeight = 0; - for (unsigned i = 0; i < mTabs.size(); ++i) + for (auto &tab : mTabs) { - if (mTabs[i].first->getHeight() > maxTabHeight) + if (tab.first->getHeight() > maxTabHeight) { - maxTabHeight = mTabs[i].first->getHeight(); + maxTabHeight = tab.first->getHeight(); } } diff --git a/src/gui/widgets/tablemodel.cpp b/src/gui/widgets/tablemodel.cpp index 5273e929..9c7bc92d 100644 --- a/src/gui/widgets/tablemodel.cpp +++ b/src/gui/widgets/tablemodel.cpp @@ -37,14 +37,14 @@ void TableModel::removeListener(TableModelListener *listener) void TableModel::signalBeforeUpdate() { - for (auto it = listeners.begin(); it != listeners.end(); it++) - (*it)->modelUpdated(false); + for (auto listener : listeners) + listener->modelUpdated(false); } void TableModel::signalAfterUpdate() { - for (auto it = listeners.begin(); it != listeners.end(); it++) - (*it)->modelUpdated(true); + for (auto listener : listeners) + listener->modelUpdated(true); } @@ -146,9 +146,9 @@ int StaticTableModel::getWidth() const { int width = 0; - for (unsigned int i = 0; i < mWidths.size(); i++) + for (int w : mWidths) { - width += mWidths[i]; + width += w; } return width; diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 1609e002..2239bed4 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -69,10 +69,10 @@ TextField::TextField(const std::string &text, bool loseFocusOnTab): gridx[x], gridy[y], gridx[x + 1] - gridx[x] + 1, gridy[y + 1] - gridy[y] + 1); - skin.grid[a]->setAlpha(config.getFloatValue("guialpha")); a++; } } + skin.setAlpha(config.getFloatValue("guialpha")); textbox->decRef(); } @@ -96,8 +96,7 @@ void TextField::updateAlpha() if (alpha != mAlpha) { mAlpha = alpha; - for (int a = 0; a < 9; a++) - skin.grid[a]->setAlpha(mAlpha); + skin.setAlpha(mAlpha); } } diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp index ad87788f..a0c227ab 100644 --- a/src/gui/widgets/vertcontainer.cpp +++ b/src/gui/widgets/vertcontainer.cpp @@ -45,8 +45,8 @@ void VertContainer::clear() void VertContainer::widgetResized(const gcn::Event &event) { - for (auto it = mWidgets.begin(); it != mWidgets.end(); it++) + for (auto &widget : mWidgets) { - (*it)->setWidth(getWidth()); + widget->setWidth(getWidth()); } } diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp index c7ac5d99..8cee550b 100644 --- a/src/gui/widgets/windowcontainer.cpp +++ b/src/gui/widgets/windowcontainer.cpp @@ -43,7 +43,7 @@ void WindowContainer::scheduleDelete(gcn::Widget *widget) void WindowContainer::adjustAfterResize(int oldScreenWidth, int oldScreenHeight) { - for (auto i = mWidgets.begin(); i != mWidgets.end(); ++i) - if (auto *window = dynamic_cast<Window*>(*i)) + for (auto &widget : mWidgets) + if (auto *window = dynamic_cast<Window*>(widget)) window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight); } diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index 5b13d0f3..0da51928 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -199,9 +199,9 @@ void WindowMenu::addButton(const std::string& text, int &x, int &h, void WindowMenu::updatePopUpCaptions() { - for (auto it = mWidgets.begin(); it != mWidgets.end(); ++it) + for (auto &widget : mWidgets) { - auto *button = dynamic_cast<Button*> (*it); + auto *button = dynamic_cast<Button*>(widget); if (!button) continue; diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 3632acf9..818a7966 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -122,26 +122,25 @@ void KeyboardConfig::init() void KeyboardConfig::retrieve() { - for (int i = 0; i < KEY_TOTAL; i++) + for (auto &key : mKey) { - mKey[i].value = (int) config.getValue( - mKey[i].configField, mKey[i].defaultValue); + key.value = (int) config.getValue(key.configField, key.defaultValue); } } void KeyboardConfig::store() { - for (int i = 0; i < KEY_TOTAL; i++) + for (auto &key : mKey) { - config.setValue(mKey[i].configField, mKey[i].value); + config.setValue(key.configField, key.value); } } void KeyboardConfig::makeDefault() { - for (int i = 0; i < KEY_TOTAL; i++) + for (auto &key : mKey) { - mKey[i].value = mKey[i].defaultValue; + key.value = key.defaultValue; } } diff --git a/src/log.cpp b/src/log.cpp index 74246b7e..1a37abae 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -30,9 +30,9 @@ void MacDialogBox(const std::string &error); #include <sys/time.h> #include <iostream> #include <sstream> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> +#include <cstdarg> +#include <cstdio> +#include <cstdlib> Logger::Logger(): mLogToStandardOut(true) diff --git a/src/map.cpp b/src/map.cpp index 1ba62fcd..9639ddf2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -39,7 +39,7 @@ #include "utils/stringutils.h" #include <queue> -#include <limits.h> +#include <climits> /** * A location on a tile map. Used for pathfinding, open list. @@ -85,10 +85,9 @@ void TileAnimation::update(int ticks) Image *img = mAnimation->getCurrentImage(); if (img != mLastImage) { - for (auto i = - mAffected.begin(); i != mAffected.end(); i++) + for (auto &affected : mAffected) { - i->first->setTile(i->second, img); + affected.first->setTile(affected.second, img); } mLastImage = img; } @@ -229,10 +228,10 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): const int size = mWidth * mHeight; mMetaTiles = new MetaTile[size]; - for (int i = 0; i < NB_BLOCKTYPES; i++) + for (auto &occupation : mOccupation) { - mOccupation[i] = new unsigned[size]; - memset(mOccupation[i], 0, size * sizeof(unsigned)); + occupation = new unsigned[size]; + memset(occupation, 0, size * sizeof(unsigned)); } } @@ -240,9 +239,9 @@ Map::~Map() { // delete metadata, layers, tilesets and overlays delete[] mMetaTiles; - for (int i = 0; i < NB_BLOCKTYPES; i++) + for (auto &occupation : mOccupation) { - delete[] mOccupation[i]; + delete[] occupation; } delete_all(mLayers); delete_all(mTilesets); @@ -321,11 +320,9 @@ bool actorCompare(const Actor *a, const Actor *b) void Map::update(int ticks) { // Update animated tiles - for (auto iAni = mTileAnimations.begin(); - iAni != mTileAnimations.end(); - iAni++) + for (auto &tileAnimation : mTileAnimations) { - iAni->second->update(ticks); + tileAnimation.second->update(ticks); } } @@ -488,20 +485,19 @@ void Map::updateAmbientLayers(float scrollX, float scrollY) float dy = scrollY - mLastScrollY; int timePassed = get_elapsed_time(lastTick); - std::list<AmbientLayer*>::iterator i; - for (i = mBackgrounds.begin(); i != mBackgrounds.end(); i++) + for (auto &background : mBackgrounds) { - if (((*i)->mMask & mMask) == 0) + if ((background->mMask & mMask) == 0) continue; - (*i)->update(timePassed, dx, dy); + background->update(timePassed, dx, dy); } - for (i = mForegrounds.begin(); i != mForegrounds.end(); i++) + for (auto &foreground : mForegrounds) { - if (((*i)->mMask & mMask) == 0) + if ((foreground->mMask & mMask) == 0) continue; - (*i)->update(timePassed, dx, dy); + foreground->update(timePassed, dx, dy); } mLastScrollX = scrollX; mLastScrollY = scrollY; @@ -532,13 +528,12 @@ void Map::drawAmbientLayers(Graphics *graphics, LayerType type, } // Draw overlays - for (auto i = layers->begin(); - i != layers->end(); i++) + for (auto &layer : *layers) { - if (((*i)->mMask & mMask) == 0) + if ((layer->mMask & mMask) == 0) continue; - (*i)->draw(graphics, graphics->getWidth(), graphics->getHeight()); + layer->draw(graphics, graphics->getWidth(), graphics->getHeight()); // Detail 1: only one overlay, higher: all overlays if (detail == 1) @@ -597,12 +592,8 @@ bool Map::getWalk(int x, int y, unsigned char walkmask) const bool Map::occupied(int x, int y) const { - const ActorSprites &actors = actorSpriteManager->getAll(); - ActorSpritesConstIterator it, it_end; - for (it = actors.begin(), it_end = actors.end(); it != it_end; it++) + for (auto actor : actorSpriteManager->getAll()) { - const ActorSprite *actor = *it; - if (actor->getTileX() == x && actor->getTileY() == y && actor->getType() != ActorSprite::FLOOR_ITEM) return true; @@ -1019,15 +1010,12 @@ void Map::initializeParticleEffects(Particle *particleEngine) if (config.getBoolValue("particleeffects")) { - for (auto i = particleEffects.begin(); - i != particleEffects.end(); - i++ - ) + for (auto &particleEffect : particleEffects) { - p = particleEngine->addEffect(i->file, i->x, i->y); - if (p && i->w > 0 && i->h > 0) + p = particleEngine->addEffect(particleEffect.file, particleEffect.x, particleEffect.y); + if (p && particleEffect.w > 0 && particleEffect.h > 0) { - p->adjustEmitterSize(i->w, i->h); + p->adjustEmitterSize(particleEffect.w, particleEffect.h); } } } diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index d5a5497e..c8c23c7f 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -397,11 +397,10 @@ void CharHandler::updateCharacters() character->data.mAttributes[CHAR_POINTS] = info.characterPoints; character->data.mAttributes[CORR_POINTS] = info.correctionPoints; - for (auto it = info.attribute.begin(), - it_end = info.attribute.end(); it != it_end; it++) + for (const auto &it : info.attribute) { - character->data.mStats[i].base = it->second.base; - character->data.mStats[i].mod = it->second.mod; + character->data.mStats[i].base = it.second.base; + character->data.mStats[i].mod = it.second.mod; } mCharacters.push_back(character); diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index af482400..8898db55 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -99,13 +99,12 @@ void EquipBackend::triggerUnequip(int slotIndex) const void EquipBackend::clear() { - for (auto i = mSlots.begin(), i_end = mSlots.end(); - i != i_end; ++i) + for (auto &slot : mSlots) { - if (i->second.item) + if (slot.second.item) { - delete i->second.item; - i->second.item = nullptr; + delete slot.second.item; + slot.second.item = nullptr; } } mSlots.clear(); @@ -280,22 +279,20 @@ void EquipBackend::readBoxNode(xmlNodePtr slotNode) bool EquipBackend::isWeaponSlot(int slotTypeId) const { - for (auto it = mSlots.begin(), it_end = mSlots.end(); - it != it_end; ++it) + for (const auto &slot : mSlots) { - if (it->second.slotTypeId == (unsigned)slotTypeId) - return it->second.weaponSlot; + if (slot.second.slotTypeId == (unsigned)slotTypeId) + return slot.second.weaponSlot; } return false; } bool EquipBackend::isAmmoSlot(int slotTypeId) const { - for (auto it = mSlots.begin(), it_end = mSlots.end(); - it != it_end; ++it) + for (const auto &slot : mSlots) { - if (it->second.slotTypeId == (unsigned)slotTypeId) - return it->second.ammoSlot; + if (slot.second.slotTypeId == (unsigned)slotTypeId) + return slot.second.ammoSlot; } return false; } diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 6f32fb3d..7b08d83c 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -158,8 +158,8 @@ void InventoryHandler::handleMessage(MessageIn &msg) identified = msg.readInt8(); amount = msg.readInt16(); msg.readInt16(); // Arrow - for (int i = 0; i < 4; i++) - cards[i] = msg.readInt16(); + for (int &card : cards) + card = msg.readInt16(); index -= (msg.getId() == SMSG_PLAYER_INVENTORY) ? INVENTORY_OFFSET : STORAGE_OFFSET; @@ -195,8 +195,8 @@ void InventoryHandler::handleMessage(MessageIn &msg) msg.readInt16(); // Another Equip Point? msg.readInt8(); // Attribute (broken) msg.readInt8(); // Refine level - for (int i = 0; i < 4; i++) - cards[i] = msg.readInt16(); + for (int &card : cards) + card = msg.readInt16(); if (debugInventory) { @@ -218,8 +218,8 @@ void InventoryHandler::handleMessage(MessageIn &msg) identified = msg.readInt8(); msg.readInt8(); // attribute msg.readInt8(); // refine - for (int i = 0; i < 4; i++) - cards[i] = msg.readInt16(); + for (int &card : cards) + card = msg.readInt16(); msg.readInt16(); // EquipType itemType = msg.readInt8(); @@ -331,8 +331,8 @@ void InventoryHandler::handleMessage(MessageIn &msg) identified = msg.readInt8(); msg.readInt8(); // attribute msg.readInt8(); // refine - for (int i = 0; i < 4; i++) - cards[i] = msg.readInt16(); + for (int &card : cards) + card = msg.readInt16(); if (Item *item = mStorage->getItem(index)) { diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index d0a5dc62..c1862f00 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -31,7 +31,7 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include <assert.h> +#include <cassert> #include <sstream> /** Warning: buffers and other variables are shared, diff --git a/src/particle.cpp b/src/particle.cpp index 64f25999..5edb11e1 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -195,15 +195,13 @@ bool Particle::update() // Update child emitters if ((mLifetimePast-1)%Particle::emitterSkip == 0) { - for (auto e = mChildEmitters.begin(); - e != mChildEmitters.end(); e++) + for (auto &childEmitter : mChildEmitters) { - Particles newParticles = (*e)->createParticles(mLifetimePast); - for (auto p = newParticles.begin(); - p != newParticles.end(); p++) + Particles newParticles = childEmitter->createParticles(mLifetimePast); + for (auto &newParticle : newParticles) { - (*p)->moveBy(mPos); - mChildParticles.push_back (*p); + newParticle->moveBy(mPos); + mChildParticles.push_back(newParticle); } } } @@ -212,7 +210,7 @@ bool Particle::update() // create death effect when the particle died if (mAlive != ALIVE && mAlive != DEAD_LONG_AGO) { - if ((mAlive & mDeathEffectConditions) > 0x00 && !mDeathEffect.empty()) + if ((mAlive & mDeathEffectConditions) > 0x00 && !mDeathEffect.empty()) { Particle* deathEffect = particleEngine->addEffect(mDeathEffect, 0, 0); deathEffect->moveBy(mPos); @@ -254,12 +252,11 @@ bool Particle::update() void Particle::moveBy(const Vector &change) { mPos += change; - for (auto p = mChildParticles.begin(); - p != mChildParticles.end(); p++) + for (auto &childParticle : mChildParticles) { - if ((*p)->doesFollow()) + if (childParticle->doesFollow()) { - (*p)->moveBy(change); + childParticle->moveBy(change); } } } @@ -432,10 +429,9 @@ void Particle::adjustEmitterSize(int w, int h) { if (mAllowSizeAdjust) { - for (auto e = mChildEmitters.begin(); - e != mChildEmitters.end(); e++) + for (auto &childEmitter : mChildEmitters) { - (*e)->adjustSize(w, h); + childEmitter->adjustSize(w, h); } } } diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp index 002d4488..b3798a33 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -87,9 +87,8 @@ void ParticleList::removeLocally(Particle *particle) void ParticleList::clearLocally() { - for (auto it = mElements.begin(); - it != mElements.end(); it++) - (*it)->kill(); + for (auto &element : mElements) + element->kill(); mElements.clear(); } @@ -160,17 +159,16 @@ void ParticleVector::moveTo(float x, float y) { ParticleContainer::moveTo(x, y); - for (auto it = mIndexedElements.begin(); - it != mIndexedElements.end(); it++) + for (auto &indexedElement : mIndexedElements) { - if (*it) + if (indexedElement) { - (*it)->moveTo(x, y); + indexedElement->moveTo(x, y); - if ((*it)->isExtinct()) + if (indexedElement->isExtinct()) { - (*it)->kill(); - *it = NULL; + indexedElement->kill(); + indexedElement = NULL; } } } diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index ec646f97..81258d80 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -506,11 +506,9 @@ std::list<Particle *> ParticleEmitter::createParticles(int tick) newParticle->setFadeIn(mParticleFadeIn.value(tick)); newParticle->setAlpha(mParticleAlpha.value(tick)); - for (auto i = mParticleChildEmitters.begin(); - i != mParticleChildEmitters.end(); - i++) + for (auto &particleChildEmitter : mParticleChildEmitters) { - newParticle->addEmitter(new ParticleEmitter(*i)); + newParticle->addEmitter(new ParticleEmitter(particleChildEmitter)); } if (!mDeathEffect.empty()) diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index 22c01516..a3e83c42 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -319,13 +319,12 @@ void logic() if ((mSpecialRechargeUpdateNeeded%11) == 0) { mSpecialRechargeUpdateNeeded = 0; - for (auto it = mSpecials.begin(), - it_end = mSpecials.end(); it != it_end; it++) + for (auto &special : mSpecials) { - it->second.currentMana += it->second.recharge; - if (it->second.currentMana > it->second.neededMana) + special.second.currentMana += special.second.recharge; + if (special.second.currentMana > special.second.neededMana) { - it->second.currentMana = it->second.neededMana; + special.second.currentMana = special.second.neededMana; } } } diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index f65b1fc7..39a2447a 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -108,10 +108,9 @@ PlayerRelationsManager::~PlayerRelationsManager() void PlayerRelationsManager::clear() { std::vector<std::string> *names = getPlayers(); - for (std::vector<std::string>::const_iterator - it = names->begin(); it != names->end(); it++) + for (const auto &name : *names) { - removePlayer(*it); + removePlayer(name); } delete names; } @@ -261,13 +260,13 @@ void PlayerRelationsManager::setRelation(const std::string &playerName, signalUpdate(playerName); } -std::vector<std::string> * PlayerRelationsManager::getPlayers() const +std::vector<std::string> *PlayerRelationsManager::getPlayers() const { auto *retval = new std::vector<std::string>(); - for (auto it = mRelations.begin(); it != mRelations.end(); it++) - if (it->second) - retval->push_back(it->first); + for (const auto &relation : mRelations) + if (relation.second) + retval->push_back(relation.first); sort(retval->begin(), retval->end()); @@ -276,8 +275,7 @@ std::vector<std::string> * PlayerRelationsManager::getPlayers() const void PlayerRelationsManager::removePlayer(const std::string &name) { - auto it = - mRelations.find(name); + auto it = mRelations.find(name); if (it != mRelations.end()) { delete it->second; diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index ba2ad4b5..92c830dc 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -23,7 +23,7 @@ #include "log.h" -#include <math.h> +#include <cmath> #include <sstream> DyePalette::DyePalette(const std::string &description) @@ -178,8 +178,8 @@ void DyePalette::getColor(double intensity, int color[3]) const Dye::Dye(const std::string &description) { - for (int i = 0; i < 7; ++i) - mDyePalettes[i] = nullptr; + for (auto &dyePalette : mDyePalettes) + dyePalette = nullptr; if (description.empty()) return; @@ -223,8 +223,8 @@ Dye::Dye(const std::string &description) Dye::~Dye() { - for (int i = 0; i < 7; ++i) - delete mDyePalettes[i]; + for (auto &dyePalette : mDyePalettes) + delete dyePalette; } void Dye::update(int color[3]) const diff --git a/src/resources/dye.h b/src/resources/dye.h index 4c6c3a53..ce5565f8 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -54,7 +54,7 @@ class DyePalette struct Color { unsigned char value[3]; }; - std::vector< Color > mColors; + std::vector<Color> mColors; }; /** diff --git a/src/resources/hairdb.cpp b/src/resources/hairdb.cpp index 4ca4fa5c..310ba0c4 100644 --- a/src/resources/hairdb.cpp +++ b/src/resources/hairdb.cpp @@ -23,7 +23,7 @@ #include "log.h" -#include <assert.h> +#include <cassert> #define COLOR_WHITE "#ffffff" @@ -78,31 +78,30 @@ void HairDB::addHairStyle(int id) mHairStyles.insert(id); } -const std::string &HairDB::getHairColor(int id) +const std::string &HairDB::getHairColor(int id) const { if (!mLoaded) { // no idea if this can happen, but that check existed before logger->log("WARNING: HairDB::getHairColor() called before settings were loaded!"); } - ColorConstIterator it = mHairColors.find(id); + auto it = mHairColors.find(id); if (it != mHairColors.end()) return it->second; logger->log("HairDb: Error, unknown color Id# %d", id); - return mHairColors[0]; + return mHairColors.at(0); } std::vector<int> HairDB::getHairStyleIds(int maxId) const { std::vector<int> hairStylesIds; - for (auto it = mHairStyles.begin(), - it_end = mHairStyles.end(); it != it_end; ++it) + for (int hairStyle : mHairStyles) { // Don't give ids higher than the requested maximum. - if (maxId > 0 && (*it) > maxId) + if (maxId > 0 && hairStyle > maxId) continue; - hairStylesIds.push_back(*it); + hairStylesIds.push_back(hairStyle); } return hairStylesIds; } @@ -110,13 +109,12 @@ std::vector<int> HairDB::getHairStyleIds(int maxId) const std::vector<int> HairDB::getHairColorIds(int maxId) const { std::vector<int> hairColorsIds; - for (auto it = mHairColors.begin(), - it_end = mHairColors.end(); it != it_end; ++it) + for (const auto &hairColor : mHairColors) { // Don't give ids higher than the requested maximum. - if (maxId > 0 && it->first > maxId) + if (maxId > 0 && hairColor.first > maxId) continue; - hairColorsIds.push_back(it->first); + hairColorsIds.push_back(hairColor.first); } return hairColorsIds; } diff --git a/src/resources/hairdb.h b/src/resources/hairdb.h index 48354243..80c1bb7b 100644 --- a/src/resources/hairdb.h +++ b/src/resources/hairdb.h @@ -52,7 +52,7 @@ class HairDB */ void unload(); - const std::string &getHairColor(int id); + const std::string &getHairColor(int id) const; /** * Returns the available hair style ids @@ -89,13 +89,9 @@ class HairDB // Hair colors Db using Colors = std::map<int, std::string>; - using ColorIterator = Colors::iterator; - using ColorConstIterator = Colors::const_iterator; Colors mHairColors; using HairStyles = std::set<int>; - using HairStylesIterator = HairStyles::iterator; - using HairStylesConstIterator = HairStyles::const_iterator; HairStyles mHairStyles; bool mLoaded; diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 225bdb71..7297041f 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -341,20 +341,19 @@ void TaItemDB::readItemNode(xmlNodePtr node, const std::string &filename) // Load nano description std::vector<std::string> effect; - for (int i = 0; i < int(sizeof(fields) / sizeof(fields[0])); ++i) + for (auto field : fields) { - int value = XML::getProperty(node, fields[i][0], 0); + int value = XML::getProperty(node, field[0], 0); if (!value) continue; - effect.push_back(strprintf(gettext(fields[i][1]), value)); + effect.push_back(strprintf(gettext(field[1]), value)); } - for (auto it = extraStats.begin(); - it != extraStats.end(); it++) + for (auto &extraStat : extraStats) { - int value = XML::getProperty(node, it->mTag.c_str(), 0); + int value = XML::getProperty(node, extraStat.mTag.c_str(), 0); if (!value) continue; - effect.push_back(strprintf(it->mFormat.c_str(), value)); + effect.push_back(strprintf(extraStat.mFormat.c_str(), value)); } std::string temp = XML::getProperty(node, "effect", ""); if (!temp.empty()) diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 46e1ab30..a810a11e 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -552,10 +552,9 @@ void ResourceManager::scheduleDelete(SDL_Surface* surface) void ResourceManager::clearScheduled() { - for (auto i = mDeletedSurfaces.begin(), - i_end = mDeletedSurfaces.end(); i != i_end; ++i) + for (auto mDeletedSurface : mDeletedSurfaces) { - SDL_FreeSurface(*i); + SDL_FreeSurface(mDeletedSurface); } mDeletedSurfaces.clear(); } diff --git a/src/resources/settingsmanager.cpp b/src/resources/settingsmanager.cpp index ad872385..b307d565 100644 --- a/src/resources/settingsmanager.cpp +++ b/src/resources/settingsmanager.cpp @@ -31,7 +31,6 @@ #include "statuseffect.h" #include "units.h" -#include "net/manaserv/itemhandler.h" #include "net/net.h" #include "utils/xml.h" diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index f33ade55..3a5195cc 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -320,23 +320,20 @@ void SpriteDef::includeSprite(xmlNodePtr includeNode) SpriteDef::~SpriteDef() { // Actions are shared, so ensure they are deleted only once. - std::set< Action * > actions; - for (Actions::const_iterator i = mActions.begin(), - i_end = mActions.end(); i != i_end; ++i) + std::set<Action*> actions; + for (const auto &action : mActions) { - actions.insert(i->second); + actions.insert(action.second); } - for (auto i = actions.begin(), - i_end = actions.end(); i != i_end; ++i) + for (auto action : actions) { - delete *i; + delete action; } - for (auto i = mImageSets.begin(); - i != mImageSets.end(); ++i) + for (auto &imageSet : mImageSets) { - i->second->decRef(); + imageSet.second->decRef(); } } diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index c44b7401..f4ea1902 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -71,8 +71,8 @@ Skin::Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown, Skin::~Skin() { // Clean up static resources - for (int i = 0; i < 9; i++) - delete mBorder.grid[i]; + for (auto img : mBorder.grid) + delete img; mCloseImage->decRef(); delete mStickyImageUp; @@ -84,8 +84,7 @@ void Skin::updateAlpha(float minimumOpacityAllowed) const float alpha = std::max(minimumOpacityAllowed, config.getFloatValue("guialpha")); - std::for_each(mBorder.grid, mBorder.grid + 9, - [=] (Image *img) { img->setAlpha(alpha); }); + mBorder.setAlpha(alpha); mCloseImage->setAlpha(alpha); mStickyImageUp->setAlpha(alpha); @@ -196,7 +195,8 @@ Skin *Theme::load(const std::string &filename, const std::string &defaultPath) void Theme::setMinimumOpacity(float minimumOpacity) { - if (minimumOpacity > 1.0f) return; + if (minimumOpacity > 1.0f) + return; mMinimumOpacity = minimumOpacity; updateAlpha(); @@ -204,8 +204,8 @@ void Theme::setMinimumOpacity(float minimumOpacity) void Theme::updateAlpha() { - for (auto iter = mSkins.begin(); iter != mSkins.end(); ++iter) - iter->second->updateAlpha(mMinimumOpacity); + for (auto &skin : mSkins) + skin.second->updateAlpha(mMinimumOpacity); } void Theme::event(Event::Channel channel, const Event &event) diff --git a/src/resources/userpalette.cpp b/src/resources/userpalette.cpp index 8bc681b3..4ce9db66 100644 --- a/src/resources/userpalette.cpp +++ b/src/resources/userpalette.cpp @@ -30,7 +30,7 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include <math.h> +#include <cmath> static const std::string ColorTypeNames[] = { "ColorBeing", @@ -115,19 +115,18 @@ UserPalette::UserPalette(): UserPalette::~UserPalette() { - for (auto col = mColors.begin(), - colEnd = mColors.end(); col != colEnd; ++col) + for (auto &color : mColors) { - const std::string &configName = ColorTypeNames[col->type]; - config.setValue(configName + "Gradient", col->committedGrad); + const std::string &configName = ColorTypeNames[color.type]; + config.setValue(configName + "Gradient", color.committedGrad); - if (col->grad != STATIC) - config.setValue(configName + "Delay", col->delay); + if (color.grad != STATIC) + config.setValue(configName + "Delay", color.delay); - if (col->grad == STATIC || col->grad == PULSE) + if (color.grad == STATIC || color.grad == PULSE) { char buffer[20]; - sprintf(buffer, "0x%06x", col->getRGB()); + sprintf(buffer, "0x%06x", color.getRGB()); config.setValue(configName, std::string(buffer)); } } @@ -176,39 +175,37 @@ std::string UserPalette::getElementAt(int i) void UserPalette::commit(bool commitNonStatic) { - for (auto i = mColors.begin(), iEnd = mColors.end(); - i != iEnd; ++i) + for (auto &color : mColors) { - i->committedGrad = i->grad; - i->committedDelay = i->delay; - if (commitNonStatic || i->grad == STATIC) + color.committedGrad = color.grad; + color.committedDelay = color.delay; + if (commitNonStatic || color.grad == STATIC) { - i->committedColor = i->color; + color.committedColor = color.color; } - else if (i->grad == PULSE) + else if (color.grad == PULSE) { - i->committedColor = i->testColor; + color.committedColor = color.testColor; } } } void UserPalette::rollback() { - for (auto i = mColors.begin(), iEnd = mColors.end(); - i != iEnd; ++i) + for (auto &color : mColors) { - if (i->grad != i->committedGrad) + if (color.grad != color.committedGrad) { - setGradient(i->type, i->committedGrad); + setGradient(color.type, color.committedGrad); } - setGradientDelay(i->type, i->committedDelay); - setColor(i->type, i->committedColor.r, - i->committedColor.g, i->committedColor.b); - if (i->grad == PULSE) + setGradientDelay(color.type, color.committedDelay); + setColor(color.type, color.committedColor.r, + color.committedColor.g, color.committedColor.b); + if (color.grad == PULSE) { - i->testColor.r = i->committedColor.r; - i->testColor.g = i->committedColor.g; - i->testColor.b = i->committedColor.b; + color.testColor.r = color.committedColor.r; + color.testColor.g = color.committedColor.g; + color.testColor.b = color.committedColor.b; } } } diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index 306e4120..a1990ed0 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -31,7 +31,7 @@ #include <algorithm> #include <cstring> -#include <time.h> +#include <ctime> #include <vector> struct WallpaperData diff --git a/src/text.cpp b/src/text.cpp index 14ae747b..b71667c5 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -66,10 +66,7 @@ Text::Text(const std::string &text, int x, int y, mBubble.grid[8] = sbImage->getSubImage(10, 10, 5, 5); mBubbleArrow = sbImage->getSubImage(0, 15, 15, 10); const float bubbleAlpha = config.getFloatValue("speechBubbleAlpha"); - for (int i = 0; i < 9; i++) - { - mBubble.grid[i]->setAlpha(bubbleAlpha); - } + mBubble.setAlpha(bubbleAlpha); mBubbleArrow->setAlpha(bubbleAlpha); sbImage->decRef(); } @@ -101,15 +98,8 @@ Text::~Text() { delete textManager; textManager = nullptr; - delete mBubble.grid[0]; - delete mBubble.grid[1]; - delete mBubble.grid[2]; - delete mBubble.grid[3]; - delete mBubble.grid[4]; - delete mBubble.grid[5]; - delete mBubble.grid[6]; - delete mBubble.grid[7]; - delete mBubble.grid[8]; + for (auto img : mBubble.grid) + delete img; delete mBubbleArrow; } } diff --git a/src/textmanager.cpp b/src/textmanager.cpp index 5f87bd29..35a20781 100644 --- a/src/textmanager.cpp +++ b/src/textmanager.cpp @@ -63,10 +63,9 @@ TextManager::~TextManager() void TextManager::draw(gcn::Graphics *graphics, int xOff, int yOff) { - for (auto bPtr = mTextList.begin(), ePtr = mTextList.end(); - bPtr != ePtr; ++bPtr) + for (auto &text : mTextList) { - (*bPtr)->draw(graphics, xOff, yOff); + text->draw(graphics, xOff, yOff); } } @@ -81,15 +80,14 @@ void TextManager::place(const Text *textObj, const Text *omit, int wantedTop = (TEST - h) / 2; // Entry in occupied at top of text int occupiedTop = y - wantedTop; // Line in map representing to of occupied - for (TextList::const_iterator ptr = mTextList.begin(), - pEnd = mTextList.end(); ptr != pEnd; ++ptr) + for (auto text : mTextList) { - if (*ptr != omit && - (*ptr)->mX <= xRight && - (*ptr)->mX + (*ptr)->mWidth > xLeft) + if (text != omit && + text->mX <= xRight && + text->mX + text->mWidth > xLeft) { - int from = (*ptr)->mY - occupiedTop; - int to = from + (*ptr)->mHeight - 1; + int from = text->mY - occupiedTop; + int to = from + text->mHeight - 1; if (to < 0 || from >= TEST) // out of range considered continue; if (from < 0) diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp index cf10c8fd..189407d7 100644 --- a/src/utils/base64.cpp +++ b/src/utils/base64.cpp @@ -29,8 +29,8 @@ #include "utils/base64.h" -#include <stdlib.h> -#include <string.h> +#include <cstdlib> +#include <cstring> static char base64_table[] = { diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp index a97dce3c..a18e5f18 100644 --- a/src/utils/sha256.cpp +++ b/src/utils/sha256.cpp @@ -265,10 +265,10 @@ std::string SHA256Hash(const char *src, int len) // Convert it to hex const char* hxc = "0123456789abcdef"; std::string hash = ""; - for (int i = 0; i < SHA256_DIGEST_SIZE; i++) + for (unsigned char i : bytehash) { - hash += hxc[bytehash[i] / 16]; - hash += hxc[bytehash[i] % 16]; + hash += hxc[i / 16]; + hash += hxc[i % 16]; } return hash; } diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 59a3f17d..5083770c 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -23,7 +23,7 @@ #include "log.h" -#include <string.h> +#include <cstring> #include <algorithm> #include <cstdarg> #include <cstdio> diff --git a/src/vector.h b/src/vector.h index 25f6c120..9ff98aa1 100644 --- a/src/vector.h +++ b/src/vector.h @@ -22,7 +22,7 @@ #ifndef VECTOR_H #define VECTOR_H -#include <math.h> +#include <cmath> #include <iostream> |