summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2006-03-20 22:42:08 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2006-03-20 22:42:08 +0000
commit5a3fad8c2d2846f33821507930b7a7f833b66eff (patch)
treec0d5104408d30de02e060aa424a2531cfc27ea41 /src
parentd1958facb18ff8311924b1eb0c7cf8688dc983be (diff)
downloadmana-5a3fad8c2d2846f33821507930b7a7f833b66eff.tar.gz
mana-5a3fad8c2d2846f33821507930b7a7f833b66eff.tar.bz2
mana-5a3fad8c2d2846f33821507930b7a7f833b66eff.tar.xz
mana-5a3fad8c2d2846f33821507930b7a7f833b66eff.zip
Fixed a crash on map change.
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp37
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);