From 42e0413e0f8212aa711782d7e351f8d7485dcd72 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 20 Jan 2004 06:08:56 +0000 Subject: [PATCH] make SOUND handle ScreenGameplay's music --- stepmania/src/ScreenDemonstration.cpp | 5 ++-- stepmania/src/ScreenEdit.cpp | 2 +- stepmania/src/ScreenGameplay.cpp | 43 ++++++++++----------------- stepmania/src/ScreenGameplay.h | 2 +- stepmania/src/ScreenJukebox.cpp | 4 +-- stepmania/src/StepMania.cpp | 4 +++ 6 files changed, 25 insertions(+), 35 deletions(-) diff --git a/stepmania/src/ScreenDemonstration.cpp b/stepmania/src/ScreenDemonstration.cpp index d5b02c8367..c3ca1e606a 100644 --- a/stepmania/src/ScreenDemonstration.cpp +++ b/stepmania/src/ScreenDemonstration.cpp @@ -19,6 +19,7 @@ #include "ScreenAttract.h" // for AttractInput() #include "ScreenManager.h" #include "RageSoundManager.h" +#include "RageSounds.h" #define SHOW_RANDOM_MODIFIERS THEME->GetMetricF("ScreenDemonstration","SecondsToShow") @@ -102,7 +103,7 @@ void ScreenDemonstration::Input( const DeviceInput& DeviceI, const InputEventTyp if( GAMESTATE->m_iCoins < PREFSMAN->m_iCoinsPerCredit ) break; // don't fall through - m_soundMusic.Stop(); + SOUND->StopMusic(); if( !GAMESTATE->IsTimeToPlayAttractSounds() ) SOUNDMAN->SetPrefs( PREFSMAN->m_fSoundVolume ); // turn volume back on @@ -123,7 +124,7 @@ void ScreenDemonstration::HandleScreenMessage( const ScreenMessage SM ) m_Out.StartTransitioning( SM_GoToNextScreen ); return; case SM_GoToNextScreen: - m_soundMusic.Stop(); + SOUND->StopMusic(); if( !GAMESTATE->IsTimeToPlayAttractSounds() ) SOUNDMAN->SetPrefs( PREFSMAN->m_fSoundVolume ); // turn volume back on diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index 7ac94333c7..3cf7bb7115 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -397,7 +397,7 @@ void ScreenEdit::PlayTicks() void ScreenEdit::PlayPreviewMusic() { SOUND->PlayMusic(""); - SOUND->PlayMusic( m_pSong->GetMusicPath(), false, + SOUND->PlayMusic( m_pSong->GetMusicPath(), true, m_pSong->m_fMusicSampleStartSeconds, m_pSong->m_fMusicSampleLengthSeconds, 1.5f ); diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index f740da4833..6d3bfc828e 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -101,8 +101,7 @@ ScreenGameplay::ScreenGameplay( CString sName, bool bDemonstration ) : Screen("S else LIGHTSMAN->SetLightMode( LIGHTMODE_GAMEPLAY ); - /* We do this ourself. */ - SOUND->HandleSongTimer( false ); + m_soundMusic = NULL; SECONDS_BETWEEN_COMMENTS.Refresh(); TICK_EARLY_SECONDS.Refresh(); @@ -752,7 +751,7 @@ ScreenGameplay::~ScreenGameplay() } SAFE_DELETE( m_pCombinedLifeMeter ); - m_soundMusic.StopPlaying(); + SOUND->StopMusic(); m_soundAssistTick.StopPlaying(); /* Stop any queued assist ticks. */ } @@ -950,8 +949,9 @@ void ScreenGameplay::LoadNextSong() LL.LoadFromLRCFile(GAMESTATE->m_pCurSong->GetLyricsPath(), *GAMESTATE->m_pCurSong); - m_soundMusic.SetAccurateSync(); - m_soundMusic.Load( GAMESTATE->m_pCurSong->GetMusicPath() ); + m_soundMusic = new RageSound; + m_soundMusic->SetAccurateSync(); + m_soundMusic->Load( GAMESTATE->m_pCurSong->GetMusicPath() ); /* Set up song-specific graphics. */ @@ -1005,12 +1005,16 @@ float ScreenGameplay::StartPlayingSong(float MinTimeToNotes, float MinTimeToMusi fStartSecond = min(fStartSecond, -MinTimeToMusic); - m_soundMusic.SetPositionSeconds( fStartSecond ); - m_soundMusic.SetPlaybackRate( GAMESTATE->m_SongOptions.m_fMusicRate ); + ASSERT( m_soundMusic ); + m_soundMusic->SetPositionSeconds( fStartSecond ); + m_soundMusic->SetPlaybackRate( GAMESTATE->m_SongOptions.m_fMusicRate ); /* Keep the music playing after it's finished; we'll stop it. */ - m_soundMusic.SetStopMode(RageSound::M_CONTINUE); - m_soundMusic.StartPlaying(); + m_soundMusic->SetStopMode(RageSound::M_CONTINUE); + m_soundMusic->StartPlaying(); + + SOUND->TakeOverSound( m_soundMusic, &GAMESTATE->m_pCurSong->m_Timing ); + m_soundMusic = NULL; // SOUND owns it now /* Return the amount of time until the first beat. */ return fFirstSecond - fStartSecond; @@ -1098,23 +1102,6 @@ void ScreenGameplay::Update( float fDeltaTime ) } - - /* Very important: Update GAMESTATE's song beat information - * -before- calling update on all the classes that depend on it. - * If you don't do this first, the classes are all acting on old - * information and will lag. -Chris */ - - /* If ScreenJukebox is changing screens, it'll stop m_soundMusic to tell - * us not to update the time here. (In that case, we've already created - * a new ScreenJukebox and reset music statistics, and if we do this then - * we'll un-reset them.) */ - if( m_soundMusic.IsPlaying() ) - { - RageTimer tm; - const float fSeconds = m_soundMusic.GetPositionSeconds( NULL, &tm ); - GAMESTATE->UpdateSongPosition( fSeconds, GAMESTATE->m_pCurSong->m_Timing, tm ); - } - if( m_bZeroDeltaOnNextUpdate ) { Screen::Update( 0 ); @@ -1507,7 +1494,7 @@ void ScreenGameplay::Input( const DeviceInput& DeviceI, const InputEventType typ * * We're doing #3. I'm not sure which is best. */ - m_soundMusic.StopPlaying(); + SOUND->StopMusic(); m_soundAssistTick.StopPlaying(); /* Stop any queued assist ticks. */ this->ClearMessageQueue(); @@ -2145,7 +2132,7 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM ) case SM_BeginFailed: m_DancingState = STATE_OUTRO; - m_soundMusic.StopPlaying(); + SOUND->StopMusic(); m_soundAssistTick.StopPlaying(); /* Stop any queued assist ticks. */ TweenOffScreen(); m_Failed.StartTransitioning( SM_GoToScreenAfterFail ); diff --git a/stepmania/src/ScreenGameplay.h b/stepmania/src/ScreenGameplay.h index 0f5b6b1ff0..8a91c14a88 100644 --- a/stepmania/src/ScreenGameplay.h +++ b/stepmania/src/ScreenGameplay.h @@ -199,7 +199,7 @@ protected: bool m_bDemonstration; RageSound m_soundAssistTick; - RageSound m_soundMusic; + RageSound *m_soundMusic; BeginnerHelper m_BeginnerHelper; }; diff --git a/stepmania/src/ScreenJukebox.cpp b/stepmania/src/ScreenJukebox.cpp index 99d139399c..d4ea987ac0 100644 --- a/stepmania/src/ScreenJukebox.cpp +++ b/stepmania/src/ScreenJukebox.cpp @@ -217,9 +217,7 @@ void ScreenJukebox::HandleScreenMessage( const ScreenMessage SM ) m_Out.StartTransitioning( SM_GoToNextScreen ); return; case SM_GoToNextScreen: - /* We're actually under Update(), so make sure ScreenGameplay doesn't - * continue grading for this call. */ - m_soundMusic.StopPlaying(); + SOUND->StopMusic(); SCREENMAN->SetNewScreen( "ScreenJukebox" ); return; } diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index ddda9ea900..9713460647 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -1303,6 +1303,10 @@ static void GameLoop() } DISPLAY->Update( fDeltaTime ); + + /* Update song beat information -before- calling update on all the classes that + * depend on it. If you don't do this first, the classes are all acting on old + * information and will lag. (but no longer fatally, due to timestamping -glenn) */ SOUND->Update( fDeltaTime ); TEXTUREMAN->Update( fDeltaTime ); GAMESTATE->Update( fDeltaTime );