move params t oa struct
simplify fallback
This commit is contained in:
@@ -43,7 +43,6 @@ static float g_fDimVolume = 1.0f;
|
|||||||
static float g_fOriginalVolume = 1.0f;
|
static float g_fOriginalVolume = 1.0f;
|
||||||
static float g_fDimDurationRemaining = 0.0f;
|
static float g_fDimDurationRemaining = 0.0f;
|
||||||
static bool g_bWasPlayingOnLastUpdate = false;
|
static bool g_bWasPlayingOnLastUpdate = false;
|
||||||
static RString g_sFallbackMusicPath;
|
|
||||||
|
|
||||||
struct MusicPlaying
|
struct MusicPlaying
|
||||||
{
|
{
|
||||||
@@ -95,6 +94,7 @@ struct MusicToPlay
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
vector<MusicToPlay> g_MusicsToPlay;
|
vector<MusicToPlay> g_MusicsToPlay;
|
||||||
|
static GameSoundManager::PlayMusicParams g_FallbackMusic;
|
||||||
|
|
||||||
static void StartMusic( MusicToPlay &ToPlay )
|
static void StartMusic( MusicToPlay &ToPlay )
|
||||||
{
|
{
|
||||||
@@ -470,10 +470,11 @@ void GameSoundManager::Update( float fDeltaTime )
|
|||||||
g_Mutex->Lock();
|
g_Mutex->Lock();
|
||||||
bool bIsPlaying = g_Playing->m_Music->IsPlaying();
|
bool bIsPlaying = g_Playing->m_Music->IsPlaying();
|
||||||
g_Mutex->Unlock();
|
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 );
|
PlayMusic( g_FallbackMusic );
|
||||||
g_sFallbackMusicPath = "";
|
|
||||||
|
g_FallbackMusic.sFile = "";
|
||||||
}
|
}
|
||||||
g_bWasPlayingOnLastUpdate = bIsPlaying;
|
g_bWasPlayingOnLastUpdate = bIsPlaying;
|
||||||
}
|
}
|
||||||
@@ -651,34 +652,47 @@ void GameSoundManager::PlayMusic(
|
|||||||
float fLengthSeconds,
|
float fLengthSeconds,
|
||||||
float fFadeInLengthSeconds,
|
float fFadeInLengthSeconds,
|
||||||
float fFadeOutLengthSeconds,
|
float fFadeOutLengthSeconds,
|
||||||
bool bAlignBeat,
|
bool bAlignBeat
|
||||||
RString sFallback
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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());
|
// LOG->Trace("play '%s' (current '%s')", file.c_str(), g_Playing->m_Music->GetLoadedFilePath().c_str());
|
||||||
|
|
||||||
MusicToPlay ToPlay;
|
MusicToPlay ToPlay;
|
||||||
|
|
||||||
ToPlay.m_sFile = sFile;
|
ToPlay.m_sFile = params.sFile;
|
||||||
if( pTiming )
|
if( params.pTiming )
|
||||||
{
|
{
|
||||||
ToPlay.HasTiming = true;
|
ToPlay.HasTiming = true;
|
||||||
ToPlay.m_TimingData = *pTiming;
|
ToPlay.m_TimingData = *params.pTiming;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* If no timing data was provided, look for it in the same place as the music file. */
|
/* 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.bForceLoop = params.bForceLoop;
|
||||||
ToPlay.fStartSecond = fStartSecond;
|
ToPlay.fStartSecond = params.fStartSecond;
|
||||||
ToPlay.fLengthSeconds = fLengthSeconds;
|
ToPlay.fLengthSeconds = params.fLengthSeconds;
|
||||||
ToPlay.fFadeInLengthSeconds = fFadeInLengthSeconds;
|
ToPlay.fFadeInLengthSeconds = params.fFadeInLengthSeconds;
|
||||||
ToPlay.fFadeOutLengthSeconds = fFadeOutLengthSeconds;
|
ToPlay.fFadeOutLengthSeconds = params.fFadeOutLengthSeconds;
|
||||||
ToPlay.bAlignBeat = bAlignBeat;
|
ToPlay.bAlignBeat = params.bAlignBeat;
|
||||||
|
|
||||||
/* Add the MusicToPlay to the g_MusicsToPlay queue. */
|
/* Add the MusicToPlay to the g_MusicsToPlay queue. */
|
||||||
g_Mutex->Lock();
|
g_Mutex->Lock();
|
||||||
|
|||||||
@@ -16,6 +16,29 @@ public:
|
|||||||
~GameSoundManager();
|
~GameSoundManager();
|
||||||
void Update( float fDeltaTime );
|
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(
|
void PlayMusic(
|
||||||
RString sFile,
|
RString sFile,
|
||||||
const TimingData *pTiming = NULL,
|
const TimingData *pTiming = NULL,
|
||||||
@@ -24,8 +47,7 @@ public:
|
|||||||
float length_sec = -1,
|
float length_sec = -1,
|
||||||
float fFadeInLengthSeconds = 0,
|
float fFadeInLengthSeconds = 0,
|
||||||
float fade_len = 0,
|
float fade_len = 0,
|
||||||
bool align_beat = true,
|
bool align_beat = true );
|
||||||
RString sFallback = "" );
|
|
||||||
void StopMusic() { PlayMusic(""); }
|
void StopMusic() { PlayMusic(""); }
|
||||||
void DimMusic( float fVolume, float fDurationSeconds );
|
void DimMusic( float fVolume, float fDurationSeconds );
|
||||||
RString GetMusicPath() const;
|
RString GetMusicPath() const;
|
||||||
|
|||||||
@@ -289,13 +289,21 @@ void ScreenSelectMusic::CheckBackgroundRequests( bool bForce )
|
|||||||
|
|
||||||
g_bSampleMusicWaiting = false;
|
g_bSampleMusicWaiting = false;
|
||||||
|
|
||||||
SOUND->PlayMusic(
|
GameSoundManager::PlayMusicParams PlayParams;
|
||||||
m_sSampleMusicToPlay, m_pSampleMusicTimingData,
|
PlayParams.sFile = m_sSampleMusicToPlay;
|
||||||
SAMPLE_MUSIC_LOOPS, m_fSampleStartSeconds, m_fSampleLengthSeconds,
|
PlayParams.pTiming = m_pSampleMusicTimingData;
|
||||||
0.0f,
|
PlayParams.bForceLoop = SAMPLE_MUSIC_LOOPS;
|
||||||
1.5f, /* fade out for 1.5 seconds */
|
PlayParams.fStartSecond = m_fSampleStartSeconds;
|
||||||
ALIGN_MUSIC_BEATS,
|
PlayParams.fLengthSeconds = m_fSampleLengthSeconds;
|
||||||
m_sLoopMusicPath );
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user