diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 8b21f6e63..af8434bba 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -6,6 +6,7 @@ #include #include +#include "components/esm/records.hpp" #include #include #include @@ -41,6 +42,8 @@ #include "mwgui/class.hpp" +//using namespace ESM; + void OMW::Engine::executeLocalScripts() { for (MWWorld::World::ScriptList::const_iterator iter ( @@ -60,53 +63,14 @@ void OMW::Engine::executeLocalScripts() mIgnoreLocalPtr = MWWorld::Ptr(); } -void OMW::Engine::MP3Lookup() -{ - boost::filesystem::directory_iterator dir_iter(mDataDir / "Music/Explore/"), dir_end; - - std::string mp3extension = ".mp3"; - for(;dir_iter != dir_end; dir_iter++) - { - if(boost::filesystem::extension(*dir_iter) == mp3extension) - { - files.push_back(*dir_iter); - } - } -} - -void OMW::Engine::startRandomTitle() -{ - std::vector::iterator fileIter; - - if(files.size() > 0) - { - fileIter = files.begin(); - srand ( time(NULL) ); - int r = rand() % files.size() + 1; //old random code - for(int i = 1; i < r; i++) - { - fileIter++; - } - std::string music = fileIter->file_string(); - try - { - std::cout << "Playing " << music << "\n"; - mEnvironment.mSoundManager->streamMusic(music); - } - catch(std::exception &e) - { - std::cout << " Music Error: " << e.what() << "\n"; - } - } -} bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) { if(! (mEnvironment.mSoundManager->isMusicPlaying())) { // Play some good 'ol tunes - startRandomTitle(); + mEnvironment.mSoundManager->startRandomTitle(); } std::string effect; @@ -120,7 +84,7 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) if (test.name != current->cell->region) { total = 0; - test = *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); + test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); } if(test.soundList.size() > 0) @@ -329,7 +293,6 @@ void OMW::Engine::go() assert (!mCellName.empty()); assert (!mMaster.empty()); - MP3Lookup(); test.name = ""; total = 0; @@ -374,7 +337,7 @@ void OMW::Engine::go() mEnvironment.mSoundManager = new MWSound::SoundManager(mOgre.getRoot(), mOgre.getCamera(), mEnvironment.mWorld->getStore(), - (mDataDir / "Sound").file_string(), + (mDataDir), mUseSound); // Create script system @@ -412,7 +375,7 @@ void OMW::Engine::go() mOgre.getRoot()->addFrameListener (this); // Play some good 'ol tunes - startRandomTitle(); + mEnvironment.mSoundManager->startRandomTitle(); // Start the main rendering loop mOgre.start(); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 54748b2c6..89ce320a8 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -54,7 +54,7 @@ namespace OMW class Engine : private Ogre::FrameListener { - std::vector files; + //int nFiles; boost::filesystem::path mDataDir; OEngine::Render::OgreRenderer mOgre; @@ -85,8 +85,7 @@ namespace OMW /// add resources directory /// \note This function works recursively. - void OMW::Engine::MP3Lookup(); - void startRandomTitle(); + void addResourcesDirectory (const boost::filesystem::path& path); /// Load all BSA files in data directory. diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 3dedab9ef..8bdd8e2b9 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -306,12 +306,13 @@ namespace MWSound SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &store, - const std::string &soundDir, + boost::filesystem::path dataDir, bool useSound) : mData(NULL) { + MP3Lookup(dataDir / "Music/Explore/"); if(useSound) - mData = new SoundImpl(root, camera, store, soundDir); + mData = new SoundImpl(root, camera, store, (dataDir / "Sound").file_string()); } SoundManager::~SoundManager() @@ -320,6 +321,48 @@ namespace MWSound delete mData; } + void SoundManager::MP3Lookup(boost::filesystem::path dir) +{ + boost::filesystem::directory_iterator dir_iter(dir), dir_end; + + std::string mp3extension = ".mp3"; + for(;dir_iter != dir_end; dir_iter++) + { + if(boost::filesystem::extension(*dir_iter) == mp3extension) + { + files.push_back(*dir_iter); + } + } +} + + void SoundManager::startRandomTitle() +{ + std::vector::iterator fileIter; + + if(files.size() > 0) + { + fileIter = files.begin(); + srand ( time(NULL) ); + int r = rand() % files.size() + 1; //old random code + + for(int i = 1; i < r; i++) + { + fileIter++; + } + std::string music = fileIter->file_string(); + try + { + std::cout << "Playing " << music << "\n"; + streamMusic(music); + } + catch(std::exception &e) + { + std::cout << " Music Error: " << e.what() << "\n"; + } + } +} + + bool SoundManager::isMusicPlaying() { bool test = mData->music->isPlaying(); @@ -369,7 +412,6 @@ namespace MWSound void SoundManager::playSound (const std::string& soundId, float volume, float pitch) { if(!mData) return; - // Play and forget float min, max; const std::string &file = mData->lookup(soundId, volume, min, max); diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 017069a63..8717bf8dd 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -4,6 +4,7 @@ #include #include +#include #include "../mwworld/ptr.hpp" #include @@ -28,12 +29,16 @@ namespace MWSound struct SoundImpl; SoundImpl *mData; + std::vector files; public: SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, - const std::string &soundDir, bool useSound); + boost::filesystem::path dataDir, bool useSound); ~SoundManager(); + + void startRandomTitle(); + void MP3Lookup(boost::filesystem::path dir); //struct SoundImpl; bool isMusicPlaying();