diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 2068ca11e7..99a65d8c87 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -186,6 +186,8 @@ void Course::LoadFromCRSFile( CString sPath ) new_entry.players_index = atoi( sParams[1].Right(sParams[1].size()-strlen("BEST")) ) - 1; CLAMP( new_entry.players_index, 0, 500 ); } + else if( sParams[1] == "CAPRICE" ) + new_entry.type = Entry::caprice; else if( sParams[1].Left(strlen("WORST")) == "WORST" ) { new_entry.type = Entry::worst; @@ -452,7 +454,7 @@ void Course::GetCourseInfo( NotesType nt, vector &ci, int Difficul for( unsigned i=0; i &ci, int Difficul switch( e.type ) { + case Entry::caprice: + if (m_bCapriceCached) + { + if (i > m_CapriceEntries.size()) break; // out of range + + pSong = m_CapriceEntries[i]; + LOG->Trace("Accessing caprice at %d - %s", pSong, pSong->GetFullTranslitTitle().c_str()); + if( pSong ) + { + if( e.difficulty == DIFFICULTY_INVALID ) + pNotes = pSong->GetNotes( nt, low_meter, high_meter, PREFSMAN->m_bAutogenMissingTypes ); + else + pNotes = pSong->GetNotes( nt, e.difficulty, PREFSMAN->m_bAutogenMissingTypes ); + } + } + else + { + // find a song with the notes we want + for( unsigned j=0; jm_sGroupName.CompareNoCase(e.group_name)) + continue; /* wrong group */ + + if( e.difficulty == DIFFICULTY_INVALID ) + pNotes = pSong->GetNotes( nt, low_meter, high_meter, PREFSMAN->m_bAutogenMissingTypes ); + else + pNotes = pSong->GetNotes( nt, e.difficulty, PREFSMAN->m_bAutogenMissingTypes ); + + if( pNotes ) // found a match + { + LOG->Trace("Accessing caprice at %d", pSong); + m_CapriceEntries.push_back(pSong); // cache it for later + LOG->Trace("Song title: %s", pSong->GetFullTranslitTitle().c_str() ); + break; // stop searching + } + + pSong = NULL; + pNotes = NULL; + } + } + break; case Entry::fixed: pSong = e.pSong; if( pSong ) @@ -560,6 +608,8 @@ void Course::GetCourseInfo( NotesType nt, vector &ci, int Difficul cinfo.Difficult = IsDifficult(Difficult); ci.push_back( cinfo ); } + + m_bCapriceCached = true; } RageColor Course::GetColor() const @@ -862,6 +912,9 @@ void Course::UpdateCourseStats() { LOG->Trace("Updating course stats for %s", this->m_sName.c_str() ); + m_CapriceEntries.clear(); // regenerate caprice entries + m_bCapriceCached = false; // on update + SortOrder_AvgDifficulty = 0; SortOrder_Ranking = 2; SortOrder_TotalDifficulty = 0; diff --git a/stepmania/src/Course.h b/stepmania/src/Course.h index 3e7cd2c6df..0d03cad2d6 100644 --- a/stepmania/src/Course.h +++ b/stepmania/src/Course.h @@ -22,7 +22,7 @@ class Notes; class Course { struct Entry { - enum Type { fixed, random, random_within_group, best, worst } type; + enum Type { fixed, random, random_within_group, best, worst, caprice } type; Song* pSong; // used in type=fixed CString group_name; // used in type=random_within_group Difficulty difficulty; // = DIFFICULTY_INVALID if no difficulty specified @@ -41,6 +41,9 @@ class Course }; vector m_entries; + mutable bool m_bCapriceCached; // whether or not caprice has been generated + mutable vector m_CapriceEntries; // caprice entries + public: Course();