move params t oa struct

simplify fallback
This commit is contained in:
Glenn Maynard
2007-04-06 18:56:53 +00:00
parent 1067755333
commit af1d2c40ed
3 changed files with 70 additions and 26 deletions
+31 -17
View File
@@ -43,7 +43,6 @@ static float g_fDimVolume = 1.0f;
static float g_fOriginalVolume = 1.0f;
static float g_fDimDurationRemaining = 0.0f;
static bool g_bWasPlayingOnLastUpdate = false;
static RString g_sFallbackMusicPath;
struct MusicPlaying
{
@@ -95,6 +94,7 @@ struct MusicToPlay
}
};
vector<MusicToPlay> g_MusicsToPlay;
static GameSoundManager::PlayMusicParams g_FallbackMusic;
static void StartMusic( MusicToPlay &ToPlay )
{
@@ -470,10 +470,11 @@ void GameSoundManager::Update( float fDeltaTime )
g_Mutex->Lock();
bool bIsPlaying = g_Playing->m_Music->IsPlaying();
g_Mutex->Unlock();
if( !bIsPlaying && g_bWasPlayingOnLastUpdate && !g_sFallbackMusicPath.empty() )
if( !bIsPlaying && g_bWasPlayingOnLastUpdate && !g_FallbackMusic.sFile.empty() )
{
PlayMusic( g_sFallbackMusicPath, NULL, false, 0, -1, 1.5f );
g_sFallbackMusicPath = "";
PlayMusic( g_FallbackMusic );
g_FallbackMusic.sFile = "";
}
g_bWasPlayingOnLastUpdate = bIsPlaying;
}
@@ -651,34 +652,47 @@ void GameSoundManager::PlayMusic(
float fLengthSeconds,
float fFadeInLengthSeconds,
float fFadeOutLengthSeconds,
bool bAlignBeat,
RString sFallback
bool bAlignBeat
)
{
g_sFallbackMusicPath = sFallback;
PlayMusicParams params;
params.sFile = sFile;
params.pTiming = pTiming;
params.bForceLoop = bForceLoop;
params.fStartSecond = fStartSecond;
params.fLengthSeconds = fLengthSeconds;
params.fFadeInLengthSeconds = fFadeInLengthSeconds;
params.fFadeOutLengthSeconds = fFadeOutLengthSeconds;
params.bAlignBeat = bAlignBeat;
PlayMusic( params );
}
void GameSoundManager::PlayMusic( PlayMusicParams params, PlayMusicParams FallbackMusic )
{
g_FallbackMusic = FallbackMusic;
// LOG->Trace("play '%s' (current '%s')", file.c_str(), g_Playing->m_Music->GetLoadedFilePath().c_str());
MusicToPlay ToPlay;
ToPlay.m_sFile = sFile;
if( pTiming )
ToPlay.m_sFile = params.sFile;
if( params.pTiming )
{
ToPlay.HasTiming = true;
ToPlay.m_TimingData = *pTiming;
ToPlay.m_TimingData = *params.pTiming;
}
else
{
/* If no timing data was provided, look for it in the same place as the music file. */
ToPlay.m_sTimingFile = SetExtension( sFile, "sm" );
ToPlay.m_sTimingFile = SetExtension( params.sFile, "sm" );
}
ToPlay.bForceLoop = bForceLoop;
ToPlay.fStartSecond = fStartSecond;
ToPlay.fLengthSeconds = fLengthSeconds;
ToPlay.fFadeInLengthSeconds = fFadeInLengthSeconds;
ToPlay.fFadeOutLengthSeconds = fFadeOutLengthSeconds;
ToPlay.bAlignBeat = bAlignBeat;
ToPlay.bForceLoop = params.bForceLoop;
ToPlay.fStartSecond = params.fStartSecond;
ToPlay.fLengthSeconds = params.fLengthSeconds;
ToPlay.fFadeInLengthSeconds = params.fFadeInLengthSeconds;
ToPlay.fFadeOutLengthSeconds = params.fFadeOutLengthSeconds;
ToPlay.bAlignBeat = params.bAlignBeat;
/* Add the MusicToPlay to the g_MusicsToPlay queue. */
g_Mutex->Lock();
+24 -2
View File
@@ -16,6 +16,29 @@ public:
~GameSoundManager();
void Update( float fDeltaTime );
struct PlayMusicParams
{
PlayMusicParams()
{
pTiming = NULL;
bForceLoop = false;
fStartSecond = 0;
fLengthSeconds = -1;
fFadeInLengthSeconds = 0;
fFadeOutLengthSeconds = 0;
bAlignBeat = true;
}
RString sFile;
const TimingData *pTiming;
bool bForceLoop;
float fStartSecond;
float fLengthSeconds;
float fFadeInLengthSeconds;
float fFadeOutLengthSeconds;
bool bAlignBeat;
};
void PlayMusic( PlayMusicParams params, PlayMusicParams FallbackMusic = PlayMusicParams() );
void PlayMusic(
RString sFile,
const TimingData *pTiming = NULL,
@@ -24,8 +47,7 @@ public:
float length_sec = -1,
float fFadeInLengthSeconds = 0,
float fade_len = 0,
bool align_beat = true,
RString sFallback = "" );
bool align_beat = true );
void StopMusic() { PlayMusic(""); }
void DimMusic( float fVolume, float fDurationSeconds );
RString GetMusicPath() const;
+15 -7
View File
@@ -289,13 +289,21 @@ void ScreenSelectMusic::CheckBackgroundRequests( bool bForce )
g_bSampleMusicWaiting = false;
SOUND->PlayMusic(
m_sSampleMusicToPlay, m_pSampleMusicTimingData,
SAMPLE_MUSIC_LOOPS, m_fSampleStartSeconds, m_fSampleLengthSeconds,
0.0f,
1.5f, /* fade out for 1.5 seconds */
ALIGN_MUSIC_BEATS,
m_sLoopMusicPath );
GameSoundManager::PlayMusicParams PlayParams;
PlayParams.sFile = m_sSampleMusicToPlay;
PlayParams.pTiming = m_pSampleMusicTimingData;
PlayParams.bForceLoop = SAMPLE_MUSIC_LOOPS;
PlayParams.fStartSecond = m_fSampleStartSeconds;
PlayParams.fLengthSeconds = m_fSampleLengthSeconds;
PlayParams.fFadeOutLengthSeconds = 1.5f;
PlayParams.bAlignBeat = ALIGN_MUSIC_BEATS;
GameSoundManager::PlayMusicParams FallbackMusic;
FallbackMusic.sFile = m_sLoopMusicPath;
FallbackMusic.fFadeInLengthSeconds = 1.5f;
FallbackMusic.bAlignBeat = ALIGN_MUSIC_BEATS;
SOUND->PlayMusic( PlayParams, FallbackMusic );
}
}