mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 20:56:39 +00:00 
			
		
		
		
	MP3 functions moved to soundmanager
This commit is contained in:
		
							parent
							
								
									be1582a88f
								
							
						
					
					
						commit
						a9892161af
					
				
					 4 changed files with 60 additions and 51 deletions
				
			
		|  | @ -6,6 +6,7 @@ | |||
| #include <iostream> | ||||
| #include <utility> | ||||
| 
 | ||||
| #include "components/esm/records.hpp" | ||||
| #include <components/esm_store/cell_store.hpp> | ||||
| #include <components/misc/fileops.hpp> | ||||
| #include <components/bsa/bsa_archive.hpp> | ||||
|  | @ -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<boost::filesystem::path>::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(); | ||||
|  |  | |||
|  | @ -54,7 +54,7 @@ namespace OMW | |||
| 
 | ||||
|     class Engine : private Ogre::FrameListener | ||||
|     { | ||||
| 			std::vector<boost::filesystem::path> 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.
 | ||||
|  |  | |||
|  | @ -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<boost::filesystem::path>::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); | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| #include <string> | ||||
| #include <map> | ||||
| 
 | ||||
| #include <boost/filesystem.hpp> | ||||
| #include "../mwworld/ptr.hpp" | ||||
| #include <openengine/sound/sndmanager.hpp> | ||||
| 
 | ||||
|  | @ -28,12 +29,16 @@ namespace MWSound | |||
|             struct SoundImpl; | ||||
| 			 | ||||
|             SoundImpl *mData; | ||||
| 			std::vector<boost::filesystem::path> 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(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue