diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/engine.cpp | 3 | ||||
-rw-r--r-- | src/localplayer.cpp | 1 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 21 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 8 | ||||
-rw-r--r-- | src/sound.cpp | 4 |
7 files changed, 41 insertions, 4 deletions
@@ -1,3 +1,9 @@ +2008-01-13 David Athay <ko2fan@gmail.com> + + * src/resources/resourcemanager.h, src/resources/resourcemanager.cpp, + src/main.cpp, src/sound.cpp, src/engine.cpp: Fixed music loading from + non-default location. + 2008-01-03 Philipp Sehmisch <tmw@crushnet.org> * data/maps/new_1-1.tmx, data/maps/new_3-1.tmx: Some map bugs reported diff --git a/src/engine.cpp b/src/engine.cpp index 49ffbbfc..d84b8e00 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -116,8 +116,7 @@ void Engine::changeMap(const std::string &mapPath) std::string newMusic = newMap->getProperty("music"); if (newMusic != oldMusic) { - newMusic = std::string(TMW_DATADIR) + "data/music/" + newMusic; - sound.playMusic(newMusic.c_str(), -1); + sound.playMusic(newMusic, -1); } mCurrentMap = newMap; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 2d9da036..1b65d9bb 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -406,6 +406,7 @@ void LocalPlayer::attack(Being *target, bool keep) setAction(ATTACK); mWalkTime = tick_time; + if (mEquippedWeapon) { std::string soundFile = mEquippedWeapon->getSound(EQUIP_EVENT_STRIKE); diff --git a/src/main.cpp b/src/main.cpp index 4b6cfd3f..4e9936e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -615,7 +615,7 @@ int main(int argc, char *argv[]) progressBar->getY() + 4); progressBar->setVisible(false); - sound.playMusic(TMW_DATADIR "data/music/Magick - Real.ogg"); + sound.playMusic("Magick - Real.ogg"); loginData.username = options.username; if (loginData.username.empty()) { diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index fb9da9d7..59202ad8 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -200,6 +200,27 @@ ResourceManager::isDirectory(const std::string &path) return PHYSFS_isDirectory(path.c_str()); } +std::string +ResourceManager::getPath(const std::string &file) +{ + // get the real path to the file + const char* tmp = PHYSFS_getRealDir(file.c_str()); + std::string path; + + // if the file is not in the search path, then its NULL + if (tmp) + { + path = std::string(tmp) + "/" + file; + } + else + { + // if not found in search path return the default path + path = std::string(TMW_DATADIR) + std::string("data") + "/" + file; + } + + return path; +} + Resource *ResourceManager::get(std::string const &idPath, generator fun, void *data) { // Check if the id exists, and return the value if it does. diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index abfd629a..da85e2f9 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -104,6 +104,14 @@ class ResourceManager */ bool isDirectory(const std::string &path); + + /** + * Returns the real path to a file + * + * @param file The file to get the real path to. + * @return The real path. + */ + std::string getPath(const std::string &file); /** * Creates a resource and adds it to the resource map. diff --git a/src/sound.cpp b/src/sound.cpp index cf77cfab..9e265b52 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -126,13 +126,15 @@ void Sound::setSfxVolume(int volume) Mix_Volume(-1, volume); } -void Sound::playMusic(const std::string &path, int loop) +void Sound::playMusic(const std::string &filename, int loop) { if (!mInstalled) return; if (mMusic != NULL) { stopMusic(); } + + std::string path = mResourceManager->getPath("music/" + filename); logger->log("Sound::startMusic() Playing \"%s\" %i times", path.c_str(), loop); |