summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-12-30 18:12:35 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-12-30 18:12:35 +0000
commitaf8b15193ebaed1de77a8a77ec2a0fed75a0d253 (patch)
tree677b9b675008ea191ab765ca9c716f56244db7b1
parent3c0af406c2b8d74558e236f9f99862ea0e33bf4a (diff)
downloadmanaserv-af8b15193ebaed1de77a8a77ec2a0fed75a0d253.tar.gz
manaserv-af8b15193ebaed1de77a8a77ec2a0fed75a0d253.tar.bz2
manaserv-af8b15193ebaed1de77a8a77ec2a0fed75a0d253.tar.xz
manaserv-af8b15193ebaed1de77a8a77ec2a0fed75a0d253.zip
Added on-the-fly map loading.
-rw-r--r--ChangeLog2
-rw-r--r--src/game-server/mapmanager.cpp33
-rw-r--r--src/game-server/mapmanager.hpp6
3 files changed, 20 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 117de309..e6ab7d16 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,8 @@
src/player.h, src/game-server/gamehandler.cpp, src/Makefile.am:
Embedded a simplified version of GameClient into GameHandler. Removed
the original files.
+ * src/game-server/mapmanager.hpp, src/game-server/mapmanager.cpp: Added
+ on-the-fly map loading.
2006-12-29 Guillaume Melquiond <guillaume.melquiond@gmail.com>
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;
};