Say strict

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

@ -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,

@ -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()

@ -30,13 +30,16 @@ namespace MWSound
SoundImpl *mData;
std::vector<boost::filesystem::path> 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;

@ -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<path_less> FileFinder;
typedef FileFinderT<path_slash> FileFinderStrict;
}
#endif

@ -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<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

Loading…
Cancel
Save