diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/main.cpp | 29 | ||||
-rw-r--r-- | src/mapmanager.cpp | 77 | ||||
-rw-r--r-- | src/mapmanager.h | 75 | ||||
-rw-r--r-- | src/mapreader.cpp | 10 | ||||
-rw-r--r-- | tmwserv.dev | 230 |
6 files changed, 303 insertions, 124 deletions
@@ -1,3 +1,9 @@ +2005-12-18 Eugenio Favalli <elvenprogrammer@gmail.com> + + * src/main.cpp, src/mapreader.cpp, tmwserv.dev, + src/mapmanager.cpp, src/mapmanager.h: Added a map manager to + load/unload/relod maps. + 2005-12-18 Yohann Ferreira <bertram@cegetel.net> * src/accounthandler.cpp, src/netcomputer.h, src/netcomputer.cpp, diff --git a/src/main.cpp b/src/main.cpp index 419c00e2..f3064eda 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,28 +20,27 @@ * $Id$ */ - +#include <cstdlib> #include <iostream> - +#include <physfs.h> #include <SDL.h> #include <SDL_net.h> -#include <cstdlib> - #ifdef __USE_UNIX98 #include "../config.h" #endif -#include "netsession.h" -#include "connectionhandler.h" #include "accounthandler.h" -#include "gamehandler.h" #include "chathandler.h" -#include "storage.h" #include "configuration.h" -#include "state.h" - +#include "connectionhandler.h" +#include "gamehandler.h" +#include "mapmanager.h" +#include "netsession.h" +#include "resourcemanager.h" #include "skill.h" +#include "state.h" +#include "storage.h" #include "utils/logger.h" @@ -176,6 +175,14 @@ void initialize() config.init(configPath); LOG_INFO("Using Config File: " << configPath) LOG_INFO("Using Log File: " << LOG_FILE) + + // Initialize PhysicsFS + PHYSFS_init(""); + + // TODO: only a test, maps should be loaded as they are needed + tmwserv::MapManager::instance().loadMap("tulimshar.tmx.gz"); + tmwserv::MapManager::instance().reloadMap("tulimshar.tmx.gz"); + tmwserv::MapManager::instance().unloadMap("tulimshar.tmx.gz"); } @@ -206,6 +213,8 @@ void deinitialize() // Get rid of persistent data storage tmwserv::Storage::destroy(); + + PHYSFS_deinit(); } diff --git a/src/mapmanager.cpp b/src/mapmanager.cpp new file mode 100644 index 00000000..c307ee33 --- /dev/null +++ b/src/mapmanager.cpp @@ -0,0 +1,77 @@ +/* + * 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 "mapmanager.h" + +#include "mapreader.h" + +#include "utils/logger.h" + +namespace tmwserv +{ + + +MapManager::~MapManager() + throw() +{ +} + +void MapManager::loadMap(const std::string& mapFile) +{ + Map *map = MapReader::readMap("maps/" + mapFile); + if (map == NULL) + { + LOG_ERROR("Error: Unable to load map file (" << mapFile << ")"); + } + else + { + LOG_INFO("Loaded map " << maps.size() << " (" << mapFile << ")"); + maps[mapFile] = map; + } +} + +void MapManager::unloadMap(const std::string& mapFile) +{ + std::map<std::string, Map *>::iterator i; + + i = maps.find(mapFile); + if (i != maps.end()) + { + delete i->second; + maps.erase(i); + LOG_INFO("Unloaded map (" << mapFile << ")"); + } + else + { + LOG_WARN("Unable to unload map (" << mapFile << ")"); + } +} + +void MapManager::reloadMap(const std::string& mapFile) +{ + unloadMap(mapFile); + loadMap(mapFile); +} + + +} // namespace tmwserv diff --git a/src/mapmanager.h b/src/mapmanager.h new file mode 100644 index 00000000..c4051c4a --- /dev/null +++ b/src/mapmanager.h @@ -0,0 +1,75 @@ +/* + * 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_MAPMANAGER_H +#define _TMW_MAPMANAGER_H + +#include <map> + +#include "map.h" + +#include "utils/singleton.h" + +namespace tmwserv +{ + + +/** + * MapManager loads/unloads maps + */ +class MapManager: public utils::Singleton<MapManager> +{ + // friend so that Singleton can call the constructor. + friend class utils::Singleton<MapManager>; + + public: + /** + * Load the specified map + */ + void loadMap(const std::string& mapFile); + + /** + * Unload the specified map + */ + void unloadMap(const std::string& mapFile); + + /** + * Reload the specified map + */ + void reloadMap(const std::string& mapFile); + + protected: + /** + * Destructor. + */ + ~MapManager(void) + throw(); + + private: + // Hold all the loaded maps. + std::map<std::string, Map *> maps; +}; + +} // namespace tmwserv + +#endif diff --git a/src/mapreader.cpp b/src/mapreader.cpp index 15623b1b..ce41208d 100644 --- a/src/mapreader.cpp +++ b/src/mapreader.cpp @@ -38,13 +38,6 @@ namespace tmwserv const unsigned int DEFAULT_TILE_WIDTH = 32; const unsigned int DEFAULT_TILE_HEIGHT = 32; -// MSVC libxml2 at the moment doesn't work right when using MinGW, missing this -// function at link time. -#ifdef WIN32 -#undef xmlFree -#define xmlFree(x) ; -#endif - /** * Inflates either zlib or gzip deflated memory. The inflated memory is * expected to be freed by the caller. @@ -127,7 +120,7 @@ Map *MapReader::readMap(const std::string &filename) if (buffer == NULL) { - LOG_ERROR("Map file not found (" << filename.c_str() << ")"); + LOG_ERROR("Error: Map file not found (" << filename.c_str() << ")"); return NULL; } @@ -224,7 +217,6 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path) } else if (xmlStrEqual(node->name, BAD_CAST "layer")) { - LOG_INFO("- Loading layer " << layerNr); readLayer(node, map, layerNr); layerNr++; } diff --git a/tmwserv.dev b/tmwserv.dev index 697a008f..e9073186 100644 --- a/tmwserv.dev +++ b/tmwserv.dev @@ -5,7 +5,7 @@ Name=tmwserv UnitCount=17 ======= Name=tmwserv -UnitCount=71 +UnitCount=72 >>>>>>> 1.2 Type=1 Ver=1 @@ -17,7 +17,7 @@ ResourceIncludes= MakeIncludes= Compiler=_@@_ CppCompiler=-DSQLITE_SUPPORT_@@_ -Linker=-lmingw32_@@_-lSDL_@@_-lSDL_net_@@_-lsqlite3_@@_-lcrypto_@@_-llibxml2_@@_-lphysfs_@@_-lz_@@_-mconsole_@@_-mwindows_@@_ +Linker=-lmingw32_@@_-lSDL_@@_-lSDL_net_@@_-lsqlite3_@@_-lxml2_@@_-lphysfs_@@_-lz_@@_-lmsvcrt-ruby18.dll_@@_-mconsole_@@_-mwindows_@@_ IsCpp=1 Icon= ExeOutput= @@ -45,7 +45,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit14] -FileName=src\accounthandler.cpp +FileName=src\accounthandler.h CompileCpp=1 Folder= Compile=1 @@ -55,7 +55,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit15] -FileName=src\accounthandler.h +FileName=src\connectionhandler.cpp CompileCpp=1 Folder= Compile=1 @@ -83,7 +83,7 @@ ProductVersion= AutoIncBuildNr=0 [Unit24] -FileName=src\messagehandler.h +FileName=src\messagein.cpp CompileCpp=1 Folder= Compile=1 @@ -93,7 +93,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit26] -FileName=src\messagein.h +FileName=src\messageout.cpp CompileCpp=1 Folder= Compile=1 @@ -103,7 +103,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit27] -FileName=src\messageout.cpp +FileName=src\messageout.h CompileCpp=1 Folder= Compile=1 @@ -113,7 +113,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit28] -FileName=src\messageout.h +FileName=src\netcomputer.cpp CompileCpp=1 Folder= Compile=1 @@ -123,7 +123,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit29] -FileName=src\netcomputer.cpp +FileName=src\netcomputer.h CompileCpp=1 Folder= Compile=1 @@ -133,7 +133,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit31] -FileName=src\netsession.cpp +FileName=src\netsession.h CompileCpp=1 Folder= Compile=1 @@ -143,7 +143,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit30] -FileName=src\netcomputer.h +FileName=src\netsession.cpp CompileCpp=1 Folder= Compile=1 @@ -153,7 +153,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit34] -FileName=src\object.h +FileName=src\packet.cpp CompileCpp=1 Folder= Compile=1 @@ -163,7 +163,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit36] -FileName=src\packet.h +FileName=src\script.cpp CompileCpp=1 Folder= Compile=1 @@ -173,7 +173,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit32] -FileName=src\netsession.h +FileName=src\object.cpp CompileCpp=1 Folder= Compile=1 @@ -183,7 +183,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit33] -FileName=src\object.cpp +FileName=src\object.h CompileCpp=1 Folder= Compile=1 @@ -193,16 +193,6 @@ OverrideBuildCmd=0 BuildCmd= [Unit37] -FileName=src\script.cpp -CompileCpp=1 -Folder= -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit38] FileName=src\script.h CompileCpp=1 Folder= @@ -212,8 +202,8 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit39] -FileName=src\script-squirrel.cpp +[Unit38] +FileName=src\skill.cpp CompileCpp=1 Folder= Compile=1 @@ -223,7 +213,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit40] -FileName=src\script-squirrel.h +FileName=src\storage.cpp CompileCpp=1 Folder= Compile=1 @@ -233,7 +223,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit41] -FileName=src\skill.cpp +FileName=src\storage.h CompileCpp=1 Folder= Compile=1 @@ -243,7 +233,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit21] -FileName=src\defines.h +FileName=src\main.cpp CompileCpp=1 Folder= Compile=1 @@ -313,7 +303,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit12] -FileName=src\utils\logger.h +FileName=src\utils\singleton.h CompileCpp=1 Folder=utils Compile=1 @@ -323,9 +313,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit13] -FileName=src\utils\singleton.h +FileName=src\accounthandler.cpp CompileCpp=1 -Folder=utils +Folder= Compile=1 Link=1 Priority=1000 @@ -333,7 +323,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit18] -FileName=src\dalstorage.cpp +FileName=src\debug.cpp CompileCpp=1 Folder= Compile=1 @@ -343,7 +333,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit19] -FileName=src\debug.cpp +FileName=src\debug.h CompileCpp=1 Folder= Compile=1 @@ -353,7 +343,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit20] -FileName=src\debug.h +FileName=src\defines.h CompileCpp=1 Folder= Compile=1 @@ -363,7 +353,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit35] -FileName=src\packet.cpp +FileName=src\packet.h CompileCpp=1 Folder= Compile=1 @@ -373,9 +363,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit42] -FileName=src\skill.h +FileName=src\dalstorage.h CompileCpp=1 -Folder= +Folder=tmwserv Compile=1 Link=1 Priority=1000 @@ -383,9 +373,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit43] -FileName=src\storage.cpp +FileName=src\account.h CompileCpp=1 -Folder= +Folder=tmwserv Compile=1 Link=1 Priority=1000 @@ -393,17 +383,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit44] -FileName=src\storage.h -CompileCpp=1 -Folder= -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit45] -FileName=src\dalstorage.h +FileName=src\account.cpp CompileCpp=1 Folder=tmwserv Compile=1 @@ -413,7 +393,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit47] -FileName=src\account.cpp +FileName=src\being.cpp CompileCpp=1 Folder=tmwserv Compile=1 @@ -423,9 +403,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit49] -FileName=src\utils\countedptr.h +FileName=src\configuration.cpp CompileCpp=1 -Folder=utils +Folder=tmwserv Compile=1 Link=1 Priority=1000 @@ -433,7 +413,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit54] -FileName=src\configuration.h +FileName=src\chathandler.h CompileCpp=1 Folder=tmwserv Compile=1 @@ -443,7 +423,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit55] -FileName=src\dalstoragesql.h +FileName=src\chathandler.cpp CompileCpp=1 Folder=tmwserv Compile=1 @@ -453,7 +433,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit56] -FileName=src\items.h +FileName=src\resourcemanager.h CompileCpp=1 Folder=tmwserv Compile=1 @@ -463,7 +443,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit58] -FileName=src\chathandler.h +FileName=src\map.h CompileCpp=1 Folder=tmwserv Compile=1 @@ -473,7 +453,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit59] -FileName=src\chathandler.cpp +FileName=src\mapreader.h CompileCpp=1 Folder=tmwserv Compile=1 @@ -483,9 +463,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit61] -FileName=src\map.cpp +FileName=src\utils\base64.h CompileCpp=1 -Folder=tmwserv +Folder=utils Compile=1 Link=1 Priority=1000 @@ -493,9 +473,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit62] -FileName=src\map.h +FileName=src\utils\base64.cpp CompileCpp=1 -Folder=tmwserv +Folder=utils Compile=1 Link=1 Priority=1000 @@ -503,7 +483,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit64] -FileName=src\resourcemanager.cpp +FileName=src\state.cpp CompileCpp=1 Folder=tmwserv Compile=1 @@ -513,9 +493,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit65] -FileName=src\utils\base64.h +FileName=src\gamehandler.h CompileCpp=1 -Folder=utils +Folder=tmwserv Compile=1 Link=1 Priority=1000 @@ -543,17 +523,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit11] -FileName=src\utils\logger.cpp -CompileCpp=1 -Folder=utils -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit10] -FileName=src\utils\cipher.h +FileName=src\utils\logger.h CompileCpp=1 Folder=utils Compile=1 @@ -563,7 +533,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit17] -FileName=src\connectionhandler.h +FileName=src\dalstorage.cpp CompileCpp=1 Folder= Compile=1 @@ -573,7 +543,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit22] -FileName=src\main.cpp +FileName=src\messagehandler.cpp CompileCpp=1 Folder= Compile=1 @@ -583,7 +553,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit23] -FileName=src\messagehandler.cpp +FileName=src\messagehandler.h CompileCpp=1 Folder= Compile=1 @@ -593,7 +563,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit25] -FileName=src\messagein.cpp +FileName=src\messagein.h CompileCpp=1 Folder= Compile=1 @@ -603,9 +573,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit46] -FileName=src\account.h +FileName=src\utils\functors.h CompileCpp=1 -Folder=tmwserv +Folder=utils Compile=1 Link=1 Priority=1000 @@ -613,7 +583,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit16] -FileName=src\connectionhandler.cpp +FileName=src\connectionhandler.h CompileCpp=1 Folder= Compile=1 @@ -623,7 +593,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit63] -FileName=src\mapreader.h +FileName=src\state.h CompileCpp=1 Folder=tmwserv Compile=1 @@ -633,9 +603,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit50] -FileName=src\utils\functors.h +FileName=src\configuration.h CompileCpp=1 -Folder=utils +Folder=tmwserv Compile=1 Link=1 Priority=1000 @@ -643,7 +613,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit51] -FileName=src\being.cpp +FileName=src\dalstoragesql.h CompileCpp=1 Folder=tmwserv Compile=1 @@ -653,7 +623,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit52] -FileName=src\being.h +FileName=src\items.h CompileCpp=1 Folder=tmwserv Compile=1 @@ -663,9 +633,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit48] -FileName=src\utils\cipher.cpp +FileName=src\being.h CompileCpp=1 -Folder=utils +Folder=tmwserv Compile=1 Link=1 Priority=1000 @@ -673,7 +643,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit53] -FileName=src\configuration.cpp +FileName=src\SDL_win32_main.c CompileCpp=1 Folder=tmwserv Compile=1 @@ -683,7 +653,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit57] -FileName=src\SDL_win32_main.c +FileName=src\map.cpp CompileCpp=1 Folder=tmwserv Compile=1 @@ -693,7 +663,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit60] -FileName=src\resourcemanager.h +FileName=src\resourcemanager.cpp CompileCpp=1 Folder=tmwserv Compile=1 @@ -703,9 +673,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit66] -FileName=src\utils\base64.cpp +FileName=src\items.cpp CompileCpp=1 -Folder=utils +Folder=tmwserv Compile=1 Link=1 Priority=1000 @@ -713,7 +683,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit67] -FileName=src\state.h +FileName=src\gamehandler.cpp CompileCpp=1 Folder=tmwserv Compile=1 @@ -723,9 +693,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit68] -FileName=src\state.cpp +FileName=src\mapmanager.h CompileCpp=1 -Folder=tmwserv +Folder= Compile=1 Link=1 Priority=1000 @@ -733,9 +703,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit69] -FileName=src\gamehandler.h +FileName=src\mapmanager.cpp CompileCpp=1 -Folder=tmwserv +Folder= Compile=1 Link=1 Priority=1000 @@ -743,17 +713,67 @@ OverrideBuildCmd=0 BuildCmd= [Unit70] -FileName=src\items.cpp +FileName=src\bindings.i +CompileCpp=1 +Folder=tmwserv +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit71] +FileName=scripts\init.rb CompileCpp=1 Folder=tmwserv +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit39] +FileName=src\skill.h +CompileCpp=1 +Folder= Compile=1 Link=1 Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit71] -FileName=src\gamehandler.cpp +[Unit74] +FileName=src\resource.h +CompileCpp=1 +Folder=tmwserv +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=src\utils\logger.cpp +CompileCpp=1 +Folder=utils +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit45] +FileName=src\utils\countedptr.h +CompileCpp=1 +Folder=utils +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit72] +FileName=src\mapreader.cpp CompileCpp=1 Folder=tmwserv Compile=1 |