diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-03-20 22:42:08 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-03-20 22:42:08 +0000 |
commit | 5a3fad8c2d2846f33821507930b7a7f833b66eff (patch) | |
tree | c0d5104408d30de02e060aa424a2531cfc27ea41 /src/engine.cpp | |
parent | d1958facb18ff8311924b1eb0c7cf8688dc983be (diff) | |
download | mana-5a3fad8c2d2846f33821507930b7a7f833b66eff.tar.gz mana-5a3fad8c2d2846f33821507930b7a7f833b66eff.tar.bz2 mana-5a3fad8c2d2846f33821507930b7a7f833b66eff.tar.xz mana-5a3fad8c2d2846f33821507930b7a7f833b66eff.zip |
Fixed a crash on map change.
Diffstat (limited to 'src/engine.cpp')
-rw-r--r-- | src/engine.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index 8d78a078..724c0930 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -116,42 +116,47 @@ Engine::~Engine() void Engine::changeMap(const std::string &mapPath) { - // Clear floor items and beings + // Clean up floor items floorItemManager->clear(); - beingManager->clear(); - std::string oldMusic; - // Remove old map - if (mCurrentMap) { - oldMusic = mCurrentMap->getProperty("music"); - delete mCurrentMap; - } + beingManager->clear(); - // Generate full map path + // Store full map path in global var map_path = "maps/" + mapPath.substr(0, mapPath.rfind(".")) + ".tmx.gz"; // Attempt to load the new map - if (!(mCurrentMap = MapReader::readMap(map_path))) { + Map *newMap = MapReader::readMap(map_path); + + if (!newMap) { logger->error("Could not find map file"); } // Notify the minimap and beingManager about the map change Image *mapImage = NULL; - if (mCurrentMap->hasProperty("minimap")) { + if (newMap->hasProperty("minimap")) { ResourceManager *resman = ResourceManager::getInstance(); - mapImage = resman->getImage(mCurrentMap->getProperty("minimap")); + mapImage = resman->getImage(newMap->getProperty("minimap")); } minimap->setMapImage(mapImage); - beingManager->setMap(mCurrentMap); + beingManager->setMap(newMap); - // Change the music, if necessary - std::string newMusic = mCurrentMap->getProperty("music"); + // Start playing new music file when necessary + std::string oldMusic = ""; + + if (mCurrentMap) { + oldMusic = mCurrentMap->getProperty("music"); + delete mCurrentMap; + } + + std::string newMusic = newMap->getProperty("music"); if (newMusic != oldMusic) { - newMusic = std::string(TMW_DATADIR "data/music/") + newMusic; + newMusic = std::string(TMW_DATADIR) + "data/music/" + newMusic; sound.playMusic(newMusic.c_str(), -1); } + mCurrentMap = newMap; + // Send "map loaded" MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_MAP_LOADED); |