From d62369baf12ec59f629a4d75b6e42ff5a33bb5be Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 18 Apr 2004 19:36:42 +0000 Subject: [PATCH] don't throw away Course scores for Courses that aren't currently loaded on the machine --- stepmania/src/CourseUtil.cpp | 36 ++++++++++++++- stepmania/src/CourseUtil.h | 9 ++++ stepmania/src/Profile.cpp | 81 +++++++++++++++++++-------------- stepmania/src/Profile.h | 5 +- stepmania/src/ReceptorArrow.cpp | 2 + stepmania/src/SongUtil.cpp | 1 - stepmania/src/SongUtil.h | 1 - stepmania/src/StepsUtil.h | 1 - 8 files changed, 94 insertions(+), 42 deletions(-) diff --git a/stepmania/src/CourseUtil.cpp b/stepmania/src/CourseUtil.cpp index 43e4ec75a2..b11a604a35 100644 --- a/stepmania/src/CourseUtil.cpp +++ b/stepmania/src/CourseUtil.cpp @@ -185,8 +185,16 @@ void CourseID::FromCourse( const Course *p ) { if( p ) { - sPath = p->m_sPath; - sName = p->m_sName; + if( p->m_bIsAutogen ) + { + sPath = ""; + sName = p->m_sName; + } + else + { + sPath = p->m_sPath; + sName = ""; + } } else { @@ -205,3 +213,27 @@ Course *CourseID::ToCourse() const return pCourse; } +XNode* CourseID::CreateNode() const +{ + XNode* pNode = new XNode; + pNode->name = "Course"; + + if( !sPath.empty() ) + pNode->AppendAttr( "Path", sPath ); + if( !sName.empty() ) + pNode->AppendAttr( "Name", sName ); + + return pNode; +} + +void CourseID::LoadFromNode( const XNode* pNode ) +{ + ASSERT( pNode->name == "Course" ); + pNode->GetAttrValue("Path", sPath); + pNode->GetAttrValue("Name", sName); +} + +bool CourseID::IsValid() const +{ + return !sPath.empty() || !sName.empty(); +} diff --git a/stepmania/src/CourseUtil.h b/stepmania/src/CourseUtil.h index 9f2bcb60b2..8af3bd6f2c 100644 --- a/stepmania/src/CourseUtil.h +++ b/stepmania/src/CourseUtil.h @@ -15,6 +15,7 @@ class Course; class Profile; +struct XNode; namespace CourseUtil { @@ -38,6 +39,14 @@ public: CourseID() { FromCourse(NULL); } void FromCourse( const Course *p ); Course *ToCourse() const; + bool operator<( const CourseID &other ) const + { + return sPath < other.sPath || sName < other.sName; + } + + XNode* CreateNode() const; + void LoadFromNode( const XNode* pNode ); + bool IsValid() const; }; #endif diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index bbd09ad912..6d704d6372 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -235,18 +235,23 @@ int Profile::GetTotalHighScoreDancePointsForStepsType( StepsType st ) const // add course high scores { - for( std::map::const_iterator iter = m_CourseHighScores.begin(); - iter != m_CourseHighScores.end(); - iter++ ) + for( std::map::const_iterator i = m_CourseHighScores.begin(); + i != m_CourseHighScores.end(); + i++ ) { - const Course* pCourse = iter->first; - ASSERT( pCourse ); + CourseID id = i->first; + const Course* pCourse = id.ToCourse(); + + // If the Course isn't loaded on the current machine, then we can't + // get radar values to compute dance points. + if( pCourse == NULL ) + continue; // Don't count any course that has any entries that change over time. if( !pCourse->AllSongsAreFixed() ) continue; - const HighScoresForACourse& h = iter->second; + const HighScoresForACourse& h = i->second; FOREACH_CourseDifficulty( cd ) { const HighScoreList& hs = h.hs[st][cd]; @@ -336,30 +341,44 @@ void Profile::IncrementStepsPlayCount( const Song* pSong, const Steps* pSteps ) // void Profile::AddCourseHighScore( const Course* pCourse, StepsType st, CourseDifficulty cd, HighScore hs, int &iIndexOut ) { - std::map::iterator iter = m_CourseHighScores.find( pCourse ); + CourseID courseID; + courseID.FromCourse( pCourse ); + + std::map::iterator iter = m_CourseHighScores.find( courseID ); if( iter == m_CourseHighScores.end() ) - m_CourseHighScores[pCourse].hs[st][cd].AddHighScore( hs, iIndexOut ); // operator[] inserts into map + m_CourseHighScores[courseID].hs[st][cd].AddHighScore( hs, iIndexOut ); // operator[] inserts into map else iter->second.hs[st][cd].AddHighScore( hs, iIndexOut ); } const HighScoreList& Profile::GetCourseHighScoreList( const Course* pCourse, StepsType st, CourseDifficulty cd ) const { - return ((Profile *)this)->m_CourseHighScores[pCourse].hs[st][cd]; + return ((Profile *)this)->GetCourseHighScoreList( pCourse, st, cd ); } HighScoreList& Profile::GetCourseHighScoreList( const Course* pCourse, StepsType st, CourseDifficulty cd ) { - std::map::iterator iter = m_CourseHighScores.find( pCourse ); + CourseID courseID; + courseID.FromCourse( pCourse ); + + std::map::iterator iter = m_CourseHighScores.find( courseID ); if( iter == m_CourseHighScores.end() ) - return m_CourseHighScores[pCourse].hs[st][cd]; // operator[] inserts into map + return m_CourseHighScores[courseID].hs[st][cd]; // operator[] inserts into map else return iter->second.hs[st][cd]; } int Profile::GetCourseNumTimesPlayed( const Course* pCourse ) const { - std::map::const_iterator iter = m_CourseHighScores.find( pCourse ); + CourseID courseID; + courseID.FromCourse( pCourse ); + + return GetCourseNumTimesPlayed( courseID ); +} + +int Profile::GetCourseNumTimesPlayed( const CourseID &courseID ) const +{ + std::map::const_iterator iter = m_CourseHighScores.find( courseID ); if( iter == m_CourseHighScores.end() ) { return 0; @@ -1275,19 +1294,19 @@ XNode* Profile::SaveCourseScoresCreateNode() const XNode* pNode = new XNode; pNode->name = "CourseScores"; - vector vpCourses; - SONGMAN->GetAllCourses( vpCourses, true ); - for( unsigned c=0; c::const_iterator i = m_CourseHighScores.begin(); + i != m_CourseHighScores.end(); + i++ ) { - Course *pCourse = vpCourses[c]; + const CourseID &id = i->first; + const HighScoresForACourse &hsCourse = i->second; // skip courses that have never been played - if( pProfile->GetCourseNumTimesPlayed(pCourse) == 0 ) + if( pProfile->GetCourseNumTimesPlayed(id) == 0 ) continue; - XNode* pCourseNode = pNode->AppendChild( "Course" ); - pCourseNode->AppendAttr( "Name", pCourse->m_bIsAutogen ? pCourse->m_sName : pCourse->m_sPath ); + XNode* pCourseNode = pNode->AppendChild( id.CreateNode() ); for( StepsType st=(StepsType)0; stGetCourseHighScoreList(pCourse, st, cd).iNumTimesPlayed == 0 ) + if( hsl.iNumTimesPlayed == 0 ) continue; LPXNode pCourseDifficultyNode = pStepsTypeNode->AppendChild( "CourseDifficulty" ); pCourseDifficultyNode->AppendAttr( "Type", CourseDifficultyToString(cd) ); - - const HighScoreList &hsl = pProfile->GetCourseHighScoreList( pCourse, st, cd ); - + pCourseDifficultyNode->AppendChild( hsl.CreateNode() ); } @@ -1332,19 +1351,11 @@ void Profile::LoadCourseScoresFromNode( const XNode* pNode ) if( (*course)->name != "Course" ) continue; - CString sCourse; - if( !(*course)->GetAttrValue( "Name", sCourse ) ) + CourseID id; + id.LoadFromNode( *course ); + if( !id.IsValid() ) WARN_AND_CONTINUE; - Course* pCourse = SONGMAN->GetCourseFromPath( sCourse ); - if( pCourse == NULL ) - pCourse = SONGMAN->GetCourseFromName( sCourse ); - if( pCourse == NULL ) - { - LOG->Trace("Couldn't find course \"%s\"; scoring data will be lost", sCourse.c_str() ); - continue; - } - for( XNodes::iterator stepsType = (*course)->childs.begin(); stepsType != (*course)->childs.end(); stepsType++ ) @@ -1375,7 +1386,7 @@ void Profile::LoadCourseScoresFromNode( const XNode* pNode ) if( pHighScoreListNode == NULL ) WARN_AND_CONTINUE; - HighScoreList &hsl = this->GetCourseHighScoreList( pCourse, st, cd ); + HighScoreList &hsl = m_CourseHighScores[id].hs[st][cd]; hsl.LoadFromNode( pHighScoreListNode ); } } diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index c9c7452cb4..bbce50840d 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -22,7 +22,7 @@ #include "TimeConstants.h" #include "SongUtil.h" // for SongID #include "StepsUtil.h" // for StepsID - +#include "CourseUtil.h" // for CourseID // // Current file versions @@ -148,12 +148,13 @@ public: { HighScoreList hs[NUM_STEPS_TYPES][NUM_COURSE_DIFFICULTIES]; }; - std::map m_CourseHighScores; + std::map 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; int GetCourseNumTimesPlayed( const Course* pCourse ) const; + int GetCourseNumTimesPlayed( const CourseID& courseID ) const; void IncrementCoursePlayCount( const Course* pCourse, StepsType st, CourseDifficulty cd ); diff --git a/stepmania/src/ReceptorArrow.cpp b/stepmania/src/ReceptorArrow.cpp index e9bc736402..f1c531dc18 100644 --- a/stepmania/src/ReceptorArrow.cpp +++ b/stepmania/src/ReceptorArrow.cpp @@ -80,6 +80,8 @@ void ReceptorArrow::DrawPrimitives() void ReceptorArrow::Step() { + m_pReceptorGo->FinishTweening(); + m_pReceptorWaiting->FinishTweening(); m_pReceptorGo->Command( m_sStepCommand ); m_pReceptorWaiting->Command( m_sStepCommand ); } diff --git a/stepmania/src/SongUtil.cpp b/stepmania/src/SongUtil.cpp index 901d40a2d8..ce3dd438b1 100644 --- a/stepmania/src/SongUtil.cpp +++ b/stepmania/src/SongUtil.cpp @@ -369,7 +369,6 @@ Song *SongID::ToSong() const return SONGMAN->GetSongFromDir( sDir ); } - XNode* SongID::CreateNode() const { XNode* pNode = new XNode; diff --git a/stepmania/src/SongUtil.h b/stepmania/src/SongUtil.h index ac96c37d6c..8d92588d37 100644 --- a/stepmania/src/SongUtil.h +++ b/stepmania/src/SongUtil.h @@ -49,7 +49,6 @@ public: XNode* CreateNode() const; void LoadFromNode( const XNode* pNode ); - bool IsValid() const; }; diff --git a/stepmania/src/StepsUtil.h b/stepmania/src/StepsUtil.h index 2415446329..b15a6a8c86 100644 --- a/stepmania/src/StepsUtil.h +++ b/stepmania/src/StepsUtil.h @@ -49,7 +49,6 @@ public: XNode* CreateNode() const; void LoadFromNode( const XNode* pNode ); - bool IsValid() const; };