Say strict

actorid
Jason Hooks 14 years ago
parent 93f41e25a4
commit 9eefee7168

@ -392,7 +392,7 @@ void OMW::Engine::go()
mOgre.getCamera(), mOgre.getCamera(),
mEnvironment.mWorld->getStore(), mEnvironment.mWorld->getStore(),
(mDataDir), (mDataDir),
mUseSound); mUseSound, mFSStrict);
// Create script system // Create script system
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full, mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full,

@ -63,7 +63,7 @@ namespace MWSound
*/ */
OEManagerPtr mgr; OEManagerPtr mgr;
SoundPtr music; SoundPtr music;
/* This class calls update() on the sound manager each frame /* This class calls update() on the sound manager each frame
using and Ogre::FrameListener using and Ogre::FrameListener
*/ */
@ -84,20 +84,22 @@ namespace MWSound
// finding. It takes DOS paths (any case, \\ slashes or / slashes) // finding. It takes DOS paths (any case, \\ slashes or / slashes)
// relative to the sound dir, and translates them into full paths // relative to the sound dir, and translates them into full paths
// of existing files in the filesystem, if they exist. // of existing files in the filesystem, if they exist.
bool FSstrict;
FileFinder::FileFinder files; FileFinder::FileFinder files;
FileFinder::FileFinderStrict strict;
SoundImpl(Ogre::Root *root, Ogre::Camera *camera, SoundImpl(Ogre::Root *root, Ogre::Camera *camera,
const ESMS::ESMStore &str, const ESMS::ESMStore &str,
const std::string &soundDir) const std::string &soundDir, bool fsstrict)
: mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY))) : mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY)))
, updater(mgr) , updater(mgr)
, cameraTracker(mgr) , cameraTracker(mgr)
, store(str) , store(str)
, files(soundDir) , files(soundDir), strict(soundDir)
{ {
FSstrict = fsstrict;
cout << "Sound output: " << SOUND_OUT << endl; cout << "Sound output: " << SOUND_OUT << endl;
cout << "Sound decoder: " << SOUND_IN << endl; cout << "Sound decoder: " << SOUND_IN << endl;
// Attach the camera to the camera tracker // Attach the camera to the camera tracker
cameraTracker.followCamera(camera); cameraTracker.followCamera(camera);
@ -124,15 +126,23 @@ namespace MWSound
bool hasFile(const std::string &str) bool hasFile(const std::string &str)
{ {
if(FSstrict == false){
if(files.has(str)) return true; if(files.has(str)) return true;
// Not found? Try with .mp3 // 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)); return files.has(toMp3(str));
} }
}
// Convert a Morrowind sound path (eg. Fx\funny.wav) to full path // Convert a Morrowind sound path (eg. Fx\funny.wav) to full path
// with proper slash conversion (eg. datadir/Sound/Fx/funny.wav) // with proper slash conversion (eg. datadir/Sound/Fx/funny.wav)
std::string convertPath(const std::string &str) std::string convertPath(const std::string &str)
{ {
if(FSstrict == false){
// Search and return // Search and return
if(files.has(str)) if(files.has(str))
return files.lookup(str); return files.lookup(str);
@ -141,6 +151,18 @@ namespace MWSound
std::string mp3 = toMp3(str); std::string mp3 = toMp3(str);
if(files.has(mp3)) if(files.has(mp3))
return files.lookup(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 // Give up
return ""; return "";
@ -307,12 +329,13 @@ namespace MWSound
SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera, SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera,
const ESMS::ESMStore &store, const ESMS::ESMStore &store,
boost::filesystem::path dataDir, boost::filesystem::path dataDir,
bool useSound) bool useSound, bool fsstrict)
: mData(NULL) : mData(NULL)
{ {
fsStrict = fsstrict;
MP3Lookup(dataDir / "Music/Explore/"); MP3Lookup(dataDir / "Music/Explore/");
if(useSound) if(useSound)
mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string()); mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), fsstrict);
} }
SoundManager::~SoundManager() SoundManager::~SoundManager()

@ -30,13 +30,16 @@ namespace MWSound
SoundImpl *mData; SoundImpl *mData;
std::vector<boost::filesystem::path> files; std::vector<boost::filesystem::path> files;
bool fsStrict;
public: public:
SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store,
boost::filesystem::path dataDir, bool useSound); boost::filesystem::path dataDir, bool useSound, bool fsstrict);
~SoundManager(); ~SoundManager();
void startRandomTitle(); void startRandomTitle();
void MP3Lookup(boost::filesystem::path dir); void MP3Lookup(boost::filesystem::path dir);
//struct SoundImpl; //struct SoundImpl;

@ -22,7 +22,7 @@ class FileFinderT
{ {
std::string file = pth.string(); std::string file = pth.string();
std::string key = file.substr(cut); 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 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. // Find the full path from a relative path.
const std::string &lookup(const std::string& file) const 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 // The default is to use path_less for equality checks
typedef FileFinderT<path_less> FileFinder; typedef FileFinderT<path_less> FileFinder;
typedef FileFinderT<path_slash> FileFinderStrict;
} }
#endif #endif

@ -44,6 +44,41 @@ struct path_less
return compareString(a.c_str(), b.c_str()) < 0; 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<b) return -1;
return 0;
}
int comparePathChar(char a, char b) const
{
if(a == '\\') a = '/';
if(b == '\\') b = '/';
return compareChar(a,b);
}
int compareString(const char *a, const char *b) const
{
while(*a && *b)
{
int i = comparePathChar(*a,*b);
if(i != 0) return i;
a++; b++;
}
// At this point, one or both of the chars is a null terminator.
// Normal char comparison will get the correct final result here.
return compareChar(*a,*b);
}
bool operator() (const std::string& a, const std::string& b) const
{
return compareString(a.c_str(), b.c_str()) < 0;
}
};
} }
#endif #endif

Loading…
Cancel
Save