move many bookkeeping numbers to ProfileManager
This commit is contained in:
@@ -24,10 +24,9 @@
|
||||
|
||||
Bookkeeper* BOOKKEEPER = NULL; // global and accessable from anywhere in our program
|
||||
|
||||
static const CString BOOKKEEPING_INI = BASE_PATH "Data" SLASH "Bookkeeping.ini";
|
||||
static const CString COINS_DAT = BASE_PATH "Data" SLASH "Coins.dat";
|
||||
|
||||
|
||||
const int COINS_DAT_VERSION = 1;
|
||||
|
||||
tm GetDaysAgo( tm start, int iDaysAgo )
|
||||
{
|
||||
@@ -60,10 +59,6 @@ Bookkeeper::Bookkeeper()
|
||||
int i, j;
|
||||
|
||||
m_iLastSeenTime = time(NULL);
|
||||
m_iTotalCoins = 0;
|
||||
m_iTotalUptimeSeconds = 0;
|
||||
m_iTotalPlaySeconds = 0;
|
||||
m_iTotalPlays = 0;
|
||||
for( i=0; i<DAYS_PER_YEAR; i++ )
|
||||
for( j=0; j<HOURS_PER_DAY; j++ )
|
||||
m_iCoinsByHourForYear[i][j] = 0;
|
||||
@@ -78,68 +73,56 @@ Bookkeeper::~Bookkeeper()
|
||||
WriteToDisk();
|
||||
}
|
||||
|
||||
#define WARN_AND_RETURN { LOG->Warn("Error parsing at %s:%d",__FILE__,__LINE__); return; }
|
||||
|
||||
void Bookkeeper::ReadFromDisk()
|
||||
{
|
||||
// read ini
|
||||
IniFile ini;
|
||||
ini.SetPath( BOOKKEEPING_INI );
|
||||
ini.ReadFile();
|
||||
RageFile f;
|
||||
if( !f.Open(COINS_DAT, RageFile::READ) )
|
||||
{
|
||||
LOG->Warn( "Couldn't open file '%s'", COINS_DAT.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
ini.GetValue( "MachineStatistics", "LastSeenTime", m_iLastSeenTime );
|
||||
ini.GetValue( "MachineStatistics", "TotalCoins", m_iTotalCoins );
|
||||
ini.GetValue( "MachineStatistics", "TotalUptimeSeconds", m_iTotalUptimeSeconds );
|
||||
ini.GetValue( "MachineStatistics", "TotalPlaySeconds", m_iTotalPlaySeconds );
|
||||
ini.GetValue( "MachineStatistics", "TotalPlays", m_iTotalPlays );
|
||||
int iVer;
|
||||
if( !FileRead(f, iVer) )
|
||||
WARN_AND_RETURN;
|
||||
if( iVer != COINS_DAT_VERSION )
|
||||
WARN_AND_RETURN;
|
||||
|
||||
// read dat
|
||||
RageFile file( COINS_DAT );
|
||||
if (file.IsOpen())
|
||||
{
|
||||
const CString line = file.GetLine();
|
||||
if( !FileRead(f, m_iLastSeenTime) )
|
||||
WARN_AND_RETURN;
|
||||
|
||||
vector<CString> parts;
|
||||
split( line, " ", parts, true );
|
||||
for (int i=0; i<DAYS_PER_YEAR; ++i)
|
||||
{
|
||||
for (int j=0; j<HOURS_PER_DAY; ++j)
|
||||
{
|
||||
int iCoins;
|
||||
if( !FileRead(f, iCoins) )
|
||||
WARN_AND_RETURN;
|
||||
|
||||
unsigned p = 0;
|
||||
for (int i=0; i<DAYS_PER_YEAR; ++i)
|
||||
for (int j=0; j<HOURS_PER_DAY; ++j)
|
||||
{
|
||||
if( p >= parts.size() )
|
||||
{
|
||||
LOG->Warn( "Parse error in %s", COINS_DAT.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
m_iCoinsByHourForYear[i][j] = atoi( parts[p++] );
|
||||
}
|
||||
}
|
||||
m_iCoinsByHourForYear[i][j] = iCoins;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Bookkeeper::WriteToDisk()
|
||||
{
|
||||
// write ini
|
||||
IniFile ini;
|
||||
ini.SetPath( BOOKKEEPING_INI );
|
||||
|
||||
ini.SetValue( "MachineStatistics", "LastSeenTime", m_iLastSeenTime );
|
||||
ini.SetValue( "MachineStatistics", "TotalCoins", m_iTotalCoins );
|
||||
ini.SetValue( "MachineStatistics", "TotalUptimeSeconds", m_iTotalUptimeSeconds );
|
||||
ini.SetValue( "MachineStatistics", "TotalPlaySeconds", m_iTotalPlaySeconds );
|
||||
ini.SetValue( "MachineStatistics", "TotalPlays", m_iTotalPlays );
|
||||
|
||||
ini.WriteFile();
|
||||
|
||||
// write dat
|
||||
RageFile file( COINS_DAT, RageFile::WRITE );
|
||||
RageFile f;
|
||||
if( !f.Open(COINS_DAT, RageFile::WRITE) )
|
||||
{
|
||||
LOG->Warn( "Couldn't open file '%s'", COINS_DAT.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.IsOpen())
|
||||
{
|
||||
CString line;
|
||||
for (int i=0; i<DAYS_PER_YEAR; ++i)
|
||||
for (int j=0; j<HOURS_PER_DAY; ++j)
|
||||
line += ssprintf( "%d ", m_iCoinsByHourForYear[i][j] );
|
||||
file.PutLine( line );
|
||||
}
|
||||
FileWrite(f, COINS_DAT_VERSION );
|
||||
|
||||
FileWrite(f, m_iLastSeenTime);
|
||||
|
||||
for (int i=0; i<DAYS_PER_YEAR; ++i)
|
||||
for (int j=0; j<HOURS_PER_DAY; ++j)
|
||||
FileWrite( f, m_iCoinsByHourForYear[i][j] );
|
||||
}
|
||||
|
||||
void Bookkeeper::UpdateLastSeenTime()
|
||||
|
||||
@@ -40,10 +40,6 @@ private:
|
||||
int GetCoinsForDay( int iDayOfYear );
|
||||
|
||||
int m_iLastSeenTime;
|
||||
int m_iTotalCoins;
|
||||
int m_iTotalUptimeSeconds;
|
||||
int m_iTotalPlaySeconds;
|
||||
int m_iTotalPlays;
|
||||
int m_iCoinsByHourForYear[DAYS_PER_YEAR][HOURS_PER_DAY];
|
||||
};
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "LightsManager.h"
|
||||
#include "RageFile.h"
|
||||
#include "Bookkeeper.h"
|
||||
#include <time.h>
|
||||
|
||||
#define DEFAULT_MODIFIERS THEME->GetMetric( "Common","DefaultModifiers" )
|
||||
|
||||
@@ -63,10 +64,15 @@ GameState::~GameState()
|
||||
|
||||
void GameState::Reset()
|
||||
{
|
||||
if( m_timeGameStated != 0 && m_vPlayedStageStats.size() ) // we were in the middle of a game and played at least one song
|
||||
EndGame();
|
||||
|
||||
|
||||
ASSERT( THEME );
|
||||
|
||||
int p;
|
||||
|
||||
m_timeGameStated = 0;
|
||||
m_CurStyle = STYLE_INVALID;
|
||||
for( p=0; p<NUM_PLAYERS; p++ )
|
||||
m_bSideIsJoined[p] = false;
|
||||
@@ -145,7 +151,38 @@ void GameState::Reset()
|
||||
|
||||
LIGHTSMAN->SetLightMode( LIGHTMODE_ATTRACT );
|
||||
|
||||
// HACK: save stats intermitently in case of crash
|
||||
}
|
||||
|
||||
void GameState::BeginGame()
|
||||
{
|
||||
m_timeGameStated = time(NULL);
|
||||
}
|
||||
|
||||
void GameState::EndGame()
|
||||
{
|
||||
// Update profile stats
|
||||
|
||||
time_t now = time(NULL);
|
||||
int iPlaySeconds = now - m_timeGameStated;
|
||||
if( iPlaySeconds < 0 )
|
||||
iPlaySeconds = 0;
|
||||
|
||||
for( int p=0; p<NUM_PLAYERS; p++ )
|
||||
{
|
||||
int iGameplaySeconds = 0;
|
||||
for( int i=0; i<m_vPlayedStageStats.size(); i++ )
|
||||
iGameplaySeconds += m_vPlayedStageStats[i].fAliveSeconds[p];
|
||||
|
||||
|
||||
Profile* pProfile = PROFILEMAN->GetProfile( (PlayerNumber)p );
|
||||
if( pProfile==NULL )
|
||||
continue;
|
||||
|
||||
pProfile->m_iTotalPlaySeconds += iPlaySeconds;
|
||||
pProfile->m_iTotalGameplaySeconds += iGameplaySeconds;
|
||||
pProfile->m_iTotalPlays++;
|
||||
}
|
||||
|
||||
BOOKKEEPER->WriteToDisk();
|
||||
PROFILEMAN->SaveMachineScoresToDisk();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
GameState();
|
||||
~GameState();
|
||||
void Reset();
|
||||
void BeginGame(); // called when first player joins
|
||||
void EndGame(); // called on ScreenGameOver, ScreenMusicScroll, ScreenCredits
|
||||
|
||||
void Update( float fDelta );
|
||||
|
||||
@@ -52,7 +54,8 @@ public:
|
||||
int m_iCoins; // not "credits"
|
||||
PlayerNumber m_MasterPlayerNumber; // used in Styles where one player controls both sides
|
||||
bool m_bIsOnSystemMenu; // system screens will not be effected by the operator key -- Miryokuteki
|
||||
bool m_bDifficultCourses; //used in nonstop
|
||||
bool m_bDifficultCourses; // used in nonstop
|
||||
time_t m_timeGameStated; // from the moment the first player pressed Start
|
||||
|
||||
/* This is set to a random number per-game/round; it can be used for a random seed. */
|
||||
int m_iGameSeed, m_iRoundSeed;
|
||||
|
||||
@@ -245,20 +245,26 @@ bool Profile::LoadFromIni( CString sIniPath )
|
||||
if( !ini.ReadFile() )
|
||||
return false;
|
||||
|
||||
ini.GetValue( "Profile", "DisplayName", m_sName );
|
||||
ini.GetValue( "Profile", "LastUsedHighScoreName", m_sLastUsedHighScoreName );
|
||||
ini.GetValue( "Profile", "UsingProfileDefaultModifiers", m_bUsingProfileDefaultModifiers );
|
||||
ini.GetValue( "Profile", "DefaultModifiers", m_sDefaultModifiers );
|
||||
ini.GetValue( "Profile", "DisplayName", m_sName );
|
||||
ini.GetValue( "Profile", "LastUsedHighScoreName", m_sLastUsedHighScoreName );
|
||||
ini.GetValue( "Profile", "UsingProfileDefaultModifiers", m_bUsingProfileDefaultModifiers );
|
||||
ini.GetValue( "Profile", "DefaultModifiers", m_sDefaultModifiers );
|
||||
ini.GetValue( "Profile", "TotalPlays", m_iTotalPlays );
|
||||
ini.GetValue( "Profile", "TotalPlaySeconds", m_iTotalPlaySeconds );
|
||||
ini.GetValue( "Profile", "TotalGameplaySeconds", m_iTotalGameplaySeconds );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Profile::SaveToIni( CString sIniPath )
|
||||
{
|
||||
IniFile ini( sIniPath );
|
||||
ini.SetValue( "Profile", "DisplayName", m_sName );
|
||||
ini.SetValue( "Profile", "LastUsedHighScoreName", m_sLastUsedHighScoreName );
|
||||
ini.SetValue( "Profile", "UsingProfileDefaultModifiers", m_bUsingProfileDefaultModifiers );
|
||||
ini.SetValue( "Profile", "DefaultModifiers", m_sDefaultModifiers );
|
||||
ini.SetValue( "Profile", "DisplayName", m_sName );
|
||||
ini.SetValue( "Profile", "LastUsedHighScoreName", m_sLastUsedHighScoreName );
|
||||
ini.SetValue( "Profile", "UsingProfileDefaultModifiers", m_bUsingProfileDefaultModifiers );
|
||||
ini.SetValue( "Profile", "DefaultModifiers", m_sDefaultModifiers );
|
||||
ini.SetValue( "Profile", "TotalPlays", m_iTotalPlays );
|
||||
ini.SetValue( "Profile", "TotalPlaySeconds", m_iTotalPlaySeconds );
|
||||
ini.SetValue( "Profile", "TotalGameplaySeconds", m_iTotalGameplaySeconds );
|
||||
ini.WriteFile();
|
||||
return true;
|
||||
}
|
||||
@@ -360,63 +366,6 @@ void ProfileManager::CategoryData::AddHighScore( HighScore hs, int &iIndexOut )
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Helper function for reading/writing scores
|
||||
//
|
||||
bool FileRead(RageFile& f, CString& sOut)
|
||||
{
|
||||
if (f.AtEOF())
|
||||
return false;
|
||||
sOut = f.GetLine();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileRead(RageFile& f, int& iOut)
|
||||
{
|
||||
CString s;
|
||||
if (!FileRead(f, s))
|
||||
return false;
|
||||
iOut = atoi(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileRead(RageFile& f, unsigned& uOut)
|
||||
{
|
||||
CString s;
|
||||
if (!FileRead(f, s))
|
||||
return false;
|
||||
uOut = atoi(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileRead(RageFile& f, float& fOut)
|
||||
{
|
||||
CString s;
|
||||
if (!FileRead(f, s))
|
||||
return false;
|
||||
fOut = (float)atof(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileWrite(RageFile& f, const CString& sWrite)
|
||||
{
|
||||
f.PutLine( sWrite );
|
||||
}
|
||||
|
||||
void FileWrite(RageFile& f, int iWrite)
|
||||
{
|
||||
f.PutLine( ssprintf("%d", iWrite) );
|
||||
}
|
||||
|
||||
void FileWrite(RageFile& f, size_t uWrite)
|
||||
{
|
||||
f.PutLine( ssprintf("%lu", uWrite) );
|
||||
}
|
||||
|
||||
void FileWrite(RageFile& f, float fWrite)
|
||||
{
|
||||
f.PutLine( ssprintf("%f", fWrite) );
|
||||
}
|
||||
|
||||
#define WARN_AND_RETURN { LOG->Warn("Error parsing file '%s' at %s:%d",fn.c_str(),__FILE__,__LINE__); return; }
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ struct Profile
|
||||
m_sLastUsedHighScoreName = "";
|
||||
m_bUsingProfileDefaultModifiers = false;
|
||||
m_sDefaultModifiers = "";
|
||||
m_iTotalPlays = 0;
|
||||
m_iTotalPlaySeconds = 0;
|
||||
m_iTotalGameplaySeconds = 0;
|
||||
}
|
||||
|
||||
bool LoadFromIni( CString sIniPath );
|
||||
@@ -33,6 +36,9 @@ struct Profile
|
||||
CString m_sLastUsedHighScoreName;
|
||||
bool m_bUsingProfileDefaultModifiers;
|
||||
CString m_sDefaultModifiers;
|
||||
int m_iTotalPlays;
|
||||
int m_iTotalPlaySeconds;
|
||||
int m_iTotalGameplaySeconds;
|
||||
};
|
||||
|
||||
class ProfileManager
|
||||
|
||||
@@ -964,3 +964,62 @@ char char_traits_char_nocase::uptab[256] =
|
||||
'\xE0','\xE1','\xE2','\xE3','\xE4','\xE5','\xE6','\xE7','\xE8','\xE9','\xEA','\xEB','\xEC','\xED','\xEE','\xEF',
|
||||
'\xF0','\xF1','\xF2','\xF3','\xF4','\xF5','\xF6','\xF7','\xF8','\xF9','\xFA','\xFB','\xFC','\xFD','\xFE','\xFF',
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Helper function for reading/writing scores
|
||||
//
|
||||
bool FileRead(RageFile& f, CString& sOut)
|
||||
{
|
||||
if (f.AtEOF())
|
||||
return false;
|
||||
sOut = f.GetLine();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileRead(RageFile& f, int& iOut)
|
||||
{
|
||||
CString s;
|
||||
if (!FileRead(f, s))
|
||||
return false;
|
||||
iOut = atoi(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileRead(RageFile& f, unsigned& uOut)
|
||||
{
|
||||
CString s;
|
||||
if (!FileRead(f, s))
|
||||
return false;
|
||||
uOut = atoi(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileRead(RageFile& f, float& fOut)
|
||||
{
|
||||
CString s;
|
||||
if (!FileRead(f, s))
|
||||
return false;
|
||||
fOut = (float)atof(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileWrite(RageFile& f, const CString& sWrite)
|
||||
{
|
||||
f.PutLine( sWrite );
|
||||
}
|
||||
|
||||
void FileWrite(RageFile& f, int iWrite)
|
||||
{
|
||||
f.PutLine( ssprintf("%d", iWrite) );
|
||||
}
|
||||
|
||||
void FileWrite(RageFile& f, size_t uWrite)
|
||||
{
|
||||
f.PutLine( ssprintf("%lu", uWrite) );
|
||||
}
|
||||
|
||||
void FileWrite(RageFile& f, float fWrite)
|
||||
{
|
||||
f.PutLine( ssprintf("%f", fWrite) );
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include "RageFile.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// SAFE_ Macros
|
||||
@@ -284,5 +285,17 @@ unsigned GetFileSizeInBytes( const CString &sFilePath );
|
||||
int GetFileModTime( const CString &sPath );
|
||||
void FlushDirCache();
|
||||
|
||||
// helper file functions used by Bookkeeper and ProfileManager
|
||||
//
|
||||
// Helper function for reading/writing scores
|
||||
//
|
||||
bool FileRead(RageFile& f, CString& sOut);
|
||||
bool FileRead(RageFile& f, int& iOut);
|
||||
bool FileRead(RageFile& f, unsigned& uOut);
|
||||
bool FileRead(RageFile& f, float& fOut);
|
||||
void FileWrite(RageFile& f, const CString& sWrite);
|
||||
void FileWrite(RageFile& f, int iWrite);
|
||||
void FileWrite(RageFile& f, size_t uWrite);
|
||||
void FileWrite(RageFile& f, float fWrite);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -198,6 +198,10 @@ bool Screen::JoinInput( const DeviceInput& DeviceI, const InputEventType type, c
|
||||
|
||||
SOUND->PlayOnce( THEME->GetPathToS("Common start") );
|
||||
|
||||
// if first player to join, set start time
|
||||
if( GAMESTATE->GetNumSidesJoined() == 1 )
|
||||
GAMESTATE->BeginGame();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,8 +97,3 @@ void ScreenMusicScroll::Update( float fDeltaTime )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScreenMusicScroll::HandleScreenMessage( const ScreenMessage SM )
|
||||
{
|
||||
ScreenAttract::HandleScreenMessage( SM );
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ public:
|
||||
|
||||
virtual void Update( float fDeltaTime );
|
||||
|
||||
virtual void HandleScreenMessage( const ScreenMessage SM );
|
||||
|
||||
private:
|
||||
vector<BitmapText *> m_textLines;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user