From a84133850af6d348c0c4e252b26618148702153b Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 20 Sep 2007 13:24:20 +0000 Subject: Merged a bunch of small changes from trunk to 0.0 and set svn:eol-style to native for some files that were still missing this property. This is a feeble attempt to reduce the amount of conflicts for future merges. --- CMake/Modules/FindLibXml2.cmake | 59 ---- CMake/Modules/FindLibcurl.cmake | 41 --- ChangeLog | 12 + src/CMakeLists.txt | 11 +- src/being.cpp | 4 +- src/being.h | 6 +- src/game.cpp | 7 +- src/graphics.h | 2 +- src/gui/gui.cpp | 6 +- src/gui/newskill.cpp | 2 +- src/gui/playerbox.cpp | 4 +- src/gui/progressbar.cpp | 5 +- src/gui/vbox.cpp | 2 +- src/gui/widgets/resizegrip.cpp | 2 +- src/gui/window.h | 10 +- src/inventory.cpp | 2 +- src/joystick.h | 7 +- src/log.cpp | 9 + src/log.h | 11 + src/map.cpp | 12 +- src/map.h | 16 +- src/particleemitter.cpp | 646 +++++++++++++++++++------------------- src/particleemitter.h | 240 +++++++------- src/player.cpp | 2 +- src/player.h | 2 +- src/properties.h | 16 +- src/resources/image.cpp | 4 +- src/resources/image.h | 1 + src/resources/itemdb.h | 106 +++---- src/resources/mapreader.h | 5 +- src/resources/monsterdb.cpp | 350 ++++++++++----------- src/resources/monsterdb.h | 3 + src/resources/monsterinfo.cpp | 140 ++++----- src/resources/music.h | 1 + src/resources/resourcemanager.cpp | 5 +- src/resources/soundeffect.h | 1 + src/simpleanimation.cpp | 2 +- src/sound.cpp | 2 +- src/sound.h | 18 +- src/utils/minmax.h | 96 +++--- 40 files changed, 909 insertions(+), 961 deletions(-) delete mode 100644 CMake/Modules/FindLibXml2.cmake delete mode 100644 CMake/Modules/FindLibcurl.cmake diff --git a/CMake/Modules/FindLibXml2.cmake b/CMake/Modules/FindLibXml2.cmake deleted file mode 100644 index b45d7293..00000000 --- a/CMake/Modules/FindLibXml2.cmake +++ /dev/null @@ -1,59 +0,0 @@ -# - Try to find LibXml2 -# Once done this will define -# -# LIBXML2_FOUND - system has LibXml2 -# LIBXML2_INCLUDE_DIR - the LibXml2 include directory -# LIBXML2_LIBRARIES - the libraries needed to use LibXml2 -# LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2 -# -# Copyright (c) 2006, Alexander Neundorf -# This code is available under the BSD license, see licenses/BSD for details. - -# Copyright (c) 2006, Alexander Neundorf, -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - - -IF (LIBXML2_INCLUDE_DIR AND LIBXML2_LIBRARIES) - # in cache already - SET(LibXml2_FIND_QUIETLY TRUE) -ENDIF (LIBXML2_INCLUDE_DIR AND LIBXML2_LIBRARIES) - -IF (NOT WIN32) - # use pkg-config to get the directories and then use these values - # in the FIND_PATH() and FIND_LIBRARY() calls - INCLUDE(UsePkgConfig) - PKGCONFIG(libxml-2.0 _LibXml2IncDir _LibXml2LinkDir _LibXml2LinkFlags _LibXml2Cflags) - SET(LIBXML2_DEFINITIONS ${_LibXml2Cflags}) -ENDIF (NOT WIN32) - -FIND_PATH(LIBXML2_INCLUDE_DIR libxml/xpath.h - PATHS - ${_LibXml2IncDir} - PATH_SUFFIXES libxml2 - ) - -FIND_LIBRARY(LIBXML2_LIBRARIES NAMES xml2 libxml2 - PATHS - ${_LibXml2LinkDir} - ) - -IF (LIBXML2_INCLUDE_DIR AND LIBXML2_LIBRARIES) - SET(LIBXML2_FOUND TRUE) -ELSE (LIBXML2_INCLUDE_DIR AND LIBXML2_LIBRARIES) - SET(LIBXML2_FOUND FALSE) -ENDIF (LIBXML2_INCLUDE_DIR AND LIBXML2_LIBRARIES) - -IF (LIBXML2_FOUND) - IF (NOT LibXml2_FIND_QUIETLY) - MESSAGE(STATUS "Found LibXml2: ${LIBXML2_LIBRARIES}") - ENDIF (NOT LibXml2_FIND_QUIETLY) -ELSE (LIBXML2_FOUND) - IF (LibXml2_FIND_REQUIRED) - MESSAGE(SEND_ERROR "Could NOT find LibXml2") - ENDIF (LibXml2_FIND_REQUIRED) -ENDIF (LIBXML2_FOUND) - -MARK_AS_ADVANCED(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES) - diff --git a/CMake/Modules/FindLibcurl.cmake b/CMake/Modules/FindLibcurl.cmake deleted file mode 100644 index fe389c49..00000000 --- a/CMake/Modules/FindLibcurl.cmake +++ /dev/null @@ -1,41 +0,0 @@ -# - Try to find libcurl -# Once done this will define -# -# LIBCURL_FOUND - system has libcurl -# LIBCURL_INCLUDE_DIR - the libcurl include directory -# LIBCURL_LIBRARIES - the libraries needed to use libcurl -# LIBCURL_DEFINITIONS - Compiler switches required for using libcurl - -IF (Libcurl_INCLUDE_DIR AND Libcurl_LIBRARY) - SET(Libcurl_FIND_QUIETLY TRUE) -ENDIF (Libcurl_INCLUDE_DIR AND Libcurl_LIBRARY) - -FIND_PATH(Libcurl_INCLUDE_DIR curl/curl.h - /usr/include - /usr/local/include - ) - -FIND_LIBRARY(Libcurl_LIBRARY - NAMES curl - PATHS /usr/lib /usr/local/lib - ) - -IF (Libcurl_INCLUDE_DIR AND Libcurl_LIBRARY) - SET(LIBCURL_FOUND TRUE) - SET(LIBCURL_INCLUDE_DIR ${Libcurl_INCLUDE_DIR}) - SET(LIBCURL_LIBRARIES ${Libcurl_LIBRARY}) -ELSE (Libcurl_INCLUDE_DIR AND Libcurl_LIBRARY) - SET(LIBCURL_FOUND TRUE) -ENDIF (Libcurl_INCLUDE_DIR AND Libcurl_LIBRARY) - -IF (LIBCURL_FOUND) - IF (NOT Libcurl_FIND_QUIETLY) - MESSAGE(STATUS "Found libcurl: ${Libcurl_LIBRARY}") - ENDIF (NOT Libcurl_FIND_QUIETLY) -ELSE (LIBCURL_FOUND) - IF (Libcurl_FIND_REQUIRED) - MESSAGE(SEND_ERROR "Could NOT find libcurl") - ENDIF (Libcurl_FIND_REQUIRED) -ENDIF (LIBCURL_FOUND) - -MARK_AS_ADVANCED(Libcurl_INCLUDE_DIR Libcurl_LIBRARY) diff --git a/ChangeLog b/ChangeLog index cb92d5f8..82835517 100644 --- a/ChangeLog +++ b/ChangeLog @@ -256,6 +256,12 @@ village indoor tilesets. * data/maps/new_20-1.tmx.gz: Added woodland village indoor map. +2007-07-29 Guillaume Melquiond + + * CMake/Modules/FindLibXml2.cmake, CMake/Modules/FindLibcurl.cmake, + src/CMakeLists.txt: Switch to upstream CMake modules for libxml2 and + curl. + 2007-07-25 Joshua Langley * src/gui/setup.cpp, src/gui/setup_keyboard.cpp, @@ -2422,8 +2428,14 @@ * data/graphics/sprites/item003.png, data/graphics/sprites/item003.xml: Added the leather shirt +2007-07-25 Guillaume Melquiond + + * src/resources/image.cpp: Added support for subimages of subimages. + 2006-07-25 Bjørn Lindeijer + * src/log.cpp, src/log.h: Added support for writing log to standard + output. * src/gui/updatewindow.cpp: Fixed updating on Windows. 2006-07-24 Bjørn Lindeijer diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c744ba78..86d446b6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,8 +2,7 @@ FIND_PACKAGE(SDL REQUIRED) FIND_PACKAGE(SDL_image REQUIRED) FIND_PACKAGE(SDL_mixer REQUIRED) FIND_PACKAGE(SDL_net REQUIRED) - -FIND_PACKAGE(Libcurl REQUIRED) +FIND_PACKAGE(CURL REQUIRED) FIND_PACKAGE(LibXml2 REQUIRED) FIND_PACKAGE(PhysFS REQUIRED) FIND_PACKAGE(PNG REQUIRED) @@ -31,7 +30,7 @@ INCLUDE_DIRECTORIES( ${SDLNET_INCLUDE_DIR} ${PNG_INCLUDE_DIR} ${PHYSFS_INCLUDE_DIR} - ${LIBCURL_INCLUDE_DIR} + ${CURL_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR} ${GUICHAN_INCLUDE_DIR} ) @@ -52,8 +51,8 @@ MARK_AS_ADVANCED(SDL_LIBRARY) SET(SRCS gui/widgets/resizegrip.cpp gui/widgets/resizegrip.h - gui/box.h gui/box.cpp + gui/box.h gui/browserbox.cpp gui/browserbox.h gui/buddywindow.cpp @@ -90,8 +89,8 @@ SET(SRCS gui/gccontainer.h gui/gui.cpp gui/gui.h - gui/hbox.h gui/hbox.cpp + gui/hbox.h gui/help.cpp gui/help.h gui/inttextbox.cpp @@ -345,7 +344,7 @@ TARGET_LINK_LIBRARIES(tmw ${SDLNET_LIBRARY} ${PNG_LIBRARIES} ${PHYSFS_LIBRARY} - ${LIBCURL_LIBRARIES} + ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${GUICHAN_LIBRARIES} ${OPENGL_LIBRARIES} diff --git a/src/being.cpp b/src/being.cpp index b0fde6d1..bfd35e21 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -415,7 +415,7 @@ Being::draw(Graphics *graphics, int offsetX, int offsetY) const } void -Being::drawEmotion(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) +Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) { if (!mEmotion) return; @@ -427,7 +427,7 @@ Being::drawEmotion(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) } void -Being::drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) +Being::drawSpeech(Graphics *graphics, int offsetX, int offsetY) { int px = mPx + offsetX; int py = mPy + offsetY; diff --git a/src/being.h b/src/being.h index 5914014b..ff65bbef 100644 --- a/src/being.h +++ b/src/being.h @@ -238,19 +238,19 @@ class Being : public Sprite * Draws the speech text above the being. */ void - drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY); + drawSpeech(Graphics *graphics, int offsetX, int offsetY); /** * Draws the emotion picture above the being. */ void - drawEmotion(Graphics *graphics, Sint32 offsetX, Sint32 offsetY); + drawEmotion(Graphics *graphics, int offsetX, int offsetY); /** * Draws the name text below the being. */ virtual void - drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) {}; + drawName(Graphics *, int, int) {}; /** * Returns the type of the being. diff --git a/src/game.cpp b/src/game.cpp index b53fbb8b..ca6f4993 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -677,8 +677,8 @@ void Game::handleInput() // Get the state of the keyboard keys keyboard.refreshActiveKeys(); - Uint16 x = player_node->mX; - Uint16 y = player_node->mY; + const Uint16 x = player_node->mX; + const Uint16 y = player_node->mY; unsigned char direction = 0; // Translate pressed keys to movement and direction @@ -754,8 +754,7 @@ void Game::handleInput() { if (joystick->buttonPressed(1)) { - FloorItem *item = floorItemManager->findByCoordinates( - player_node->mX, player_node->mY); + FloorItem *item = floorItemManager->findByCoordinates(x, y); if (item) player_node->pickUp(item); diff --git a/src/graphics.h b/src/graphics.h index b3d36653..4637973f 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -29,7 +29,7 @@ class Image; class ImageRect; -class SDL_Surface; +struct SDL_Surface; /** * 9 images defining a rectangle. 4 corners, 4 sides and a middle area. The diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 84680da8..a83f794c 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -206,9 +206,9 @@ Gui::draw() mCustomCursor) { static_cast(mGraphics)->drawImage( - mMouseCursors->get(mCursorType), - mouseX - 15, - mouseY - 17); + mMouseCursors->get(mCursorType), + mouseX - 15, + mouseY - 17); } mGraphics->popClipArea(); diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp index c84c9449..6783a546 100644 --- a/src/gui/newskill.cpp +++ b/src/gui/newskill.cpp @@ -123,7 +123,7 @@ NewSkillDialog::NewSkillDialog(): void NewSkillDialog::action(const gcn::ActionEvent &event) { - int osp = startPoint; + int osp = startPoint; if (event.getId() == "close") { setVisible(false); diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index fad156f1..95366bee 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -80,7 +80,7 @@ PlayerBox::draw(gcn::Graphics *graphics) if (mPlayer) { // Draw character - mPlayer->draw(dynamic_cast(graphics), 40, 42); + mPlayer->draw(static_cast(graphics), 40, 42); } } @@ -92,5 +92,5 @@ PlayerBox::drawBorder(gcn::Graphics *graphics) w = getWidth() + bs * 2; h = getHeight() + bs * 2; - dynamic_cast(graphics)->drawImageRect(0, 0, w, h, background); + static_cast(graphics)->drawImageRect(0, 0, w, h, background); } diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 2bdfc856..6d18b2f7 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -93,9 +93,8 @@ void ProgressBar::logic() void ProgressBar::draw(gcn::Graphics *graphics) { - dynamic_cast(graphics)->drawImageRect(0, 0, - getWidth(), getHeight(), - mBorder); + static_cast(graphics)-> + drawImageRect(0, 0, getWidth(), getHeight(), mBorder); // The bar if (mProgress > 0) diff --git a/src/gui/vbox.cpp b/src/gui/vbox.cpp index eb838ead..b503508e 100644 --- a/src/gui/vbox.cpp +++ b/src/gui/vbox.cpp @@ -25,7 +25,7 @@ void VBox::draw(gcn::Graphics *graphics) { - if (mWidgets.size() == 0) + if (mWidgets.empty()) { return; } diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp index 50a6fce4..6be50f2c 100644 --- a/src/gui/widgets/resizegrip.cpp +++ b/src/gui/widgets/resizegrip.cpp @@ -61,5 +61,5 @@ ResizeGrip::~ResizeGrip() void ResizeGrip::draw(gcn::Graphics *graphics) { - dynamic_cast(graphics)->drawImage(gripImage, 0, 0); + static_cast(graphics)->drawImage(gripImage, 0, 0); } diff --git a/src/gui/window.h b/src/gui/window.h index b83aa78b..583601ab 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -52,11 +52,11 @@ class Window : public gcn::Window * Constructor. Initializes the title to the given text and hooks * itself into the window container. * - * @param text The initial window title, "Window" by default. - * @param modal Block input to other windows. - * @param parent The parent window. This is the window standing above - * this one in the window hiearchy. When reordering, - * a window will never go below its parent window. + * @param caption The initial window title, "Window" by default. + * @param modal Block input to other windows. + * @param parent The parent window. This is the window standing above + * this one in the window hiearchy. When reordering, + * a window will never go below its parent window. */ Window(const std::string &caption = "Window", bool modal = false, Window *parent = NULL); diff --git a/src/inventory.cpp b/src/inventory.cpp index 0467df10..e476857f 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -49,7 +49,7 @@ Inventory::~Inventory() Item* Inventory::getItem(int index) { - if (index < 0 || index > INVENTORY_SIZE) + if (index < 0 || index >= INVENTORY_SIZE) { return 0; } diff --git a/src/joystick.h b/src/joystick.h index f0759add..321e3e7d 100644 --- a/src/joystick.h +++ b/src/joystick.h @@ -32,15 +32,12 @@ class Joystick /** * Number of buttons we can handle. */ - static const unsigned char MAX_BUTTONS = 6; + enum { MAX_BUTTONS = 6 }; /** * Directions, to be used as bitmask values. */ - static const char UP = 1; - static const char DOWN = 2; - static const char LEFT = 4; - static const char RIGHT = 8; + enum { UP = 1, DOWN = 2, LEFT = 4, RIGHT = 8 }; /** * Initializes the joystick subsystem. diff --git a/src/log.cpp b/src/log.cpp index 0d54a368..224736bd 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -35,6 +35,10 @@ #include #include +Logger::Logger(): + mLogToStandardOut(false) +{ +} Logger::~Logger() { @@ -92,6 +96,11 @@ void Logger::log(const char *log_text, ...) mLogFile << timeStr.str() << buf << std::endl; + if (mLogToStandardOut) + { + std::cout << timeStr.str() << buf << std::endl; + } + // Delete temporary buffer delete[] buf; } diff --git a/src/log.h b/src/log.h index 4876a9aa..36328527 100644 --- a/src/log.h +++ b/src/log.h @@ -31,6 +31,11 @@ class Logger { public: + /** + * Constructor. + */ + Logger(); + /** * Destructor, closes log file. */ @@ -41,6 +46,11 @@ class Logger */ void setLogFile(const std::string &logFilename); + /** + * Sets whether the log should be written to standard output. + */ + void setLogToStandardOut(bool value) { mLogToStandardOut = value; } + /** * Enters a message in the log. The message will be timestamped. */ @@ -54,6 +64,7 @@ class Logger private: std::ofstream mLogFile; + bool mLogToStandardOut; }; extern Logger *logger; diff --git a/src/map.cpp b/src/map.cpp index 1f0c22b9..1ee2248f 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -148,8 +148,8 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer) if (startX < 0) startX = 0; if (startY < 0) startY = 0; - if (endX >= mWidth) endX = mWidth; - if (endY >= mHeight) endY = mHeight; + if (endX > mWidth) endX = mWidth; + if (endY > mHeight) endY = mHeight; for (int y = startY; y < endY; y++) { @@ -281,13 +281,13 @@ Map::setWalk(int x, int y, bool walkable) } bool -Map::getWalk(int x, int y) +Map::getWalk(int x, int y) const { return !tileCollides(x, y) && !occupied(x, y); } bool -Map::occupied(int x, int y) +Map::occupied(int x, int y) const { Beings &beings = beingManager->getAll(); for (BeingIterator i = beings.begin(); i != beings.end(); i++) @@ -303,13 +303,13 @@ Map::occupied(int x, int y) } bool -Map::tileCollides(int x, int y) +Map::tileCollides(int x, int y) const { return !(contains(x, y) && mMetaTiles[x + y * mWidth].walkable); } bool -Map::contains(int x, int y) +Map::contains(int x, int y) const { return x >= 0 && y >= 0 && x < mWidth && y < mHeight; } diff --git a/src/map.h b/src/map.h index 3ccbe7ae..17772847 100644 --- a/src/map.h +++ b/src/map.h @@ -137,36 +137,36 @@ class Map : public Properties /** * Tell if a tile is walkable or not, includes checking beings. */ - bool getWalk(int x, int y); + bool getWalk(int x, int y) const; /** * Tell if a tile collides, not including a check on beings. */ - bool tileCollides(int x, int y); + bool tileCollides(int x, int y) const; /** * Returns the width of this map. */ int - getWidth() { return mWidth; } + getWidth() const { return mWidth; } /** * Returns the height of this map. */ int - getHeight() { return mHeight; } + getHeight() const { return mHeight; } /** * Returns the tile width of this map. */ int - getTileWidth() { return mTileWidth; } + getTileWidth() const { return mTileWidth; } /** * Returns the tile height used by this map. */ int - getTileHeight() { return mTileHeight; } + getTileHeight() const { return mTileHeight; } /** * Find a path from one location to the next. @@ -214,12 +214,12 @@ class Map : public Properties /** * Tells whether a tile is occupied by a being. */ - bool occupied(int x, int y); + bool occupied(int x, int y) const; /** * Tells whether the given coordinates fall within the map boundaries. */ - bool contains(int x, int y); + bool contains(int x, int y) const; int mWidth, mHeight; int mTileWidth, mTileHeight; diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index ea7b87d6..035882b6 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -1,323 +1,323 @@ -/* - * The Mana World - * Copyright 2006 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#include "particleemitter.h" - -#include "animationparticle.h" -#include "imageparticle.h" -#include "log.h" -#include "particle.h" - -#include "resources/animation.h" -#include "resources/image.h" -#include "resources/resourcemanager.h" -#include "resources/imageset.h" - -#include - -#define SIN45 0.707106781f -#define DEG_RAD_FACTOR 0.017453293f - -ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map): - mParticleImage(0) -{ - mMap = map; - mParticleTarget = target; - - //initializing default values - mParticlePosX.set(0.0f); - mParticlePosY.set(0.0f); - mParticlePosZ.set(0.0f); - mParticleAngleHorizontal.set(0.0f); - mParticleAngleVertical.set(0.0f); - mParticlePower.set(0.0f); - mParticleGravity.set(0.0f); - mParticleRandomnes.set(0); - mParticleBounce.set(0.0f); - mParticleAcceleration.set(0.0f); - mParticleDieDistance.set(-1.0f); - mParticleMomentum.set(1.0f); - mParticleLifetime.set(-1); - mParticleFadeOut.set(0); - mParticleFadeIn.set(0); - mOutput.set(1); - - for_each_xml_child_node(propertyNode, emitterNode) - { - if (xmlStrEqual(propertyNode->name, BAD_CAST "property")) - { - std::string name = XML::getProperty(propertyNode, "name", ""); - - if (name == "position-x") - { - mParticlePosX = readMinMax(propertyNode, 0.0f); - } - else if (name == "position-y") - { - - mParticlePosY = readMinMax(propertyNode, 0.0f); - mParticlePosY.minVal *= SIN45; - mParticlePosY.maxVal *= SIN45; - } - else if (name == "position-z") - { - mParticlePosZ = readMinMax(propertyNode, 0.0f); - mParticlePosZ.minVal *= SIN45; - mParticlePosZ.maxVal *= SIN45; - } - else if (name == "image") - { - std::string image = XML::getProperty(propertyNode, "value", ""); - // Don't leak when multiple images are defined - if (image != "" && !mParticleImage) - { - ResourceManager *resman = ResourceManager::getInstance(); - mParticleImage = resman->getImage(image); - } - } - else if (name == "horizontal-angle") - { - mParticleAngleHorizontal = readMinMax(propertyNode, 0.0f); - mParticleAngleHorizontal.minVal *= DEG_RAD_FACTOR; - mParticleAngleHorizontal.maxVal *= DEG_RAD_FACTOR; - } - else if (name == "vertical-angle") - { - mParticleAngleVertical = readMinMax(propertyNode, 0.0f); - mParticleAngleVertical.minVal *= DEG_RAD_FACTOR; - mParticleAngleVertical.maxVal *= DEG_RAD_FACTOR; - } - else if (name == "power") - { - mParticlePower = readMinMax(propertyNode, 0.0f); - } - else if (name == "gravity") - { - mParticleGravity = readMinMax(propertyNode, 0.0f); - } - else if (name == "randomnes") - { - mParticleRandomnes = readMinMax(propertyNode, 0); - } - else if (name == "bounce") - { - mParticleBounce = readMinMax(propertyNode, 0.0f); - } - else if (name == "lifetime") - { - mParticleLifetime = readMinMax(propertyNode, 0); - mParticleLifetime.minVal += 1; - } - else if (name == "output") - { - mOutput = readMinMax(propertyNode, 0); - mOutput.maxVal +=1; - } - else if (name == "acceleration") - { - mParticleAcceleration = readMinMax(propertyNode, 0.0f); - } - else if (name == "die-distance") - { - mParticleDieDistance = readMinMax(propertyNode, 0.0f); - } - else if (name == "momentum") - { - mParticleMomentum = readMinMax(propertyNode, 1.0f); - } - else if (name == "fade-out") - { - mParticleFadeOut = readMinMax(propertyNode, 0); - } - else if (name == "fade-in") - { - mParticleFadeIn = readMinMax(propertyNode, 0); - } - else - { - logger->log("Particle Engine: Warning, unknown emitter property \"%s\"", - name.c_str() - ); - } - } - else if (xmlStrEqual(propertyNode->name, BAD_CAST "emitter")) - { - ParticleEmitter newEmitter(propertyNode, mParticleTarget, map); - mParticleChildEmitters.push_back(newEmitter); - } - else if (xmlStrEqual(propertyNode->name, BAD_CAST "animation")) - { - ImageSet *imageset = ResourceManager::getInstance()->getImageSet( - XML::getProperty(propertyNode, "imageset", ""), - XML::getProperty(propertyNode, "width", 0), - XML::getProperty(propertyNode, "height", 0) - ); - - // Get animation frames - for_each_xml_child_node(frameNode, propertyNode) - { - int delay = XML::getProperty(frameNode, "delay", 0); - int offsetX = XML::getProperty(frameNode, "offsetX", 0); - int offsetY = XML::getProperty(frameNode, "offsetY", 0); - offsetY -= imageset->getHeight() - 32; - offsetX -= imageset->getWidth() / 2 - 16; - - if (xmlStrEqual(frameNode->name, BAD_CAST "frame")) - { - int index = XML::getProperty(frameNode, "index", -1); - - if (index < 0) - { - logger->log("No valid value for 'index'"); - continue; - } - - Image *img = imageset->get(index); - - if (!img) - { - logger->log("No image at index " + (index)); - continue; - } - - mParticleAnimation.addFrame(img, delay, offsetX, offsetY); - } - else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence")) - { - int start = XML::getProperty(frameNode, "start", -1); - int end = XML::getProperty(frameNode, "end", -1); - - if (start < 0 || end < 0) - { - logger->log("No valid value for 'start' or 'end'"); - continue; - } - - while (end >= start) - { - Image *img = imageset->get(start); - - if (!img) - { - logger->log("No image at index " + - (start)); - continue; - } - - mParticleAnimation.addFrame(img, delay, offsetX, offsetY); - start++; - } - } - else if (xmlStrEqual(frameNode->name, BAD_CAST "end")) - { - mParticleAnimation.addTerminator(); - } - } // for frameNode - } - } -} - - -ParticleEmitter::~ParticleEmitter() -{ -} - - -template MinMax -ParticleEmitter::readMinMax(xmlNodePtr propertyNode, T def) -{ - MinMax retval; - - def = (T) XML::getFloatProperty(propertyNode, "value", (double) def); - retval.set((T) XML::getFloatProperty(propertyNode, "min", (double) def), - (T) XML::getFloatProperty(propertyNode, "max", (double) def)); - - return retval; -} - - -std::list -ParticleEmitter::createParticles() -{ - std::list newParticles; - - for (int i = mOutput.value(); i > 0; i--) - { - // Limit maximum particles - if (Particle::particleCount > Particle::maxCount) break; - - Particle *newParticle; - if (mParticleImage) - { - newParticle = new ImageParticle(mMap, mParticleImage); - } - else if (mParticleAnimation.getLength() > 0) - { - Animation *newAnimation = new Animation(mParticleAnimation); - newParticle = new AnimationParticle(mMap, newAnimation); - } - else - { - newParticle = new Particle(mMap); - } - - - newParticle->setPosition( - mParticlePosX.value(), - mParticlePosY.value(), - mParticlePosZ.value()); - - float angleH = mParticleAngleHorizontal.value(); - float angleV = mParticleAngleVertical.value(); - float power = mParticlePower.value(); - newParticle->setVelocity( - cos(angleH) * cos(angleV) * power, - sin(angleH) * cos(angleV) * power, - sin(angleV) * power); - - newParticle->setRandomnes(mParticleRandomnes.value()); - newParticle->setGravity(mParticleGravity.value()); - newParticle->setBounce(mParticleBounce.value()); - - newParticle->setDestination(mParticleTarget, - mParticleAcceleration.value(), - mParticleMomentum.value() - ); - newParticle->setDieDistance(mParticleDieDistance.value()); - - newParticle->setLifetime(mParticleLifetime.value()); - newParticle->setFadeOut(mParticleFadeOut.value()); - newParticle->setFadeIn(mParticleFadeIn.value()); - - for (std::list::iterator i = mParticleChildEmitters.begin(); - i != mParticleChildEmitters.end(); - i++) - { - newParticle->addEmitter(new ParticleEmitter(*i)); - } - - newParticles.push_back(newParticle); - } - - return newParticles; -} +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "particleemitter.h" + +#include "animationparticle.h" +#include "imageparticle.h" +#include "log.h" +#include "particle.h" + +#include "resources/animation.h" +#include "resources/image.h" +#include "resources/resourcemanager.h" +#include "resources/imageset.h" + +#include + +#define SIN45 0.707106781f +#define DEG_RAD_FACTOR 0.017453293f + +ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map): + mParticleImage(0) +{ + mMap = map; + mParticleTarget = target; + + //initializing default values + mParticlePosX.set(0.0f); + mParticlePosY.set(0.0f); + mParticlePosZ.set(0.0f); + mParticleAngleHorizontal.set(0.0f); + mParticleAngleVertical.set(0.0f); + mParticlePower.set(0.0f); + mParticleGravity.set(0.0f); + mParticleRandomnes.set(0); + mParticleBounce.set(0.0f); + mParticleAcceleration.set(0.0f); + mParticleDieDistance.set(-1.0f); + mParticleMomentum.set(1.0f); + mParticleLifetime.set(-1); + mParticleFadeOut.set(0); + mParticleFadeIn.set(0); + mOutput.set(1); + + for_each_xml_child_node(propertyNode, emitterNode) + { + if (xmlStrEqual(propertyNode->name, BAD_CAST "property")) + { + std::string name = XML::getProperty(propertyNode, "name", ""); + + if (name == "position-x") + { + mParticlePosX = readMinMax(propertyNode, 0.0f); + } + else if (name == "position-y") + { + + mParticlePosY = readMinMax(propertyNode, 0.0f); + mParticlePosY.minVal *= SIN45; + mParticlePosY.maxVal *= SIN45; + } + else if (name == "position-z") + { + mParticlePosZ = readMinMax(propertyNode, 0.0f); + mParticlePosZ.minVal *= SIN45; + mParticlePosZ.maxVal *= SIN45; + } + else if (name == "image") + { + std::string image = XML::getProperty(propertyNode, "value", ""); + // Don't leak when multiple images are defined + if (image != "" && !mParticleImage) + { + ResourceManager *resman = ResourceManager::getInstance(); + mParticleImage = resman->getImage(image); + } + } + else if (name == "horizontal-angle") + { + mParticleAngleHorizontal = readMinMax(propertyNode, 0.0f); + mParticleAngleHorizontal.minVal *= DEG_RAD_FACTOR; + mParticleAngleHorizontal.maxVal *= DEG_RAD_FACTOR; + } + else if (name == "vertical-angle") + { + mParticleAngleVertical = readMinMax(propertyNode, 0.0f); + mParticleAngleVertical.minVal *= DEG_RAD_FACTOR; + mParticleAngleVertical.maxVal *= DEG_RAD_FACTOR; + } + else if (name == "power") + { + mParticlePower = readMinMax(propertyNode, 0.0f); + } + else if (name == "gravity") + { + mParticleGravity = readMinMax(propertyNode, 0.0f); + } + else if (name == "randomnes") + { + mParticleRandomnes = readMinMax(propertyNode, 0); + } + else if (name == "bounce") + { + mParticleBounce = readMinMax(propertyNode, 0.0f); + } + else if (name == "lifetime") + { + mParticleLifetime = readMinMax(propertyNode, 0); + mParticleLifetime.minVal += 1; + } + else if (name == "output") + { + mOutput = readMinMax(propertyNode, 0); + mOutput.maxVal +=1; + } + else if (name == "acceleration") + { + mParticleAcceleration = readMinMax(propertyNode, 0.0f); + } + else if (name == "die-distance") + { + mParticleDieDistance = readMinMax(propertyNode, 0.0f); + } + else if (name == "momentum") + { + mParticleMomentum = readMinMax(propertyNode, 1.0f); + } + else if (name == "fade-out") + { + mParticleFadeOut = readMinMax(propertyNode, 0); + } + else if (name == "fade-in") + { + mParticleFadeIn = readMinMax(propertyNode, 0); + } + else + { + logger->log("Particle Engine: Warning, unknown emitter property \"%s\"", + name.c_str() + ); + } + } + else if (xmlStrEqual(propertyNode->name, BAD_CAST "emitter")) + { + ParticleEmitter newEmitter(propertyNode, mParticleTarget, map); + mParticleChildEmitters.push_back(newEmitter); + } + else if (xmlStrEqual(propertyNode->name, BAD_CAST "animation")) + { + ImageSet *imageset = ResourceManager::getInstance()->getImageSet( + XML::getProperty(propertyNode, "imageset", ""), + XML::getProperty(propertyNode, "width", 0), + XML::getProperty(propertyNode, "height", 0) + ); + + // Get animation frames + for_each_xml_child_node(frameNode, propertyNode) + { + int delay = XML::getProperty(frameNode, "delay", 0); + int offsetX = XML::getProperty(frameNode, "offsetX", 0); + int offsetY = XML::getProperty(frameNode, "offsetY", 0); + offsetY -= imageset->getHeight() - 32; + offsetX -= imageset->getWidth() / 2 - 16; + + if (xmlStrEqual(frameNode->name, BAD_CAST "frame")) + { + int index = XML::getProperty(frameNode, "index", -1); + + if (index < 0) + { + logger->log("No valid value for 'index'"); + continue; + } + + Image *img = imageset->get(index); + + if (!img) + { + logger->log("No image at index " + (index)); + continue; + } + + mParticleAnimation.addFrame(img, delay, offsetX, offsetY); + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence")) + { + int start = XML::getProperty(frameNode, "start", -1); + int end = XML::getProperty(frameNode, "end", -1); + + if (start < 0 || end < 0) + { + logger->log("No valid value for 'start' or 'end'"); + continue; + } + + while (end >= start) + { + Image *img = imageset->get(start); + + if (!img) + { + logger->log("No image at index " + + (start)); + continue; + } + + mParticleAnimation.addFrame(img, delay, offsetX, offsetY); + start++; + } + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "end")) + { + mParticleAnimation.addTerminator(); + } + } // for frameNode + } + } +} + + +ParticleEmitter::~ParticleEmitter() +{ +} + + +template MinMax +ParticleEmitter::readMinMax(xmlNodePtr propertyNode, T def) +{ + MinMax retval; + + def = (T) XML::getFloatProperty(propertyNode, "value", (double) def); + retval.set((T) XML::getFloatProperty(propertyNode, "min", (double) def), + (T) XML::getFloatProperty(propertyNode, "max", (double) def)); + + return retval; +} + + +std::list +ParticleEmitter::createParticles() +{ + std::list newParticles; + + for (int i = mOutput.value(); i > 0; i--) + { + // Limit maximum particles + if (Particle::particleCount > Particle::maxCount) break; + + Particle *newParticle; + if (mParticleImage) + { + newParticle = new ImageParticle(mMap, mParticleImage); + } + else if (mParticleAnimation.getLength() > 0) + { + Animation *newAnimation = new Animation(mParticleAnimation); + newParticle = new AnimationParticle(mMap, newAnimation); + } + else + { + newParticle = new Particle(mMap); + } + + + newParticle->setPosition( + mParticlePosX.value(), + mParticlePosY.value(), + mParticlePosZ.value()); + + float angleH = mParticleAngleHorizontal.value(); + float angleV = mParticleAngleVertical.value(); + float power = mParticlePower.value(); + newParticle->setVelocity( + cos(angleH) * cos(angleV) * power, + sin(angleH) * cos(angleV) * power, + sin(angleV) * power); + + newParticle->setRandomnes(mParticleRandomnes.value()); + newParticle->setGravity(mParticleGravity.value()); + newParticle->setBounce(mParticleBounce.value()); + + newParticle->setDestination(mParticleTarget, + mParticleAcceleration.value(), + mParticleMomentum.value() + ); + newParticle->setDieDistance(mParticleDieDistance.value()); + + newParticle->setLifetime(mParticleLifetime.value()); + newParticle->setFadeOut(mParticleFadeOut.value()); + newParticle->setFadeIn(mParticleFadeIn.value()); + + for (std::list::iterator i = mParticleChildEmitters.begin(); + i != mParticleChildEmitters.end(); + i++) + { + newParticle->addEmitter(new ParticleEmitter(*i)); + } + + newParticles.push_back(newParticle); + } + + return newParticles; +} diff --git a/src/particleemitter.h b/src/particleemitter.h index ca6d8622..37d067a6 100644 --- a/src/particleemitter.h +++ b/src/particleemitter.h @@ -1,120 +1,120 @@ -/* - * The Mana World - * Copyright 2006 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _PARTICLEEMITTER_H -#define _PARTICLEEMITTER_H - -#include - -#include "utils/xml.h" -#include "utils/minmax.h" - -#include "resources/animation.h" - -class Image; -class Map; -class Particle; - -/** - * Every Particle can have one or more particle emitters that create new - * particles when they are updated - */ -class ParticleEmitter -{ - public: - /** - * Constructor. - */ - ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map); - - /** - * Destructor. - */ - ~ParticleEmitter(); - - /** - * Spawns new particles - * @return: a list of created particles - */ - std::list createParticles(); - - /** - * Sets the target of the particles that are created - */ - void - setTarget(Particle *target) - { mParticleTarget = target; }; - - private: - template MinMax readMinMax(xmlNodePtr propertyNode, T def); - - /** - * initial position of particles: - */ - MinMax mParticlePosX, mParticlePosY, mParticlePosZ; - - /** - * initial vector of particles: - */ - MinMax mParticleAngleHorizontal, mParticleAngleVertical; - - /** - * Initial velocity of particles - */ - MinMax mParticlePower; - - /* - * Vector changing of particles: - */ - MinMax mParticleGravity; - MinMax mParticleRandomnes; - MinMax mParticleBounce; - - /* - * Properties of targeting particles: - */ - Particle *mParticleTarget; - MinMax mParticleAcceleration; - MinMax mParticleDieDistance; - MinMax mParticleMomentum; - - /* - * Behavior over time of the particles: - */ - MinMax mParticleLifetime; - MinMax mParticleFadeOut; - MinMax mParticleFadeIn; - - Map *mMap; /**< Map the particles are spawned on */ - - MinMax mOutput; /**< Number of particles spawned per update */ - - Image *mParticleImage; /**< Particle image, if used */ - - /** Filename of particle animation file */ - Animation mParticleAnimation; - - /** List of emitters the spawned particles are equipped with */ - std::list mParticleChildEmitters; -}; -#endif +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _PARTICLEEMITTER_H +#define _PARTICLEEMITTER_H + +#include + +#include "utils/xml.h" +#include "utils/minmax.h" + +#include "resources/animation.h" + +class Image; +class Map; +class Particle; + +/** + * Every Particle can have one or more particle emitters that create new + * particles when they are updated + */ +class ParticleEmitter +{ + public: + /** + * Constructor. + */ + ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map); + + /** + * Destructor. + */ + ~ParticleEmitter(); + + /** + * Spawns new particles + * @return: a list of created particles + */ + std::list createParticles(); + + /** + * Sets the target of the particles that are created + */ + void + setTarget(Particle *target) + { mParticleTarget = target; }; + + private: + template MinMax readMinMax(xmlNodePtr propertyNode, T def); + + /** + * initial position of particles: + */ + MinMax mParticlePosX, mParticlePosY, mParticlePosZ; + + /** + * initial vector of particles: + */ + MinMax mParticleAngleHorizontal, mParticleAngleVertical; + + /** + * Initial velocity of particles + */ + MinMax mParticlePower; + + /* + * Vector changing of particles: + */ + MinMax mParticleGravity; + MinMax mParticleRandomnes; + MinMax mParticleBounce; + + /* + * Properties of targeting particles: + */ + Particle *mParticleTarget; + MinMax mParticleAcceleration; + MinMax mParticleDieDistance; + MinMax mParticleMomentum; + + /* + * Behavior over time of the particles: + */ + MinMax mParticleLifetime; + MinMax mParticleFadeOut; + MinMax mParticleFadeIn; + + Map *mMap; /**< Map the particles are spawned on */ + + MinMax mOutput; /**< Number of particles spawned per update */ + + Image *mParticleImage; /**< Particle image, if used */ + + /** Filename of particle animation file */ + Animation mParticleAnimation; + + /** List of emitters the spawned particles are equipped with */ + std::list mParticleChildEmitters; +}; +#endif diff --git a/src/player.cpp b/src/player.cpp index fbac7fa9..9b9b3c09 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -74,7 +74,7 @@ Player::getType() const } void -Player::drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) +Player::drawName(Graphics *graphics, int offsetX, int offsetY) { int px = mPx + offsetX; int py = mPy + offsetY; diff --git a/src/player.h b/src/player.h index 90d8e5a9..a6bd557c 100644 --- a/src/player.h +++ b/src/player.h @@ -46,7 +46,7 @@ class Player : public Being getType() const; virtual void - drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY); + drawName(Graphics *graphics, int offsetX, int offsetY); virtual void setSex(Uint8 sex); diff --git a/src/properties.h b/src/properties.h index 56e90c0e..bcd114c1 100644 --- a/src/properties.h +++ b/src/properties.h @@ -34,13 +34,17 @@ class Properties { public: + /** + * Destructor. + */ virtual ~Properties() {} /** * Get a map property. * - * @param def default value, empty string by default + * @param name The name of the property. + * @param def Default value, empty string by default. * @return the value of the given property or the given default when it * doesn't exist. */ @@ -54,7 +58,8 @@ class Properties /** * Gets a map property as a float. * - * @param def default value, 0.0f by default + * @param name The name of the property. + * @param def Default value, 0.0f by default. * @return the value of the given property, or 0.0f when it doesn't * exist. */ @@ -74,6 +79,10 @@ class Properties /** * Returns whether a certain property is available. + * + * @param name The name of the property. + * @return true when a property is defined, + * false otherwise. */ bool hasProperty(const std::string &name) @@ -83,6 +92,9 @@ class Properties /** * Set a map property. + * + * @param name The name of the property. + * @param value The value of the property. */ void setProperty(const std::string &name, const std::string &value) diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 2d5cbe82..ad280eeb 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -159,7 +159,7 @@ Image* Image::load(void *buffer, unsigned int bufferSize, GLenum error = glGetError(); if (error) { - std::string errmsg = "Unkown error"; + std::string errmsg = "Unknown error"; switch (error) { case GL_INVALID_ENUM: @@ -343,5 +343,5 @@ SubImage::~SubImage() Image *SubImage::getSubImage(int x, int y, int w, int h) { - return NULL; + return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h); } diff --git a/src/resources/image.h b/src/resources/image.h index 1bdfbf48..23715ecb 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -60,6 +60,7 @@ class Image : public Resource * * @param buffer The memory buffer containing the image data. * @param bufferSize The size of the memory buffer in bytes. + * @param idPath The path identifying the resource. * * @return NULL if the an error occurred, a valid pointer * otherwise. diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 54a07c46..0029129c 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -1,53 +1,53 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_ITEM_MANAGER_H -#define _TMW_ITEM_MANAGER_H - -#include "iteminfo.h" - -#include - -/** - * The namespace that holds the item information. - */ -namespace ItemDB -{ - /** - * Loads the item data from items.xml. - */ - void load(); - - /** - * Frees item data. - */ - void unload(); - - const ItemInfo& get(int id); - - // Items database - typedef std::map ItemInfos; - typedef ItemInfos::iterator ItemInfoIterator; -} - -#endif +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_ITEM_MANAGER_H +#define _TMW_ITEM_MANAGER_H + +#include "iteminfo.h" + +#include + +/** + * The namespace that holds the item information. + */ +namespace ItemDB +{ + /** + * Loads the item data from items.xml. + */ + void load(); + + /** + * Frees item data. + */ + void unload(); + + const ItemInfo& get(int id); + + // Items database + typedef std::map ItemInfos; + typedef ItemInfos::iterator ItemInfoIterator; +} + +#endif diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h index ad21762d..d16ff1d5 100644 --- a/src/resources/mapreader.h +++ b/src/resources/mapreader.h @@ -55,8 +55,9 @@ class MapReader /** * Reads the properties element. * - * @param props the Properties instance to which the properties will - * be assigned + * @param node The properties element. + * @param props The Properties instance to which the properties will + * be assigned. */ static void readProperties(xmlNodePtr node, Properties* props); diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 2ea9aebe..f4864eea 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -1,175 +1,175 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#include "monsterdb.h" - -#include "resourcemanager.h" - -#include "../log.h" - -#include "../utils/dtor.h" -#include "../utils/xml.h" - -namespace -{ - MonsterDB::MonsterInfos mMonsterInfos; - MonsterInfo mUnknown; - bool mLoaded = false; -} - -void -MonsterDB::load() -{ - if (mLoaded) - return; - - mUnknown.setSprite("error.xml"); - mUnknown.setName("unnamed"); - - logger->log("Initializing monster database..."); - - ResourceManager *resman = ResourceManager::getInstance(); - int size; - char *data = (char*)resman->loadFile("monsters.xml", size); - - if (!data) - { - logger->error("Monster Database: Could not find monsters.xml!"); - } - - xmlDocPtr doc = xmlParseMemory(data, size); - free(data); - - if (!doc) - { - logger->error("Monster Database: Error while parsing monster database (monsters.xml)!"); - } - - xmlNodePtr rootNode = xmlDocGetRootElement(doc); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "monsters")) - { - logger->error("Monster Database: monster.xml is not a valid database file!"); - } - - //iterate s - for_each_xml_child_node(monsterNode, rootNode) - { - if (!xmlStrEqual(monsterNode->name, BAD_CAST "monster")) - { - continue; - } - - MonsterInfo *currentInfo = new MonsterInfo(); - - currentInfo->setName (XML::getProperty(monsterNode, "name", "unnamed")); - - std::string targetCursor; - targetCursor = XML::getProperty(monsterNode, "targetCursor", "medium"); - if (targetCursor == "small") - { - currentInfo->setTargetCursorSize(Being::TC_SMALL); - } - else if (targetCursor == "medium") - { - currentInfo->setTargetCursorSize(Being::TC_MEDIUM); - } - else if (targetCursor == "large") - { - currentInfo->setTargetCursorSize(Being::TC_LARGE); - } - else - { - logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s - using medium sized one", - targetCursor.c_str(), currentInfo->getName().c_str()); - currentInfo->setTargetCursorSize(Being::TC_MEDIUM); - } - - //iterate s and s - for_each_xml_child_node(spriteNode, monsterNode) - { - if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) - { - currentInfo->setSprite((const char*) spriteNode->xmlChildrenNode->content); - } - - if (xmlStrEqual(spriteNode->name, BAD_CAST "sound")) - { - std::string event = XML::getProperty(spriteNode, "event", ""); - const char *filename; - filename = (const char*) spriteNode->xmlChildrenNode->content; - - if (event == "hit") - { - currentInfo->addSound(MONSTER_EVENT_HIT, filename); - } - else if (event == "miss") - { - currentInfo->addSound(MONSTER_EVENT_MISS, filename); - } - else if (event == "hurt") - { - currentInfo->addSound(MONSTER_EVENT_HURT, filename); - } - else if (event == "die") - { - currentInfo->addSound(MONSTER_EVENT_DIE, filename); - } - else - { - logger->log("MonsterDB: Warning, sound effect %s for unknown event %s of monster %s", - filename, event.c_str(), currentInfo->getName().c_str()); - } - } - } - mMonsterInfos[XML::getProperty(monsterNode, "id", 0)] = currentInfo; - } - - mLoaded = true; -} - -void -MonsterDB::unload() -{ - for_each ( mMonsterInfos.begin(), mMonsterInfos.end(), - make_dtor(mMonsterInfos)); - mMonsterInfos.clear(); - - mLoaded = false; -} - - -const MonsterInfo& -MonsterDB::get (int id) -{ - MonsterInfoIterator i = mMonsterInfos.find(id); - - if (i == mMonsterInfos.end()) - { - logger->log("MonsterDB: Warning, unknown monster ID %d requested", id); - return mUnknown; - } - else - { - return *(i->second); - } -} +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "monsterdb.h" + +#include "resourcemanager.h" + +#include "../log.h" + +#include "../utils/dtor.h" +#include "../utils/xml.h" + +namespace +{ + MonsterDB::MonsterInfos mMonsterInfos; + MonsterInfo mUnknown; + bool mLoaded = false; +} + +void +MonsterDB::load() +{ + if (mLoaded) + return; + + mUnknown.setSprite("error.xml"); + mUnknown.setName("unnamed"); + + logger->log("Initializing monster database..."); + + ResourceManager *resman = ResourceManager::getInstance(); + int size; + char *data = (char*)resman->loadFile("monsters.xml", size); + + if (!data) + { + logger->error("Monster Database: Could not find monsters.xml!"); + } + + xmlDocPtr doc = xmlParseMemory(data, size); + free(data); + + if (!doc) + { + logger->error("Monster Database: Error while parsing monster database (monsters.xml)!"); + } + + xmlNodePtr rootNode = xmlDocGetRootElement(doc); + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "monsters")) + { + logger->error("Monster Database: monster.xml is not a valid database file!"); + } + + //iterate s + for_each_xml_child_node(monsterNode, rootNode) + { + if (!xmlStrEqual(monsterNode->name, BAD_CAST "monster")) + { + continue; + } + + MonsterInfo *currentInfo = new MonsterInfo(); + + currentInfo->setName (XML::getProperty(monsterNode, "name", "unnamed")); + + std::string targetCursor; + targetCursor = XML::getProperty(monsterNode, "targetCursor", "medium"); + if (targetCursor == "small") + { + currentInfo->setTargetCursorSize(Being::TC_SMALL); + } + else if (targetCursor == "medium") + { + currentInfo->setTargetCursorSize(Being::TC_MEDIUM); + } + else if (targetCursor == "large") + { + currentInfo->setTargetCursorSize(Being::TC_LARGE); + } + else + { + logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s - using medium sized one", + targetCursor.c_str(), currentInfo->getName().c_str()); + currentInfo->setTargetCursorSize(Being::TC_MEDIUM); + } + + //iterate s and s + for_each_xml_child_node(spriteNode, monsterNode) + { + if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) + { + currentInfo->setSprite((const char*) spriteNode->xmlChildrenNode->content); + } + + if (xmlStrEqual(spriteNode->name, BAD_CAST "sound")) + { + std::string event = XML::getProperty(spriteNode, "event", ""); + const char *filename; + filename = (const char*) spriteNode->xmlChildrenNode->content; + + if (event == "hit") + { + currentInfo->addSound(MONSTER_EVENT_HIT, filename); + } + else if (event == "miss") + { + currentInfo->addSound(MONSTER_EVENT_MISS, filename); + } + else if (event == "hurt") + { + currentInfo->addSound(MONSTER_EVENT_HURT, filename); + } + else if (event == "die") + { + currentInfo->addSound(MONSTER_EVENT_DIE, filename); + } + else + { + logger->log("MonsterDB: Warning, sound effect %s for unknown event %s of monster %s", + filename, event.c_str(), currentInfo->getName().c_str()); + } + } + } + mMonsterInfos[XML::getProperty(monsterNode, "id", 0)] = currentInfo; + } + + mLoaded = true; +} + +void +MonsterDB::unload() +{ + for_each ( mMonsterInfos.begin(), mMonsterInfos.end(), + make_dtor(mMonsterInfos)); + mMonsterInfos.clear(); + + mLoaded = false; +} + + +const MonsterInfo& +MonsterDB::get (int id) +{ + MonsterInfoIterator i = mMonsterInfos.find(id); + + if (i == mMonsterInfos.end()) + { + logger->log("MonsterDB: Warning, unknown monster ID %d requested", id); + return mUnknown; + } + else + { + return *(i->second); + } +} diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h index 9757d7f1..f0cd7d08 100644 --- a/src/resources/monsterdb.h +++ b/src/resources/monsterdb.h @@ -28,6 +28,9 @@ #include "monsterinfo.h" +/** + * Monster information database. + */ namespace MonsterDB { void diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp index b5fe3d29..7b7bad70 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -1,70 +1,70 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id: monsterinfo.cpp 2650 2006-09-03 15:00:47Z b_lindeijer $ - */ - -#include "monsterinfo.h" - -#include "../utils/dtor.h" - -MonsterInfo::MonsterInfo(): - mSprite("error.xml") -{ - -} - -MonsterInfo::~MonsterInfo() -{ - //kill vectors in mSoundEffects - for_each ( mSounds.begin(), mSounds.end(), - make_dtor(mSounds)); - mSounds.clear(); -} - - -void -MonsterInfo::addSound (MonsterSoundEvent event, std::string filename) -{ - if (mSounds.find(event) == mSounds.end()) - { - mSounds[event] = new std::vector; - } - - mSounds[event]->push_back("sfx/" + filename); -} - - -std::string -MonsterInfo::getSound (MonsterSoundEvent event) const -{ - std::map* >::const_iterator i; - - i = mSounds.find(event); - - if (i == mSounds.end()) - { - return ""; - } - else - { - return i->second->at(rand()%i->second->size()); - } -} +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: monsterinfo.cpp 2650 2006-09-03 15:00:47Z b_lindeijer $ + */ + +#include "monsterinfo.h" + +#include "../utils/dtor.h" + +MonsterInfo::MonsterInfo(): + mSprite("error.xml") +{ + +} + +MonsterInfo::~MonsterInfo() +{ + //kill vectors in mSoundEffects + for_each ( mSounds.begin(), mSounds.end(), + make_dtor(mSounds)); + mSounds.clear(); +} + + +void +MonsterInfo::addSound (MonsterSoundEvent event, std::string filename) +{ + if (mSounds.find(event) == mSounds.end()) + { + mSounds[event] = new std::vector; + } + + mSounds[event]->push_back("sfx/" + filename); +} + + +std::string +MonsterInfo::getSound (MonsterSoundEvent event) const +{ + std::map* >::const_iterator i; + + i = mSounds.find(event); + + if (i == mSounds.end()) + { + return ""; + } + else + { + return i->second->at(rand()%i->second->size()); + } +} diff --git a/src/resources/music.h b/src/resources/music.h index 9cf75928..2888eaa0 100644 --- a/src/resources/music.h +++ b/src/resources/music.h @@ -44,6 +44,7 @@ class Music : public Resource * * @param buffer The memory buffer containing the music data. * @param bufferSize The size of the memory buffer in bytes. + * @param idPath The path identifying the resource. * * @return NULL if the an error occurred, a valid pointer * otherwise. diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 985c11dd..448e7f80 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -92,7 +92,10 @@ void ResourceManager::cleanUp(Resource *res) { logger->log("ResourceManager::~ResourceManager() cleaning up %d " - "references to %s", res->mRefCount, res->mIdPath.c_str()); + "reference%s to %s", + res->mRefCount, + (res->mRefCount == 1) ? "" : "s", + res->mIdPath.c_str()); delete res; } diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index 92b0016a..007f5a77 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -45,6 +45,7 @@ class SoundEffect : public Resource * * @param buffer The memory buffer containing the sample data. * @param bufferSize The size of the memory buffer in bytes. + * @param idPath The path identifying the resource. * * @return NULL if the an error occurred, a valid pointer * otherwise. diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index f52fd172..18e732ef 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -111,7 +111,7 @@ SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode): void SimpleAnimation::update(unsigned int timePassed) { - mAnimationTime+=timePassed; + mAnimationTime += timePassed; while (mAnimationTime > mCurrentFrame->delay) { mAnimationTime -= mCurrentFrame->delay; diff --git a/src/sound.cpp b/src/sound.cpp index 1ef4c23d..8ba8fe99 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -208,6 +208,6 @@ void Sound::close() stopMusic(); mInstalled = false; - Mix_CloseAudio(); logger->log("Sound::close() Shutting down sound..."); + Mix_CloseAudio(); } diff --git a/src/sound.h b/src/sound.h index 07db0587..34490d9a 100644 --- a/src/sound.h +++ b/src/sound.h @@ -62,8 +62,8 @@ class Sound { /** * Starts background music. * - * \param in Full path to file - * \param loop The number of times the song is played (-1 = infinite) + * @param path The full path to the music file. + * @param loop The number of times the song is played (-1 = infinite) */ void playMusic(const char *path, int loop = -1); @@ -75,37 +75,37 @@ class Sound { /** * Fades in background music. * - * \param in Full path to file - * \param loop The number of times the song is played (-1 = infinite) - * \param ms Duration of fade-in effect (ms) + * @param path The full path to the music file. + * @param loop The number of times the song is played (-1 = infinite) + * @param ms Duration of fade-in effect (ms) */ void fadeInMusic(const char *path, int loop = -1, int ms = 2000); /** * Fades out currently running background music track. * - * \param ms Duration of fade-out effect (ms) + * @param ms Duration of fade-out effect (ms) */ void fadeOutMusic(int ms); /** * Sets music volume. * - * \param volume Volume value + * @param volume Volume value */ void setMusicVolume(int volume); /** * Sets sfx volume. * - * \param volume Volume value + * @param volume Volume value */ void setSfxVolume(int volume); /** * Plays an item. * - * \param path Full path to file + * @param path The resource path to the sound file. */ void playSfx(const std::string &path); diff --git a/src/utils/minmax.h b/src/utils/minmax.h index 088a23ef..ea6ad9e0 100644 --- a/src/utils/minmax.h +++ b/src/utils/minmax.h @@ -1,48 +1,48 @@ -/* - * The Mana World - * Copyright 2006 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -/** - * Returns a random numeric value that is larger than or equal min and smaller - * than max - */ - -template struct MinMax -{ - void set(T min, T max) - { - minVal=min; maxVal=max; - } - - void set(T val) - { - set(val, val); - } - - T value() - { - return (T)(minVal + (maxVal - minVal) * (rand() / ((double) RAND_MAX + 1))); - } - - T minVal; - T maxVal; -}; +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +/** + * Returns a random numeric value that is larger than or equal min and smaller + * than max + */ + +template struct MinMax +{ + void set(T min, T max) + { + minVal=min; maxVal=max; + } + + void set(T val) + { + set(val, val); + } + + T value() + { + return (T)(minVal + (maxVal - minVal) * (rand() / ((double) RAND_MAX + 1))); + } + + T minVal; + T maxVal; +}; -- cgit v1.2.3-60-g2f50