From 7807b0c703ba1fe80e1474ee3bcd4ba6bbf6f3af Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 23 Mar 2004 23:56:38 +0000 Subject: [PATCH] don't use PlayOnce in performance critical places --- stepmania/src/Screen.cpp | 2 +- stepmania/src/ScreenAttract.cpp | 2 +- stepmania/src/ScreenBookkeeping.cpp | 4 ++-- stepmania/src/ScreenManager.cpp | 6 ++++++ stepmania/src/ScreenManager.h | 14 ++++++++++++++ stepmania/src/ScreenPlayerOptions.cpp | 2 +- stepmania/src/ScreenSelectMusic.cpp | 2 +- stepmania/src/ScreenTestInput.cpp | 2 +- stepmania/src/ScreenTestLights.cpp | 2 +- stepmania/src/StepMania.cpp | 6 +++--- 10 files changed, 31 insertions(+), 11 deletions(-) diff --git a/stepmania/src/Screen.cpp b/stepmania/src/Screen.cpp index 6d214644fc..55b7346c31 100644 --- a/stepmania/src/Screen.cpp +++ b/stepmania/src/Screen.cpp @@ -198,7 +198,7 @@ bool Screen::JoinInput( const DeviceInput& DeviceI, const InputEventType type, c PROFILEMAN->LoadFirstAvailableProfile( MenuI.player ); SCREENMAN->RefreshCreditsMessages(); - SOUND->PlayOnce( THEME->GetPathToS("Common start") ); + SCREENMAN->PlayStartSound(); // if first player to join, set start time if( GAMESTATE->GetNumSidesJoined() == 1 ) diff --git a/stepmania/src/ScreenAttract.cpp b/stepmania/src/ScreenAttract.cpp index b8f56f6e31..29849e5493 100644 --- a/stepmania/src/ScreenAttract.cpp +++ b/stepmania/src/ScreenAttract.cpp @@ -114,7 +114,7 @@ void ScreenAttract::AttractInput( const DeviceInput& DeviceI, const InputEventTy SOUND->StopMusic(); /* We already played the coin sound. Don't play it again. */ if( MenuI.button != MENU_BUTTON_COIN ) - SOUND->PlayOnce( THEME->GetPathToS("Common coin") ); + SCREENMAN->PlayCoinSound(); SDL_Delay( (int)(JOIN_PAUSE_SECONDS*1000) ); // do a little pause, like the arcade does LOG->Trace("ScreenAttract::AttractInput: go to ScreenTitleMenu" ); SCREENMAN->SetNewScreen( "ScreenTitleMenu" ); diff --git a/stepmania/src/ScreenBookkeeping.cpp b/stepmania/src/ScreenBookkeeping.cpp index ccc0cdc312..7206a6e040 100644 --- a/stepmania/src/ScreenBookkeeping.cpp +++ b/stepmania/src/ScreenBookkeeping.cpp @@ -105,7 +105,7 @@ void ScreenBookkeeping::MenuStart( PlayerNumber pn ) { if( !m_Menu.IsTransitioning() ) { - SOUND->PlayOnce( THEME->GetPathToS("Common start") ); + SCREENMAN->PlayStartSound(); m_Menu.StartTransitioning( SM_GoToNextScreen ); } } @@ -114,7 +114,7 @@ void ScreenBookkeeping::MenuBack( PlayerNumber pn ) { if(!m_Menu.IsTransitioning()) { - SOUND->PlayOnce( THEME->GetPathToS("Common start") ); + SCREENMAN->PlayStartSound(); m_Menu.StartTransitioning( SM_GoToPrevScreen ); } } diff --git a/stepmania/src/ScreenManager.cpp b/stepmania/src/ScreenManager.cpp index 03825ba71a..aa7eec3e93 100644 --- a/stepmania/src/ScreenManager.cpp +++ b/stepmania/src/ScreenManager.cpp @@ -342,6 +342,12 @@ ScreenManager::ScreenManager() m_ScreenBuffered = NULL; m_MessageSendOnPop = SM_None; + + + m_soundStart.Load( THEME->GetPathS("Common","start") ); + m_soundCoin.Load( THEME->GetPathS("Common","coin") ); + m_soundInvalid.Load( THEME->GetPathS("Common","invalid") ); + m_soundScreenshot.Load( THEME->GetPathS("Common","screenshot") ); } diff --git a/stepmania/src/ScreenManager.h b/stepmania/src/ScreenManager.h index bf1858f9f5..aab8854bd9 100644 --- a/stepmania/src/ScreenManager.h +++ b/stepmania/src/ScreenManager.h @@ -20,6 +20,7 @@ #include "MenuInput.h" #include "StyleInput.h" #include "BitmapText.h" +#include "RageSound.h" class Screen; struct Menu; @@ -71,6 +72,19 @@ private: Screen* MakeNewScreen( CString sClassName ); void SetFromNewScreen( Screen *pNewScreen, bool Stack ); CString m_DelayedScreen; + + // Keep these sounds always loaded, because they could be + // played at any time. We want to eliminate SOUND->PlayOnce +public: + void PlayStartSound() { m_soundStart.Play(); } + void PlayCoinSound() { m_soundCoin.Play(); } + void PlayInvalidSound() { m_soundInvalid.Play(); } + void PlayScreenshotSound() { m_soundScreenshot.Play(); } +private: + RageSound m_soundStart; + RageSound m_soundCoin; + RageSound m_soundInvalid; + RageSound m_soundScreenshot; }; diff --git a/stepmania/src/ScreenPlayerOptions.cpp b/stepmania/src/ScreenPlayerOptions.cpp index 940f1cf119..944a28d253 100644 --- a/stepmania/src/ScreenPlayerOptions.cpp +++ b/stepmania/src/ScreenPlayerOptions.cpp @@ -114,7 +114,7 @@ void ScreenPlayerOptions::Input( const DeviceInput& DeviceI, const InputEventTyp { m_bGoToOptions = true; m_sprOptionsMessage.SetState( 1 ); - SOUND->PlayOnce( THEME->GetPathToS("Common start") ); + SCREENMAN->PlayStartSound(); } } diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 938787a715..8326b23730 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -726,7 +726,7 @@ void ScreenSelectMusic::Input( const DeviceInput& DeviceI, InputEventType type, m_bGoToOptions = true; m_sprOptionsMessage.SetState( 1 ); - SOUND->PlayOnce( THEME->GetPathToS("Common start") ); + SCREENMAN->PlayStartSound(); return; } diff --git a/stepmania/src/ScreenTestInput.cpp b/stepmania/src/ScreenTestInput.cpp index 974d080c66..1102523d12 100644 --- a/stepmania/src/ScreenTestInput.cpp +++ b/stepmania/src/ScreenTestInput.cpp @@ -128,7 +128,7 @@ void ScreenTestInput::MenuBack( PlayerNumber pn ) { if(!m_Menu.IsTransitioning()) { - SOUND->PlayOnce( THEME->GetPathToS("Common start") ); + SCREENMAN->PlayStartSound(); m_Menu.StartTransitioning( SM_GoToPrevScreen ); } } diff --git a/stepmania/src/ScreenTestLights.cpp b/stepmania/src/ScreenTestLights.cpp index 2a9ac2ec1e..833fbfe167 100644 --- a/stepmania/src/ScreenTestLights.cpp +++ b/stepmania/src/ScreenTestLights.cpp @@ -103,7 +103,7 @@ void ScreenTestLights::MenuBack( PlayerNumber pn ) { if(!m_Menu.IsTransitioning()) { - SOUND->PlayOnce( THEME->GetPathToS("Common start") ); + SCREENMAN->PlayStartSound(); m_Menu.StartTransitioning( SM_GoToPrevScreen ); } } diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 24253d47e5..a02b247b6a 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -1146,11 +1146,11 @@ CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature, bool bResult = DISPLAY->SaveScreenshot( sPath, fmt ); if( !bResult ) { - SOUND->PlayOnce( THEME->GetPathToS("Common invalid") ); + SCREENMAN->PlayInvalidSound(); return ""; } - SOUND->PlayOnce( THEME->GetPathToS("Common screenshot") ); + SCREENMAN->PlayScreenshotSound(); // We wrote a new file, and SignFile won't pick it up unless we invalidate // the Dir cache. There's got to be a better way of doing this than @@ -1198,7 +1198,7 @@ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput Gam LOG->Trace("%i coins inserted, %i needed to play", GAMESTATE->m_iCoins, PREFSMAN->m_iCoinsPerCredit); BOOKKEEPER->CoinInserted(); SCREENMAN->RefreshCreditsMessages(); - SOUND->PlayOnce( THEME->GetPathToS("Common coin") ); + SCREENMAN->PlayCoinSound(); return false; // Attract need to know because they go to TitleMenu on > 1 credit }