summaryrefslogtreecommitdiff
path: root/src/game-server/mapmanager.cpp
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-07 16:50:47 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-07 16:50:47 +0000
commit04e694b067a21dee8e13368c17d1815cc0624ce4 (patch)
treea57ab98d76040838fa369e6823544baeb19d1bbc /src/game-server/mapmanager.cpp
parent60b4a57bdfe664a6729b3573a6a614621b6c2b2c (diff)
downloadmanaserv-04e694b067a21dee8e13368c17d1815cc0624ce4.tar.gz
manaserv-04e694b067a21dee8e13368c17d1815cc0624ce4.tar.bz2
manaserv-04e694b067a21dee8e13368c17d1815cc0624ce4.tar.xz
manaserv-04e694b067a21dee8e13368c17d1815cc0624ce4.zip
Simplified code by using map pointers only, instead of using both map IDs and map pointers.
Diffstat (limited to 'src/game-server/mapmanager.cpp')
-rw-r--r--src/game-server/mapmanager.cpp62
1 files changed, 24 insertions, 38 deletions
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index dac57cac..7de489c3 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -25,6 +25,7 @@
#include "resourcemanager.h"
#include "game-server/map.hpp"
+#include "game-server/mapcomposite.hpp"
#include "game-server/mapmanager.hpp"
#include "game-server/mapreader.hpp"
#include "utils/logger.h"
@@ -72,8 +73,7 @@ MapManager::MapManager(std::string const &mapReferenceFile)
std::string name = XML::getProperty(node, "name", std::string());
if (id != 0 && !name.empty())
{
- LoadedMap m = { false, name, NULL };
- maps[id] = m;
+ maps[id] = new MapComposite(id, name);
}
}
@@ -84,54 +84,40 @@ MapManager::~MapManager()
{
for (Maps::iterator i = maps.begin(), i_end = maps.end(); i != i_end; ++i)
{
- delete i->second.map;
+ delete i->second;
}
}
-Map* MapManager::getMap(int mapId)
+MapComposite *MapManager::getMap(int mapId)
{
Maps::iterator i = maps.find(mapId);
- assert(i != maps.end() && i->second.isActive);
- 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 << ")");
- return NULL;
- }
- LOG_INFO("Loaded map \"" << file << "\" (id " << mapId << ")");
- }
- return map;
-}
-
-std::string MapManager::getMapName(int mapId) const
-{
- Maps::const_iterator i = maps.find(mapId);
assert(i != maps.end());
- return i->second.fileName;
+ return i->second;
}
void MapManager::raiseActive(int mapId)
{
Maps::iterator i = maps.find(mapId);
assert(i != maps.end());
- i->second.isActive = true;
- LOG_INFO("Activating map \"" << i->second.fileName << "\" (id "
- << i->first << ")");
-}
+ MapComposite *composite = i->second;
+ if (composite->isActive())
+ {
+ return;
+ }
-bool MapManager::isActive(int mapId) const
-{
- Maps::const_iterator i = maps.find(mapId);
- assert(i != maps.end());
- return i->second.isActive;
-}
+ std::string const &file = composite->getName();
+ Map *map = MapReader::readMap("maps/" + file);
+ if (!map)
+ {
+ LOG_ERROR("Unable to load map \"" << file << "\" (id "
+ << mapId << ")");
+ return;
+ }
-short MapManager::numberOfMaps() const
-{
- return maps.size();
+ composite->setMap(map);
+ LOG_INFO("Activated map \"" << file << "\" (id " << mapId << ")");
+ // will need to load extra map related resources here also
+ extern void testingMap(MapComposite *);
+ testingMap(composite);
}
+