From 04546763e0f965cf2f9446d5dc5ddc3d0495033c Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 1 Jul 2005 04:46:32 +0000 Subject: [PATCH] reducing ProfileManager.h dependency on Profile.h (many users only use PManager to see if a profile is loaded, etc, not to access the actual profiles) --- stepmania/src/ProfileManager.cpp | 34 ++++++++++++++++++++------------ stepmania/src/ProfileManager.h | 15 +++++++++----- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index 8e6d783afc..ae2fe58f64 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -1,5 +1,6 @@ #include "global.h" #include "ProfileManager.h" +#include "Profile.h" #include "RageUtil.h" #include "PrefsManager.h" #include "RageLog.h" @@ -36,10 +37,16 @@ static Preference g_sMemoryCardProfileImportSubdirs( "MemoryCardProfile ProfileManager::ProfileManager() { + m_pMachineProfile = new Profile; + FOREACH_PlayerNumber(pn) + m_pProfile[pn] = new Profile; } ProfileManager::~ProfileManager() { + delete m_pMachineProfile; + FOREACH_PlayerNumber(pn) + delete m_pProfile[pn]; } void ProfileManager::Init() @@ -77,7 +84,7 @@ void ProfileManager::GetLocalProfileNames( vector &asNamesOut ) const Profile::LoadResult ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ) { - LOG->Trace( "LoadingProfile P%d, %s, %d", pn+1, sProfileDir.c_str(), bIsMemCard ); + LOG->Trace( "LoadingProfile P%d, %s, %d", pn+1, sProfileDir.c_str(), bIsMemCard ); ASSERT( !sProfileDir.empty() ); ASSERT( sProfileDir.Right(1) == "/" ); @@ -88,7 +95,7 @@ Profile::LoadResult ProfileManager::LoadProfile( PlayerNumber pn, CString sProfi m_bLastLoadWasFromLastGood[pn] = false; // Try to load the original, non-backup data. - Profile::LoadResult lr = m_Profile[pn].LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData ); + Profile::LoadResult lr = m_pProfile[pn]->LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData ); CString sBackupDir = m_sProfileDir[pn] + LAST_GOOD_DIR; @@ -102,11 +109,12 @@ Profile::LoadResult ProfileManager::LoadProfile( PlayerNumber pn, CString sProfi m_bLastLoadWasTamperedOrCorrupt[pn] = lr == Profile::failed_tampered; + // // Try to load from the backup if the original data fails to load // if( lr == Profile::failed_tampered ) { - lr = m_Profile[pn].LoadAllFromDir( sBackupDir, PREFSMAN->m_bSignProfileData ); + lr = m_pProfile[pn]->LoadAllFromDir( sBackupDir, PREFSMAN->m_bSignProfileData ); m_bLastLoadWasFromLastGood[pn] = lr == Profile::success; /* If the LastGood profile doesn't exist at all, and the actual profile was failed_tampered, @@ -260,7 +268,7 @@ bool ProfileManager::SaveProfile( PlayerNumber pn ) const if( m_sProfileDir[pn].empty() ) return false; - bool b = m_Profile[pn].SaveAllToDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData ); + bool b = m_pProfile[pn]->SaveAllToDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData ); return b; } @@ -272,7 +280,7 @@ void ProfileManager::UnloadProfile( PlayerNumber pn ) m_bWasLoadedFromMemoryCard[pn] = false; m_bLastLoadWasTamperedOrCorrupt[pn] = false; m_bLastLoadWasFromLastGood[pn] = false; - m_Profile[pn].InitAll(); + m_pProfile[pn]->InitAll(); SONGMAN->FreeAllLoadedFromProfile( (ProfileSlot) pn ); } @@ -280,7 +288,7 @@ const Profile* ProfileManager::GetProfile( PlayerNumber pn ) const { ASSERT( pn >= 0 && pn (this)->m_MachineProfile.m_sDisplayName = PREFSMAN->m_sMachineName; + const_cast (this)->m_pMachineProfile->m_sDisplayName = PREFSMAN->m_sMachineName; - m_MachineProfile.SaveAllToDir( MACHINE_PROFILE_DIR, false ); /* don't sign machine profiles */ + m_pMachineProfile->SaveAllToDir( MACHINE_PROFILE_DIR, false ); /* don't sign machine profiles */ } void ProfileManager::LoadMachineProfile() { - Profile::LoadResult lr = m_MachineProfile.LoadAllFromDir(MACHINE_PROFILE_DIR, false); + Profile::LoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false); if( lr == Profile::failed_no_profile ) { Profile::CreateNewProfile(MACHINE_PROFILE_DIR, "Machine"); - m_MachineProfile.LoadAllFromDir( MACHINE_PROFILE_DIR, false ); + m_pMachineProfile->LoadAllFromDir( MACHINE_PROFILE_DIR, false ); } // If the machine name has changed, make sure we use the new name - m_MachineProfile.m_sDisplayName = PREFSMAN->m_sMachineName; + m_pMachineProfile->m_sDisplayName = PREFSMAN->m_sMachineName; SONGMAN->FreeAllLoadedFromProfile( PROFILE_SLOT_MACHINE ); SONGMAN->LoadAllFromProfileDir( MACHINE_PROFILE_DIR, PROFILE_SLOT_MACHINE ); @@ -437,9 +445,9 @@ const Profile* ProfileManager::GetProfile( ProfileSlot slot ) const if( m_sProfileDir[slot].empty() ) return NULL; else - return &m_Profile[slot]; + return m_pProfile[slot]; case PROFILE_SLOT_MACHINE: - return &m_MachineProfile; + return m_pMachineProfile; default: ASSERT(0); } diff --git a/stepmania/src/ProfileManager.h b/stepmania/src/ProfileManager.h index 1c057f42ab..11de47c964 100644 --- a/stepmania/src/ProfileManager.h +++ b/stepmania/src/ProfileManager.h @@ -5,10 +5,16 @@ #include "PlayerNumber.h" #include "GameConstantsAndTypes.h" +#include "HighScore.h" +#include "Difficulty.h" #include "Profile.h" +class Profile; class Song; +class Steps; class Style; +class Course; +class Trail; struct lua_State; class ProfileManager @@ -59,7 +65,7 @@ public: CString GetProfileDir( ProfileSlot slot ) const; CString GetProfileDirImportedFrom( ProfileSlot slot ) const; - Profile* GetMachineProfile() { return &m_MachineProfile; } + Profile* GetMachineProfile() { return m_pMachineProfile; } CString GetPlayerName( PlayerNumber pn ) const; bool ProfileWasLoadedFromMemoryCard( PlayerNumber pn ) const; @@ -72,7 +78,7 @@ public: // int GetSongNumTimesPlayed( const Song* pSong, ProfileSlot card ) const; bool IsSongNew( const Song* pSong ) const { return GetSongNumTimesPlayed(pSong,PROFILE_SLOT_MACHINE)==0; } - void AddStepsScore( const Song* pSong, const Steps* pSteps, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut ); + void AddStepsScore( const Song* pSong, const Steps* pSteps , PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut ); void IncrementStepsPlayCount( const Song* pSong, const Steps* pSteps, PlayerNumber pn ); HighScore GetHighScoreForDifficulty( const Song *s, const Style *st, ProfileSlot slot, Difficulty dc ) const; @@ -108,10 +114,9 @@ private: bool m_bLastLoadWasFromLastGood[NUM_PLAYERS]; // if true, then m_bLastLoadWasTamperedOrCorrupt is also true // actual loaded profile data - Profile m_Profile[NUM_PLAYERS]; - - Profile m_MachineProfile; + Profile *m_pProfile[NUM_PLAYERS]; + Profile *m_pMachineProfile; };