mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	Replace the sound file extension when opening fails
This should make it more efficient to lookup a sound instead of checking each time it's played. A better method would perhaps be to check if the resource exists when the ESM is loaded and replace it then as needed.
This commit is contained in:
		
							parent
							
								
									8056a7f20b
								
							
						
					
					
						commit
						aecc77a73c
					
				
					 3 changed files with 23 additions and 16 deletions
				
			
		|  | @ -238,7 +238,17 @@ size_t FFmpeg_Decoder::MyStream::readAVAudioData(void *data, size_t length) | |||
| void FFmpeg_Decoder::open(const std::string &fname) | ||||
| { | ||||
|     close(); | ||||
|     mDataStream = mResourceMgr.openResource(fname); | ||||
|     try | ||||
|     { | ||||
|         mDataStream = mResourceMgr.openResource(fname); | ||||
|     } | ||||
|     catch(Ogre::Exception &e) | ||||
|     { | ||||
|         std::string::size_type pos = fname.rfind('.'); | ||||
|         if(pos == std::string::npos) | ||||
|             throw; | ||||
|         mDataStream = mResourceMgr.openResource(fname.substr(0, pos)+".mp3"); | ||||
|     } | ||||
| 
 | ||||
|     if((mFormatCtx=avformat_alloc_context()) == NULL) | ||||
|         fail("Failed to allocate context"); | ||||
|  |  | |||
|  | @ -81,7 +81,17 @@ off_t MpgSnd_Decoder::ogrempg_lseek(void *user_data, off_t offset, int whence) | |||
| void MpgSnd_Decoder::open(const std::string &fname) | ||||
| { | ||||
|     close(); | ||||
|     mDataStream = mResourceMgr.openResource(fname); | ||||
|     try | ||||
|     { | ||||
|         mDataStream = mResourceMgr.openResource(fname); | ||||
|     } | ||||
|     catch(Ogre::Exception &e) | ||||
|     { | ||||
|         std::string::size_type pos = fname.rfind('.'); | ||||
|         if(pos == std::string::npos) | ||||
|             throw; | ||||
|         mDataStream = mResourceMgr.openResource(fname.substr(0, pos)+".mp3"); | ||||
|     } | ||||
| 
 | ||||
|     SF_VIRTUAL_IO streamIO = { | ||||
|         ogresf_get_filelen, ogresf_seek, | ||||
|  |  | |||
|  | @ -107,14 +107,7 @@ namespace MWSound | |||
|             max = std::max(min, max); | ||||
|         } | ||||
| 
 | ||||
|         std::string fname = std::string("Sound\\")+snd->sound; | ||||
|         if(!mResourceMgr->resourceExistsInAnyGroup(fname)) | ||||
|         { | ||||
|             std::string::size_type pos = fname.rfind('.'); | ||||
|             if(pos != std::string::npos) | ||||
|                 fname = fname.substr(0, pos)+".mp3"; | ||||
|         } | ||||
|         return fname; | ||||
|         return std::string("Sound/")+snd->sound; | ||||
|     } | ||||
| 
 | ||||
|     // Add a sound to the list and play it
 | ||||
|  | @ -207,12 +200,6 @@ namespace MWSound | |||
|     { | ||||
|         // The range values are not tested
 | ||||
|         std::string filePath = std::string("Sound\\")+filename; | ||||
|         if(!mResourceMgr->resourceExistsInAnyGroup(filePath)) | ||||
|         { | ||||
|             std::string::size_type pos = filePath.rfind('.'); | ||||
|             if(pos != std::string::npos) | ||||
|                 filePath = filePath.substr(0, pos)+".mp3"; | ||||
|         } | ||||
|         play3d(filePath, ptr, "_say_sound", 1, 1, 100, 20000, false); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue