diff options
author | Reid <reidyaro@gmail.com> | 2012-01-25 22:05:36 +0100 |
---|---|---|
committer | Reid <reidyaro@gmail.com> | 2012-01-25 22:05:36 +0100 |
commit | 8b612abb42853a22c1a9545e2c9280d154646543 (patch) | |
tree | f466167087c2b2de4b8aa9e6d1d1986f72f84147 /src/resources | |
parent | a913dd41df61760de6ece552f941e002251ff54c (diff) | |
parent | d340b5a27a8f3b05d1764da9c114f5f59bd0cd46 (diff) | |
download | plus-8b612abb42853a22c1a9545e2c9280d154646543.tar.gz plus-8b612abb42853a22c1a9545e2c9280d154646543.tar.bz2 plus-8b612abb42853a22c1a9545e2c9280d154646543.tar.xz plus-8b612abb42853a22c1a9545e2c9280d154646543.zip |
Merge branch 'master' of gitorious.org:manaplus/manaplus
Diffstat (limited to 'src/resources')
49 files changed, 219 insertions, 287 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp index f940bffcb..e1f88ecb7 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/action.h b/src/resources/action.h index 9ab6f98d5..1e3965363 100644 --- a/src/resources/action.h +++ b/src/resources/action.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -23,7 +23,7 @@ #ifndef ACTION_H #define ACTION_H -#include <libxml/tree.h> +#include "utils/xml.h" #include <map> diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp index 2ad25dcd0..b5640904c 100644 --- a/src/resources/ambientlayer.cpp +++ b/src/resources/ambientlayer.cpp @@ -1,7 +1,7 @@ /* * The ManaPlus Client * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/ambientlayer.h b/src/resources/ambientlayer.h index c90ef7c79..54a764841 100644 --- a/src/resources/ambientlayer.h +++ b/src/resources/ambientlayer.h @@ -1,7 +1,7 @@ /* * The ManaPlus Client * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index 1f3336a8b..1c1da6ca5 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/animation.h b/src/resources/animation.h index 19b17eb54..33bfd76e9 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -23,7 +23,7 @@ #ifndef ANIMATION_H #define ANIMATION_H -#include <libxml/tree.h> +#include "utils/xml.h" #include <vector> #include <string> diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 0b2aaa8fa..0fa815181 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index b93c11ba6..0f62ba5ea 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/chardb.cpp b/src/resources/chardb.cpp index d944f280e..f38f13224 100644 --- a/src/resources/chardb.cpp +++ b/src/resources/chardb.cpp @@ -1,7 +1,7 @@ /* * Color database * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -24,10 +24,6 @@ #include "client.h" #include "logger.h" -#include "utils/xml.h" - -#include <libxml/tree.h> - #include "debug.h" namespace @@ -48,9 +44,9 @@ void CharDB::load() unload(); XML::Document *doc = new XML::Document("charcreation.xml"); - xmlNodePtr root = doc->rootNode(); + XmlNodePtr root = doc->rootNode(); - if (!root || !xmlStrEqual(root->name, BAD_CAST "chars")) + if (!root || !xmlNameEqual(root, "chars")) { logger->log1("CharDB: Failed to parse charcreation.xml."); @@ -60,15 +56,15 @@ void CharDB::load() for_each_xml_child_node(node, root) { - if (xmlStrEqual(node->name, BAD_CAST "haircolor")) + if (xmlNameEqual(node, "haircolor")) { loadMinMax(node, &mMinHairColor, &mMaxHairColor); } - else if (xmlStrEqual(node->name, BAD_CAST "hairstyle")) + else if (xmlNameEqual(node, "hairstyle")) { loadMinMax(node, &mMinHairStyle, &mMaxHairStyle); } - else if (xmlStrEqual(node->name, BAD_CAST "stat")) + else if (xmlNameEqual(node, "stat")) { loadMinMax(node, &mMinStat, &mMaxStat); mSumStat = XML::getProperty(node, "sum", 0); @@ -80,7 +76,7 @@ void CharDB::load() mLoaded = true; } -void CharDB::loadMinMax(xmlNodePtr node, unsigned *min, unsigned *max) +void CharDB::loadMinMax(XmlNodePtr node, unsigned *min, unsigned *max) { *min = XML::getProperty(node, "min", 1); *max = XML::getProperty(node, "max", 10); diff --git a/src/resources/chardb.h b/src/resources/chardb.h index 769dedb56..60ff31084 100644 --- a/src/resources/chardb.h +++ b/src/resources/chardb.h @@ -1,7 +1,7 @@ /* * Color database * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -25,7 +25,7 @@ #include <map> #include <string> -#include <libxml/tree.h> +#include "utils/xml.h" /** * Char information database. @@ -42,7 +42,7 @@ namespace CharDB */ void unload(); - void loadMinMax(xmlNodePtr node, unsigned *min, unsigned *max); + void loadMinMax(XmlNodePtr node, unsigned *min, unsigned *max); unsigned getMinHairColor(); diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index 3b8c9d573..1ffe507b2 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -1,7 +1,7 @@ /* * Color database * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -26,8 +26,6 @@ #include "utils/xml.h" -#include <libxml/tree.h> - #include "debug.h" namespace @@ -51,10 +49,10 @@ void ColorDB::load() void ColorDB::loadHair() { XML::Document *doc = new XML::Document("hair.xml"); - xmlNodePtr root = doc->rootNode(); + XmlNodePtr root = doc->rootNode(); bool hairXml = true; - if (!root || !xmlStrEqual(root->name, BAD_CAST "colors")) + if (!root || !xmlNameEqual(root, "colors")) { logger->log1("Trying to fall back on colors.xml"); @@ -64,7 +62,7 @@ void ColorDB::loadHair() doc = new XML::Document("colors.xml"); root = doc->rootNode(); - if (!root || !xmlStrEqual(root->name, BAD_CAST "colors")) + if (!root || !xmlNameEqual(root, "colors")) { logger->log1("ColorDB: Failed to find any color files."); mHairColors[0] = mFail; @@ -78,7 +76,7 @@ void ColorDB::loadHair() for_each_xml_child_node(node, root) { - if (xmlStrEqual(node->name, BAD_CAST "color")) + if (xmlNameEqual(node, "color")) { int id = XML::getProperty(node, "id", 0); @@ -99,7 +97,7 @@ void ColorDB::loadHair() void ColorDB::loadColorLists() { XML::Document *doc = new XML::Document("itemcolors.xml"); - xmlNodePtr root = doc->rootNode(); + XmlNodePtr root = doc->rootNode(); if (!root) { delete doc; @@ -108,7 +106,7 @@ void ColorDB::loadColorLists() for_each_xml_child_node(node, root) { - if (xmlStrEqual(node->name, BAD_CAST "list")) + if (xmlNameEqual(node, "list")) { std::string name = XML::getProperty(node, "name", ""); if (name.empty()) @@ -122,7 +120,7 @@ void ColorDB::loadColorLists() for_each_xml_child_node(colorNode, node) { - if (xmlStrEqual(colorNode->name, BAD_CAST "color")) + if (xmlNameEqual(colorNode, "color")) { ItemColor c(XML::getProperty(colorNode, "id", -1), XML::getProperty(colorNode, "name", ""), diff --git a/src/resources/colordb.h b/src/resources/colordb.h index f4cc88a59..36907095e 100644 --- a/src/resources/colordb.h +++ b/src/resources/colordb.h @@ -1,7 +1,7 @@ /* * Color database * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 29b1c864e..6800c5170 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2007-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/dye.h b/src/resources/dye.h index 85192041a..94bee3b58 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2007-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index c456c49e4..c6126a57b 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -52,9 +52,9 @@ void EmoteDB::load() logger->log1("Initializing emote database..."); XML::Document doc("emotes.xml"); - xmlNodePtr rootNode = doc.rootNode(); + XmlNodePtr rootNode = doc.rootNode(); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "emotes")) + if (!rootNode || !xmlNameEqual(rootNode, "emotes")) { logger->log1("Emote Database: Error while loading emotes.xml!"); return; @@ -63,7 +63,7 @@ void EmoteDB::load() //iterate <emote>s for_each_xml_child_node(emoteNode, rootNode) { - if (!xmlStrEqual(emoteNode->name, BAD_CAST "emote")) + if (!xmlNameEqual(emoteNode, "emote")) continue; int id = XML::getProperty(emoteNode, "id", -1); @@ -81,7 +81,7 @@ void EmoteDB::load() if (!spriteNode->xmlChildrenNode) continue; - if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) + if (xmlNameEqual(spriteNode, "sprite")) { EmoteSprite *currentSprite = new EmoteSprite; std::string file = paths.getStringValue("sprites") @@ -92,7 +92,7 @@ void EmoteDB::load() currentSprite->name = XML::getProperty(spriteNode, "name", ""); currentInfo->sprites.push_back(currentSprite); } - else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) + else if (xmlNameEqual(spriteNode, "particlefx")) { std::string particlefx = reinterpret_cast<const char*>( spriteNode->xmlChildrenNode->content); @@ -108,7 +108,7 @@ void EmoteDB::load() XML::Document doc2("graphics/sprites/manaplus_emotes.xml"); rootNode = doc2.rootNode(); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "emotes")) + if (!rootNode || !xmlNameEqual(rootNode, "emotes")) { logger->log1("Emote Database: Error while loading" " manaplus_emotes.xml!"); @@ -118,7 +118,7 @@ void EmoteDB::load() //iterate <emote>s for_each_xml_child_node(emoteNode, rootNode) { - if (!xmlStrEqual(emoteNode->name, BAD_CAST "emote")) + if (!xmlNameEqual(emoteNode, "emote")) continue; int id = XML::getProperty(emoteNode, "id", -1); @@ -136,7 +136,7 @@ void EmoteDB::load() if (!spriteNode->xmlChildrenNode) continue; - if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) + if (xmlNameEqual(spriteNode, "sprite")) { EmoteSprite *currentSprite = new EmoteSprite; std::string file = paths.getStringValue("sprites") @@ -147,7 +147,7 @@ void EmoteDB::load() currentSprite->name = XML::getProperty(spriteNode, "name", ""); currentInfo->sprites.push_back(currentSprite); } - else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) + else if (xmlNameEqual(spriteNode, "particlefx")) { std::string particlefx = reinterpret_cast<const char*>( spriteNode->xmlChildrenNode->content); diff --git a/src/resources/image.cpp b/src/resources/image.cpp index df07c16a2..9e9124ab6 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -119,10 +119,8 @@ Image::~Image() unload(); } -Resource *Image::load(void *buffer, unsigned bufferSize) +Resource *Image::load(SDL_RWops *rw) { - // Load the raw file data from the buffer in an RWops structure - SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize); SDL_Surface *tmpImage = IMG_Load_RW(rw, 1); if (!tmpImage) @@ -137,9 +135,8 @@ Resource *Image::load(void *buffer, unsigned bufferSize) return image; } -Resource *Image::load(void *buffer, unsigned bufferSize, Dye const &dye) +Resource *Image::load(SDL_RWops *rw, Dye const &dye) { - SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize); SDL_Surface *tmpImage = IMG_Load_RW(rw, 1); if (!tmpImage) @@ -473,10 +470,10 @@ Image* Image::SDLmerge(Image *image, int x, int y) static_cast<Uint16>(mBounds.h - y)); // for each pixel lines of a source image - for (offset_x = (x > 0 ? 0 : -x); offset_x < maxX; offset_x++) + for (offset_x = ((x > 0) ? 0 : -x); offset_x < maxX; offset_x++) { const int x1 = x0 + offset_x; - for (offset_y = (y > 0 ? 0 : -y); offset_y < maxY; offset_y++) + for (offset_y = ((y > 0) ? 0 : -y); offset_y < maxY; offset_y++) { // Computing offset on both images current_offset = (offset_y * getWidth()) + x1; diff --git a/src/resources/image.h b/src/resources/image.h index 333dc63f9..d22ed4be2 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -66,28 +66,25 @@ class Image : public Resource virtual ~Image(); /** - * Loads an image from a buffer in memory. + * Loads an image from an SDL_RWops structure. * - * @param buffer The memory buffer containing the image data. - * @param bufferSize The size of the memory buffer in bytes. + * @param rw The SDL_RWops to load the image from. * * @return <code>NULL</code> if an error occurred, a valid pointer * otherwise. */ - static Resource *load(void *buffer, unsigned bufferSize); + static Resource *load(SDL_RWops *rw); /** - * Loads an image from a buffer in memory and recolors it. + * Loads an image from an SDL_RWops structure and recolors it. * - * @param buffer The memory buffer containing the image data. - * @param bufferSize The size of the memory buffer in bytes. + * @param rw The SDL_RWops to load the image from. * @param dye The dye used to recolor the image. * * @return <code>NULL</code> if an error occurred, a valid pointer * otherwise. */ - static Resource *load(void *buffer, unsigned bufferSize, - Dye const &dye); + static Resource *load(SDL_RWops *rw, Dye const &dye); /** * Loads an image from an SDL surface. diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index a8563c679..decf17189 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2007-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/imageloader.h b/src/resources/imageloader.h index 5c3d29c74..1dcd046ca 100644 --- a/src/resources/imageloader.h +++ b/src/resources/imageloader.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2007-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index 09b57be28..9e3513e91 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/imageset.h b/src/resources/imageset.h index fd320295a..69ebebdc0 100644 --- a/src/resources/imageset.h +++ b/src/resources/imageset.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index a3a35cfd1..9501c98a5 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/imagewriter.h b/src/resources/imagewriter.h index ae94730f2..ca8150694 100644 --- a/src/resources/imagewriter.h +++ b/src/resources/imagewriter.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 2911fa06f..5fa68a88f 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -23,6 +23,7 @@ #include "resources/itemdb.h" #include "client.h" +#include "configuration.h" #include "logger.h" #include "resources/iteminfo.h" @@ -32,9 +33,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" #include "utils/xml.h" -#include "configuration.h" - -#include <libxml/tree.h> #include "debug.h" @@ -49,11 +47,11 @@ namespace } // Forward declarations -static void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); -static void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); -static void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node); -static void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode); -static void loadOrderSprite(ItemInfo *itemInfo, xmlNodePtr node, +static void loadSpriteRef(ItemInfo *itemInfo, XmlNodePtr node); +static void loadSoundRef(ItemInfo *itemInfo, XmlNodePtr node); +static void loadFloorSprite(SpriteDisplay *display, XmlNodePtr node); +static void loadReplaceSprite(ItemInfo *itemInfo, XmlNodePtr replaceNode); +static void loadOrderSprite(ItemInfo *itemInfo, XmlNodePtr node, bool drawAfter); static int parseSpriteName(std::string name); static int parseDirectionName(std::string name); @@ -174,9 +172,9 @@ void ItemDB::load() mUnknown->addTag(mTags["All"]); XML::Document doc("items.xml"); - xmlNodePtr rootNode = doc.rootNode(); + XmlNodePtr rootNode = doc.rootNode(); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items")) + if (!rootNode || !xmlNameEqual(rootNode, "items")) { logger->log("ItemDB: Error while loading items.xml!"); mLoaded = true; @@ -185,7 +183,7 @@ void ItemDB::load() for_each_xml_child_node(node, rootNode) { - if (!xmlStrEqual(node->name, BAD_CAST "item")) + if (!xmlNameEqual(node, "item")) continue; int id = XML::getProperty(node, "id", 0); @@ -326,7 +324,7 @@ void ItemDB::load() for_each_xml_child_node(itemChild, node) { - if (xmlStrEqual(itemChild->name, BAD_CAST "sprite")) + if (xmlNameEqual(itemChild, "sprite")) { std::string attackParticle = XML::getProperty( itemChild, "particle-effect", ""); @@ -334,23 +332,23 @@ void ItemDB::load() loadSpriteRef(itemInfo, itemChild); } - else if (xmlStrEqual(itemChild->name, BAD_CAST "sound")) + else if (xmlNameEqual(itemChild, "sound")) { loadSoundRef(itemInfo, itemChild); } - else if (xmlStrEqual(itemChild->name, BAD_CAST "floor")) + else if (xmlNameEqual(itemChild, "floor")) { loadFloorSprite(&display, itemChild); } - else if (xmlStrEqual(itemChild->name, BAD_CAST "replace")) + else if (xmlNameEqual(itemChild, "replace")) { loadReplaceSprite(itemInfo, itemChild); } - else if (xmlStrEqual(itemChild->name, BAD_CAST "drawAfter")) + else if (xmlNameEqual(itemChild, "drawAfter")) { loadOrderSprite(itemInfo, itemChild, true); } - else if (xmlStrEqual(itemChild->name, BAD_CAST "drawBefore")) + else if (xmlNameEqual(itemChild, "drawBefore")) { loadOrderSprite(itemInfo, itemChild, false); } @@ -595,7 +593,7 @@ int parseDirectionName(std::string name) return id; } -void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) +void loadSpriteRef(ItemInfo *itemInfo, XmlNodePtr node) { std::string gender = XML::getProperty(node, "gender", "unisex"); std::string filename = reinterpret_cast<const char*>( @@ -607,7 +605,7 @@ void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) itemInfo->setSprite(filename, GENDER_FEMALE); } -void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) +void loadSoundRef(ItemInfo *itemInfo, XmlNodePtr node) { std::string event = XML::getProperty(node, "event", ""); std::string filename = reinterpret_cast<const char*>( @@ -628,11 +626,11 @@ void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) } } -void loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode) +void loadFloorSprite(SpriteDisplay *display, XmlNodePtr floorNode) { for_each_xml_child_node(spriteNode, floorNode) { - if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) + if (xmlNameEqual(spriteNode, "sprite")) { SpriteReference *currentSprite = new SpriteReference; currentSprite->sprite = reinterpret_cast<const char*>( @@ -641,7 +639,7 @@ void loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode) = XML::getProperty(spriteNode, "variant", 0); display->sprites.push_back(currentSprite); } - else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) + else if (xmlNameEqual(spriteNode, "particlefx")) { std::string particlefx = reinterpret_cast<const char*>( spriteNode->xmlChildrenNode->content); @@ -650,7 +648,7 @@ void loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode) } } -void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) +void loadReplaceSprite(ItemInfo *itemInfo, XmlNodePtr replaceNode) { std::string removeSprite = XML::getProperty(replaceNode, "sprite", ""); int direction = parseDirectionName(XML::getProperty( @@ -671,7 +669,7 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) continue; for_each_xml_child_node(itemNode, replaceNode) { - if (xmlStrEqual(itemNode->name, BAD_CAST "item")) + if (xmlNameEqual(itemNode, "item")) { int from = XML::getProperty(itemNode, "from", 0); int to = XML::getProperty(itemNode, "to", 1); @@ -693,7 +691,7 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) for_each_xml_child_node(itemNode, replaceNode) { - if (xmlStrEqual(itemNode->name, BAD_CAST "item")) + if (xmlNameEqual(itemNode, "item")) { int from = XML::getProperty(itemNode, "from", 0); int to = XML::getProperty(itemNode, "to", 1); @@ -726,7 +724,7 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) for_each_xml_child_node(itemNode, replaceNode) { - if (xmlStrEqual(itemNode->name, BAD_CAST "item")) + if (xmlNameEqual(itemNode, "item")) { int from = XML::getProperty(itemNode, "from", 0); int to = XML::getProperty(itemNode, "to", 1); @@ -756,7 +754,7 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) return; for_each_xml_child_node(itemNode, replaceNode) { - if (xmlStrEqual(itemNode->name, BAD_CAST "item")) + if (xmlNameEqual(itemNode, "item")) { int from = XML::getProperty(itemNode, "from", 0); int to = XML::getProperty(itemNode, "to", 1); @@ -768,7 +766,7 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) } } -void loadOrderSprite(ItemInfo *itemInfo, xmlNodePtr node, bool drawAfter) +void loadOrderSprite(ItemInfo *itemInfo, XmlNodePtr node, bool drawAfter) { int sprite = parseSpriteName(XML::getProperty(node, "name", "")); int priority = XML::getProperty(node, "priority", 0); diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 71f0a490e..e56840c16 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index dfcff3f76..f163fc590 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 1fe8f3bad..8c5e2dd8f 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp index e7288e039..b186ad658 100644 --- a/src/resources/mapdb.cpp +++ b/src/resources/mapdb.cpp @@ -1,7 +1,7 @@ /* * Color database * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -27,8 +27,6 @@ #include "utils/xml.h" -#include <libxml/tree.h> - #include "debug.h" namespace @@ -45,7 +43,7 @@ void MapDB::load() XML::Document *doc = new XML::Document( paths.getStringValue("maps") + "remap.xml"); - xmlNodePtr root = doc->rootNode(); + XmlNodePtr root = doc->rootNode(); if (!root) { delete doc; @@ -54,7 +52,7 @@ void MapDB::load() for_each_xml_child_node(node, root) { - if (xmlStrEqual(node->name, BAD_CAST "map")) + if (xmlNameEqual(node, "map")) { std::string name = XML::getProperty(node, "name", ""); if (name.empty()) diff --git a/src/resources/mapdb.h b/src/resources/mapdb.h index 2ba084297..d249a5cc6 100644 --- a/src/resources/mapdb.h +++ b/src/resources/mapdb.h @@ -1,7 +1,7 @@ /* * Color database * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 68d39f0ae..8d71779f2 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -35,7 +35,6 @@ #include "utils/base64.h" #include "utils/gettext.h" #include "utils/stringutils.h" -#include "utils/xml.h" #include <iostream> #include <zlib.h> @@ -223,12 +222,12 @@ Map *MapReader::readMap(const std::string &filename, XML::Document doc(reinterpret_cast<char*>(inflated), inflatedSize); free(inflated); - xmlNodePtr node = doc.rootNode(); + XmlNodePtr node = doc.rootNode(); // Parse the inflated map data if (node) { - if (!xmlStrEqual(node->name, BAD_CAST "map")) + if (!xmlNameEqual(node, "map")) logger->log("Error: Not a map file (%s)!", realFilename.c_str()); else map = readMap(node, realFilename); @@ -248,7 +247,7 @@ Map *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) { if (!node) return nullptr; @@ -277,23 +276,23 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path) for_each_xml_child_node(childNode, node) { - if (xmlStrEqual(childNode->name, BAD_CAST "tileset")) + if (xmlNameEqual(childNode, "tileset")) { Tileset *tileset = readTileset(childNode, pathDir, map); if (tileset) map->addTileset(tileset); } - else if (xmlStrEqual(childNode->name, BAD_CAST "layer")) + else if (xmlNameEqual(childNode, "layer")) { readLayer(childNode, map); } - else if (xmlStrEqual(childNode->name, BAD_CAST "properties")) + else if (xmlNameEqual(childNode, "properties")) { readProperties(childNode, map); map->setVersion(atoi(map->getProperty( "manaplus version").c_str())); } - else if (xmlStrEqual(childNode->name, BAD_CAST "objectgroup")) + else if (xmlNameEqual(childNode, "objectgroup")) { // The object group offset is applied to each object individually const int tileOffsetX = XML::getProperty(childNode, "x", 0); @@ -303,7 +302,7 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path) for_each_xml_child_node(objectNode, childNode) { - if (xmlStrEqual(objectNode->name, BAD_CAST "object")) + if (xmlNameEqual(objectNode, "object")) { std::string objType = XML::getProperty( objectNode, "type", ""); @@ -380,14 +379,14 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path) return map; } -void MapReader::readProperties(xmlNodePtr node, Properties *props) +void MapReader::readProperties(XmlNodePtr node, Properties *props) { if (!node || !props) return; for_each_xml_child_node(childNode, node) { - if (!xmlStrEqual(childNode->name, BAD_CAST "property")) + if (!xmlNameEqual(childNode, "property")) continue; // Example: <property name="name" value="value"/> @@ -443,7 +442,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(XmlNodePtr node, Map *map) { // Layers are not necessarily the same size as the map const int w = XML::getProperty(node, "width", map->getWidth()); @@ -473,7 +472,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) // Load the tile data for_each_xml_child_node(childNode, node) { - if (!xmlStrEqual(childNode->name, BAD_CAST "data")) + if (!xmlNameEqual(childNode, "data")) continue; const std::string encoding = @@ -492,7 +491,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) } // Read base64 encoded map file - xmlNodePtr dataChild = childNode->xmlChildrenNode; + XmlNodePtr dataChild = childNode->xmlChildrenNode; if (!dataChild) continue; @@ -577,7 +576,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) } else if (encoding == "csv") { - xmlNodePtr dataChild = childNode->xmlChildrenNode; + XmlNodePtr dataChild = childNode->xmlChildrenNode; if (!dataChild) continue; @@ -620,7 +619,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) // Read plain XML map file for_each_xml_child_node(childNode2, childNode) { - if (!xmlStrEqual(childNode2->name, BAD_CAST "tile")) + if (!xmlNameEqual(childNode2, "tile")) continue; const int gid = XML::getProperty(childNode2, "gid", -1); @@ -647,7 +646,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) } -Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, +Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path, Map *map) { if (!map) @@ -679,7 +678,7 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, for_each_xml_child_node(childNode, node) { - if (xmlStrEqual(childNode->name, BAD_CAST "image")) + if (xmlNameEqual(childNode, "image")) { const std::string source = XML::getProperty( childNode, "source", ""); @@ -704,11 +703,11 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, } } } - else if (xmlStrEqual(childNode->name, BAD_CAST "tile")) + else if (xmlNameEqual(childNode, "tile")) { for_each_xml_child_node(tileNode, childNode) { - if (!xmlStrEqual(tileNode->name, BAD_CAST "properties")) + if (!xmlNameEqual(tileNode, "properties")) continue; int tileGID = firstGid + XML::getProperty(childNode, "id", 0); @@ -717,7 +716,7 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, std::map<std::string, int> tileProperties; for_each_xml_child_node(propertyNode, tileNode) { - if (!xmlStrEqual(propertyNode->name, BAD_CAST "property")) + if (!xmlNameEqual(propertyNode, "property")) continue; std::string name = XML::getProperty( propertyNode, "name", ""); diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h index c15a83b6f..c9c742ecd 100644 --- a/src/resources/mapreader.h +++ b/src/resources/mapreader.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -23,7 +23,7 @@ #ifndef MAPREADER_H #define MAPREADER_H -#include <libxml/tree.h> +#include "utils/xml.h" #include <string> @@ -47,7 +47,7 @@ class MapReader * 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,17 +57,17 @@ 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, + static Tileset *readTileset(XmlNodePtr node, const std::string &path, Map *map); }; diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index dbf9d3e9a..9d295db35 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -52,9 +52,9 @@ void MonsterDB::load() logger->log1("Initializing monster database..."); XML::Document doc("monsters.xml"); - xmlNodePtr rootNode = doc.rootNode(); + XmlNodePtr rootNode = doc.rootNode(); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "monsters")) + if (!rootNode || !xmlNameEqual(rootNode, "monsters")) { logger->log("Monster Database: Error while loading monster.xml!"); mLoaded = true; @@ -71,7 +71,7 @@ void MonsterDB::load() //iterate <monster>s for_each_xml_child_node(monsterNode, rootNode) { - if (!xmlStrEqual(monsterNode->name, BAD_CAST "monster")) + if (!xmlNameEqual(monsterNode, "monster")) continue; BeingInfo *currentInfo = new BeingInfo; @@ -119,7 +119,7 @@ void MonsterDB::load() if (!spriteNode->xmlChildrenNode) continue; - if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) + if (xmlNameEqual(spriteNode, "sprite")) { SpriteReference *currentSprite = new SpriteReference; currentSprite->sprite = reinterpret_cast<const char*>( @@ -129,7 +129,7 @@ void MonsterDB::load() spriteNode, "variant", 0); display.sprites.push_back(currentSprite); } - else if (xmlStrEqual(spriteNode->name, BAD_CAST "sound")) + else if (xmlNameEqual(spriteNode, "sound")) { std::string event = XML::getProperty(spriteNode, "event", ""); const char *filename; @@ -172,7 +172,7 @@ void MonsterDB::load() currentInfo->getName().c_str()); } } - else if (xmlStrEqual(spriteNode->name, BAD_CAST "attack")) + else if (xmlNameEqual(spriteNode, "attack")) { const int id = XML::getProperty(spriteNode, "id", 0); const std::string particleEffect = XML::getProperty( @@ -185,7 +185,7 @@ void MonsterDB::load() currentInfo->addAttack(id, spriteAction, particleEffect, missileParticle); } - else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) + else if (xmlNameEqual(spriteNode, "particlefx")) { display.particles.push_back(reinterpret_cast<const char*>( spriteNode->xmlChildrenNode->content)); diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h index 1a9d0e64f..3ddc68c08 100644 --- a/src/resources/monsterdb.h +++ b/src/resources/monsterdb.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/music.cpp b/src/resources/music.cpp index 099d030b0..b13812f18 100644 --- a/src/resources/music.cpp +++ b/src/resources/music.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -26,30 +26,21 @@ #include "debug.h" -Music::Music(Mix_Chunk *music): - mChunk(music), - mChannel(-1) +Music::Music(Mix_Music *music) : + mMusic(music) { } Music::~Music() { - //Mix_FreeMusic(music); - Mix_FreeChunk(mChunk); + Mix_FreeMusic(mMusic); } -Resource *Music::load(void *buffer, unsigned bufferSize) +Resource *Music::load(SDL_RWops *rw) { - // Load the raw file data from the buffer in an RWops structure - SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize); - - // Use Mix_LoadMUS to load the raw music data - //Mix_Music* music = Mix_LoadMUS_RW(rw); Need to be implemeted - Mix_Chunk *tmpMusic = Mix_LoadWAV_RW(rw, 1); - - if (tmpMusic) + if (Mix_Music *music = Mix_LoadMUS_RW(rw)) { - return new Music(tmpMusic); + return new Music(music); } else { @@ -58,30 +49,10 @@ Resource *Music::load(void *buffer, unsigned bufferSize) } } -bool Music::play(int loops) -{ - /* - * Warning: loops should be always set to -1 (infinite) with current - * implementation to avoid halting the playback of other samples - */ - - /*if (Mix_PlayMusic(music, loops)) - return true;*/ - Mix_VolumeChunk(mChunk, 120); - mChannel = Mix_PlayChannel(-1, mChunk, loops); - - return mChannel != -1; -} - -void Music::stop() +bool Music::play(int loops, int fadeIn) { - /* - * Warning: very dungerous trick, it could try to stop channels occupied - * by samples rather than the current music file - */ - - //Mix_HaltMusic(); - - if (mChannel != -1) - Mix_HaltChannel(mChannel); + if (fadeIn > 0) + return Mix_FadeInMusic(mMusic, loops, fadeIn); + else + return Mix_PlayMusic(mMusic, loops); } diff --git a/src/resources/music.h b/src/resources/music.h index a4b5b4973..88cc752bc 100644 --- a/src/resources/music.h +++ b/src/resources/music.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -41,38 +41,32 @@ class Music : public Resource /** * Loads a music from a buffer in memory. * - * @param buffer The memory buffer containing the music data. - * @param bufferSize The size of the memory buffer in bytes. + * @param rw The SDL_RWops to load the music data from. * * @return <code>NULL</code> if the an error occurred, a valid pointer * otherwise. */ - static Resource *load(void *buffer, unsigned bufferSize); + static Resource *load(SDL_RWops *rw); /** * Plays the music. * - * @param loops Number of times to repeat the playback. + * @param loops Number of times to repeat the playback (-1 means + * forever). + * @param fadeIn Duration in milliseconds to fade in the music. * * @return <code>true</code> if the playback started properly * <code>false</code> otherwise. */ - virtual bool play(int loops); - - /** - * Stops the music. - */ - virtual void stop(); + bool play(int loops = -1, int fadeIn = 0); protected: /** * Constructor. */ - Music(Mix_Chunk *music); + Music(Mix_Music *music); - //Mix_Music *music; - Mix_Chunk *mChunk; - int mChannel; + Mix_Music *mMusic; }; #endif diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index d04a2518f..832fa26d6 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2008-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -46,9 +46,9 @@ void NPCDB::load() logger->log1("Initializing NPC database..."); XML::Document doc("npcs.xml"); - xmlNodePtr rootNode = doc.rootNode(); + XmlNodePtr rootNode = doc.rootNode(); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "npcs")) + if (!rootNode || !xmlNameEqual(rootNode, "npcs")) { logger->log("NPC Database: Error while loading npcs.xml!"); mLoaded = true; @@ -58,7 +58,7 @@ void NPCDB::load() //iterate <npc>s for_each_xml_child_node(npcNode, rootNode) { - if (!xmlStrEqual(npcNode->name, BAD_CAST "npc")) + if (!xmlNameEqual(npcNode, "npc")) continue; int id = XML::getProperty(npcNode, "id", 0); @@ -84,7 +84,7 @@ void NPCDB::load() if (!spriteNode->xmlChildrenNode) continue; - if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) + if (xmlNameEqual(spriteNode, "sprite")) { SpriteReference *currentSprite = new SpriteReference; currentSprite->sprite = reinterpret_cast<const char*>( @@ -93,7 +93,7 @@ void NPCDB::load() XML::getProperty(spriteNode, "variant", 0); display.sprites.push_back(currentSprite); } - else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) + else if (xmlNameEqual(spriteNode, "particlefx")) { std::string particlefx = reinterpret_cast<const char*>( spriteNode->xmlChildrenNode->content); diff --git a/src/resources/npcdb.h b/src/resources/npcdb.h index 1d8a72aa6..9b686691a 100644 --- a/src/resources/npcdb.h +++ b/src/resources/npcdb.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2008-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index 552af06ec..e9449f0c9 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/resource.h b/src/resources/resource.h index 7196fa916..b8e06aaa7 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index c7552b9b7..c26526b97 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -35,6 +35,7 @@ #include "resources/spritedef.h" #include "utils/mkdir.h" +#include "utils/physfsrwops.h" #include <physfs.h> #include <SDL_image.h> @@ -42,6 +43,7 @@ #include <fstream> #include <iostream> #include <sstream> +#include <zlib.h> #include <sys/stat.h> #include <sys/time.h> @@ -397,19 +399,16 @@ struct ResourceLoader ResourceManager *manager; std::string path; ResourceManager::loader fun; + static Resource *load(void *v) { if (!v) return nullptr; ResourceLoader *l = static_cast< ResourceLoader * >(v); - int fileSize; - if (!l->manager) + SDL_RWops *rw = PHYSFSRWOPS_openRead(l->path.c_str()); + if (!rw) return nullptr; - void *buffer = l->manager->loadFile(l->path, fileSize); - if (!buffer) - return nullptr; - Resource *res = l->fun(buffer, fileSize); - free(buffer); + Resource *res = l->fun(rw); return res; } }; @@ -451,16 +450,14 @@ struct DyedImageLoader d = new Dye(path.substr(p + 1)); path = path.substr(0, p); } - int fileSize; - void *buffer = l->manager->loadFile(path, fileSize); - if (!buffer) + SDL_RWops *rw = PHYSFSRWOPS_openRead(path.c_str()); + if (!rw) { delete d; - return 0; + return nullptr; } - Resource *res = d ? Image::load(buffer, fileSize, *d) - : Image::load(buffer, fileSize); - free(buffer); + Resource *res = d ? Image::load(rw, *d) + : Image::load(rw); delete d; return res; } @@ -695,18 +692,10 @@ void ResourceManager::saveTextFile(std::string path, std::string name, SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename) { - int fileSize; - void *buffer = loadFile(filename, fileSize); - SDL_Surface *tmp = nullptr; - - if (buffer) - { - SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize); - tmp = IMG_Load_RW(rw, 1); - ::free(buffer); - } - - return tmp; + SDL_Surface *surface = nullptr; + if (SDL_RWops *rw = PHYSFSRWOPS_openRead(filename.c_str())) + surface = IMG_Load_RW(rw, 1); + return surface; } void ResourceManager::scheduleDelete(SDL_Surface* surface) diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 8cc851cca..7b61e2eaa 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -37,7 +37,9 @@ class Music; class Resource; class SoundEffect; class SpriteDef; + struct SDL_Surface; +struct SDL_RWops; /** * A class for loading and managing resources. @@ -48,7 +50,7 @@ class ResourceManager public: - typedef Resource *(*loader)(void *, unsigned); + typedef Resource *(*loader)(SDL_RWops *); typedef Resource *(*generator)(void *); ResourceManager(); diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index a8da8dd80..6a3a980a7 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -31,14 +31,10 @@ SoundEffect::~SoundEffect() Mix_FreeChunk(mChunk); } -Resource *SoundEffect::load(void *buffer, unsigned bufferSize) +Resource *SoundEffect::load(SDL_RWops *rw) { - if (!buffer) + if (!rw) return nullptr; - - // Load the raw file data from the buffer in an RWops structure - SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize); - // Load the music data and free the RWops structure Mix_Chunk *tmpSoundEffect = Mix_LoadWAV_RW(rw, 1); diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index fdd4bd275..0df7f50d5 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -41,13 +41,12 @@ class SoundEffect : public Resource /** * Loads a sample from a buffer in memory. * - * @param buffer The memory buffer containing the sample data. - * @param bufferSize The size of the memory buffer in bytes. + * @param rw The SDL_RWops to load the sample data from. * * @return <code>NULL</code> if the an error occurred, a valid pointer * otherwise. */ - static Resource *load(void *buffer, unsigned bufferSize); + static Resource *load(SDL_RWops *rw); /** * Plays the sample. diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp index 51ba4bc74..b1a3a9c4d 100644 --- a/src/resources/specialdb.cpp +++ b/src/resources/specialdb.cpp @@ -1,7 +1,7 @@ /* * The ManaPlus Client * Copyright (C) 2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -55,9 +55,9 @@ void SpecialDB::load() logger->log("Initializing special database..."); XML::Document doc("specials.xml"); - xmlNodePtr root = doc.rootNode(); + XmlNodePtr root = doc.rootNode(); - if (!root || !xmlStrEqual(root->name, BAD_CAST "specials")) + if (!root || !xmlNameEqual(root, "specials")) { logger->log("Error loading specials file specials.xml"); return; @@ -67,13 +67,13 @@ void SpecialDB::load() for_each_xml_child_node(set, root) { - if (xmlStrEqual(set->name, BAD_CAST "set")) + if (xmlNameEqual(set, "set")) { setName = XML::getProperty(set, "name", "Actions"); for_each_xml_child_node(special, set) { - if (xmlStrEqual(special->name, BAD_CAST "special")) + if (xmlNameEqual(special, "special")) { SpecialInfo *info = new SpecialInfo(); int id = XML::getProperty(special, "id", 0); diff --git a/src/resources/specialdb.h b/src/resources/specialdb.h index 8a9e6bb23..f6ef73862 100644 --- a/src/resources/specialdb.h +++ b/src/resources/specialdb.h @@ -1,7 +1,7 @@ /* * The ManaPlus Client * Copyright (C) 2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 32d18b6b8..0d9b95f6f 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -33,8 +33,6 @@ #include "configuration.h" -#include "utils/xml.h" - #include "debug.h" SpriteReference *SpriteReference::Empty = nullptr; @@ -83,9 +81,9 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) palettes = animationFile.substr(pos + 1); XML::Document doc(animationFile.substr(0, pos)); - xmlNodePtr rootNode = doc.rootNode(); + XmlNodePtr rootNode = doc.rootNode(); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite")) + if (!rootNode || !xmlNameEqual(rootNode, "sprite")) { logger->log("Error, failed to parse %s", animationFile.c_str()); @@ -136,7 +134,7 @@ void SpriteDef::substituteActions() substituteAction(SpriteAction::SPAWN, SpriteAction::STAND); } -void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant, +void SpriteDef::loadSprite(XmlNodePtr spriteNode, int variant, const std::string &palettes) { // Get the variant @@ -151,16 +149,16 @@ void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant, for_each_xml_child_node(node, spriteNode) { - if (xmlStrEqual(node->name, BAD_CAST "imageset")) + if (xmlNameEqual(node, "imageset")) loadImageSet(node, palettes); - else if (xmlStrEqual(node->name, BAD_CAST "action")) + else if (xmlNameEqual(node, "action")) loadAction(node, variant_offset); - else if (xmlStrEqual(node->name, BAD_CAST "include")) + else if (xmlNameEqual(node, "include")) includeSprite(node); } } -void SpriteDef::loadImageSet(xmlNodePtr node, const std::string &palettes) +void SpriteDef::loadImageSet(XmlNodePtr node, const std::string &palettes) { const std::string name = XML::getProperty(node, "name", ""); @@ -188,7 +186,7 @@ void SpriteDef::loadImageSet(xmlNodePtr node, const std::string &palettes) mImageSets[name] = imageSet; } -void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) +void SpriteDef::loadAction(XmlNodePtr node, int variant_offset) { const std::string actionName = XML::getProperty(node, "name", ""); const std::string imageSetName = XML::getProperty(node, "imageset", ""); @@ -225,12 +223,12 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) // Load animations for_each_xml_child_node(animationNode, node) { - if (xmlStrEqual(animationNode->name, BAD_CAST "animation")) + if (xmlNameEqual(animationNode, "animation")) loadAnimation(animationNode, action, imageSet, variant_offset); } } -void SpriteDef::loadAnimation(xmlNodePtr animationNode, +void SpriteDef::loadAnimation(XmlNodePtr animationNode, Action *action, ImageSet *imageSet, int variant_offset) { @@ -264,7 +262,7 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, offsetY -= imageSet->getHeight() - 32; offsetX -= imageSet->getWidth() / 2 - 16; - if (xmlStrEqual(frameNode->name, BAD_CAST "frame")) + if (xmlNameEqual(frameNode, "frame")) { const int index = XML::getProperty(frameNode, "index", -1); @@ -284,7 +282,7 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, animation->addFrame(img, delay, offsetX, offsetY, rand); } - else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence")) + else if (xmlNameEqual(frameNode, "sequence")) { const int start = XML::getProperty(frameNode, "start", -1); const int end = XML::getProperty(frameNode, "end", -1); @@ -324,22 +322,22 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, repeat --; } } - else if (xmlStrEqual(frameNode->name, BAD_CAST "end")) + else if (xmlNameEqual(frameNode, "end")) { animation->addTerminator(rand); } - else if (xmlStrEqual(frameNode->name, BAD_CAST "jump")) + else if (xmlNameEqual(frameNode, "jump")) { animation->addJump(XML::getProperty( frameNode, "action", ""), rand); } - else if (xmlStrEqual(frameNode->name, BAD_CAST "label")) + else if (xmlNameEqual(frameNode, "label")) { std::string name = XML::getProperty(frameNode, "name", ""); if (!name.empty()) animation->addLabel(name); } - else if (xmlStrEqual(frameNode->name, BAD_CAST "goto")) + else if (xmlNameEqual(frameNode, "goto")) { std::string name = XML::getProperty(frameNode, "label", ""); if (!name.empty()) @@ -348,7 +346,7 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, } // for frameNode } -void SpriteDef::includeSprite(xmlNodePtr includeNode) +void SpriteDef::includeSprite(XmlNodePtr includeNode) { std::string filename = XML::getProperty(includeNode, "file", ""); @@ -365,9 +363,9 @@ void SpriteDef::includeSprite(xmlNodePtr includeNode) mProcessedFiles.insert(filename); XML::Document doc(filename); - xmlNodePtr rootNode = doc.rootNode(); + XmlNodePtr rootNode = doc.rootNode(); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite")) + if (!rootNode || !xmlNameEqual(rootNode, "sprite")) { logger->log("Error, no sprite root node in %s", filename.c_str()); return; diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 3aa6369dd..0490bdcb3 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -25,7 +25,7 @@ #include "resources/resource.h" -#include <libxml/tree.h> +#include "utils/xml.h" #include <list> #include <map> @@ -145,30 +145,30 @@ class SpriteDef : public Resource /** * Loads a sprite element. */ - void loadSprite(xmlNodePtr spriteNode, int variant, + void loadSprite(XmlNodePtr spriteNode, int variant, const std::string &palettes = ""); /** * Loads an imageset element. */ - void loadImageSet(xmlNodePtr node, const std::string &palettes); + void loadImageSet(XmlNodePtr node, const std::string &palettes); /** * Loads an action element. */ - void loadAction(xmlNodePtr node, int variant_offset); + void loadAction(XmlNodePtr node, int variant_offset); /** * Loads an animation element. */ - void loadAnimation(xmlNodePtr animationNode, + void loadAnimation(XmlNodePtr animationNode, Action *action, ImageSet *imageSet, int variant_offset); /** * Include another sprite into this one. */ - void includeSprite(xmlNodePtr includeNode); + void includeSprite(XmlNodePtr includeNode); /** * Complete missing actions by copying existing ones. diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index c8cd5ad60..7ebc5a11a 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/wallpaper.h b/src/resources/wallpaper.h index 55f5eec93..7123cfd96 100644 --- a/src/resources/wallpaper.h +++ b/src/resources/wallpaper.h @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * |