diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 112b39e1b6..5e3f0862d5 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -79,29 +79,9 @@ void Course::SetDefaultScore() Song *Course::FindSong(CString sGroup, CString sSong) const { - const vector &apSongs = SONGMAN->GetAllSongs(); - - // foreach song - for( unsigned i = 0; i < apSongs.size(); i++ ) - { - Song* pSong = apSongs[i]; - - if( sGroup.size() && sGroup.CompareNoCase(pSong->m_sGroupName) != 0) - continue; /* wrong group */ - - CString sDir = pSong->GetSongDir(); - sDir.Replace("\\","/"); - CStringArray bits; - split( sDir, "/", bits ); - ASSERT(bits.size() >= 2); /* should always have at least two parts */ - CString sLastBit = bits[bits.size()-1]; - - // match on song dir or title (ala DWI) - if( sSong.CompareNoCase(sLastBit)==0 ) - return pSong; - if( sSong.CompareNoCase(pSong->GetFullTranslitTitle())==0 ) - return pSong; - } + Song *pSong = SONGMAN->FindSong( sGroup, sSong ); + if( pSong ) + return pSong; LOG->Trace( "Course file '%s' contains a song '%s%s%s' that is not present", m_sPath.c_str(), sGroup.c_str(), sGroup.size()? "/":"", sSong.c_str()); diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index c14ee6a528..116105f56e 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -1570,3 +1570,25 @@ int Song::GetNumNotesWithGrade( Grade g ) const iCount++; return iCount; } + +bool Song::Matches(CString sGroup, CString sSong) const +{ + if( sGroup.size() && sGroup.CompareNoCase(this->m_sGroupName) != 0) + return false; + + CString sDir = this->GetSongDir(); + sDir.Replace("\\","/"); + CStringArray bits; + split( sDir, "/", bits ); + ASSERT(bits.size() >= 2); /* should always have at least two parts */ + CString sLastBit = bits[bits.size()-1]; + + // match on song dir or title (ala DWI) + if( !sSong.CompareNoCase(sLastBit) ) + return true; + if( !sSong.CompareNoCase(this->GetFullTranslitTitle()) ) + return true; + + return false; +} + diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index c6e7059aa2..f505e11953 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1067,4 +1067,15 @@ void SongManager::AddScores( NotesType nt, bool bPlayerEnabled[NUM_PLAYERS], } } +Song *SongManager::FindSong( CString sGroup, CString sSong ) +{ + // foreach song + for( unsigned i = 0; i < m_pSongs.size(); i++ ) + { + if( m_pSongs[i]->Matches(sGroup, sSong) ) + return m_pSongs[i]; + } + + return NULL; +} diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index 074198a522..6ce4ed0408 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -60,6 +60,7 @@ public: void GetSongs( vector &AddTo, CString sGroupName, int iMaxStages = 100000 /*inf*/ ) const; void GetSongs( vector &AddTo, int iMaxStages ) const { GetSongs(AddTo,"",iMaxStages); } void GetSongs( vector &AddTo ) const { GetSongs(AddTo,"",100000 /*inf*/ ); } + Song *FindSong( CString sGroup, CString sSong ); int GetNumSongs() const; int GetNumGroups() const; int GetNumCourses() const; diff --git a/stepmania/src/song.h b/stepmania/src/song.h index 6fc8e4e21a..cc234f29bc 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -170,6 +170,8 @@ public: bool HasLyrics() const; bool m_bIsLocked; + bool Matches(CString sGroup, CString sSong) const; + vector m_BPMSegments; // this must be sorted before gameplay vector m_StopSegments; // this must be sorted before gameplay vector m_BackgroundChanges; // this must be sorted before gameplay