summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2010-01-10 17:19:24 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-01-10 17:20:33 +0100
commitf5a394a5051384a930d635da22ccafc6beb1cb84 (patch)
treed28fc14408a6bb91170e05880b4d2af6a17fcc14 /src/resources
parent5757066312cab082378dbc5d8df97dea3fe40af0 (diff)
downloadmana-client-f5a394a5051384a930d635da22ccafc6beb1cb84.tar.gz
mana-client-f5a394a5051384a930d635da22ccafc6beb1cb84.tar.bz2
mana-client-f5a394a5051384a930d635da22ccafc6beb1cb84.tar.xz
mana-client-f5a394a5051384a930d635da22ccafc6beb1cb84.zip
Change code style
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/image.cpp3
-rw-r--r--src/resources/imagewriter.cpp6
-rw-r--r--src/resources/mapreader.cpp67
-rw-r--r--src/resources/resourcemanager.cpp9
-rw-r--r--src/resources/sdlrescalefacility.cpp105
-rw-r--r--src/resources/spritedef.cpp107
6 files changed, 158 insertions, 139 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 15ad3b54..41c3a194 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -483,9 +483,8 @@ Image *Image::_GLload(SDL_Surface *tmpImage)
glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- if (SDL_MUSTLOCK(tmpImage)) {
+ if (SDL_MUSTLOCK(tmpImage))
SDL_UnlockSurface(tmpImage);
- }
SDL_FreeSurface(tmpImage);
diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp
index 86f92561..634d80fc 100644
--- a/src/resources/imagewriter.cpp
+++ b/src/resources/imagewriter.cpp
@@ -36,9 +36,8 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename)
png_bytep *row_pointers;
int colortype;
- if (SDL_MUSTLOCK(surface)) {
+ if (SDL_MUSTLOCK(surface))
SDL_LockSurface(surface);
- }
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
if (!png_ptr)
@@ -103,9 +102,8 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename)
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
- if (SDL_MUSTLOCK(surface)) {
+ if (SDL_MUSTLOCK(surface))
SDL_UnlockSurface(surface);
- }
return true;
}
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 60b5e9d2..28bc91c3 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -76,7 +76,8 @@ int inflateMemory(unsigned char *in, unsigned int inLength,
ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR);
- switch (ret) {
+ switch (ret)
+ {
case Z_NEED_DICT:
ret = Z_DATA_ERROR;
case Z_DATA_ERROR:
@@ -185,14 +186,19 @@ Map *MapReader::readMap(const std::string &filename)
xmlNodePtr node = doc.rootNode();
// Parse the inflated map data
- if (node) {
- if (!xmlStrEqual(node->name, BAD_CAST "map")) {
+ if (node)
+ {
+ if (!xmlStrEqual(node->name, BAD_CAST "map"))
+ {
logger->log("Error: Not a map file (%s)!", filename.c_str());
}
- else {
+ else
+ {
map = readMap(node, filename);
}
- } else {
+ }
+ else
+ {
logger->log("Error while parsing map file (%s)!", filename.c_str());
}
@@ -217,7 +223,8 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
if (xmlStrEqual(childNode->name, BAD_CAST "tileset"))
{
Tileset *tileset = readTileset(childNode, pathDir, map);
- if (tileset) {
+ if (tileset)
+ {
map->addTileset(tileset);
}
}
@@ -261,7 +268,8 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
if (objType == "PARTICLE_EFFECT")
{
- if (objName.empty()) {
+ if (objName.empty())
+ {
logger->log(" Warning: No particle file given");
continue;
}
@@ -308,7 +316,9 @@ static void setTile(Map *map, MapLayer *layer, int x, int y, int gid)
// Set regular tile on a layer
Image * const img = set ? set->get(gid - set->getFirstGid()) : 0;
layer->setTile(x, y, img);
- } else {
+ }
+ else
+ {
// Set collision tile
if (set && (gid - set->getFirstGid() != 0))
map->blockTile(x, y, Map::BLOCKTYPE_WALL);
@@ -330,7 +340,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
MapLayer *layer = 0;
- if (!isCollisionLayer) {
+ if (!isCollisionLayer)
+ {
layer = new MapLayer(offsetX, offsetY, w, h, isFringeLayer);
map->addLayer(layer);
}
@@ -352,7 +363,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
if (encoding == "base64")
{
- if (!compression.empty() && compression != "gzip") {
+ if (!compression.empty() && compression != "gzip")
+ {
logger->log("Warning: only gzip layer compression supported!");
return;
}
@@ -367,7 +379,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
const char *charStart = (const char*)dataChild->content;
unsigned char *charIndex = charData;
- while (*charStart) {
+ while (*charStart)
+ {
if (*charStart != ' ' && *charStart != '\t' &&
*charStart != '\n')
{
@@ -384,8 +397,10 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
delete[] charData;
- if (binData) {
- if (compression == "gzip") {
+ if (binData)
+ {
+ if (compression == "gzip")
+ {
// Inflate the gzipped layer data
unsigned char *inflated;
unsigned int inflatedSize =
@@ -395,13 +410,15 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
binData = inflated;
binLen = inflatedSize;
- if (!inflated) {
+ if (!inflated)
+ {
logger->log("Error: Could not decompress layer!");
return;
}
}
- for (int i = 0; i < binLen - 3; i += 4) {
+ for (int i = 0; i < binLen - 3; i += 4)
+ {
const int gid = binData[i] |
binData[i + 1] << 8 |
binData[i + 2] << 16 |
@@ -416,7 +433,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
}
x++;
- if (x == w) {
+ if (x == w)
+ {
x = 0; y++;
// When we're done, don't crash on too much data
@@ -427,7 +445,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
free(binData);
}
}
- else {
+ else
+ {
// Read plain XML map file
for_each_xml_child_node(childNode2, childNode)
{
@@ -438,7 +457,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
setTile(map, layer, x, y, gid);
x++;
- if (x == w) {
+ if (x == w)
+ {
x = 0; y++;
if (y >= h)
break;
@@ -496,7 +516,8 @@ Tileset *MapReader::readTileset(xmlNodePtr node,
set = new Tileset(tilebmp, tw, th, firstGid);
tilebmp->decRef();
}
- else {
+ else
+ {
logger->log("Warning: Failed to load tileset (%s)",
source.c_str());
}
@@ -531,18 +552,18 @@ Tileset *MapReader::readTileset(xmlNodePtr node,
iFrame = tileProperties.find("animation-frame" + toString(i));
iDelay = tileProperties.find("animation-delay" + toString(i));
if (iFrame != tileProperties.end() && iDelay != tileProperties.end())
- {
ani->addFrame(set->get(iFrame->second), iDelay->second, 0, 0);
- } else {
+ else
break;
- }
}
if (ani->getLength() > 0)
{
map->addAnimation(tileGID, new TileAnimation(ani));
logger->log("Animation length: %d", ani->getLength());
- } else {
+ }
+ else
+ {
delete ani;
}
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index bc3267da..fe594a3f 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -146,7 +146,8 @@ bool ResourceManager::setWriteDir(const std::string &path)
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)) {
+ if (!PHYSFS_addToSearchPath(path.c_str(), append ? 1 : 0))
+ {
logger->log("Error: %s", PHYSFS_getLastError());
return false;
}
@@ -409,7 +410,8 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
PHYSFS_file *file = PHYSFS_openRead(fileName.c_str());
// If the handler is an invalid pointer indicate failure
- if (file == NULL) {
+ if (file == NULL)
+ {
logger->log("Warning: Failed to load %s: %s",
fileName.c_str(), PHYSFS_getLastError());
return NULL;
@@ -488,7 +490,8 @@ SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename)
void *buffer = loadFile(filename, fileSize);
SDL_Surface *tmp = NULL;
- if (buffer) {
+ if (buffer)
+ {
SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize);
tmp = IMG_Load_RW(rw, 1);
::free(buffer);
diff --git a/src/resources/sdlrescalefacility.cpp b/src/resources/sdlrescalefacility.cpp
index 49ba8aa4..82c1216c 100644
--- a/src/resources/sdlrescalefacility.cpp
+++ b/src/resources/sdlrescalefacility.cpp
@@ -43,24 +43,22 @@ void zoomSurfaceSize(int width, int height, double zoomx, double zoomy,
/*
* Sanity check zoom factors
*/
- if (zoomx < VALUE_LIMIT) {
+ if (zoomx < VALUE_LIMIT)
zoomx = VALUE_LIMIT;
- }
- if (zoomy < VALUE_LIMIT) {
+
+ if (zoomy < VALUE_LIMIT)
zoomy = VALUE_LIMIT;
- }
/*
* Calculate target size
*/
*dstwidth = (int) ((double) width * zoomx);
*dstheight = (int) ((double) height * zoomy);
- if (*dstwidth < 1) {
+ if (*dstwidth < 1)
*dstwidth = 1;
- }
- if (*dstheight < 1) {
+
+ if (*dstheight < 1)
*dstheight = 1;
- }
}
int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
@@ -74,7 +72,8 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
/*
* Variable setup
*/
- if (smooth) {
+ if (smooth)
+ {
/*
* For interpolation: assume source dimension is one pixel
*/
@@ -83,7 +82,9 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
*/
sx = (int) (65536.0 * (float) (src->w - 1) / (float) dst->w);
sy = (int) (65536.0 * (float) (src->h - 1) / (float) dst->h);
- } else {
+ }
+ else
+ {
sx = (int) (65536.0 * (float) src->w / (float) dst->w);
sy = (int) (65536.0 * (float) src->h / (float) dst->h);
}
@@ -91,10 +92,10 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
/*
* Allocate memory for row increments
*/
- if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) {
+ if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL)
return (-1);
- }
- if ((say = (int *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) {
+ if ((say = (int *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL)
+ {
free(sax);
return (-1);
}
@@ -110,7 +111,8 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
csx = 0;
csax = sax;
- for (x = 0; x <= dst->w; x++) {
+ for (x = 0; x <= dst->w; x++)
+ {
*csax = csx;
csax++;
csx &= 0xffff;
@@ -118,7 +120,8 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
}
csy = 0;
csay = say;
- for (y = 0; y <= dst->h; y++) {
+ for (y = 0; y <= dst->h; y++)
+ {
*csay = csy;
csay++;
csy &= 0xffff;
@@ -130,7 +133,8 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
/*
* Switch between interpolating and non-interpolating code
*/
- if (smooth) {
+ if (smooth)
+ {
/*
* Interpolating Zoom
@@ -141,7 +145,8 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
*/
ly = 0;
csay = say;
- for (y = 0; y < dst->h; y++) {
+ for (y = 0; y < dst->h; y++)
+ {
/*
* Setup color source pointers
*/
@@ -152,16 +157,19 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
c11 = c10;
c11++;
csax = sax;
- if (flipx) {
+ if (flipx)
+ {
cswap = c00; c00=c01; c01=cswap;
cswap = c10; c10=c11; c11=cswap;
}
- if (flipy) {
+ if (flipy)
+ {
cswap = c00; c00=c10; c10=cswap;
cswap = c01; c01=c11; c11=cswap;
}
lx = 0;
- for (x = 0; x < dst->w; x++) {
+ for (x = 0; x < dst->w; x++)
+ {
/*
* Interpolate colors
*/
@@ -213,17 +221,20 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface * dst,
*/
dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
}
- } else {
-
+ }
+ else
+ {
/*
* Non-Interpolating Zoom
*/
csay = say;
- for (y = 0; y < dst->h; y++) {
+ for (y = 0; y < dst->h; y++)
+ {
sp = csp;
csax = sax;
- for (x = 0; x < dst->w; x++) {
+ for (x = 0; x < dst->w; x++)
+ {
/*
* Draw
*/
@@ -283,10 +294,11 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy)
/*
* Allocate memory for row increments
*/
- if ((sax = (Uint32 *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) {
+ if ((sax = (Uint32 *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL)
return (-1);
- }
- if ((say = (Uint32 *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) {
+
+ if ((say = (Uint32 *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL)
+ {
free(sax);
return (-1);
}
@@ -306,7 +318,8 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy)
*/
csx = 0;
csax = sax;
- for (x = 0; x <= dst->w; x++) {
+ for (x = 0; x <= dst->w; x++)
+ {
*csax = csx;
csax++;
csx &= 0xffff;
@@ -314,7 +327,8 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy)
}
csy = 0;
csay = say;
- for (y = 0; y <= dst->h; y++) {
+ for (y = 0; y <= dst->h; y++)
+ {
*csay = csy;
csay++;
csy &= 0xffff;
@@ -326,10 +340,12 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy)
* Draw
*/
csay = say;
- for (y = 0; y < dst->h; y++) {
+ for (y = 0; y < dst->h; y++)
+ {
csax = sax;
sp = csp;
- for (x = 0; x < dst->w; x++) {
+ for (x = 0; x < dst->w; x++)
+ {
/*
* Draw
*/
@@ -390,13 +406,16 @@ SDL_Surface *_SDLzoomSurface(SDL_Surface * src, double zoomx, double zoomy, int
* Determine if source surface is 32bit or 8bit
*/
is32bit = (src->format->BitsPerPixel == 32);
- if ((is32bit) || (src->format->BitsPerPixel == 8)) {
+ if ((is32bit) || (src->format->BitsPerPixel == 8))
+ {
/*
* Use source surface 'as is'
*/
rz_src = src;
src_converted = 0;
- } else {
+ }
+ else
+ {
/*
* New source surface is 32bit with a defined RGBA ordering
*/
@@ -425,7 +444,8 @@ SDL_Surface *_SDLzoomSurface(SDL_Surface * src, double zoomx, double zoomy, int
* Alloc space to completely contain the zoomed surface
*/
rz_dst = NULL;
- if (is32bit) {
+ if (is32bit)
+ {
/*
* Target surface is 32bit with source RGBA/ABGR ordering
*/
@@ -433,7 +453,9 @@ SDL_Surface *_SDLzoomSurface(SDL_Surface * src, double zoomx, double zoomy, int
SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32,
rz_src->format->Rmask, rz_src->format->Gmask,
rz_src->format->Bmask, rz_src->format->Amask);
- } else {
+ }
+ else
+ {
/*
* Target surface is 8bit
*/
@@ -447,7 +469,8 @@ SDL_Surface *_SDLzoomSurface(SDL_Surface * src, double zoomx, double zoomy, int
/*
* Check which kind of surface we have
*/
- if (is32bit) {
+ if (is32bit)
+ {
/*
* Call the 32bit transformation routine to do the zooming (using alpha)
*/
@@ -456,11 +479,14 @@ SDL_Surface *_SDLzoomSurface(SDL_Surface * src, double zoomx, double zoomy, int
* Turn on source-alpha support
*/
SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
- } else {
+ }
+ else
+ {
/*
* Copy palette and colorkey info
*/
- for (i = 0; i < rz_src->format->palette->ncolors; i++) {
+ for (i = 0; i < rz_src->format->palette->ncolors; i++)
+ {
rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
}
rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
@@ -478,9 +504,8 @@ SDL_Surface *_SDLzoomSurface(SDL_Surface * src, double zoomx, double zoomy, int
/*
* Cleanup temp surface
*/
- if (src_converted) {
+ if (src_converted)
SDL_FreeSurface(rz_src);
- }
/*
* Return destination surface
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 30d8e778..62db7b66 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -61,9 +61,12 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant)
{
logger->log("Error, failed to parse %s", animationFile.c_str());
- if (animationFile != "graphics/sprites/error.xml") {
+ if (animationFile != "graphics/sprites/error.xml")
+ {
return load("graphics/sprites/error.xml", 0);
- } else {
+ }
+ else
+ {
return NULL;
}
}
@@ -292,7 +295,8 @@ void SpriteDef::substituteAction(SpriteAction complete, SpriteAction with)
if (mActions.find(complete) == mActions.end())
{
Actions::iterator i = mActions.find(with);
- if (i != mActions.end()) {
+ if (i != mActions.end())
+ {
mActions[complete] = i->second;
}
}
@@ -323,104 +327,73 @@ SpriteDef::~SpriteDef()
SpriteAction SpriteDef::makeSpriteAction(const std::string &action)
{
- if (action.empty() || action == "default") {
+ if (action.empty() || action == "default")
return ACTION_DEFAULT;
- }
- if (action == "stand") {
+
+ if (action == "stand")
return ACTION_STAND;
- }
- else if (action == "walk") {
+ else if (action == "walk")
return ACTION_WALK;
- }
- else if (action == "run") {
+ else if (action == "run")
return ACTION_RUN;
- }
- else if (action == "attack") {
+ else if (action == "attack")
return ACTION_ATTACK;
- }
- else if (action == "attack_swing") {
+ else if (action == "attack_swing")
return ACTION_ATTACK_SWING;
- }
- else if (action == "attack_stab") {
+ else if (action == "attack_stab")
return ACTION_ATTACK_STAB;
- }
- else if (action == "attack_bow") {
+ else if (action == "attack_bow")
return ACTION_ATTACK_BOW;
- }
- else if (action == "attack_throw") {
+ else if (action == "attack_throw")
return ACTION_ATTACK_THROW;
- }
- else if (action == "special0") {
+ else if (action == "special0")
return ACTION_SPECIAL_0;
- }
- else if (action == "special1") {
+ else if (action == "special1")
return ACTION_SPECIAL_1;
- }
- else if (action == "special2") {
+ else if (action == "special2")
return ACTION_SPECIAL_2;
- }
- else if (action == "special3") {
+ else if (action == "special3")
return ACTION_SPECIAL_3;
- }
- else if (action == "special4") {
+ else if (action == "special4")
return ACTION_SPECIAL_4;
- }
- else if (action == "special5") {
+ else if (action == "special5")
return ACTION_SPECIAL_5;
- }
- else if (action == "special6") {
+ else if (action == "special6")
return ACTION_SPECIAL_6;
- }
- else if (action == "special7") {
+ else if (action == "special7")
return ACTION_SPECIAL_7;
- }
- else if (action == "special8") {
+ else if (action == "special8")
return ACTION_SPECIAL_8;
- }
- else if (action == "special9") {
+ else if (action == "special9")
return ACTION_SPECIAL_9;
- }
- else if (action == "cast_magic") {
+ else if (action == "cast_magic")
return ACTION_CAST_MAGIC;
- }
- else if (action == "use_item") {
+ else if (action == "use_item")
return ACTION_USE_ITEM;
- }
- else if (action == "sit") {
+ else if (action == "sit")
return ACTION_SIT;
- }
- else if (action == "sleep") {
+ else if (action == "sleep")
return ACTION_SLEEP;
- }
- else if (action == "hurt") {
+ else if (action == "hurt")
return ACTION_HURT;
- }
- else if (action == "dead") {
+ else if (action == "dead")
return ACTION_DEAD;
- }
- else {
+ else
return ACTION_INVALID;
- }
}
SpriteDirection SpriteDef::makeSpriteDirection(const std::string &direction)
{
- if (direction.empty() || direction == "default") {
+ if (direction.empty() || direction == "default")
return DIRECTION_DEFAULT;
- }
- else if (direction == "up") {
+ else if (direction == "up")
return DIRECTION_UP;
- }
- else if (direction == "left") {
+ else if (direction == "left")
return DIRECTION_LEFT;
- }
- else if (direction == "right") {
+ else if (direction == "right")
return DIRECTION_RIGHT;
- }
- else if (direction == "down") {
+ else if (direction == "down")
return DIRECTION_DOWN;
- }
- else {
+ else
return DIRECTION_INVALID;
- }
}