From 9eefee7168ca3a6fe6b5b75e4e39918309a39f6a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 11 Jun 2011 20:01:21 -0400 Subject: [PATCH] Say strict --- apps/openmw/engine.cpp | 2 +- apps/openmw/mwsound/soundmanager.cpp | 35 ++++++++++++++++++++---- apps/openmw/mwsound/soundmanager.hpp | 7 +++-- components/file_finder/file_finder.hpp | 7 +++-- components/file_finder/filename_less.hpp | 35 ++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 12 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index a160e0993..97596301c 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -392,7 +392,7 @@ void OMW::Engine::go() mOgre.getCamera(), mEnvironment.mWorld->getStore(), (mDataDir), - mUseSound); + mUseSound, mFSStrict); // Create script system mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full, diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 564ebe941..72e62421f 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -63,7 +63,7 @@ namespace MWSound */ OEManagerPtr mgr; SoundPtr music; - + /* This class calls update() on the sound manager each frame using and Ogre::FrameListener */ @@ -84,20 +84,22 @@ namespace MWSound // finding. It takes DOS paths (any case, \\ slashes or / slashes) // relative to the sound dir, and translates them into full paths // of existing files in the filesystem, if they exist. + bool FSstrict; FileFinder::FileFinder files; + FileFinder::FileFinderStrict strict; SoundImpl(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &str, - const std::string &soundDir) + const std::string &soundDir, bool fsstrict) : mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY))) , updater(mgr) , cameraTracker(mgr) , store(str) - , files(soundDir) + , files(soundDir), strict(soundDir) { + FSstrict = fsstrict; cout << "Sound output: " << SOUND_OUT << endl; cout << "Sound decoder: " << SOUND_IN << endl; - // Attach the camera to the camera tracker cameraTracker.followCamera(camera); @@ -124,15 +126,23 @@ namespace MWSound bool hasFile(const std::string &str) { + if(FSstrict == false){ if(files.has(str)) return true; // Not found? Try with .mp3 + return files.has(toMp3(str)); + } + else{ + if(strict.has(str)) return true; + // Not found? Try with .mp3 return files.has(toMp3(str)); } + } // Convert a Morrowind sound path (eg. Fx\funny.wav) to full path // with proper slash conversion (eg. datadir/Sound/Fx/funny.wav) std::string convertPath(const std::string &str) { + if(FSstrict == false){ // Search and return if(files.has(str)) return files.lookup(str); @@ -141,6 +151,18 @@ namespace MWSound std::string mp3 = toMp3(str); if(files.has(mp3)) return files.lookup(mp3); + } + + else + { + if(files.has(str)) + return files.lookup(str); + + // Try mp3 if the wav wasn't found + std::string mp3 = toMp3(str); + if(files.has(mp3)) + return files.lookup(mp3); + } // Give up return ""; @@ -307,12 +329,13 @@ namespace MWSound SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &store, boost::filesystem::path dataDir, - bool useSound) + bool useSound, bool fsstrict) : mData(NULL) { + fsStrict = fsstrict; MP3Lookup(dataDir / "Music/Explore/"); if(useSound) - mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string()); + mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), fsstrict); } SoundManager::~SoundManager() diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 8c48986db..b76e71e39 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -30,13 +30,16 @@ namespace MWSound SoundImpl *mData; std::vector files; + bool fsStrict; - public: + + SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, - boost::filesystem::path dataDir, bool useSound); + boost::filesystem::path dataDir, bool useSound, bool fsstrict); ~SoundManager(); + void startRandomTitle(); void MP3Lookup(boost::filesystem::path dir); //struct SoundImpl; diff --git a/components/file_finder/file_finder.hpp b/components/file_finder/file_finder.hpp index cfa07dce9..358563afa 100644 --- a/components/file_finder/file_finder.hpp +++ b/components/file_finder/file_finder.hpp @@ -22,7 +22,7 @@ class FileFinderT { std::string file = pth.string(); std::string key = file.substr(cut); - owner->table[key] = file; + owner->table[key] = file; } }; @@ -50,17 +50,18 @@ public: bool has(const std::string& file) const { - return table.find(file) != table.end(); + return table.find(file) != table.end(); } // Find the full path from a relative path. const std::string &lookup(const std::string& file) const { - return table.find(file)->second; + return table.find(file)->second; } }; // The default is to use path_less for equality checks typedef FileFinderT FileFinder; +typedef FileFinderT FileFinderStrict; } #endif diff --git a/components/file_finder/filename_less.hpp b/components/file_finder/filename_less.hpp index 9f251b1c8..bc3186ce9 100644 --- a/components/file_finder/filename_less.hpp +++ b/components/file_finder/filename_less.hpp @@ -44,6 +44,41 @@ struct path_less return compareString(a.c_str(), b.c_str()) < 0; } }; + +struct path_slash +{ + int compareChar(char a, char b) const + { + if(a>b) return 1; + else if(a