mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-01 08:06:41 +00:00
Say strict
This commit is contained in:
parent
93f41e25a4
commit
9eefee7168
5 changed files with 74 additions and 12 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -62,5 +62,6 @@ public:
|
|||
|
||||
// The default is to use path_less for equality checks
|
||||
typedef FileFinderT<path_less> FileFinder;
|
||||
typedef FileFinderT<path_slash> FileFinderStrict;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,5 +45,40 @@ struct path_less
|
|||
}
|
||||
};
|
||||
|
||||
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…
Reference in a new issue