clean up Course score saving (use Trail)

This commit is contained in:
Chris Danford
2004-05-23 09:17:10 +00:00
parent cd93cb4347
commit 4ff8b8ec2b
16 changed files with 210 additions and 48 deletions
+2
View File
@@ -551,6 +551,8 @@ Trail* Course::GetTrail( StepsType nt, CourseDifficulty cd ) const
int CurSong = 0; /* Current offset into AllSongsShuffled */
Trail trail;
trail.m_StepsType = nt;
trail.m_CourseDifficulty = cd;
for( unsigned i=0; i<entries.size(); i++ )
{
+4 -2
View File
@@ -1473,7 +1473,8 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector<RankingFeat> &asFeatsOu
// Find Machine Records
{
Profile* pProfile = PROFILEMAN->GetMachineProfile();
HighScoreList &hsl = pProfile->GetCourseHighScoreList( pCourse, nt, cd );
Trail *pTrail = pCourse->GetTrail( nt, cd );
HighScoreList &hsl = pProfile->GetCourseHighScoreList( pCourse, pTrail );
for( unsigned i=0; i<hsl.vHighScores.size(); i++ )
{
HighScore &hs = hsl.vHighScores[i];
@@ -1497,7 +1498,8 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector<RankingFeat> &asFeatsOu
// Find Personal Records
if( PROFILEMAN->IsUsingProfile( pn ) )
{
HighScoreList &hsl = pProf->GetCourseHighScoreList( pCourse, nt, cd );
Trail *pTrail = pCourse->GetTrail( nt, cd );
HighScoreList &hsl = pProf->GetCourseHighScoreList( pCourse, pTrail );
for( unsigned i=0; i<hsl.vHighScores.size(); i++ )
{
HighScore& hs = hsl.vHighScores[i];
+5 -3
View File
@@ -167,6 +167,7 @@ void PaneDisplay::SetContent( PaneContents c )
StepsType st = GAMESTATE->GetCurrentStyleDef()->m_StepsType;
const Course *pCourse = GAMESTATE->m_pCurCourse;
const CourseDifficulty cd = GAMESTATE->m_PreferredCourseDifficulty[m_PlayerNumber];
const Trail *pTrail = pCourse ? pCourse->GetTrail(st,cd) : NULL;
float val = 0;
CString str;
@@ -218,7 +219,7 @@ void PaneDisplay::SetContent( PaneContents c )
case COURSE_MACHINE_HIGH_NAME: /* set val for color */
case COURSE_MACHINE_HIGH_SCORE:
val = 100.0f * PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,st,cd).GetTopScore().fPercentDP;
val = 100.0f * PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,pTrail).GetTopScore().fPercentDP;
break;
case COURSE_MACHINE_NUM_PLAYS:
@@ -234,7 +235,7 @@ void PaneDisplay::SetContent( PaneContents c )
break;
case COURSE_PROFILE_HIGH_SCORE:
val = 100.0f * PROFILEMAN->GetProfile(m_PlayerNumber)->GetCourseHighScoreList(pCourse,st,cd).GetTopScore().fPercentDP;
val = 100.0f * PROFILEMAN->GetProfile(m_PlayerNumber)->GetCourseHighScoreList(pCourse,pTrail).GetTopScore().fPercentDP;
break;
case COURSE_PROFILE_NUM_PLAYS:
val = (float) PROFILEMAN->GetProfile(m_PlayerNumber)->GetCourseNumTimesPlayed( pCourse );
@@ -267,7 +268,8 @@ void PaneDisplay::SetContent( PaneContents c )
str = PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps).GetTopScore().sName;
break;
case COURSE_MACHINE_HIGH_NAME:
str = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,st,cd).GetTopScore().sName;
str = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,pTrail).GetTopScore().sName;
break;
case SONG_MACHINE_HIGH_SCORE:
+13 -16
View File
@@ -22,6 +22,7 @@
#include "SongUtil.h" // for SongID
#include "StepsUtil.h" // for StepsID
#include "CourseUtil.h" // for CourseID
#include "TrailUtil.h" // for TrailID
struct XNode;
@@ -150,18 +151,22 @@ public:
//
// struct was a typedef'd array of HighScores, but VC6 freaks out
// in processing the templates for map::operator[].
struct HighScoresForATrail
{
HighScoreList hs;
};
struct HighScoresForACourse
{
HighScoreList hs[NUM_STEPS_TYPES][NUM_COURSE_DIFFICULTIES];
std::map<TrailID,HighScoresForATrail> m_TrailHighScores;
};
std::map<CourseID,HighScoresForACourse> m_CourseHighScores;
void AddCourseHighScore( const Course* pCourse, StepsType st, CourseDifficulty cd, HighScore hs, int &iIndexOut );
HighScoreList& GetCourseHighScoreList( const Course* pCourse, StepsType st, CourseDifficulty cd );
const HighScoreList& GetCourseHighScoreList( const Course* pCourse, StepsType st, CourseDifficulty cd ) const;
void AddCourseHighScore( const Course* pCourse, const Trail* pTrail, HighScore hs, int &iIndexOut );
HighScoreList& GetCourseHighScoreList( const Course* pCourse, const Trail* pTrail );
const HighScoreList& GetCourseHighScoreList( const Course* pCourse, const Trail* pTrail ) const;
int GetCourseNumTimesPlayed( const Course* pCourse ) const;
int GetCourseNumTimesPlayed( const CourseID& courseID ) const;
void IncrementCoursePlayCount( const Course* pCourse, StepsType st, CourseDifficulty cd );
void IncrementCoursePlayCount( const Course* pCourse, const Trail* pTrail );
//
@@ -267,6 +272,7 @@ public:
struct HighScoreForACourse
{
CourseID courseID;
TrailID trailID;
HighScore hs;
HighScoreForACourse() { Unset(); }
@@ -276,7 +282,7 @@ public:
void LoadFromNode( const XNode* pNode );
};
vector<HighScoreForACourse> m_vRecentCourseScores;
void AddCourseRecentScore( const Course* pCourse, StepsType st, CourseDifficulty cd, HighScore hs );
void AddCourseRecentScore( const Course* pCourse, const Trail* pTrail, HighScore hs );
//
// Init'ing
@@ -311,11 +317,6 @@ public:
bool LoadAllFromDir( CString sDir, bool bRequireSignature ); // return false on error
bool SaveAllToDir( CString sDir, bool bSignData ) const;
void LoadProfileDataFromDirSM390a12( CString sDir );
void LoadSongScoresFromDirSM390a12( CString sDir );
void LoadCourseScoresFromDirSM390a12( CString sDir );
void LoadCategoryScoresFromDirSM390a12( CString sDir );
void LoadEditableDataFromDir( CString sDir );
void LoadGeneralDataFromNode( const XNode* pNode );
void LoadSongScoresFromNode( const XNode* pNode );
@@ -338,16 +339,12 @@ public:
XNode* SaveRecentSongScoresCreateNode() const;
XNode* SaveRecentCourseScoresCreateNode() const;
void DeleteProfileDataFromDirSM390a12( CString sDir ) const;
void DeleteSongScoresFromDirSM390a12( CString sDir ) const;
void DeleteCourseScoresFromDirSM390a12( CString sDir ) const;
void DeleteCategoryScoresFromDirSM390a12( CString sDir ) const;
void SaveStatsWebPageToDir( CString sDir ) const;
void SaveMachinePublicKeyToDir( CString sDir ) const;
private:
const HighScoresForASong *GetHighScoresForASong( const SongID& songID ) const;
const HighScoresForACourse *GetHighScoresForACourse( const CourseID& courseID ) const;
};
+8 -3
View File
@@ -737,7 +737,11 @@ bool PrintHighScoresForCourse( RageFile &f, const Profile *pProfile, Course* pCo
{
FOREACH_ShownCourseDifficulty( cd )
{
const HighScoreList &hsl = pProfile->GetCourseHighScoreList( pCourse, st, cd );
Trail *pTrail = pCourse->GetTrail( st, cd );
if( pTrail == NULL )
continue;
const HighScoreList &hsl = pProfile->GetCourseHighScoreList( pCourse, pTrail );
if( hsl.vHighScores.empty() )
continue;
@@ -886,7 +890,8 @@ bool PrintPercentCompleteForStepsType( RageFile &f, const Profile *pProfile, Ste
FOREACH_ShownCourseDifficulty( cd )
{
if( pCourse->HasCourseDifficulty(st,cd) )
Trail *pTrail = pCourse->GetTrail( st, cd );
if( pTrail )
{
TranslatedWrite(f,"<td>");
/* HACK: Course::GetMeter() requires that a style be set, since
@@ -896,7 +901,7 @@ bool PrintPercentCompleteForStepsType( RageFile &f, const Profile *pProfile, Ste
GAMESTATE->m_CurStyle = STYLE_DANCE_SINGLE;
float fMeter = pCourse->GetMeter(st,cd);
TranslatedWrite(f, ssprintf("(%.2f)",fMeter) );
HighScore hs = pProfile->GetCourseHighScoreList(pCourse, st, cd).GetTopScore();
HighScore hs = pProfile->GetCourseHighScoreList(pCourse,pTrail).GetTopScore();
Grade grade = hs.grade;
if( grade != GRADE_NO_DATA )
{
+8 -8
View File
@@ -498,29 +498,29 @@ HighScore ProfileManager::GetHighScoreForDifficulty( const Song *s, const StyleD
//
// Course stats
//
void ProfileManager::AddCourseScore( const Course* pCourse, StepsType st, CourseDifficulty cd, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut )
void ProfileManager::AddCourseScore( const Course* pCourse, const Trail* pTrail, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut )
{
// Don't use a minimum percentage for Course scores
// if( hs.fPercentDP >= PREFSMAN->m_fMinPercentageForHighScore )
{
hs.sName = RANKING_TO_FILL_IN_MARKER[pn];
if( PROFILEMAN->IsUsingProfile(pn) )
PROFILEMAN->GetProfile(pn)->AddCourseHighScore( pCourse, st, cd, hs, iPersonalIndexOut );
PROFILEMAN->GetProfile(pn)->AddCourseHighScore( pCourse, pTrail, hs, iPersonalIndexOut );
else
iPersonalIndexOut = -1;
PROFILEMAN->GetMachineProfile()->AddCourseHighScore( pCourse, st, cd, hs, iMachineIndexOut );
PROFILEMAN->GetMachineProfile()->AddCourseHighScore( pCourse, pTrail, hs, iMachineIndexOut );
}
if( PROFILEMAN->IsUsingProfile(pn) )
PROFILEMAN->GetProfile(pn)->AddCourseRecentScore( pCourse, st, cd, hs );
PROFILEMAN->GetMachineProfile()->AddCourseRecentScore( pCourse, st, cd, hs );
PROFILEMAN->GetProfile(pn)->AddCourseRecentScore( pCourse, pTrail, hs );
PROFILEMAN->GetMachineProfile()->AddCourseRecentScore( pCourse, pTrail, hs );
}
void ProfileManager::IncrementCoursePlayCount( const Course* pCourse, StepsType st, CourseDifficulty cd, PlayerNumber pn )
void ProfileManager::IncrementCoursePlayCount( const Course* pCourse, const Trail* pTrail, PlayerNumber pn )
{
if( PROFILEMAN->IsUsingProfile(pn) )
PROFILEMAN->GetProfile(pn)->IncrementCoursePlayCount( pCourse, st, cd );
PROFILEMAN->GetMachineProfile()->IncrementCoursePlayCount( pCourse, st, cd );
PROFILEMAN->GetProfile(pn)->IncrementCoursePlayCount( pCourse, pTrail );
PROFILEMAN->GetMachineProfile()->IncrementCoursePlayCount( pCourse, pTrail );
}
+2 -2
View File
@@ -77,8 +77,8 @@ public:
//
// Course stats
//
void AddCourseScore( const Course* pCourse, StepsType st, CourseDifficulty cd, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut );
void IncrementCoursePlayCount( const Course* pCourse, StepsType st, CourseDifficulty cd, PlayerNumber pn );
void AddCourseScore( const Course* pCourse, const Trail* pTrail, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut );
void IncrementCoursePlayCount( const Course* pCourse, const Trail* pTrail, PlayerNumber pn );
//
// Category stats
+9 -5
View File
@@ -946,15 +946,17 @@ void ScreenEvaluation::CommitScores(
case course:
{
Course* pCourse = GAMESTATE->m_pCurCourse;
CourseDifficulty cd = GAMESTATE->m_PreferredCourseDifficulty[p];
ASSERT( pCourse );
CourseDifficulty cd = GAMESTATE->m_PreferredCourseDifficulty[p];
StepsType st = GAMESTATE->GetCurrentStyleDef()->m_StepsType;
Trail* pTrail = pCourse->GetTrail( st, cd );
// don't save scores for a failed Nonstop
// DO save scores for a failed Oni/Endless
if( stageStats.bFailed[p] && pCourse->IsNonstop() )
continue;
PROFILEMAN->AddCourseScore( pCourse, nt, cd, p, hs, iPersonalHighScoreIndexOut[p], iMachineHighScoreIndexOut[p] );
PROFILEMAN->AddCourseScore( pCourse, pTrail, p, hs, iPersonalHighScoreIndexOut[p], iMachineHighScoreIndexOut[p] );
}
break;
default:
@@ -976,7 +978,7 @@ void ScreenEvaluation::CommitScores(
HighScore &hs = m_HighScore[p];
Profile* pProfile = PROFILEMAN->GetMachineProfile();
StepsType nt = GAMESTATE->GetCurrentStyleDef()->m_StepsType;
StepsType st = GAMESTATE->GetCurrentStyleDef()->m_StepsType;
const HighScoreList *pHSL = NULL;
switch( m_Type )
@@ -990,15 +992,17 @@ void ScreenEvaluation::CommitScores(
break;
case summary:
{
pHSL = &pProfile->GetCategoryHighScoreList( nt, rcOut[p] );
pHSL = &pProfile->GetCategoryHighScoreList( st, rcOut[p] );
}
break;
case course:
{
Course* pCourse = GAMESTATE->m_pCurCourse;
CourseDifficulty cd = GAMESTATE->m_PreferredCourseDifficulty[p];
Trail *pTrail = pCourse->GetTrail( st, cd );
ASSERT( pCourse );
pHSL = &pProfile->GetCourseHighScoreList( pCourse, nt, cd );
ASSERT( pTrail );
pHSL = &pProfile->GetCourseHighScoreList( pCourse, pTrail );
}
break;
default:
+7 -1
View File
@@ -188,8 +188,14 @@ void ScreenGameplay::Init()
/* Increment the play count. */
if( !m_bDemonstration )
{
FOREACH_EnabledPlayer(p)
PROFILEMAN->IncrementCoursePlayCount( pCourse, st, GAMESTATE->m_PreferredCourseDifficulty[p], (PlayerNumber)p );
{
CourseDifficulty cd = GAMESTATE->m_PreferredCourseDifficulty[p];
Trail* pTrail = pCourse->GetTrail( st, cd );
PROFILEMAN->IncrementCoursePlayCount( pCourse, pTrail, p );
}
}
m_apSongsQueue.clear();
PlayerNumber pnMaster = GAMESTATE->m_MasterPlayerNumber;
+5 -1
View File
@@ -322,6 +322,10 @@ ScreenNameEntryTraditional::ScreenNameEntryTraditional( CString sClassName ) : S
Song* pSong = ss.pSong;
Steps* pSteps = ss.pSteps[p];
Course* pCourse = GAMESTATE->m_pCurCourse;
StepsType st = GAMESTATE->GetCurrentStyleDef()->m_StepsType;
CourseDifficulty cd = GAMESTATE->m_PreferredCourseDifficulty[p];
Trail* pTrail = pCourse->GetTrail( st, cd );
int iHighScoreIndex = -1; // -1 means "out of ranking"
Grade grade = ss.GetGrade( p );
int iScore = ss.iScore[p];
@@ -337,7 +341,7 @@ ScreenNameEntryTraditional::ScreenNameEntryTraditional( CString sClassName ) : S
const HighScoreList& hsl =
GAMESTATE->IsCourseMode() ?
PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse, GAMESTATE->GetCurrentStyleDef()->m_StepsType, GAMESTATE->m_PreferredCourseDifficulty[p]) :
PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse, pTrail) :
PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps);
for( unsigned h=0; h<hsl.vHighScores.size(); h++ )
+5 -2
View File
@@ -721,7 +721,9 @@ float ScreenRanking::SetPage( PageToShow pts )
m_Banner.LoadFromCourse( pts.pCourse );
m_textStepsType.SetText( GameManager::NotesTypeToThemedString(pts.nt) );
const HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList( pts.pCourse, pts.nt, pts.cd );
Trail *pTrail = pts.pCourse->GetTrail( pts.nt, pts.cd );
ASSERT( pTrail );
const HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList( pts.pCourse, pTrail );
for( int l=0; l<NUM_RANKING_LINES; l++ )
{
HighScore hs;
@@ -823,7 +825,8 @@ float ScreenRanking::SetPage( PageToShow pts )
pCourseScoreRowItem->m_textSongTitle.SetText( pCourse->m_sName );
FOREACH_ShownCourseDifficulty( cd )
{
const HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList( pCourse, pts.nt, cd );
Trail *pTrail = pCourse->GetTrail( pts.nt, cd );
const HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList( pCourse, pTrail );
BitmapText* pTextStepsScore = &pCourseScoreRowItem->m_textStepsScore[cd];
HighScore hs;
+2 -1
View File
@@ -416,7 +416,8 @@ void ScreenSelectCourse::AfterCourseChange()
* have an opinion on which should be used here for
* each of oni, endless, nonstop --
* should this choice be an option or a metric? */
const HighScoreList& hsl = pProfile->GetCourseHighScoreList( pCourse, st, cd );
Trail *pTrail = pCourse->GetTrail( st, cd );
const HighScoreList& hsl = pProfile->GetCourseHighScoreList( pCourse, pTrail );
if ( pCourse->IsOni() || pCourse->IsEndless() )
{
/* use survive time */
+1
View File
@@ -123,6 +123,7 @@ void StepsUtil::SortStepsByTypeAndDifficulty( vector<Steps*> &arraySongPointers
sort( arraySongPointers.begin(), arraySongPointers.end(), CompareStepsPointersByTypeAndDifficulty );
}
void StepsID::FromSteps( const Steps *p )
{
if( p == NULL )
+14 -4
View File
@@ -1,5 +1,15 @@
#ifndef Trail_H
#define Trail_H
/*
-----------------------------------------------------------------------------
Class: TrialUtil
Desc:
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "Attack.h"
@@ -30,14 +40,14 @@ struct TrailEntry
class Trail
{
public:
StepsType m_st;
CourseDifficulty m_cd;
StepsType m_StepsType;
CourseDifficulty m_CourseDifficulty;
vector<TrailEntry> m_vEntries;
Trail()
{
m_st = STEPS_TYPE_INVALID;
m_cd = COURSE_DIFFICULTY_INVALID;
m_StepsType = STEPS_TYPE_INVALID;
m_CourseDifficulty = COURSE_DIFFICULTY_INVALID;
}
RadarValues GetRadarValues() const;
+85
View File
@@ -0,0 +1,85 @@
#include "global.h"
/*
-----------------------------------------------------------------------------
Class: TrailUtil
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "TrailUtil.h"
#include "Trail.h"
#include "Course.h"
#include "XmlFile.h"
#include "GameManager.h"
void TrailID::FromTrail( const Trail *p )
{
if( p == NULL )
{
st = STEPS_TYPE_INVALID;
cd = COURSE_DIFFICULTY_INVALID;
}
else
{
st = p->m_StepsType;
cd = p->m_CourseDifficulty;
}
}
Trail *TrailID::ToTrail( const Course *p, bool bAllowNull ) const
{
if( st == STEPS_TYPE_INVALID || cd == COURSE_DIFFICULTY_INVALID )
return NULL;
return p->GetTrail( st, cd );
}
XNode* TrailID::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "Trail";
pNode->AppendAttr( "StepsType", GameManager::NotesTypeToString(st) );
pNode->AppendAttr( "CourseDifficulty", CourseDifficultyToString(cd) );
return pNode;
}
void TrailID::LoadFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "Trail" );
CString sTemp;
pNode->GetAttrValue("StepsType", sTemp);
st = GameManager::StringToNotesType( sTemp );
pNode->GetAttrValue("CourseDifficulty", sTemp);
cd = StringToCourseDifficulty( sTemp );
}
CString TrailID::ToString() const
{
CString s = GameManager::NotesTypeToString(st);
s += " " + CourseDifficultyToString(cd);
return s;
}
bool TrailID::IsValid() const
{
return st != STEPS_TYPE_INVALID && cd != COURSE_DIFFICULTY_INVALID;
}
bool TrailID::operator<( const TrailID &rhs ) const
{
#define COMP(a) if(a<rhs.a) return true; if(a>rhs.a) return false;
COMP(st);
COMP(cd);
#undef COMP
return false;
}
+40
View File
@@ -0,0 +1,40 @@
#ifndef TrialUtil_H
#define TrialUtil_H
/*
-----------------------------------------------------------------------------
Class: TrialUtil
Desc: An queue of Songs and Steps that are generated from a Course.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "GameConstantsAndTypes.h"
class Trail;
class Course;
struct XNode;
class TrailID
{
StepsType st;
CourseDifficulty cd;
public:
TrailID() { Unset(); }
void Unset() { FromTrail(NULL); }
void FromTrail( const Trail *p );
Trail *ToTrail( const Course *p, bool bAllowNull ) const;
bool operator<( const TrailID &rhs ) const;
bool MatchesStepsType( StepsType s ) const { return st == s; }
XNode* CreateNode() const;
void LoadFromNode( const XNode* pNode );
CString ToString() const;
bool IsValid() const;
static void FlushCache();
};
#endif