summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/action.cpp11
-rw-r--r--src/resources/mapreader.cpp29
-rw-r--r--src/resources/mapreader.h19
-rw-r--r--src/resources/monsterdb.cpp11
-rw-r--r--src/resources/resourcemanager.cpp53
-rw-r--r--src/resources/resourcemanager.h54
6 files changed, 63 insertions, 114 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp
index ffbbffb2..bbea45c9 100644
--- a/src/resources/action.cpp
+++ b/src/resources/action.cpp
@@ -21,8 +21,6 @@
#include "action.h"
-#include <algorithm>
-
#include "animation.h"
#include "../utils/dtor.h"
@@ -34,12 +32,10 @@ Action::Action()
Action::~Action()
{
- std::for_each(mAnimations.begin(), mAnimations.end(),
- make_dtor(mAnimations));
+ delete_all(mAnimations);
}
-Animation*
-Action::getAnimation(int direction) const
+Animation *Action::getAnimation(int direction) const
{
Animations::const_iterator i = mAnimations.find(direction);
@@ -53,8 +49,7 @@ Action::getAnimation(int direction) const
return (i == mAnimations.end()) ? NULL : i->second;
}
-void
-Action::setAnimation(int direction, Animation *animation)
+void Action::setAnimation(int direction, Animation *animation)
{
mAnimations[direction] = animation;
}
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 34018022..949d7913 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -43,9 +43,8 @@ const unsigned int DEFAULT_TILE_HEIGHT = 32;
* 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,
- unsigned char *&out, unsigned int &outLength)
+int inflateMemory(unsigned char *in, unsigned int inLength,
+ unsigned char *&out, unsigned int &outLength)
{
int bufferSize = 256 * 1024;
int ret;
@@ -109,9 +108,8 @@ 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,
- unsigned char *&out)
+int inflateMemory(unsigned char *in, unsigned int inLength,
+ unsigned char *&out)
{
unsigned int outLength = 0;
int ret = inflateMemory(in, inLength, out, outLength);
@@ -143,8 +141,7 @@ inflateMemory(unsigned char *in, unsigned int inLength,
return outLength;
}
-Map*
-MapReader::readMap(const std::string &filename)
+Map *MapReader::readMap(const std::string &filename)
{
// Load the file through resource manager
ResourceManager *resman = ResourceManager::getInstance();
@@ -201,8 +198,7 @@ MapReader::readMap(const std::string &filename)
return map;
}
-Map*
-MapReader::readMap(xmlNodePtr node, const std::string &path)
+Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
{
// Take the filename off the path
const std::string pathDir = path.substr(0, path.rfind("/") + 1);
@@ -280,8 +276,7 @@ MapReader::readMap(xmlNodePtr node, const std::string &path)
return map;
}
-void
-MapReader::readProperties(xmlNodePtr node, Properties* props)
+void MapReader::readProperties(xmlNodePtr node, Properties *props)
{
for_each_xml_child_node(childNode, node)
{
@@ -311,8 +306,7 @@ static void setTile(Map *map, MapLayer *layer, int x, int y, int gid)
}
}
-void
-MapReader::readLayer(xmlNodePtr node, Map *map)
+void MapReader::readLayer(xmlNodePtr node, Map *map)
{
// Layers are not necessarily the same size as the map
const int w = XML::getProperty(node, "width", map->getWidth());
@@ -446,10 +440,9 @@ MapReader::readLayer(xmlNodePtr node, Map *map)
}
}
-Tileset*
-MapReader::readTileset(xmlNodePtr node,
- const std::string &path,
- Map *map)
+Tileset *MapReader::readTileset(xmlNodePtr node,
+ const std::string &path,
+ Map *map)
{
if (xmlHasProp(node, BAD_CAST "source"))
{
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 0142eb45..04e83b99 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -39,15 +39,13 @@ class MapReader
/**
* Read an XML map from a file.
*/
- static Map*
- readMap(const std::string &filename);
+ static Map *readMap(const std::string &filename);
/**
* Read an XML map from a parsed XML tree. The path is used to find the
* location of referenced tileset images.
*/
- static Map*
- readMap(xmlNodePtr node, const std::string &path);
+ static Map *readMap(xmlNodePtr node, const std::string &path);
private:
/**
@@ -57,26 +55,23 @@ class MapReader
* @param props The Properties instance to which the properties will
* be assigned.
*/
- static void
- readProperties(xmlNodePtr node, Properties* props);
+ static void readProperties(xmlNodePtr node, Properties* props);
/**
* Reads a map layer and adds it to the given map.
*/
- static void
- readLayer(xmlNodePtr node, Map *map);
+ static void readLayer(xmlNodePtr node, Map *map);
/**
* Reads a tile set.
*/
- static Tileset*
- readTileset(xmlNodePtr node, const std::string &path, Map *map);
+ static Tileset *readTileset(xmlNodePtr node, const std::string &path,
+ Map *map);
/**
* Gets an integer property from an xmlNodePtr.
*/
- static int
- getProperty(xmlNodePtr node, const char* name, int def);
+ static int getProperty(xmlNodePtr node, const char* name, int def);
};
#endif
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index e0c47db8..ed4acd38 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -19,8 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-
#include "monsterdb.h"
#include "resourcemanager.h"
@@ -147,19 +145,16 @@ MonsterDB::load()
mLoaded = true;
}
-void
-MonsterDB::unload()
+void MonsterDB::unload()
{
- for_each(mMonsterInfos.begin(), mMonsterInfos.end(),
- make_dtor(mMonsterInfos));
+ delete_all(mMonsterInfos);
mMonsterInfos.clear();
mLoaded = false;
}
-const MonsterInfo&
-MonsterDB::get(int id)
+const MonsterInfo &MonsterDB::get(int id)
{
MonsterInfoIterator i = mMonsterInfos.find(id);
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 08a4eec9..8c6d1376 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -93,8 +93,7 @@ ResourceManager::~ResourceManager()
}
}
-void
-ResourceManager::cleanUp(Resource *res)
+void ResourceManager::cleanUp(Resource *res)
{
logger->log("ResourceManager::~ResourceManager() cleaning up %d "
"reference%s to %s",
@@ -136,14 +135,12 @@ void ResourceManager::cleanOrphans()
mOldestOrphan = oldest;
}
-bool
-ResourceManager::setWriteDir(const std::string &path)
+bool ResourceManager::setWriteDir(const std::string &path)
{
return (bool) PHYSFS_setWriteDir(path.c_str());
}
-bool
-ResourceManager::addToSearchPath(const std::string &path, bool append)
+bool ResourceManager::addToSearchPath(const std::string &path, bool append)
{
logger->log("Adding to PhysicsFS: %s", path.c_str());
if (!PHYSFS_addToSearchPath(path.c_str(), append ? 1 : 0)) {
@@ -153,8 +150,7 @@ ResourceManager::addToSearchPath(const std::string &path, bool append)
return true;
}
-void
-ResourceManager::searchAndAddArchives(const std::string &path,
+void ResourceManager::searchAndAddArchives(const std::string &path,
const std::string &ext,
bool append)
{
@@ -180,31 +176,27 @@ ResourceManager::searchAndAddArchives(const std::string &path,
PHYSFS_freeList(list);
}
-bool
-ResourceManager::mkdir(const std::string &path)
+bool ResourceManager::mkdir(const std::string &path)
{
return (bool) PHYSFS_mkdir(path.c_str());
}
-bool
-ResourceManager::exists(const std::string &path)
+bool ResourceManager::exists(const std::string &path)
{
return PHYSFS_exists(path.c_str());
}
-bool
-ResourceManager::isDirectory(const std::string &path)
+bool ResourceManager::isDirectory(const std::string &path)
{
return PHYSFS_isDirectory(path.c_str());
}
-std::string
-ResourceManager::getPath(const std::string &file)
+std::string ResourceManager::getPath(const std::string &file)
{
// get the real path to the file
const char* tmp = PHYSFS_getRealDir(file.c_str());
std::string path;
-
+
// if the file is not in the search path, then its NULL
if (tmp)
{
@@ -215,11 +207,12 @@ ResourceManager::getPath(const std::string &file)
// if not found in search path return the default path
path = std::string(TMW_DATADIR) + std::string("data") + "/" + file;
}
-
+
return path;
}
-Resource *ResourceManager::get(std::string const &idPath, generator fun, void *data)
+Resource *ResourceManager::get(std::string const &idPath, generator fun,
+ void *data)
{
// Check if the id exists, and return the value if it does.
ResourceIterator resIter = mResources.find(idPath);
@@ -276,14 +269,12 @@ Resource *ResourceManager::load(std::string const &path, loader fun)
return get(path, ResourceLoader::load, &l);
}
-Music*
-ResourceManager::getMusic(const std::string &idPath)
+Music *ResourceManager::getMusic(const std::string &idPath)
{
return static_cast<Music*>(load(idPath, Music::load));
}
-SoundEffect*
-ResourceManager::getSoundEffect(const std::string &idPath)
+SoundEffect *ResourceManager::getSoundEffect(const std::string &idPath)
{
return static_cast<SoundEffect*>(load(idPath, SoundEffect::load));
}
@@ -336,8 +327,8 @@ struct ImageSetLoader
}
};
-ImageSet*
-ResourceManager::getImageSet(const std::string &imagePath, int w, int h)
+ImageSet *ResourceManager::getImageSet(const std::string &imagePath,
+ int w, int h)
{
ImageSetLoader l = { this, imagePath, w, h };
std::stringstream ss;
@@ -383,23 +374,20 @@ void ResourceManager::release(Resource *res)
mResources.erase(resIter);
}
-ResourceManager*
-ResourceManager::getInstance()
+ResourceManager *ResourceManager::getInstance()
{
// Create a new instance if necessary.
if (instance == NULL) instance = new ResourceManager();
return instance;
}
-void
-ResourceManager::deleteInstance()
+void ResourceManager::deleteInstance()
{
delete instance;
instance = NULL;
}
-void*
-ResourceManager::loadFile(const std::string &fileName, int &fileSize)
+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());
@@ -451,8 +439,7 @@ ResourceManager::loadTextFile(const std::string &fileName)
return lines;
}
-SDL_Surface*
-ResourceManager::loadSDLSurface(const std::string& filename)
+SDL_Surface *ResourceManager::loadSDLSurface(const std::string& filename)
{
int fileSize;
void *buffer = loadFile(filename, fileSize);
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 66813a9c..c1007f4a 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -64,8 +64,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);
/**
* Adds a directory or archive to the search path. If append is true
@@ -74,35 +73,30 @@ 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, bool append);
/**
* Searches for zip files and adds them to the search path.
*/
- void
- searchAndAddArchives(const std::string &path,
- const std::string &ext,
- bool append);
+ void searchAndAddArchives(const std::string &path,
+ const std::string &ext,
+ bool append);
/**
* Creates a directory in the write path
*/
- bool
- mkdir(const std::string &path);
+ bool mkdir(const std::string &path);
/**
* Checks whether the given file or directory exists in the search path
*/
- bool
- exists(const std::string &path);
+ bool exists(const std::string &path);
/**
* Checks whether the given path is a directory.
*/
- bool
- isDirectory(const std::string &path);
-
+ bool isDirectory(const std::string &path);
+
/**
* Returns the real path to a file
*
@@ -136,29 +130,25 @@ class ResourceManager
* Convenience wrapper around ResourceManager::get for loading
* images.
*/
- Image*
- getImage(const std::string &idPath);
+ Image *getImage(const std::string &idPath);
/**
* Convenience wrapper around ResourceManager::get for loading
* songs.
*/
- Music*
- getMusic(const std::string &idPath);
+ Music *getMusic(const std::string &idPath);
/**
* Convenience wrapper around ResourceManager::get for loading
* samples.
*/
- SoundEffect*
- getSoundEffect(const std::string &idPath);
+ SoundEffect *getSoundEffect(const std::string &idPath);
/**
* 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, int w, int h);
/**
* Creates a sprite definition based on a given path and the supplied
@@ -181,41 +171,35 @@ class ResourceManager
* @return An allocated byte array containing the data that was loaded,
* or <code>NULL</code> on fail.
*/
- void*
- loadFile(const std::string &fileName, int &fileSize);
+ void *loadFile(const std::string &fileName, int &fileSize);
/**
* Retrieves the contents of a text file.
*/
- std::vector<std::string>
- loadTextFile(const std::string &fileName);
+ std::vector<std::string> loadTextFile(const std::string &fileName);
/**
* 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);
/**
* Returns an instance of the class, creating one if it does not
* already exist.
*/
- static ResourceManager*
- getInstance();
+ static ResourceManager *getInstance();
/**
* Deletes the class instance if it exists.
*/
- static void
- deleteInstance();
+ static void deleteInstance();
private:
/**
* Deletes the resource after logging a cleanup message.
*/
- static void
- cleanUp(Resource *resource);
+ static void cleanUp(Resource *resource);
void cleanOrphans();