summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-09-03 00:32:00 +0300
committerAndrei Karas <akaras@inbox.ru>2012-09-03 00:32:00 +0300
commitfa21c1b65dbe91a1e6ac880db977416162f268df (patch)
tree7fa06ef18a171d62ff892c99e710d4df7aff91b5 /src/resources
parent0534847df83047f1ce2605187d45a762ffeae11e (diff)
downloadmanaverse-fa21c1b65dbe91a1e6ac880db977416162f268df.tar.gz
manaverse-fa21c1b65dbe91a1e6ac880db977416162f268df.tar.bz2
manaverse-fa21c1b65dbe91a1e6ac880db977416162f268df.tar.xz
manaverse-fa21c1b65dbe91a1e6ac880db977416162f268df.zip
Add const to more classes.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/mapreader.cpp56
-rw-r--r--src/resources/mapreader.h7
-rw-r--r--src/resources/monsterdb.cpp14
-rw-r--r--src/resources/monsterdb.h2
-rw-r--r--src/resources/music.cpp8
-rw-r--r--src/resources/music.h6
-rw-r--r--src/resources/npcdb.cpp12
-rw-r--r--src/resources/npcdb.h2
-rw-r--r--src/resources/openglimagehelper.cpp20
-rw-r--r--src/resources/openglimagehelper.h10
-rw-r--r--src/resources/resource.cpp2
-rw-r--r--src/resources/resourcemanager.cpp156
-rw-r--r--src/resources/resourcemanager.h57
-rw-r--r--src/resources/sdlimagehelper.cpp36
-rw-r--r--src/resources/sdlimagehelper.h11
-rw-r--r--src/resources/soundeffect.cpp6
-rw-r--r--src/resources/soundeffect.h7
-rw-r--r--src/resources/specialdb.cpp10
-rw-r--r--src/resources/specialdb.h2
19 files changed, 227 insertions, 197 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 7e9fdd753..8a193a627 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -42,10 +42,10 @@
#include "debug.h"
-static int inflateMemory(unsigned char *in, unsigned int inLength,
+static int inflateMemory(unsigned char *const in, const unsigned int inLength,
unsigned char *&out, unsigned int &outLength);
-static int inflateMemory(unsigned char *in, unsigned int inLength,
+static int inflateMemory(unsigned char *const in, const unsigned int inLength,
unsigned char *&out);
static std::string resolveRelativePath(std::string base, std::string relative)
@@ -78,7 +78,7 @@ static std::string resolveRelativePath(std::string base, std::string relative)
* Inflates either zlib or gzip deflated memory. The inflated memory is
* expected to be freed by the caller.
*/
-int inflateMemory(unsigned char *in, unsigned int inLength,
+int inflateMemory(unsigned char *const in, const unsigned int inLength,
unsigned char *&out, unsigned int &outLength)
{
int bufferSize = 256 * 1024;
@@ -147,11 +147,11 @@ int inflateMemory(unsigned char *in, unsigned int inLength,
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
-int inflateMemory(unsigned char *in, unsigned int inLength,
+int inflateMemory(unsigned char *const in, const unsigned int inLength,
unsigned char *&out)
{
unsigned int outLength = 0;
- int ret = inflateMemory(in, inLength, out, outLength);
+ const int ret = inflateMemory(in, inLength, out, outLength);
if (ret != Z_OK || !out)
{
@@ -185,7 +185,7 @@ Map *MapReader::readMap(const std::string &filename,
{
logger->log("Attempting to read map %s", realFilename.c_str());
// Load the file through resource manager
- ResourceManager *resman = ResourceManager::getInstance();
+ const ResourceManager *const resman = ResourceManager::getInstance();
int fileSize;
void *buffer = resman->loadFile(realFilename, fileSize);
Map *map = nullptr;
@@ -258,7 +258,7 @@ Map *MapReader::readMap(XmlNodePtr node, const std::string &path)
const int tilew = XML::getProperty(node, "tilewidth", -1);
const int tileh = XML::getProperty(node, "tileheight", -1);
- bool showWarps = config.getBoolValue("warpParticle");
+ const bool showWarps = config.getBoolValue("warpParticle");
const std::string warpPath = paths.getStringValue("particles")
+ paths.getStringValue("portalEffectFile");
@@ -270,13 +270,13 @@ Map *MapReader::readMap(XmlNodePtr node, const std::string &path)
return nullptr;
}
- Map *map = new Map(w, h, tilew, tileh);
+ Map *const map = new Map(w, h, tilew, tileh);
for_each_xml_child_node(childNode, node)
{
if (xmlNameEqual(childNode, "tileset"))
{
- Tileset *tileset = readTileset(childNode, pathDir, map);
+ Tileset *const tileset = readTileset(childNode, pathDir, map);
if (tileset)
map->addTileset(tileset);
}
@@ -377,7 +377,7 @@ Map *MapReader::readMap(XmlNodePtr node, const std::string &path)
return map;
}
-void MapReader::readProperties(XmlNodePtr node, Properties *props)
+void MapReader::readProperties(const XmlNodePtr node, Properties *const props)
{
if (!node || !props)
return;
@@ -396,7 +396,8 @@ void MapReader::readProperties(XmlNodePtr node, Properties *props)
}
}
-inline static void setTile(Map *map, MapLayer *layer, int x, int y, int gid)
+inline static void setTile(Map *const map, MapLayer *const layer,
+ const int x, const int y, const int gid)
{
const Tileset * const set = map->getTilesetWithGid(gid);
if (layer)
@@ -443,7 +444,7 @@ inline static void setTile(Map *map, MapLayer *layer, int x, int y, int gid)
}
}
-void MapReader::readLayer(XmlNodePtr node, Map *map)
+void MapReader::readLayer(const XmlNodePtr node, Map *const map)
{
// Layers are not necessarily the same size as the map
const int w = XML::getProperty(node, "width", map->getWidth());
@@ -514,10 +515,10 @@ void MapReader::readLayer(XmlNodePtr node, Map *map)
if (!dataChild)
continue;
- int len = static_cast<int>(strlen(
+ const int len = static_cast<int>(strlen(
reinterpret_cast<const char*>(dataChild->content)) + 1);
unsigned char *charData = new unsigned char[len + 1];
- xmlChar *xmlChars = xmlNodeGetContent(dataChild);
+ xmlChar *const xmlChars = xmlNodeGetContent(dataChild);
const char *charStart = reinterpret_cast<const char*>(xmlChars);
if (!charStart)
{
@@ -553,7 +554,7 @@ void MapReader::readLayer(XmlNodePtr node, Map *map)
{
// Inflate the gzipped layer data
unsigned char *inflated;
- unsigned int inflatedSize =
+ const unsigned int inflatedSize =
inflateMemory(binData, binLen, inflated);
free(binData);
@@ -576,7 +577,7 @@ void MapReader::readLayer(XmlNodePtr node, Map *map)
setTile(map, layer, x, y, gid);
- TileAnimation* ani = map->getAnimationForGid(gid);
+ TileAnimation *const ani = map->getAnimationForGid(gid);
if (ani)
ani->addAffectedTile(layer, x + y * w);
@@ -599,8 +600,8 @@ void MapReader::readLayer(XmlNodePtr node, Map *map)
if (!dataChild)
continue;
- xmlChar *xmlChars = xmlNodeGetContent(dataChild);
- const char *data = reinterpret_cast<const char*>(xmlChars);
+ xmlChar *const xmlChars = xmlNodeGetContent(dataChild);
+ const char *const data = reinterpret_cast<const char*>(xmlChars);
if (!data)
return;
@@ -666,14 +667,14 @@ void MapReader::readLayer(XmlNodePtr node, Map *map)
}
Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
- Map *map)
+ Map *const map)
{
if (!map)
return nullptr;
- int firstGid = XML::getProperty(node, "firstgid", 0);
- int margin = XML::getProperty(node, "margin", 0);
- int spacing = XML::getProperty(node, "spacing", 0);
+ const int firstGid = XML::getProperty(node, "firstgid", 0);
+ const int margin = XML::getProperty(node, "margin", 0);
+ const int spacing = XML::getProperty(node, "spacing", 0);
XML::Document* doc = nullptr;
Tileset *set = nullptr;
std::string pathDir(path);
@@ -707,8 +708,8 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
{
std::string sourceStr = resolveRelativePath(pathDir, source);
- ResourceManager *resman = ResourceManager::getInstance();
- Image* tilebmp = resman->getImage(sourceStr);
+ ResourceManager *const resman = ResourceManager::getInstance();
+ Image *const tilebmp = resman->getImage(sourceStr);
if (tilebmp)
{
@@ -743,7 +744,8 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
if (!xmlNameEqual(tileNode, "properties"))
continue;
- int tileGID = firstGid + XML::getProperty(childNode, "id", 0);
+ const int tileGID = firstGid + XML::getProperty(
+ childNode, "id", 0);
// read tile properties to a map for simpler handling
std::map<std::string, int> tileProperties;
@@ -753,7 +755,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
continue;
std::string name = XML::getProperty(
propertyNode, "name", "");
- int value = XML::getProperty(propertyNode, "value", 0);
+ const int value = XML::getProperty(propertyNode, "value", 0);
if (!name.empty())
{
tileProperties[name] = value;
@@ -812,7 +814,7 @@ Map *MapReader::createEmptyMap(const std::string &filename,
const std::string &realFilename)
{
logger->log("Creating empty map");
- Map *map = new Map(300, 300, 32, 32);
+ Map *const map = new Map(300, 300, 32, 32);
map->setProperty("_filename", realFilename);
map->setProperty("_realfilename", filename);
map->setCustom(true);
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 28fa628db..186d643fc 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -60,18 +60,19 @@ class MapReader
* @param props The Properties instance to which the properties will
* be assigned.
*/
- static void readProperties(XmlNodePtr node, Properties* props);
+ static void readProperties(const XmlNodePtr node,
+ Properties *const props);
/**
* Reads a map layer and adds it to the given map.
*/
- static void readLayer(XmlNodePtr node, Map *map);
+ static void readLayer(const XmlNodePtr node, Map *const map);
/**
* Reads a tile set.
*/
static Tileset *readTileset(XmlNodePtr node, const std::string &path,
- Map *map);
+ Map *const map);
};
#endif
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index af0cd765c..26c72ed2f 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -61,10 +61,12 @@ void MonsterDB::load()
}
#ifdef MANASERV_SUPPORT
- int offset = XML::getProperty(rootNode, "offset", Net::getNetworkType() !=
- ServerInfo::MANASERV ? OLD_TMWATHENA_OFFSET : 0);
+ const int offset = XML::getProperty(rootNode, "offset",
+ Net::getNetworkType() != ServerInfo::MANASERV
+ ? OLD_TMWATHENA_OFFSET : 0);
#else
- int offset = XML::getProperty(rootNode, "offset", OLD_TMWATHENA_OFFSET);
+ const int offset = XML::getProperty(rootNode,
+ "offset", OLD_TMWATHENA_OFFSET);
#endif
//iterate <monster>s
@@ -73,7 +75,7 @@ void MonsterDB::load()
if (!xmlNameEqual(monsterNode, "monster"))
continue;
- BeingInfo *currentInfo = new BeingInfo;
+ BeingInfo *const currentInfo = new BeingInfo;
currentInfo->setWalkMask(Map::BLOCKMASK_WALL
| Map::BLOCKMASK_CHARACTER | Map::BLOCKMASK_MONSTER);
@@ -121,7 +123,7 @@ void MonsterDB::load()
if (xmlNameEqual(spriteNode, "sprite"))
{
- SpriteReference *currentSprite = new SpriteReference;
+ SpriteReference *const currentSprite = new SpriteReference;
currentSprite->sprite = reinterpret_cast<const char*>(
spriteNode->xmlChildrenNode->content);
@@ -213,7 +215,7 @@ void MonsterDB::unload()
}
-BeingInfo *MonsterDB::get(int id)
+BeingInfo *MonsterDB::get(const int id)
{
BeingInfoIterator i = mMonsterInfos.find(id);
diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h
index 3ddc68c08..b1c284f48 100644
--- a/src/resources/monsterdb.h
+++ b/src/resources/monsterdb.h
@@ -34,7 +34,7 @@ namespace MonsterDB
void unload();
- BeingInfo *get(int id);
+ BeingInfo *get(const int id);
}
#endif
diff --git a/src/resources/music.cpp b/src/resources/music.cpp
index b13812f18..1b66e6bad 100644
--- a/src/resources/music.cpp
+++ b/src/resources/music.cpp
@@ -26,7 +26,7 @@
#include "debug.h"
-Music::Music(Mix_Music *music) :
+Music::Music(Mix_Music *const music) :
mMusic(music)
{
}
@@ -36,9 +36,9 @@ Music::~Music()
Mix_FreeMusic(mMusic);
}
-Resource *Music::load(SDL_RWops *rw)
+Resource *Music::load(SDL_RWops *const rw)
{
- if (Mix_Music *music = Mix_LoadMUS_RW(rw))
+ if (Mix_Music *const music = Mix_LoadMUS_RW(rw))
{
return new Music(music);
}
@@ -49,7 +49,7 @@ Resource *Music::load(SDL_RWops *rw)
}
}
-bool Music::play(int loops, int fadeIn)
+bool Music::play(const int loops, const int fadeIn)
{
if (fadeIn > 0)
return Mix_FadeInMusic(mMusic, loops, fadeIn);
diff --git a/src/resources/music.h b/src/resources/music.h
index 88cc752bc..0afbb428b 100644
--- a/src/resources/music.h
+++ b/src/resources/music.h
@@ -46,7 +46,7 @@ class Music : public Resource
* @return <code>NULL</code> if the an error occurred, a valid pointer
* otherwise.
*/
- static Resource *load(SDL_RWops *rw);
+ static Resource *load(SDL_RWops *const rw);
/**
* Plays the music.
@@ -58,13 +58,13 @@ class Music : public Resource
* @return <code>true</code> if the playback started properly
* <code>false</code> otherwise.
*/
- bool play(int loops = -1, int fadeIn = 0);
+ bool play(const int loops = -1, const int fadeIn = 0);
protected:
/**
* Constructor.
*/
- Music(Mix_Music *music);
+ Music(Mix_Music *const music);
Mix_Music *mMusic;
};
diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp
index 40c7182f6..3ce300138 100644
--- a/src/resources/npcdb.cpp
+++ b/src/resources/npcdb.cpp
@@ -47,7 +47,7 @@ void NPCDB::load()
logger->log1("Initializing NPC database...");
XML::Document doc("npcs.xml");
- XmlNodePtr rootNode = doc.rootNode();
+ const XmlNodePtr rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "npcs"))
{
@@ -62,14 +62,14 @@ void NPCDB::load()
if (!xmlNameEqual(npcNode, "npc"))
continue;
- int id = XML::getProperty(npcNode, "id", 0);
+ const int id = XML::getProperty(npcNode, "id", 0);
if (id == 0)
{
logger->log1("NPC Database: NPC with missing ID in npcs.xml!");
continue;
}
- BeingInfo *currentInfo = new BeingInfo;
+ BeingInfo *const currentInfo = new BeingInfo;
if (serverVersion > 0)
{
@@ -93,7 +93,7 @@ void NPCDB::load()
if (xmlNameEqual(spriteNode, "sprite"))
{
- SpriteReference *currentSprite = new SpriteReference;
+ SpriteReference *const currentSprite = new SpriteReference;
currentSprite->sprite = reinterpret_cast<const char*>(
spriteNode->xmlChildrenNode->content);
currentSprite->variant =
@@ -124,9 +124,9 @@ void NPCDB::unload()
mLoaded = false;
}
-BeingInfo *NPCDB::get(int id)
+BeingInfo *NPCDB::get(const int id)
{
- BeingInfoIterator i = mNPCInfos.find(id);
+ const BeingInfoIterator i = mNPCInfos.find(id);
if (i == mNPCInfos.end())
{
diff --git a/src/resources/npcdb.h b/src/resources/npcdb.h
index 9b686691a..5d8bea02f 100644
--- a/src/resources/npcdb.h
+++ b/src/resources/npcdb.h
@@ -34,7 +34,7 @@ namespace NPCDB
void unload();
- BeingInfo *get(int id);
+ BeingInfo *get(const int id);
}
#endif
diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp
index 865f5f63f..2ae819a11 100644
--- a/src/resources/openglimagehelper.cpp
+++ b/src/resources/openglimagehelper.cpp
@@ -48,9 +48,9 @@ int OpenGLImageHelper::mTextureSize = 0;
bool OpenGLImageHelper::mBlur = true;
int OpenGLImageHelper::mUseOpenGL = 0;
-Resource *OpenGLImageHelper::load(SDL_RWops *rw, Dye const &dye)
+Resource *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye)
{
- SDL_Surface *tmpImage = IMG_Load_RW(rw, 1);
+ SDL_Surface *const tmpImage = IMG_Load_RW(rw, 1);
if (!tmpImage)
{
@@ -58,17 +58,17 @@ Resource *OpenGLImageHelper::load(SDL_RWops *rw, Dye const &dye)
return nullptr;
}
- SDL_Surface *surf = convertTo32Bit(tmpImage);
+ SDL_Surface *const surf = convertTo32Bit(tmpImage);
SDL_FreeSurface(tmpImage);
uint32_t *pixels = static_cast<uint32_t *>(surf->pixels);
- int type = dye.getType();
+ const int type = dye.getType();
switch (type)
{
case 1:
{
- DyePalette *pal = dye.getSPalete();
+ DyePalette *const pal = dye.getSPalete();
if (pal)
{
@@ -86,7 +86,7 @@ Resource *OpenGLImageHelper::load(SDL_RWops *rw, Dye const &dye)
}
case 2:
{
- DyePalette *pal = dye.getAPalete();
+ DyePalette *const pal = dye.getAPalete();
if (pal)
{
for (uint32_t *p_end = pixels + surf->w * surf->h;
@@ -118,12 +118,12 @@ Resource *OpenGLImageHelper::load(SDL_RWops *rw, Dye const &dye)
}
}
- Image *image = load(surf);
+ Image *const image = load(surf);
SDL_FreeSurface(surf);
return image;
}
-Image *OpenGLImageHelper::load(SDL_Surface *tmpImage)
+Image *OpenGLImageHelper::load(SDL_Surface *const tmpImage)
{
return glLoad(tmpImage);
}
@@ -134,13 +134,13 @@ Image *OpenGLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
if (!tmpImage)
return nullptr;
- Image *img = glLoad(tmpImage);
+ Image *const img = glLoad(tmpImage);
if (img)
img->setAlpha(alpha);
return img;
}
-int OpenGLImageHelper::powerOfTwo(int input)
+int OpenGLImageHelper::powerOfTwo(int input) const
{
int value;
if (mTextureType == GL_TEXTURE_2D)
diff --git a/src/resources/openglimagehelper.h b/src/resources/openglimagehelper.h
index 9b8813f78..36d51c29b 100644
--- a/src/resources/openglimagehelper.h
+++ b/src/resources/openglimagehelper.h
@@ -67,12 +67,12 @@ class OpenGLImageHelper : public ImageHelper
* @return <code>NULL</code> if an error occurred, a valid pointer
* otherwise.
*/
- Resource *load(SDL_RWops *rw, Dye const &dye);
+ Resource *load(SDL_RWops *const rw, Dye const &dye);
/**
* Loads an image from an SDL surface.
*/
- Image *load(SDL_Surface *);
+ Image *load(SDL_Surface *const tmpImage);
Image *createTextSurface(SDL_Surface *const tmpImage,
const float alpha);
@@ -91,10 +91,10 @@ class OpenGLImageHelper : public ImageHelper
static int getInternalTextureType()
{ return mInternalTextureType; }
- static void setInternalTextureType(int n)
+ static void setInternalTextureType(const int n)
{ mInternalTextureType = n; }
- static void setBlur(bool n)
+ static void setBlur(const bool n)
{ mBlur = n; }
static int mTextureType;
@@ -111,7 +111,7 @@ class OpenGLImageHelper : public ImageHelper
/**
* Returns the first power of two equal or bigger than the input.
*/
- int powerOfTwo(int input);
+ int powerOfTwo(int input) const;
Image *glLoad(SDL_Surface *tmpImage);
diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp
index e9449f0c9..44fc59f5a 100644
--- a/src/resources/resource.cpp
+++ b/src/resources/resource.cpp
@@ -52,7 +52,7 @@ void Resource::decRef()
if (mRefCount == 0)
{
// Warn the manager that this resource is no longer used.
- ResourceManager *resman = ResourceManager::getInstance();
+ ResourceManager *const resman = ResourceManager::getInstance();
resman->release(this);
}
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index aa377f4b9..2f3d96d27 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -101,7 +101,7 @@ ResourceManager::~ResourceManager()
if (dynamic_cast<SpriteDef*>(iter->second))
{
cleanUp(iter->second);
- ResourceIterator toErase = iter;
+ const ResourceIterator toErase = iter;
++iter;
mResources.erase(toErase);
}
@@ -125,7 +125,7 @@ ResourceManager::~ResourceManager()
if (dynamic_cast<ImageSet*>(iter->second))
{
cleanUp(iter->second);
- ResourceIterator toErase = iter;
+ const ResourceIterator toErase = iter;
++iter;
mResources.erase(toErase);
}
@@ -149,7 +149,7 @@ ResourceManager::~ResourceManager()
if (iter->second)
{
cleanUp(iter->second);
- ResourceIterator toErase = iter;
+ const ResourceIterator toErase = iter;
++iter;
mResources.erase(toErase);
}
@@ -161,7 +161,7 @@ ResourceManager::~ResourceManager()
clearScheduled();
}
-void ResourceManager::cleanUp(Resource *res)
+void ResourceManager::cleanUp(Resource *const res)
{
if (!res)
return;
@@ -181,12 +181,13 @@ void ResourceManager::cleanUp(Resource *res)
#endif
}
-bool ResourceManager::cleanOrphans(bool always)
+bool ResourceManager::cleanOrphans(const bool always)
{
timeval tv;
gettimeofday(&tv, nullptr);
// Delete orphaned resources after 30 seconds.
- time_t oldest = tv.tv_sec, threshold = oldest - 30;
+ time_t oldest = tv.tv_sec;
+ const time_t threshold = oldest - 30;
if (mOrphanedResources.empty() || (!always && mOldestOrphan >= threshold))
return false;
@@ -202,7 +203,7 @@ bool ResourceManager::cleanOrphans(bool always)
++iter;
continue;
}
- time_t t = res->mTimeStamp;
+ const time_t t = res->mTimeStamp;
if (!always && t >= threshold)
{
if (t < oldest)
@@ -212,7 +213,7 @@ bool ResourceManager::cleanOrphans(bool always)
else
{
logger->log("ResourceManager::release(%s)", res->mIdPath.c_str());
- ResourceIterator toErase = iter;
+ const ResourceIterator toErase = iter;
++iter;
mOrphanedResources.erase(toErase);
delete res; // delete only after removal from list,
@@ -225,12 +226,13 @@ bool ResourceManager::cleanOrphans(bool always)
return status;
}
-bool ResourceManager::setWriteDir(const std::string &path)
+bool ResourceManager::setWriteDir(const std::string &path) const
{
return static_cast<bool>(PHYSFS_setWriteDir(path.c_str()));
}
-bool ResourceManager::addToSearchPath(const std::string &path, bool append)
+bool ResourceManager::addToSearchPath(const std::string &path,
+ const bool append) const
{
logger->log("Adding to PhysicsFS: %s (%s)", path.c_str(),
append ? "append" : "prepend");
@@ -242,7 +244,7 @@ bool ResourceManager::addToSearchPath(const std::string &path, bool append)
return true;
}
-bool ResourceManager::removeFromSearchPath(const std::string &path)
+bool ResourceManager::removeFromSearchPath(const std::string &path) const
{
logger->log("Removing from PhysicsFS: %s", path.c_str());
if (!PHYSFS_removeFromSearchPath(path.c_str()))
@@ -255,9 +257,9 @@ bool ResourceManager::removeFromSearchPath(const std::string &path)
void ResourceManager::searchAndAddArchives(const std::string &path,
const std::string &ext,
- bool append)
+ const bool append)
{
- const char *dirSep = PHYSFS_getDirSeparator();
+ const char *const dirSep = PHYSFS_getDirSeparator();
char **list = PHYSFS_enumerateFiles(path.c_str());
for (char **i = list; *i; i++)
@@ -282,7 +284,7 @@ void ResourceManager::searchAndAddArchives(const std::string &path,
void ResourceManager::searchAndRemoveArchives(const std::string &path,
const std::string &ext)
{
- const char *dirSep = PHYSFS_getDirSeparator();
+ const char *const dirSep = PHYSFS_getDirSeparator();
char **list = PHYSFS_enumerateFiles(path.c_str());
for (char **i = list; *i; i++)
@@ -304,17 +306,17 @@ void ResourceManager::searchAndRemoveArchives(const std::string &path,
PHYSFS_freeList(list);
}
-bool ResourceManager::mkdir(const std::string &path)
+bool ResourceManager::mkdir(const std::string &path) const
{
return static_cast<bool>(PHYSFS_mkdir(path.c_str()));
}
-bool ResourceManager::exists(const std::string &path)
+bool ResourceManager::exists(const std::string &path) const
{
return PHYSFS_exists(path.c_str());
}
-bool ResourceManager::existsLocal(const std::string &path)
+bool ResourceManager::existsLocal(const std::string &path) const
{
bool flg(false);
std::fstream file;
@@ -325,15 +327,15 @@ bool ResourceManager::existsLocal(const std::string &path)
return flg;
}
-bool ResourceManager::isDirectory(const std::string &path)
+bool ResourceManager::isDirectory(const std::string &path) const
{
return PHYSFS_isDirectory(path.c_str());
}
-std::string ResourceManager::getPath(const std::string &file)
+std::string ResourceManager::getPath(const std::string &file) const
{
// get the real path to the file
- const char* tmp = PHYSFS_getRealDir(file.c_str());
+ const char *const tmp = PHYSFS_getRealDir(file.c_str());
std::string path;
// if the file is not in the search path, then its nullptr
@@ -351,7 +353,7 @@ std::string ResourceManager::getPath(const std::string &file)
}
bool ResourceManager::addResource(const std::string &idPath,
- Resource* resource)
+ Resource *const resource)
{
if (resource)
{
@@ -364,7 +366,7 @@ bool ResourceManager::addResource(const std::string &idPath,
}
Resource *ResourceManager::getFromCache(const std::string &filename,
- int variant)
+ const int variant)
{
std::stringstream ss;
ss << filename << "[" << variant << "]";
@@ -385,7 +387,7 @@ Resource *ResourceManager::getFromCache(const std::string &idPath)
resIter = mOrphanedResources.find(idPath);
if (resIter != mOrphanedResources.end())
{
- Resource *res = resIter->second;
+ Resource *const res = resIter->second;
mResources.insert(*resIter);
mOrphanedResources.erase(resIter);
if (res)
@@ -395,8 +397,8 @@ Resource *ResourceManager::getFromCache(const std::string &idPath)
return nullptr;
}
-Resource *ResourceManager::get(const std::string &idPath, generator fun,
- void *data)
+Resource *ResourceManager::get(const std::string &idPath, const generator fun,
+ void *const data)
{
#ifndef DISABLE_RESOURCE_CACHING
Resource *resource = getFromCache(idPath);
@@ -435,20 +437,21 @@ struct ResourceLoader
std::string path;
ResourceManager::loader fun;
- static Resource *load(void *v)
+ static Resource *load(void *const v)
{
if (!v)
return nullptr;
- ResourceLoader *rl = static_cast< ResourceLoader * >(v);
- SDL_RWops *rw = PHYSFSRWOPS_openRead(rl->path.c_str());
+ const ResourceLoader *const
+ rl = static_cast<const ResourceLoader *const>(v);
+ SDL_RWops *const rw = PHYSFSRWOPS_openRead(rl->path.c_str());
if (!rw)
return nullptr;
- Resource *res = rl->fun(rw);
+ Resource *const res = rl->fun(rw);
return res;
}
};
-Resource *ResourceManager::load(const std::string &path, loader fun)
+Resource *ResourceManager::load(const std::string &path, const loader fun)
{
ResourceLoader rl = { this, path, fun };
return get(path, ResourceLoader::load, &rl);
@@ -468,12 +471,13 @@ struct DyedImageLoader
{
ResourceManager *manager;
std::string path;
- static Resource *load(void *v)
+ static Resource *load(void *const v)
{
if (!v)
return nullptr;
- DyedImageLoader *rl = static_cast< DyedImageLoader * >(v);
+ const DyedImageLoader *const rl
+ = static_cast<const DyedImageLoader *const>(v);
if (!rl->manager)
return nullptr;
@@ -485,14 +489,14 @@ struct DyedImageLoader
d = new Dye(path.substr(p + 1));
path = path.substr(0, p);
}
- SDL_RWops *rw = PHYSFSRWOPS_openRead(path.c_str());
+ SDL_RWops *const rw = PHYSFSRWOPS_openRead(path.c_str());
if (!rw)
{
delete d;
return nullptr;
}
- Resource *res = d ? imageHelper->load(rw, *d)
- : imageHelper->load(rw);
+ Resource *const res = d ? imageHelper->load(rw, *d)
+ : imageHelper->load(rw);
delete d;
return res;
}
@@ -524,26 +528,27 @@ struct ImageSetLoader
ResourceManager *manager;
std::string path;
int w, h;
- static Resource *load(void *v)
+ static Resource *load(void *const v)
{
if (!v)
return nullptr;
- ImageSetLoader *rl = static_cast< ImageSetLoader * >(v);
+ const ImageSetLoader *const
+ rl = static_cast<const ImageSetLoader *const>(v);
if (!rl->manager)
return nullptr;
- Image *img = rl->manager->getImage(rl->path);
+ Image *const img = rl->manager->getImage(rl->path);
if (!img)
return nullptr;
- ImageSet *res = new ImageSet(img, rl->w, rl->h);
+ ImageSet *const res = new ImageSet(img, rl->w, rl->h);
img->decRef();
return res;
}
};
ImageSet *ResourceManager::getImageSet(const std::string &imagePath,
- int w, int h)
+ const int w, const int h)
{
ImageSetLoader rl = { this, imagePath, w, h };
std::stringstream ss;
@@ -562,18 +567,20 @@ struct SubImageSetLoader
if (!v)
return nullptr;
- SubImageSetLoader *rl = static_cast< SubImageSetLoader * >(v);
+ const SubImageSetLoader *const
+ rl = static_cast<const SubImageSetLoader *const>(v);
if (!rl->manager)
return nullptr;
if (!rl->parent)
return nullptr;
- ImageSet *res = new ImageSet(rl->parent, rl->width, rl->height);
+ ImageSet *const res = new ImageSet(rl->parent, rl->width, rl->height);
return res;
}
};
-ImageSet *ResourceManager::getSubImageSet(Image *parent, int width, int height)
+ImageSet *ResourceManager::getSubImageSet(Image *const parent,
+ const int width, const int height)
{
if (!parent)
return nullptr;
@@ -590,23 +597,25 @@ struct SubImageLoader
Image *parent;
int x, y;
int width, height;
- static Resource *load(void *v)
+ static Resource *load(void *const v)
{
if (!v)
return nullptr;
- SubImageLoader *rl = static_cast< SubImageLoader * >(v);
+ const SubImageLoader *const
+ rl = static_cast<const SubImageLoader *const>(v);
if (!rl->manager || !rl->parent)
return nullptr;
- Image *res = rl->parent->getSubImage(rl->x, rl->y,
+ Image *const res = rl->parent->getSubImage(rl->x, rl->y,
rl->width, rl->height);
return res;
}
};
-Image *ResourceManager::getSubImage(Image *parent, int x, int y,
- int width, int height)
+Image *ResourceManager::getSubImage(Image *const parent,
+ const int x, const int y,
+ const int width, const int height)
{
if (!parent)
return nullptr;
@@ -623,17 +632,19 @@ struct SpriteDefLoader
{
std::string path;
int variant;
- static Resource *load(void *v)
+ static Resource *load(void *const v)
{
if (!v)
return nullptr;
- SpriteDefLoader *rl = static_cast< SpriteDefLoader * >(v);
+ const SpriteDefLoader *const
+ rl = static_cast<const SpriteDefLoader *const>(v);
return SpriteDef::load(rl->path, rl->variant);
}
};
-SpriteDef *ResourceManager::getSprite(const std::string &path, int variant)
+SpriteDef *ResourceManager::getSprite(const std::string &path,
+ const int variant)
{
SpriteDefLoader rl = { path, variant };
std::stringstream ss;
@@ -641,20 +652,20 @@ SpriteDef *ResourceManager::getSprite(const std::string &path, int variant)
return static_cast<SpriteDef*>(get(ss.str(), SpriteDefLoader::load, &rl));
}
-void ResourceManager::release(Resource *res)
+void ResourceManager::release(Resource *const res)
{
#ifndef DISABLE_RESOURCE_CACHING
if (!res || mDestruction)
return;
- ResourceIterator resIter = mResources.find(res->mIdPath);
+ const ResourceIterator resIter = mResources.find(res->mIdPath);
// The resource has to exist
assert(resIter != mResources.end() && resIter->second == res);
timeval tv;
gettimeofday(&tv, nullptr);
- time_t timestamp = tv.tv_sec;
+ const time_t timestamp = tv.tv_sec;
res->mTimeStamp = timestamp;
if (mOrphanedResources.empty())
@@ -687,7 +698,7 @@ void ResourceManager::deleteInstance()
while (iter != instance->mResources.end())
{
- Resource *res = iter->second;
+ const Resource *const res = iter->second;
if (res)
{
if (res->getRefCount())
@@ -707,7 +718,7 @@ void ResourceManager::deleteInstance()
void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
{
// Attempt to open the specified file using PhysicsFS
- PHYSFS_file *file = PHYSFS_openRead(fileName.c_str());
+ PHYSFS_file *const file = PHYSFS_openRead(fileName.c_str());
// If the handler is an invalid pointer indicate failure
if (!file)
@@ -725,7 +736,7 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
fileSize = static_cast<int>(PHYSFS_fileLength(file));
// Allocate memory and load the file
- void *buffer = calloc(fileSize, 1);
+ void *const buffer = calloc(fileSize, 1);
PHYSFS_read(file, buffer, 1, fileSize);
// Close the file and let the user deallocate the memory
@@ -734,15 +745,16 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
return buffer;
}
-bool ResourceManager::copyFile(const std::string &src, const std::string &dst)
+bool ResourceManager::copyFile(const std::string &src,
+ const std::string &dst) const
{
- PHYSFS_file *srcFile = PHYSFS_openRead(src.c_str());
+ PHYSFS_file *const srcFile = PHYSFS_openRead(src.c_str());
if (!srcFile)
{
logger->log("Read error: %s", PHYSFS_getLastError());
return false;
}
- PHYSFS_file *dstFile = PHYSFS_openWrite(dst.c_str());
+ PHYSFS_file *const dstFile = PHYSFS_openWrite(dst.c_str());
if (!dstFile)
{
logger->log("Write error: %s", PHYSFS_getLastError());
@@ -750,7 +762,7 @@ bool ResourceManager::copyFile(const std::string &src, const std::string &dst)
return false;
}
- int fileSize = static_cast<int>(PHYSFS_fileLength(srcFile));
+ const int fileSize = static_cast<const int>(PHYSFS_fileLength(srcFile));
void *buf = malloc(fileSize);
PHYSFS_read(srcFile, buf, 1, fileSize);
PHYSFS_write(dstFile, buf, 1, fileSize);
@@ -806,7 +818,7 @@ StringVect ResourceManager::loadTextFileLocal(
}
void ResourceManager::saveTextFile(std::string path, std::string name,
- std::string text)
+ std::string text) const
{
if (!mkdir_r(path.c_str()))
{
@@ -820,10 +832,10 @@ void ResourceManager::saveTextFile(std::string path, std::string name,
}
}
-SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename)
+SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename) const
{
SDL_Surface *surface = nullptr;
- if (SDL_RWops *rw = PHYSFSRWOPS_openRead(filename.c_str()))
+ if (SDL_RWops *const rw = PHYSFSRWOPS_openRead(filename.c_str()))
surface = IMG_Load_RW(rw, 1);
return surface;
}
@@ -849,21 +861,23 @@ struct RescaledLoader
Image *image;
int width;
int height;
- static Resource *load(void *v)
+ static Resource *load(void *const v)
{
if (!v)
return nullptr;
- RescaledLoader *rl = static_cast< RescaledLoader * >(v);
+ const RescaledLoader *const rl = static_cast< RescaledLoader * >(v);
if (!rl->manager || !rl->image)
return nullptr;
- Image *rescaled = rl->image->SDLgetScaledImage(rl->width, rl->height);
+ Image *const rescaled = rl->image->SDLgetScaledImage(
+ rl->width, rl->height);
if (!rescaled)
return nullptr;
return rescaled;
}
};
-Image *ResourceManager::getRescaled(Image *image, int width, int height)
+Image *ResourceManager::getRescaled(Image *const image,
+ const int width, const int height)
{
if (!image)
return nullptr;
@@ -871,7 +885,8 @@ Image *ResourceManager::getRescaled(Image *image, int width, int height)
std::string idPath = image->getIdPath() + strprintf(
"_rescaled%dx%d", width, height);
RescaledLoader rl = { this, image, width, height };
- Image *img = static_cast<Image*>(get(idPath, RescaledLoader::load, &rl));
+ Image *const img = static_cast<Image *const>(
+ get(idPath, RescaledLoader::load, &rl));
return img;
}
@@ -901,7 +916,8 @@ void ResourceManager::delayedLoad()
}
}
-void ResourceManager::removeDelayLoad(AnimationDelayLoad *delayedLoad)
+void ResourceManager::removeDelayLoad(const AnimationDelayLoad
+ *const delayedLoad)
{
for (DelayedAnimIter it = mDelayedAnimations.begin(),
it_end = mDelayedAnimations.end(); it != it_end; ++ it)
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 6abd8732e..540e5f882 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -72,7 +72,7 @@ class ResourceManager
* @param path The path of the directory to be added.
* @return <code>true</code> on success, <code>false</code> otherwise.
*/
- bool setWriteDir(const std::string &path);
+ bool setWriteDir(const std::string &path) const;
/**
* Adds a directory or archive to the search path. If append is true
@@ -81,21 +81,21 @@ class ResourceManager
*
* @return <code>true</code> on success, <code>false</code> otherwise.
*/
- bool addToSearchPath(const std::string &path, bool append);
+ bool addToSearchPath(const std::string &path, const bool append) const;
/**
* Remove a directory or archive from the search path.
*
* @return <code>true</code> on success, <code>false</code> otherwise.
*/
- bool removeFromSearchPath(const std::string &path);
+ bool removeFromSearchPath(const std::string &path) const;
/**
* Searches for zip files and adds them to the search path.
*/
void searchAndAddArchives(const std::string &path,
const std::string &ext,
- bool append);
+ const bool append);
/**
* Searches for zip files and remove them from the search path.
@@ -106,23 +106,23 @@ class ResourceManager
/**
* Creates a directory in the write path
*/
- bool mkdir(const std::string &path);
+ bool mkdir(const std::string &path) const;
/**
* Checks whether the given file or directory exists in the search path
* (PhysFS)
*/
- bool exists(const std::string &path);
+ bool exists(const std::string &path) const;
/**
* Checks whether the given file or directory exists
*/
- bool existsLocal(const std::string &path);
+ bool existsLocal(const std::string &path) const;
/**
* Checks whether the given path is a directory.
*/
- bool isDirectory(const std::string &path);
+ bool isDirectory(const std::string &path) const;
/**
* Returns the real path to a file. Note that this method will always
@@ -131,7 +131,7 @@ class ResourceManager
* @param file The file to get the real path to.
* @return The real path.
*/
- std::string getPath(const std::string &file);
+ std::string getPath(const std::string &file) const;
/**
* Creates a resource and adds it to the resource map.
@@ -142,11 +142,11 @@ class ResourceManager
* @return A valid resource or <code>NULL</code> if the resource could
* not be generated.
*/
- Resource *get(const std::string &idPath, generator fun, void *data);
+ Resource *get(const std::string &idPath, const generator fun, void *const data);
Resource *getFromCache(const std::string &idPath);
- Resource *getFromCache(const std::string &filename, int variant);
+ Resource *getFromCache(const std::string &filename, const int variant);
/**
* Loads a resource from a file and adds it to the resource map.
@@ -156,7 +156,7 @@ class ResourceManager
* @return A valid resource or <code>NULL</code> if the resource could
* not be loaded.
*/
- Resource *load(const std::string &path, loader fun);
+ Resource *load(const std::string &path, const loader fun);
/**
* Adds a preformatted resource to the resource map.
@@ -165,7 +165,7 @@ class ResourceManager
* @param Resource The Resource to add.
* @return true if successfull, false otherwise.
*/
- bool addResource(const std::string &idPath, Resource* resource);
+ bool addResource(const std::string &idPath, Resource *const resource);
/**
* Copies a file from one place to another (useful for extracting
@@ -176,7 +176,7 @@ class ResourceManager
* @return true on success, false on failure. An error message should be
* in the log file.
*/
- bool copyFile(const std::string &src, const std::string &dst);
+ bool copyFile(const std::string &src, const std::string &dst) const;
/**
* Convenience wrapper around ResourceManager::get for loading
@@ -200,22 +200,25 @@ class ResourceManager
* Creates a image set based on the image referenced by the given
* path and the supplied sprite sizes
*/
- ImageSet *getImageSet(const std::string &imagePath, int w, int h);
+ ImageSet *getImageSet(const std::string &imagePath,
+ const int w, const int h);
- ImageSet *getSubImageSet(Image *parent, int width, int height);
+ ImageSet *getSubImageSet(Image *const parent,
+ const int width, const int height);
- Image *getSubImage(Image *parent, int x, int y, int width, int height);
+ Image *getSubImage(Image *const parent, const int x, const int y,
+ const int width, const int height);
/**
* Creates a sprite definition based on a given path and the supplied
* variant.
*/
- SpriteDef *getSprite(const std::string &path, int variant = 0);
+ SpriteDef *getSprite(const std::string &path, const int variant = 0);
/**
* Releases a resource, placing it in the set of orphaned resources.
*/
- void release(Resource *);
+ void release(Resource *const res);
/**
* Allocates data into a buffer pointer for raw data loading. The
@@ -241,15 +244,16 @@ class ResourceManager
static StringVect loadTextFileLocal(const std::string &fileName);
void saveTextFile(std::string path, std::string name,
- std::string text);
+ std::string text) const;
- Image *getRescaled(Image *image, int width, int height);
+ Image *getRescaled(Image *const image,
+ const int width, const int height);
/**
* Loads the given filename as an SDL surface. The returned surface is
* expected to be freed by the caller using SDL_FreeSurface.
*/
- SDL_Surface *loadSDLSurface(const std::string &filename);
+ SDL_Surface *loadSDLSurface(const std::string &filename) const;
void scheduleDelete(SDL_Surface* surface);
@@ -280,20 +284,21 @@ class ResourceManager
{ return &mOrphanedResources; }
#endif
- bool cleanOrphans(bool always = false);
+ bool cleanOrphans(const bool always = false);
- static void addDelayedAnimation(AnimationDelayLoad *animation)
+ static void addDelayedAnimation(AnimationDelayLoad *const animation)
{ mDelayedAnimations.push_back(animation); }
static void delayedLoad();
- static void removeDelayLoad(AnimationDelayLoad *delayedLoad);
+ static void removeDelayLoad(const AnimationDelayLoad
+ *const delayedLoad);
private:
/**
* Deletes the resource after logging a cleanup message.
*/
- static void cleanUp(Resource *resource);
+ static void cleanUp(Resource *const resource);
static ResourceManager *instance;
std::set<SDL_Surface*> deletedSurfaces;
diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp
index b8fcc795e..216d39390 100644
--- a/src/resources/sdlimagehelper.cpp
+++ b/src/resources/sdlimagehelper.cpp
@@ -38,9 +38,9 @@
bool SDLImageHelper::mEnableAlphaCache = false;
-Resource *SDLImageHelper::load(SDL_RWops *rw, Dye const &dye)
+Resource *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye)
{
- SDL_Surface *tmpImage = IMG_Load_RW(rw, 1);
+ SDL_Surface *const tmpImage = IMG_Load_RW(rw, 1);
if (!tmpImage)
{
@@ -64,19 +64,19 @@ Resource *SDLImageHelper::load(SDL_RWops *rw, Dye const &dye)
SDL_FreeSurface(tmpImage);
uint32_t *pixels = static_cast<uint32_t *>(surf->pixels);
- int type = dye.getType();
+ const int type = dye.getType();
switch (type)
{
case 1:
{
- DyePalette *pal = dye.getSPalete();
+ const DyePalette *const pal = dye.getSPalete();
if (pal)
{
for (uint32_t *p_end = pixels + surf->w * surf->h;
pixels != p_end; ++pixels)
{
- uint8_t *p = reinterpret_cast<uint8_t *>(pixels);
+ uint8_t *const p = reinterpret_cast<uint8_t *>(pixels);
const int alpha = *p & 255;
if (!alpha)
continue;
@@ -87,7 +87,7 @@ Resource *SDLImageHelper::load(SDL_RWops *rw, Dye const &dye)
}
case 2:
{
- DyePalette *pal = dye.getAPalete();
+ const DyePalette *const pal = dye.getAPalete();
if (pal)
{
for (uint32_t *p_end = pixels + surf->w * surf->h;
@@ -119,17 +119,18 @@ Resource *SDLImageHelper::load(SDL_RWops *rw, Dye const &dye)
}
}
- Image *image = load(surf);
+ Image *const image = load(surf);
SDL_FreeSurface(surf);
return image;
}
-Image *SDLImageHelper::load(SDL_Surface *tmpImage)
+Image *SDLImageHelper::load(SDL_Surface *const tmpImage)
{
return _SDLload(tmpImage);
}
-Image *SDLImageHelper::createTextSurface(SDL_Surface *tmpImage, float alpha)
+Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
+ const float alpha)
{
if (!tmpImage)
return nullptr;
@@ -137,7 +138,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *tmpImage, float alpha)
Image *img;
bool hasAlpha = false;
- bool converted = false;
+ const bool converted = false;
const int sz = tmpImage->w * tmpImage->h;
@@ -151,11 +152,12 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *tmpImage, float alpha)
{
uint32_t c = (static_cast<uint32_t*>(tmpImage->pixels))[i];
- unsigned v = (c & fmt->Amask) >> fmt->Ashift;
- uint8_t a = static_cast<uint8_t>((v << fmt->Aloss)
+ const unsigned v = (c & fmt->Amask) >> fmt->Ashift;
+ const uint8_t a = static_cast<const uint8_t>((v << fmt->Aloss)
+ (v >> (8 - (fmt->Aloss << 1))));
- uint8_t a2 = static_cast<uint8_t>(static_cast<float>(a) * alpha);
+ const uint8_t a2 = static_cast<uint8_t>(
+ static_cast<float>(a) * alpha);
c &= ~fmt->Amask;
c |= ((a2 >> fmt->Aloss) << fmt->Ashift & fmt->Amask);
@@ -200,7 +202,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *tmpImage, float alpha)
return img;
}
-SDL_Surface* SDLImageHelper::SDLDuplicateSurface(SDL_Surface* tmpImage)
+SDL_Surface* SDLImageHelper::SDLDuplicateSurface(SDL_Surface *const tmpImage)
{
if (!tmpImage || !tmpImage->format)
return nullptr;
@@ -238,9 +240,9 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage)
{
for (int i = 0; i < sz; ++ i)
{
- unsigned v = ((static_cast<uint32_t*>(tmpImage->pixels))[i]
- & fmt->Amask) >> fmt->Ashift;
- uint8_t a = static_cast<uint8_t>((v << fmt->Aloss)
+ const unsigned v = ((static_cast<uint32_t*>(
+ tmpImage->pixels))[i] & fmt->Amask) >> fmt->Ashift;
+ const uint8_t a = static_cast<const uint8_t>((v << fmt->Aloss)
+ (v >> (8 - (fmt->Aloss << 1))));
if (a != 255)
diff --git a/src/resources/sdlimagehelper.h b/src/resources/sdlimagehelper.h
index cecbf6c93..995b0967e 100644
--- a/src/resources/sdlimagehelper.h
+++ b/src/resources/sdlimagehelper.h
@@ -52,16 +52,17 @@ class SDLImageHelper : public ImageHelper
* @return <code>NULL</code> if an error occurred, a valid pointer
* otherwise.
*/
- Resource *load(SDL_RWops *rw, Dye const &dye);
+ Resource *load(SDL_RWops *const rw, Dye const &dye);
/**
* Loads an image from an SDL surface.
*/
- Image *load(SDL_Surface *);
+ Image *load(SDL_Surface *const tmpImage);
- Image *createTextSurface(SDL_Surface *tmpImage, float alpha);
+ Image *createTextSurface(SDL_Surface *const tmpImage,
+ const float alpha);
- static void SDLSetEnableAlphaCache(bool n)
+ static void SDLSetEnableAlphaCache(const bool n)
{ mEnableAlphaCache = n; }
static bool SDLGetEnableAlphaCache()
@@ -73,7 +74,7 @@ class SDLImageHelper : public ImageHelper
*/
int useOpenGL();
- static SDL_Surface* SDLDuplicateSurface(SDL_Surface* tmpImage);
+ static SDL_Surface* SDLDuplicateSurface(SDL_Surface *const tmpImage);
protected:
/** SDL_Surface to SDL_Surface Image loader */
diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp
index 6a3a980a7..d142626b5 100644
--- a/src/resources/soundeffect.cpp
+++ b/src/resources/soundeffect.cpp
@@ -31,12 +31,12 @@ SoundEffect::~SoundEffect()
Mix_FreeChunk(mChunk);
}
-Resource *SoundEffect::load(SDL_RWops *rw)
+Resource *SoundEffect::load(SDL_RWops *const rw)
{
if (!rw)
return nullptr;
// Load the music data and free the RWops structure
- Mix_Chunk *tmpSoundEffect = Mix_LoadWAV_RW(rw, 1);
+ Mix_Chunk *const tmpSoundEffect = Mix_LoadWAV_RW(rw, 1);
if (tmpSoundEffect)
{
@@ -49,7 +49,7 @@ Resource *SoundEffect::load(SDL_RWops *rw)
}
}
-bool SoundEffect::play(int loops, int volume, int channel)
+bool SoundEffect::play(const int loops, const int volume, const int channel)
{
Mix_VolumeChunk(mChunk, volume);
diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h
index b8c9e8735..5f3676064 100644
--- a/src/resources/soundeffect.h
+++ b/src/resources/soundeffect.h
@@ -46,7 +46,7 @@ class SoundEffect : public Resource
* @return <code>NULL</code> if the an error occurred, a valid pointer
* otherwise.
*/
- static Resource *load(SDL_RWops *rw);
+ static Resource *load(SDL_RWops *const rw);
/**
* Plays the sample.
@@ -58,13 +58,14 @@ class SoundEffect : public Resource
* @return <code>true</code> if the playback started properly
* <code>false</code> otherwise.
*/
- virtual bool play(int loops, int volume, int channel = -1);
+ virtual bool play(const int loops, const int volume,
+ const int channel = -1);
protected:
/**
* Constructor.
*/
- SoundEffect(Mix_Chunk *soundEffect) :
+ SoundEffect(Mix_Chunk *const soundEffect) :
mChunk(soundEffect)
{ }
diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp
index 50ea773bc..8d867b144 100644
--- a/src/resources/specialdb.cpp
+++ b/src/resources/specialdb.cpp
@@ -55,7 +55,7 @@ void SpecialDB::load()
logger->log("Initializing special database...");
XML::Document doc("specials.xml");
- XmlNodePtr root = doc.rootNode();
+ const XmlNodePtr root = doc.rootNode();
if (!root || !xmlNameEqual(root, "specials"))
{
@@ -75,8 +75,8 @@ void SpecialDB::load()
{
if (xmlNameEqual(special, "special"))
{
- SpecialInfo *info = new SpecialInfo();
- int id = XML::getProperty(special, "id", 0);
+ SpecialInfo *const info = new SpecialInfo();
+ const int id = XML::getProperty(special, "id", 0);
info->id = id;
info->set = setName;
info->name = XML::getProperty(special, "name", "");
@@ -121,9 +121,9 @@ void SpecialDB::unload()
}
-SpecialInfo *SpecialDB::get(int id)
+SpecialInfo *SpecialDB::get(const int id)
{
- SpecialInfos::const_iterator i = mSpecialInfos.find(id);
+ const SpecialInfos::const_iterator i = mSpecialInfos.find(id);
if (i == mSpecialInfos.end())
return nullptr;
diff --git a/src/resources/specialdb.h b/src/resources/specialdb.h
index f6ef73862..146d9d00f 100644
--- a/src/resources/specialdb.h
+++ b/src/resources/specialdb.h
@@ -63,7 +63,7 @@ namespace SpecialDB
/** gets the special info for ID. Will return 0 when it is
* a server-specific special.
*/
- SpecialInfo *get(int id);
+ SpecialInfo *get(const int id);
SpecialInfo::TargetMode targetModeFromString(const std::string& str);
}