simplify using a functor class instead of a template
This commit is contained in:
+17
-30
@@ -1349,43 +1349,30 @@ void SortSongPointerArrayByMostPlayed( vector<Song*> &arraySongPointers )
|
|||||||
song_sort_val.clear();
|
song_sort_val.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <Difficulty dc>
|
struct CompareSongByMeter
|
||||||
int CompareSongByMeter(const Song* pSong1, const Song* pSong2)
|
|
||||||
{
|
{
|
||||||
Notes* pNotes1 = pSong1->GetNotes( GAMESTATE->GetCurrentStyleDef()->m_NotesType, dc );
|
Difficulty dc;
|
||||||
Notes* pNotes2 = pSong2->GetNotes( GAMESTATE->GetCurrentStyleDef()->m_NotesType, dc );
|
|
||||||
|
|
||||||
int iMeter1 = pNotes1 ? pNotes1->GetMeter() : 0;
|
CompareSongByMeter(Difficulty d): dc(d) { }
|
||||||
int iMeter2 = pNotes2 ? pNotes2->GetMeter() : 0;
|
bool operator() (const Song* pSong1, const Song* pSong2)
|
||||||
|
{
|
||||||
|
Notes* pNotes1 = pSong1->GetNotes( GAMESTATE->GetCurrentStyleDef()->m_NotesType, dc );
|
||||||
|
Notes* pNotes2 = pSong2->GetNotes( GAMESTATE->GetCurrentStyleDef()->m_NotesType, dc );
|
||||||
|
|
||||||
if( iMeter1 < iMeter2 )
|
const int iMeter1 = pNotes1 ? pNotes1->GetMeter() : 0;
|
||||||
return true;
|
const int iMeter2 = pNotes2 ? pNotes2->GetMeter() : 0;
|
||||||
if( iMeter1 > iMeter2 )
|
|
||||||
return false;
|
|
||||||
return CompareSongPointersByTitle( pSong1, pSong2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hack for VC6: There's no other way I could get this to work. Types of templated functions
|
if( iMeter1 < iMeter2 )
|
||||||
// are totally hosed if a templated function is used on the RHS or as a parameter a function
|
return true;
|
||||||
// (e.g. to sort()).
|
if( iMeter1 > iMeter2 )
|
||||||
int CompareSongByEasyMeter(const Song* pSong1, const Song* pSong2)
|
return false;
|
||||||
{ return CompareSongByMeter<DIFFICULTY_EASY>(pSong1,pSong2); };
|
return CompareSongPointersByTitle( pSong1, pSong2 );
|
||||||
|
}
|
||||||
int CompareSongByMediumMeter(const Song* pSong1, const Song* pSong2)
|
};
|
||||||
{ return CompareSongByMeter<DIFFICULTY_MEDIUM>(pSong1,pSong2); };
|
|
||||||
|
|
||||||
int CompareSongByHardMeter(const Song* pSong1, const Song* pSong2)
|
|
||||||
{ return CompareSongByMeter<DIFFICULTY_HARD>(pSong1,pSong2); };
|
|
||||||
|
|
||||||
void SortSongPointerArrayByMeter( vector<Song*> &arraySongPointers, Difficulty dc )
|
void SortSongPointerArrayByMeter( vector<Song*> &arraySongPointers, Difficulty dc )
|
||||||
{
|
{
|
||||||
switch( dc )
|
sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongByMeter(dc) );
|
||||||
{
|
|
||||||
case DIFFICULTY_EASY: sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongByEasyMeter ); break;
|
|
||||||
case DIFFICULTY_MEDIUM: sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongByMediumMeter ); break;
|
|
||||||
case DIFFICULTY_HARD: sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongByHardMeter ); break;
|
|
||||||
default: ASSERT(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Song::NormallyDisplayed() const
|
bool Song::NormallyDisplayed() const
|
||||||
|
|||||||
Reference in New Issue
Block a user