From 44620ada861e9060f5eb6e0dd1817bd7bd0614d9 Mon Sep 17 00:00:00 2001 From: Michael Papageorgiou Date: Fri, 9 Mar 2012 03:22:16 +0200 Subject: [PATCH] SoundManager: Finish up with Task #172, plus cleanup --- apps/openmw/mwsound/soundmanager.cpp | 27 +++++++++++++++------------ apps/openmw/mwsound/soundmanager.hpp | 21 ++++++--------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 5f48081f2..105dc5a3d 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include "../mwworld/environment.hpp" @@ -102,9 +101,6 @@ namespace MWSound // Tell Ogre to update the sound system each frame root->addFrameListener(&updater); } - - test.name = ""; - total = 0; } SoundManager::~SoundManager() @@ -430,15 +426,22 @@ namespace MWSound void SoundManager::update (float duration) { MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); + static int total = 0; + static std::string regionName = ""; + static float timePassed = 0.0; + timePassed += duration; //If the region has changed - if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10) + if(!(current->cell->data.flags & current->cell->Interior) && timePassed >= 10) { - timer.restart(); - if (test.name != current->cell->region) + + ESM::Region test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); + + timePassed = 0; + if (regionName != current->cell->region) { + regionName = current->cell->region; total = 0; - test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); } if(test.soundList.size() > 0) @@ -462,15 +465,15 @@ namespace MWSound soundIter = test.soundList.begin(); while (soundIter != test.soundList.end()) { - const ESM::NAME32 go = soundIter->sound; + const std::string go = soundIter->sound.toString(); int chance = (int) soundIter->chance; //std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; soundIter++; if( r - pos < chance) { //play sound - std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; - mEnvironment.mSoundManager->playSound(go.name, 20.0, 1.0); + std::cout << "Sound: " << go <<" Chance:" << chance << "\n"; + mEnvironment.mSoundManager->playSound(go, 20.0, 1.0); break; } @@ -480,7 +483,7 @@ namespace MWSound } else if(current->cell->data.flags & current->cell->Interior) { - test.name = ""; + regionName = ""; } } diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 64cac7713..39370d755 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -3,15 +3,11 @@ #include -#include -#include - #include #include #include -#include -#include + #include #include "../mwworld/ptr.hpp" @@ -28,17 +24,11 @@ namespace Mangle namespace Sound { typedef boost::shared_ptr SoundPtr; - //struct OgreOutputUpdater; } } typedef OEngine::Sound::SoundManagerPtr OEManagerPtr; -namespace ESMS -{ - struct ESMStore; -} - namespace MWWorld { struct Environment; @@ -57,10 +47,6 @@ namespace MWSound MWWorld::Environment& mEnvironment; - int total; - ESM::Region test; - boost::timer timer; - void streamMusicFull (const std::string& filename); ///< Play a soundifle /// \param absolute filename @@ -85,10 +71,13 @@ namespace MWSound typedef std::map PtrMap; PtrMap sounds; + // A list of all sound files used to lookup paths Files::PathContainer mSoundFiles; + // A library of all Music file paths stored by the folder they are contained in Files::FileLibrary mMusicLibrary; + // Points to the current playlist of music files stored in the music library const Files::PathContainer* mCurrentPlaylist; std::string lookup(const std::string &soundId, @@ -115,8 +104,10 @@ namespace MWSound /// \param filename name of a sound file in "Music/" in the data directory. void startRandomTitle(); + ///< Starts a random track from the current playlist bool isMusicPlaying(); + ///< Returns true if music is playing bool setPlaylist(std::string playlist=""); ///< Set the playlist to an existing folder