From 3a9b2f7f4b30f64764a7e5fb2f0dc79323398dd4 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 15 Jan 2005 01:28:29 +0000 Subject: [PATCH] working on fixing up extra loads when entering play mode in the editor --- stepmania/src/GameSoundManager.cpp | 9 +++ stepmania/src/GameSoundManager.h | 5 ++ stepmania/src/Player.cpp | 74 ++++++++++++--------- stepmania/src/Player.h | 4 +- stepmania/src/ScreenEdit.cpp | 8 ++- stepmania/src/ScreenGameplay.cpp | 4 +- stepmania/src/ScreenGameplayMultiplayer.cpp | 8 +-- stepmania/src/ScreenHowToPlay.cpp | 4 +- 8 files changed, 70 insertions(+), 46 deletions(-) diff --git a/stepmania/src/GameSoundManager.cpp b/stepmania/src/GameSoundManager.cpp index 91bdae3de8..cb945933b2 100644 --- a/stepmania/src/GameSoundManager.cpp +++ b/stepmania/src/GameSoundManager.cpp @@ -609,6 +609,15 @@ float GameSoundManager::GetPlayLatency() const return SOUNDMAN->GetPlayLatency(); } +void GameSoundManager::SetPlayerBalance( PlayerNumber pn, RageSoundParams ¶ms ) +{ + /* If two players are active, play sounds on each players' side. */ + if( GAMESTATE->GetNumPlayersEnabled() == 2 ) + params.m_Balance = (pn == PLAYER_1)? -1.0f:1.0f; + else + params.m_Balance = 0; +} + /* * Copyright (c) 2003-2004 Glenn Maynard * All rights reserved. diff --git a/stepmania/src/GameSoundManager.h b/stepmania/src/GameSoundManager.h index b78059fbea..5a9a6b697b 100644 --- a/stepmania/src/GameSoundManager.h +++ b/stepmania/src/GameSoundManager.h @@ -3,8 +3,11 @@ #ifndef RAGE_SOUNDS_H #define RAGE_SOUNDS_H +#include "PlayerNumber.h" + class TimingData; class RageSound; +struct RageSoundParams; class GameSoundManager { public: @@ -26,6 +29,8 @@ public: float GetPlayLatency() const; void HandleSongTimer( bool on=true ); float GetFrameTimingAdjustment( float fDeltaTime ); + + static void SetPlayerBalance( PlayerNumber pn, RageSoundParams ¶ms ); }; extern GameSoundManager *SOUND; diff --git a/stepmania/src/Player.cpp b/stepmania/src/Player.cpp index 84fecaa7f3..f5436b2253 100644 --- a/stepmania/src/Player.cpp +++ b/stepmania/src/Player.cpp @@ -32,6 +32,7 @@ #include "ThemeMetric.h" #include "PlayerState.h" #include "GameplayMessages.h" +#include "GameSoundManager.h" ThemeMetric GRAY_ARROWS_Y_STANDARD ("Player","ReceptorArrowsYStandard"); ThemeMetric GRAY_ARROWS_Y_REVERSE ("Player","ReceptorArrowsYReverse"); @@ -94,9 +95,9 @@ Player::~Player() delete m_pNoteField; } -void Player::Load( +/* Init() does the expensive stuff: load sounds and note skins. Load() just loads a NoteData. */ +void Player::Init( PlayerState* pPlayerState, - const NoteData& noteData, PlayerStageStats* pPlayerStageStats, LifeMeter* pLM, CombinedLifeMeter* pCombinedLM, @@ -106,8 +107,6 @@ void Player::Load( ScoreKeeper* pPrimaryScoreKeeper, ScoreKeeper* pSecondaryScoreKeeper ) { - m_iDCState = AS2D_IDLE; - m_pPlayerState = pPlayerState; m_pPlayerStageStats = pPlayerStageStats; m_pLifeMeter = pLM; @@ -117,11 +116,44 @@ void Player::Load( m_pInventory = pInventory; m_pPrimaryScoreKeeper = pPrimaryScoreKeeper; m_pSecondaryScoreKeeper = pSecondaryScoreKeeper; + + m_soundMine.Load( THEME->GetPathToS("Player mine"), true ); + + /* Attacks can be launched in course modes and in battle modes. They both come + * here to play, but allow loading a different sound for different modes. */ + switch( GAMESTATE->m_PlayMode ) + { + case PLAY_MODE_RAVE: + case PLAY_MODE_BATTLE: + m_soundAttackLaunch.Load( THEME->GetPathToS("Player battle attack launch"), true ); + m_soundAttackEnding.Load( THEME->GetPathToS("Player battle attack ending"), true ); + break; + default: + m_soundAttackLaunch.Load( THEME->GetPathToS("Player course attack launch"), true ); + m_soundAttackEnding.Load( THEME->GetPathToS("Player course attack ending"), true ); + break; + } + + // TODO: Remove use of PlayerNumber. + PlayerNumber pn = m_pPlayerState->m_PlayerNumber; + + RageSoundParams p; + GameSoundManager::SetPlayerBalance( pn, p ); + + m_soundMine.SetParams( p ); + m_soundAttackLaunch.SetParams( p ); + m_soundAttackEnding.SetParams( p ); +} + +void Player::Load( const NoteData& noteData ) +{ + m_iDCState = AS2D_IDLE; + m_iRowLastCrossed = BeatToNoteRowNotRounded( GAMESTATE->m_fSongBeat ) - 1; // why this? m_iMineRowLastCrossed = BeatToNoteRowNotRounded( GAMESTATE->m_fSongBeat ) - 1; // why this? // TODO: Remove use of PlayerNumber. - PlayerNumber pn = pPlayerState->m_PlayerNumber; + PlayerNumber pn = m_pPlayerState->m_PlayerNumber; GAMESTATE->ResetNoteSkinsForPlayer( pn ); @@ -228,40 +260,16 @@ void Player::Load( // Need to set Y positions of all these elements in Update since // they change depending on PlayerOptions. - RageSoundParams p; - m_soundMine.Load( THEME->GetPathToS("Player mine"), true ); - - /* Attacks can be launched in course modes and in battle modes. They both come - * here to play, but allow loading a different sound for different modes. */ - switch( GAMESTATE->m_PlayMode ) - { - case PLAY_MODE_RAVE: - case PLAY_MODE_BATTLE: - m_soundAttackLaunch.Load( THEME->GetPathToS("Player battle attack launch"), true ); - m_soundAttackEnding.Load( THEME->GetPathToS("Player battle attack ending"), true ); - break; - default: - m_soundAttackLaunch.Load( THEME->GetPathToS("Player course attack launch"), true ); - m_soundAttackEnding.Load( THEME->GetPathToS("Player course attack ending"), true ); - break; - } - - if( GAMESTATE->GetNumPlayersEnabled() == 2 ) - { - /* Two players are active. Play sounds on this player's side. */ - p.m_Balance = (pn == PLAYER_1)? -1.0f:1.0f; - } - m_soundMine.SetParams( p ); - m_soundAttackLaunch.SetParams( p ); - m_soundAttackEnding.SetParams( p ); - // // Load keysounds // - Song* pSong = GAMESTATE->m_pCurSong; + const Song* pSong = GAMESTATE->m_pCurSong; CString sSongDir = pSong->GetSongDir(); m_vKeysounds.clear(); m_vKeysounds.resize( pSong->m_vsKeysoundFile.size() ); + + RageSoundParams p; + GameSoundManager::SetPlayerBalance( pn, p ); for( unsigned i=0; im_vsKeysoundFile[i]; diff --git a/stepmania/src/Player.h b/stepmania/src/Player.h index eb7a3900e6..718007dc3b 100644 --- a/stepmania/src/Player.h +++ b/stepmania/src/Player.h @@ -33,9 +33,8 @@ public: virtual void Update( float fDeltaTime ); virtual void DrawPrimitives(); - void Load( + void Init( PlayerState* pPlayerState, - const NoteData& noteData, PlayerStageStats* pPlayerStageStats, LifeMeter* pLM, CombinedLifeMeter* pCombinedLM, @@ -44,6 +43,7 @@ public: Inventory* pInventory, ScoreKeeper* pPrimaryScoreKeeper, ScoreKeeper* pSecondaryScoreKeeper ); + void Load( const NoteData& noteData ); void CrossedRow( int iNoteRow ); void CrossedMineRow( int iNoteRow ); void Step( int col, RageTimer tm ); diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index 6d26bea589..79ea15a35e 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -552,9 +552,8 @@ ScreenEdit::ScreenEdit( CString sName ) : Screen( sName ) /* XXX: Do we actually have to send real note data here, and to m_NoteFieldRecord? * (We load again on play/record.) */ - m_Player.Load( + m_Player.Init( GAMESTATE->m_pPlayerState[PLAYER_1], - noteData, NULL, NULL, NULL, @@ -563,6 +562,7 @@ ScreenEdit::ScreenEdit( CString sName ) : Screen( sName ) NULL, NULL, NULL ); + m_Player.Load( noteData ); GAMESTATE->m_pPlayerState[PLAYER_1]->m_PlayerController = PC_HUMAN; m_Player.SetXY( PLAYER_X, PLAYER_Y ); @@ -2177,9 +2177,11 @@ void ScreenEdit::HandleAreaMenuChoice( AreaMenuChoice c, int* iAnswers ) float fSeconds = m_pSong->m_Timing.GetElapsedTimeFromBeat( m_NoteFieldEdit.m_fBeginMarker - 4 ); GAMESTATE->UpdateSongPosition( fSeconds, m_pSong->m_Timing ); + /* If we're in course display mode, set that up. */ SetupCourseAttacks(); - m_Player.Load( GAMESTATE->m_pPlayerState[PLAYER_1], m_NoteFieldEdit, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); + m_Player.Init( GAMESTATE->m_pPlayerState[PLAYER_1], NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); + m_Player.Load( m_NoteFieldEdit ); GAMESTATE->m_pPlayerState[PLAYER_1]->m_PlayerController = PREFSMAN->m_bAutoPlay?PC_AUTOPLAY:PC_HUMAN; m_rectRecordBack.StopTweening(); diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index f22dbeba6e..e842b33166 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -831,9 +831,8 @@ void ScreenGameplay::SetupSong( PlayerNumber p, int iSongIndex ) { NoteData nd = ndTransformed; NoteDataUtil::RemoveAllTapsOfType( nd, TapNote::autoKeysound ); - m_Player[p].Load( + m_Player[p].Init( GAMESTATE->m_pPlayerState[p], - nd, &g_CurStageStats.m_player[p], m_pLifeMeter[p], m_pCombinedLifeMeter, @@ -842,6 +841,7 @@ void ScreenGameplay::SetupSong( PlayerNumber p, int iSongIndex ) m_pInventory[p], m_pPrimaryScoreKeeper[p], m_pSecondaryScoreKeeper[p] ); + m_Player[p].Load( nd ); } // load auto keysounds diff --git a/stepmania/src/ScreenGameplayMultiplayer.cpp b/stepmania/src/ScreenGameplayMultiplayer.cpp index b33d7bf724..13b1398a3d 100644 --- a/stepmania/src/ScreenGameplayMultiplayer.cpp +++ b/stepmania/src/ScreenGameplayMultiplayer.cpp @@ -308,9 +308,8 @@ void ScreenGameplayMultiplayer::SetupSong( MultiPlayer p, int iSongIndex ) { NoteData nd = ndTransformed; NoteDataUtil::RemoveAllTapsOfType( nd, TapNote::autoKeysound ); - m_AutoPlayer.Load( + m_AutoPlayer.Init( GAMESTATE->m_pPlayerState[ GAMESTATE->m_MasterPlayerNumber ], - nd, NULL, NULL, NULL, @@ -319,10 +318,10 @@ void ScreenGameplayMultiplayer::SetupSong( MultiPlayer p, int iSongIndex ) NULL, NULL, NULL ); + m_AutoPlayer.Load( nd ); - m_HumanPlayer[p].Load( + m_HumanPlayer[p].Init( &m_PlayerState[p], - nd, &m_PlayerStageStats[p], NULL, NULL, @@ -331,6 +330,7 @@ void ScreenGameplayMultiplayer::SetupSong( MultiPlayer p, int iSongIndex ) NULL, m_pPrimaryScoreKeeper[p], NULL ); + m_HumanPlayer[p].Load( nd ); } // load auto keysounds diff --git a/stepmania/src/ScreenHowToPlay.cpp b/stepmania/src/ScreenHowToPlay.cpp index 23cb819d97..74bb49fa79 100644 --- a/stepmania/src/ScreenHowToPlay.cpp +++ b/stepmania/src/ScreenHowToPlay.cpp @@ -151,9 +151,8 @@ ScreenHowToPlay::ScreenHowToPlay( CString sName ) : ScreenAttract( sName ) GAMESTATE->m_pPlayerState[PLAYER_1]->m_PlayerController = PC_AUTOPLAY; m_pPlayer = new Player; - m_pPlayer->Load( + m_pPlayer->Init( GAMESTATE->m_pPlayerState[PLAYER_1], - m_NoteData, NULL, m_pLifeMeterBar, NULL, @@ -162,6 +161,7 @@ ScreenHowToPlay::ScreenHowToPlay( CString sName ) : ScreenAttract( sName ) NULL, NULL, NULL ); + m_pPlayer->Load( m_NoteData ); m_pPlayer->SetName( "Player" ); this->AddChild( m_pPlayer ); SET_XY_AND_ON_COMMAND( m_pPlayer );