From e8c7e797296c3055d82f403e3e33c25665368ba5 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 10 Dec 2003 10:30:53 +0000 Subject: [PATCH] fix bookkeeping bugs --- stepmania/src/Bookkeeper.cpp | 31 +++++++++++++++++------------ stepmania/src/Bookkeeper.h | 2 +- stepmania/src/ProfileManager.cpp | 15 +++++++++++++- stepmania/src/ScreenBookkeeping.cpp | 2 +- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/stepmania/src/Bookkeeper.cpp b/stepmania/src/Bookkeeper.cpp index e2082372d3..a4f885743e 100644 --- a/stepmania/src/Bookkeeper.cpp +++ b/stepmania/src/Bookkeeper.cpp @@ -28,9 +28,9 @@ static const CString COINS_DAT = "Data/Coins.dat"; const int COINS_DAT_VERSION = 1; -tm GetDaysAgo( tm start, int iDaysAgo ) +tm AddDays( tm start, int iDaysToMove ) { - start.tm_mday -= iDaysAgo; + start.tm_mday += iDaysToMove; time_t seconds = mktime( &start ); ASSERT( seconds != (time_t)-1 ); tm time = *localtime( &seconds ); @@ -39,17 +39,19 @@ tm GetDaysAgo( tm start, int iDaysAgo ) tm GetYesterday( tm start ) { - return GetDaysAgo( start, -1 ); + return AddDays( start, -1 ); } int GetDayOfWeek( tm time ) { - return time.tm_wday; + int iDayOfWeek = time.tm_wday; + ASSERT( iDayOfWeek < DAYS_IN_WEEK ); + return iDayOfWeek; } -tm GetLastSunday( tm start ) +tm GetNextSunday( tm start ) { - return GetDaysAgo( start, -GetDayOfWeek(start) ); + return AddDays( start, DAYS_IN_WEEK-GetDayOfWeek(start) ); } @@ -163,16 +165,18 @@ void Bookkeeper::UpdateLastSeenTime() m_iCoinsByHourForYear[tOld.tm_yday][tOld.tm_hour] = 0; } + + m_iLastSeenTime = lNewTime; } void Bookkeeper::CoinInserted() { UpdateLastSeenTime(); - long lOldTime = m_iLastSeenTime; - tm *pNewTime = localtime( &lOldTime ); + long lTime = m_iLastSeenTime; + tm *pTime = localtime( &lTime ); - m_iCoinsByHourForYear[pNewTime->tm_yday][pNewTime->tm_hour]++; + m_iCoinsByHourForYear[pTime->tm_yday][pTime->tm_hour]++; } int Bookkeeper::GetCoinsForDay( int iDayOfYear ) @@ -193,8 +197,8 @@ void Bookkeeper::GetCoinsLastDays( int coins[NUM_LAST_DAYS] ) for( int i=0; iGetCoinsByDayOfWeek( coins ); + PRINT_DIV_START( "Coins by Day of Week" ); + for( int i=0; iGetCoinsByHour( coins ); - PRINT_DIV_START( ssprintf("Coins for Last %d Weeks",HOURS_PER_DAY).c_str() ); + PRINT_DIV_START( ssprintf("Coins for Last %d Hours",HOURS_PER_DAY).c_str() ); for( int i=0; i