add SOUND->PlayOnceFromAnnouncer(); this is now the preferred
way to play an announcer. Announcer files are in many separate directories; scanning a directory can cause a skip, so we don't want to do that in the main thread during gameplay.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "NotesLoaderSM.h"
|
||||
#include "PrefsManager.h"
|
||||
#include "RageDisplay.h"
|
||||
#include "AnnouncerManager.h"
|
||||
|
||||
RageSounds *SOUND = NULL;
|
||||
|
||||
@@ -64,6 +65,7 @@ static RageThread MusicThread;
|
||||
#include "RageUtil_CircularBuffer.h"
|
||||
CircBuf<CString *> g_SoundsToPlayOnce;
|
||||
CircBuf<CString *> g_SoundsToPlayOnceFromDir;
|
||||
CircBuf<CString *> g_SoundsToPlayOnceFromAnnouncer;
|
||||
|
||||
struct MusicToPlay
|
||||
{
|
||||
@@ -199,6 +201,27 @@ static void StartMusic( MusicToPlay &ToPlay )
|
||||
g_Playing = NewMusic;
|
||||
}
|
||||
|
||||
static void DoPlayOnceFromDir( CString sPath )
|
||||
{
|
||||
if( sPath == "" )
|
||||
return;
|
||||
|
||||
// make sure there's a slash at the end of this path
|
||||
if( sPath.Right(1) != "/" )
|
||||
sPath += "/";
|
||||
|
||||
CStringArray arraySoundFiles;
|
||||
GetDirListing( sPath + "*.mp3", arraySoundFiles );
|
||||
GetDirListing( sPath + "*.wav", arraySoundFiles );
|
||||
GetDirListing( sPath + "*.ogg", arraySoundFiles );
|
||||
|
||||
if( arraySoundFiles.empty() )
|
||||
return;
|
||||
|
||||
int index = rand() % arraySoundFiles.size();
|
||||
SOUNDMAN->PlayOnce( sPath + arraySoundFiles[index] );
|
||||
}
|
||||
|
||||
static void StartQueuedSounds()
|
||||
{
|
||||
CString *p;
|
||||
@@ -210,26 +233,18 @@ static void StartQueuedSounds()
|
||||
}
|
||||
|
||||
while( g_SoundsToPlayOnceFromDir.read( &p, 1 ) )
|
||||
{
|
||||
CString sPath( *p );
|
||||
DoPlayOnceFromDir( sPath );
|
||||
delete p;
|
||||
}
|
||||
|
||||
while( g_SoundsToPlayOnceFromAnnouncer.read( &p, 1 ) )
|
||||
{
|
||||
CString sPath( *p );
|
||||
if( sPath != "" )
|
||||
{
|
||||
// make sure there's a slash at the end of this path
|
||||
if( sPath.Right(1) != "/" )
|
||||
sPath += "/";
|
||||
|
||||
CStringArray arraySoundFiles;
|
||||
GetDirListing( sPath + "*.mp3", arraySoundFiles );
|
||||
GetDirListing( sPath + "*.wav", arraySoundFiles );
|
||||
GetDirListing( sPath + "*.ogg", arraySoundFiles );
|
||||
|
||||
if( arraySoundFiles.empty() )
|
||||
return;
|
||||
|
||||
int index = rand() % arraySoundFiles.size();
|
||||
SOUNDMAN->PlayOnce( sPath + arraySoundFiles[index] );
|
||||
}
|
||||
|
||||
sPath = ANNOUNCER->GetPathTo( sPath );
|
||||
DoPlayOnceFromDir( sPath );
|
||||
delete p;
|
||||
}
|
||||
|
||||
@@ -264,6 +279,7 @@ RageSounds::RageSounds()
|
||||
|
||||
g_SoundsToPlayOnce.reserve( 16 );
|
||||
g_SoundsToPlayOnceFromDir.reserve( 16 );
|
||||
g_SoundsToPlayOnceFromAnnouncer.reserve( 16 );
|
||||
g_MusicsToPlay.reserve( 16 );
|
||||
|
||||
g_Mutex = new RageMutex("RageSounds");
|
||||
@@ -300,6 +316,9 @@ RageSounds::~RageSounds()
|
||||
while( g_SoundsToPlayOnceFromDir.read( &p, 1 ) )
|
||||
delete p;
|
||||
|
||||
while( g_SoundsToPlayOnceFromAnnouncer.read( &p, 1 ) )
|
||||
delete p;
|
||||
|
||||
MusicToPlay *pMusic;
|
||||
while( g_MusicsToPlay.read( &pMusic, 1 ) )
|
||||
delete pMusic;
|
||||
@@ -465,6 +484,17 @@ void RageSounds::PlayOnceFromDir( CString PlayOnceFromDir )
|
||||
StartQueuedSounds();
|
||||
}
|
||||
|
||||
void RageSounds::PlayOnceFromAnnouncer( CString sFolderName )
|
||||
{
|
||||
/* Add the path to the g_SoundsToPlayOnceFromDir queue. */
|
||||
CString *p = new CString( sFolderName );
|
||||
if( !g_SoundsToPlayOnceFromAnnouncer.write( &p, 1 ) )
|
||||
delete p;
|
||||
|
||||
if( !g_ThreadedMusicStart )
|
||||
StartQueuedSounds();
|
||||
}
|
||||
|
||||
float RageSounds::GetPlayLatency() const
|
||||
{
|
||||
return SOUNDMAN->GetPlayLatency();
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
|
||||
void PlayOnce( CString sPath );
|
||||
void PlayOnceFromDir( CString sDir );
|
||||
void PlayOnceFromAnnouncer( CString sFolderName );
|
||||
|
||||
float GetPlayLatency() const;
|
||||
void HandleSongTimer( bool on=true );
|
||||
|
||||
Reference in New Issue
Block a user