diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-12-18 20:35:54 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-12-18 20:35:54 +0000 |
commit | 78ee1357ccaf6c821f07db045841c18da0c2ab66 (patch) | |
tree | bc5232fded1bd79fb7941f1270ebe14851ae3211 /src | |
parent | f83ed8b03c85fb485e0a85439f36c555ca1910ee (diff) | |
download | manaserv-78ee1357ccaf6c821f07db045841c18da0c2ab66.tar.gz manaserv-78ee1357ccaf6c821f07db045841c18da0c2ab66.tar.bz2 manaserv-78ee1357ccaf6c821f07db045841c18da0c2ab66.tar.xz manaserv-78ee1357ccaf6c821f07db045841c18da0c2ab66.zip |
Added a map manager to load/unload/relod maps.
Diffstat (limited to 'src')
-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 |
4 files changed, 172 insertions, 19 deletions
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++; } |