diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-30 18:12:35 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-30 18:12:35 +0000 |
commit | af8b15193ebaed1de77a8a77ec2a0fed75a0d253 (patch) | |
tree | 677b9b675008ea191ab765ca9c716f56244db7b1 /src | |
parent | 3c0af406c2b8d74558e236f9f99862ea0e33bf4a (diff) | |
download | manaserv-af8b15193ebaed1de77a8a77ec2a0fed75a0d253.tar.gz manaserv-af8b15193ebaed1de77a8a77ec2a0fed75a0d253.tar.bz2 manaserv-af8b15193ebaed1de77a8a77ec2a0fed75a0d253.tar.xz manaserv-af8b15193ebaed1de77a8a77ec2a0fed75a0d253.zip |
Added on-the-fly map loading.
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/mapmanager.cpp | 33 | ||||
-rw-r--r-- | src/game-server/mapmanager.hpp | 6 |
2 files changed, 18 insertions, 21 deletions
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp index 3b2caedf..6ba7464b 100644 --- a/src/game-server/mapmanager.cpp +++ b/src/game-server/mapmanager.cpp @@ -70,8 +70,11 @@ MapManager::MapManager(std::string const &mapReferenceFile) unsigned id = XML::getProperty(node, "id", 0); std::string name = XML::getProperty(node, "name", std::string()); - // TODO: load only local maps - loadMap(id, name); + if (id != 0 && !name.empty()) + { + LoadedMap m = { name, NULL }; + maps[id] = m; + } } xmlFreeDoc(doc); @@ -85,23 +88,23 @@ MapManager::~MapManager() } } -void MapManager::loadMap(unsigned mapId, std::string const &mapFile) -{ - LoadedMap m = { mapFile, MapReader::readMap("maps/" + mapFile) }; - if (m.map == NULL) - { - LOG_ERROR("Unable to load map \"" << mapFile << "\" (id " << mapId << ")", 0); - return; - } - LOG_INFO("Loaded map \"" << mapFile << "\" (id " << mapId << ")", 0); - maps[mapId] = m; -} - Map *MapManager::getMap(unsigned mapId) { Maps::iterator i = maps.find(mapId); assert(i != maps.end()); - return i->second.map; + Map *&map = i->second.map; + if (!map) + { + std::string const &file = i->second.fileName; + map = MapReader::readMap("maps/" + file); + if (!map) + { + LOG_ERROR("Unable to load map \"" << file << "\" (id " << mapId << ")", 0); + return NULL; + } + LOG_INFO("Loaded map \"" << file << "\" (id " << mapId << ")", 0); + } + return map; } std::string MapManager::getMapName(unsigned mapId) diff --git a/src/game-server/mapmanager.hpp b/src/game-server/mapmanager.hpp index 1090a850..7ac3970b 100644 --- a/src/game-server/mapmanager.hpp +++ b/src/game-server/mapmanager.hpp @@ -69,12 +69,6 @@ class MapManager ~MapManager(); private: - /** - * Loads the specified map. - */ - void loadMap(unsigned, std::string const &); - - // Hold all the loaded maps. Maps maps; }; |