summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-01-26 16:21:43 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-01-29 14:18:06 +0100
commite7c285e3423ddd660447f6a6fc6bbae25f99f386 (patch)
tree1d700f09a5e96a2a0d390af30581097bdec0bf77 /src/resources
parente1a7c1d0ca30c2c4a293ffbff6b9c51c881d23e3 (diff)
downloadmana-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/resources')
-rw-r--r--src/resources/dye.cpp10
-rw-r--r--src/resources/dye.h2
-rw-r--r--src/resources/hairdb.cpp22
-rw-r--r--src/resources/hairdb.h6
-rw-r--r--src/resources/itemdb.cpp13
-rw-r--r--src/resources/resourcemanager.cpp5
-rw-r--r--src/resources/settingsmanager.cpp1
-rw-r--r--src/resources/spritedef.cpp17
-rw-r--r--src/resources/theme.cpp14
-rw-r--r--src/resources/userpalette.cpp53
-rw-r--r--src/resources/wallpaper.cpp2
11 files changed, 65 insertions, 80 deletions
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