From d6e52f6aac4a7ad7ba46361b9e9bd114d03ea07e Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 29 Mar 2004 06:47:10 +0000 Subject: [PATCH] optimize profile loading --- stepmania/src/GameState.cpp | 2 ++ stepmania/src/MemoryCardManager.cpp | 15 +++++++++------ stepmania/src/ProfileManager.cpp | 29 +++++++++++++---------------- stepmania/src/ProfileManager.h | 8 ++++---- stepmania/src/Screen.cpp | 2 +- stepmania/src/ScreenEvaluation.cpp | 4 ++-- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 4a00fd4bfd..45183f39a9 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -201,6 +201,8 @@ void GameState::PlayersFinalized() // apply saved default modifiers if any FOREACH_HumanPlayer( pn ) { + PROFILEMAN->LoadFirstAvailableProfile( pn, false ); // load full profile + if( !PROFILEMAN->IsUsingProfile(pn) ) continue; // skip diff --git a/stepmania/src/MemoryCardManager.cpp b/stepmania/src/MemoryCardManager.cpp index 6d80a0f7c3..eb5f7f43dd 100644 --- a/stepmania/src/MemoryCardManager.cpp +++ b/stepmania/src/MemoryCardManager.cpp @@ -63,7 +63,7 @@ void MemoryCardManager::Update( float fDelta ) { for( unsigned i=0; iTrace( ssprintf("Disconnected bus %d port %d device %d path %s", old.iBus, old.iPortOnHub, old.iDeviceOnBus, old.sOsMountDir.c_str()) ); @@ -76,7 +76,7 @@ void MemoryCardManager::Update( float fDelta ) { for( unsigned i=0; iTrace( ssprintf("Connected bus %d port %d device %d path %s", newd.iBus, newd.iPortOnHub, newd.iDeviceOnBus, newd.sOsMountDir.c_str()) ); @@ -107,10 +107,15 @@ void MemoryCardManager::Update( float fDelta ) AssignUnassignedCards(); + // Load profiles from cards that were just connected. if( !m_bCardsLocked ) { - for( int p=0; pLoadFirstAvailableProfile( (PlayerNumber)p ); + FOREACH_PlayerNumber( pn ) + { + bool bPlayersCardWasJustConnected = find(vConnects.begin(),vConnects.end(),m_Device[pn]) != vConnects.end(); + if( bPlayersCardWasJustConnected ) + PROFILEMAN->LoadFirstAvailableProfile( pn, true ); // fast load + } } SCREENMAN->RefreshCreditsMessages(); } @@ -153,8 +158,6 @@ void MemoryCardManager::LockCards( bool bLock ) // clear too late flag for( int p=0; p &asNamesOut ) const } -bool ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ) +bool ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard, bool bLoadNamesOnly ) { ASSERT( !sProfileDir.empty() ); ASSERT( sProfileDir.Right(1) == "/" ); @@ -89,13 +89,10 @@ bool ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIs m_sProfileDir[pn] = sProfileDir; m_bWasLoadedFromMemoryCard[pn] = bIsMemCard; - bool bResult = m_Profile[pn].LoadAllFromDir( m_sProfileDir[pn] ); - if( !bResult ) - { - LOG->Warn( "Attempting to load profile from '%s' and does not exist", sProfileDir.c_str() ); - UnloadProfile( pn ); - return false; - } + if( bLoadNamesOnly ) + m_Profile[pn].LoadEditableDataFromDir( m_sProfileDir[pn] ); + else + m_Profile[pn].LoadAllFromDir( m_sProfileDir[pn] ); return true; } @@ -114,7 +111,7 @@ bool ProfileManager::CreateProfile( CString sProfileDir, CString sName ) return true; } -bool ProfileManager::LoadDefaultProfileFromMachine( PlayerNumber pn ) +bool ProfileManager::LoadDefaultProfileFromMachine( PlayerNumber pn, bool bLoadNamesOnly ) { CString sProfileID = PREFSMAN->m_sDefaultLocalProfileID[pn]; if( sProfileID.empty() ) @@ -125,10 +122,10 @@ bool ProfileManager::LoadDefaultProfileFromMachine( PlayerNumber pn ) CString sDir = USER_PROFILES_DIR + sProfileID + "/"; - return LoadProfile( pn, sDir, false ); + return LoadProfile( pn, sDir, false, bLoadNamesOnly ); } -bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) +bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn, bool bLoadNamesOnly ) { UnloadProfile( pn ); #ifndef _XBOX @@ -142,13 +139,13 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) sDir += '/'; bool bResult; - bResult = LoadProfile( pn, sDir, true ); + bResult = LoadProfile( pn, sDir, true, bLoadNamesOnly ); if( bResult ) return true; CreateMemoryCardProfile( pn ); - bResult = LoadProfile( pn, sDir, true ); + bResult = LoadProfile( pn, sDir, true, bLoadNamesOnly ); return bResult; } #endif @@ -172,12 +169,12 @@ bool ProfileManager::CreateMemoryCardProfile( PlayerNumber pn ) return CreateProfile( sDir, NEW_MEM_CARD_NAME ); } -bool ProfileManager::LoadFirstAvailableProfile( PlayerNumber pn ) +bool ProfileManager::LoadFirstAvailableProfile( PlayerNumber pn, bool bLoadNamesOnly ) { - if( LoadProfileFromMemoryCard(pn) ) + if( LoadProfileFromMemoryCard(pn,bLoadNamesOnly) ) return true; - if( LoadDefaultProfileFromMachine(pn) ) + if( LoadDefaultProfileFromMachine(pn,bLoadNamesOnly) ) return true; return false; diff --git a/stepmania/src/ProfileManager.h b/stepmania/src/ProfileManager.h index 9ca4fecf7f..063d28cf15 100644 --- a/stepmania/src/ProfileManager.h +++ b/stepmania/src/ProfileManager.h @@ -33,8 +33,8 @@ public: void GetLocalProfileIDs( vector &asProfileIDsOut ) const; void GetLocalProfileNames( vector &asNamesOut ) const; - bool LoadFirstAvailableProfile( PlayerNumber pn ); // memory card or local profile - bool LoadProfileFromMemoryCard( PlayerNumber pn ); + bool LoadFirstAvailableProfile( PlayerNumber pn, bool bLoadNamesOnly ); // memory card or local profile + bool LoadProfileFromMemoryCard( PlayerNumber pn, bool bLoadNamesOnly ); bool SaveProfile( PlayerNumber pn ) const; void UnloadProfile( PlayerNumber pn ); @@ -103,9 +103,9 @@ public: // void ReadSM300NoteScores(); private: - bool LoadDefaultProfileFromMachine( PlayerNumber pn ); + bool LoadDefaultProfileFromMachine( PlayerNumber pn, bool bLoadNamesOnly ); bool CreateMemoryCardProfile( PlayerNumber pn ); - bool LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ); + bool LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard, bool bLoadNamesOnly ); bool CreateProfile( CString sProfileDir, CString sName ); // Directory that contains the profile. Either on local machine or diff --git a/stepmania/src/Screen.cpp b/stepmania/src/Screen.cpp index a8713e2510..fa2cfc8f7d 100644 --- a/stepmania/src/Screen.cpp +++ b/stepmania/src/Screen.cpp @@ -196,7 +196,7 @@ bool Screen::JoinInput( const DeviceInput& DeviceI, const InputEventType type, c if( GAMESTATE->m_MasterPlayerNumber == PLAYER_INVALID ) GAMESTATE->m_MasterPlayerNumber = MenuI.player; - PROFILEMAN->LoadFirstAvailableProfile( MenuI.player ); + PROFILEMAN->LoadFirstAvailableProfile( MenuI.player, true ); // fast load SCREENMAN->RefreshCreditsMessages(); SCREENMAN->PlayStartSound(); diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index 6b1ad1e7e0..99db93a95f 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -110,8 +110,8 @@ void ScreenEvaluation::Init() if( PREFSMAN->m_bScreenTestMode ) { - PROFILEMAN->LoadFirstAvailableProfile(PLAYER_1); - PROFILEMAN->LoadFirstAvailableProfile(PLAYER_2); + PROFILEMAN->LoadFirstAvailableProfile(PLAYER_1, false); + PROFILEMAN->LoadFirstAvailableProfile(PLAYER_2, false); GAMESTATE->m_PlayMode = PLAY_MODE_ARCADE; GAMESTATE->m_CurStyle = STYLE_DANCE_VERSUS;