fix music glitches
This commit is contained in:
@@ -54,6 +54,8 @@ struct MusicToPlay
|
|||||||
bool HasTiming;
|
bool HasTiming;
|
||||||
bool force_loop;
|
bool force_loop;
|
||||||
float start_sec, length_sec, fade_len;
|
float start_sec, length_sec, fade_len;
|
||||||
|
bool pending;
|
||||||
|
MusicToPlay() { pending=false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
static MusicToPlay g_MusicToPlay;
|
static MusicToPlay g_MusicToPlay;
|
||||||
@@ -142,10 +144,16 @@ void StartPlayingMusic( const RageTimer &when, const MusicToPlay &ToPlay, MusicP
|
|||||||
|
|
||||||
void StartMusic( MusicToPlay &ToPlay )
|
void StartMusic( MusicToPlay &ToPlay )
|
||||||
{
|
{
|
||||||
if( ToPlay.file.empty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
LockMutex L( *g_Mutex );
|
LockMutex L( *g_Mutex );
|
||||||
|
|
||||||
|
if( ToPlay.file.empty() )
|
||||||
|
{
|
||||||
|
if( g_Playing->m_Music.IsPlaying() )
|
||||||
|
g_Playing->m_Music.StopPlaying();
|
||||||
|
g_Playing->m_Music.Unload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MusicPlaying *NewMusic = new MusicPlaying;
|
MusicPlaying *NewMusic = new MusicPlaying;
|
||||||
NewMusic->m_Timing = g_Playing->m_Timing;
|
NewMusic->m_Timing = g_Playing->m_Timing;
|
||||||
|
|
||||||
@@ -239,13 +247,13 @@ int MusicThread_start( void *p )
|
|||||||
StartQueuedSounds();
|
StartQueuedSounds();
|
||||||
|
|
||||||
LockMutex L( *g_Mutex );
|
LockMutex L( *g_Mutex );
|
||||||
if( !g_MusicToPlay.file.size() )
|
if( !g_MusicToPlay.pending )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* We have a sound to start. Don't keep the lock while we do this; if another
|
/* We have a sound to start. Don't keep the lock while we do this; if another
|
||||||
* music tries to start in the meantime, it'll cause a skip. */
|
* music tries to start in the meantime, it'll cause a skip. */
|
||||||
MusicToPlay ToPlay = g_MusicToPlay;
|
MusicToPlay ToPlay = g_MusicToPlay;
|
||||||
g_MusicToPlay.file = "";
|
g_MusicToPlay.pending = false;
|
||||||
|
|
||||||
L.Unlock();
|
L.Unlock();
|
||||||
|
|
||||||
@@ -342,16 +350,9 @@ void RageSounds::PlayMusic( const CString &file, const CString &timing_file, boo
|
|||||||
{
|
{
|
||||||
LockMut( *g_Mutex );
|
LockMut( *g_Mutex );
|
||||||
// LOG->Trace("play '%s' (current '%s')", file.c_str(), g_Playing->m_Music.GetLoadedFilePath().c_str());
|
// LOG->Trace("play '%s' (current '%s')", file.c_str(), g_Playing->m_Music.GetLoadedFilePath().c_str());
|
||||||
if( g_Playing->m_Music.IsPlaying() )
|
if( g_Playing->m_Music.IsPlaying() && !g_Playing->m_Music.GetLoadedFilePath().CompareNoCase(file) )
|
||||||
{
|
|
||||||
if( !g_Playing->m_Music.GetLoadedFilePath().CompareNoCase(file) )
|
|
||||||
return; // do nothing
|
return; // do nothing
|
||||||
|
|
||||||
g_Playing->m_Music.StopPlaying();
|
|
||||||
}
|
|
||||||
|
|
||||||
g_Playing->m_Music.Unload();
|
|
||||||
|
|
||||||
MusicToPlay ToPlay;
|
MusicToPlay ToPlay;
|
||||||
|
|
||||||
ToPlay.file = file;
|
ToPlay.file = file;
|
||||||
@@ -360,6 +361,7 @@ void RageSounds::PlayMusic( const CString &file, const CString &timing_file, boo
|
|||||||
ToPlay.length_sec = length_sec;
|
ToPlay.length_sec = length_sec;
|
||||||
ToPlay.fade_len = fade_len;
|
ToPlay.fade_len = fade_len;
|
||||||
ToPlay.timing_file = timing_file;
|
ToPlay.timing_file = timing_file;
|
||||||
|
ToPlay.pending = true;
|
||||||
|
|
||||||
/* If no timing file was specified, look for one in the same place as the music file. */
|
/* If no timing file was specified, look for one in the same place as the music file. */
|
||||||
if( ToPlay.timing_file == "" )
|
if( ToPlay.timing_file == "" )
|
||||||
@@ -368,7 +370,6 @@ void RageSounds::PlayMusic( const CString &file, const CString &timing_file, boo
|
|||||||
if( g_ThreadedMusicStart )
|
if( g_ThreadedMusicStart )
|
||||||
{
|
{
|
||||||
g_MusicToPlay = ToPlay;
|
g_MusicToPlay = ToPlay;
|
||||||
/* XXX: kick the music start thread */
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
StartMusic( ToPlay );
|
StartMusic( ToPlay );
|
||||||
|
|||||||
Reference in New Issue
Block a user