change more qsorts to sort
This commit is contained in:
@@ -34,26 +34,15 @@ const float FADE_SECONDS = 1.0f;
|
||||
|
||||
#define RECT_BACKGROUND CRect(LEFT_EDGE,TOP_EDGE,RIGHT_EDGE,BOTTOM_EDGE)
|
||||
|
||||
int CompareBGSegments(const void *arg1, const void *arg2)
|
||||
int CompareBGSegments(const BGSegment &seg1, const BGSegment &seg2)
|
||||
{
|
||||
// arg1 and arg2 are of type Step**
|
||||
BGSegment* seg1 = (BGSegment*)arg1;
|
||||
BGSegment* seg2 = (BGSegment*)arg2;
|
||||
|
||||
float score1 = seg1->m_fStartBeat;
|
||||
float score2 = seg2->m_fStartBeat;
|
||||
|
||||
if( score1 == score2 )
|
||||
return 0;
|
||||
else if( score1 < score2 )
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
return seg1.m_fStartBeat < seg2.m_fStartBeat;
|
||||
}
|
||||
|
||||
void SortBGSegmentArray( CArray<BGSegment,BGSegment&> &arrayBGSegments )
|
||||
{
|
||||
qsort( arrayBGSegments.GetData(), arrayBGSegments.GetSize(), sizeof(BGSegment), CompareBGSegments );
|
||||
sort( arrayBGSegments.GetData(), arrayBGSegments.GetData()+arrayBGSegments.GetSize(),
|
||||
CompareBGSegments );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -260,23 +260,13 @@ void Course::GetSongOptions( SongOptions* pSO_out )
|
||||
// Sorting stuff
|
||||
//
|
||||
|
||||
int CompareCoursePointersByDifficulty(const void *arg1, const void *arg2)
|
||||
static int CompareCoursePointersByDifficulty(const Course* pCourse1, const Course* pCourse2)
|
||||
{
|
||||
Course* pCourse1 = *(Course**)arg1;
|
||||
Course* pCourse2 = *(Course**)arg2;
|
||||
|
||||
float fScore1 = (float)pCourse1->m_iStages;
|
||||
float fScore2 = (float)pCourse2->m_iStages;
|
||||
|
||||
if( fScore1 < fScore2 )
|
||||
return -1;
|
||||
else if( fScore1 == fScore2 )
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
return pCourse1->m_iStages < pCourse2->m_iStages;
|
||||
}
|
||||
|
||||
void SortCoursePointerArrayByDifficulty( CArray<Course*,Course*> &apCourses )
|
||||
{
|
||||
qsort( apCourses.GetData(), apCourses.GetSize(), sizeof(Course*), CompareCoursePointersByDifficulty );
|
||||
sort( apCourses.GetData(), apCourses.GetData()+apCourses.GetSize(),
|
||||
CompareCoursePointersByDifficulty );
|
||||
}
|
||||
|
||||
+16
-42
@@ -177,11 +177,8 @@ Difficulty Notes::DifficultyFromDescriptionAndMeter( CString sDescription, int i
|
||||
//
|
||||
//////////////////////////////////////////////
|
||||
|
||||
int CompareNotesPointersByRadarValues(const void *arg1, const void *arg2)
|
||||
bool CompareNotesPointersByRadarValues(const Notes* pNotes1, const Notes* pNotes2)
|
||||
{
|
||||
Notes* pNotes1 = *(Notes**)arg1;
|
||||
Notes* pNotes2 = *(Notes**)arg2;
|
||||
|
||||
float fScore1 = 0;
|
||||
float fScore2 = 0;
|
||||
|
||||
@@ -191,53 +188,30 @@ int CompareNotesPointersByRadarValues(const void *arg1, const void *arg2)
|
||||
fScore2 += pNotes2->m_fRadarValues[r];
|
||||
}
|
||||
|
||||
if( fScore1 < fScore2 )
|
||||
return -1;
|
||||
else if( fScore1 == fScore2 )
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
return fScore1 < fScore2;
|
||||
}
|
||||
|
||||
int CompareNotesPointersByMeter(const void *arg1, const void *arg2)
|
||||
bool CompareNotesPointersByMeter(const Notes *pNotes1, const Notes* pNotes2)
|
||||
{
|
||||
Notes* pNotes1 = *(Notes**)arg1;
|
||||
Notes* pNotes2 = *(Notes**)arg2;
|
||||
|
||||
int iScore1 = pNotes1->m_iMeter;
|
||||
int iScore2 = pNotes2->m_iMeter;
|
||||
|
||||
if( iScore1 < iScore2 )
|
||||
return -1;
|
||||
else if( iScore1 == iScore2 )
|
||||
return CompareNotesPointersByRadarValues( arg1, arg2 );
|
||||
else
|
||||
return 1;
|
||||
if( pNotes1->m_iMeter < pNotes2->m_iMeter )
|
||||
return true;
|
||||
if( pNotes1->m_iMeter > pNotes2->m_iMeter )
|
||||
return false;
|
||||
return CompareNotesPointersByRadarValues( pNotes1, pNotes2 );
|
||||
}
|
||||
|
||||
int CompareNotesPointersByDifficulty(Notes* pNotes1, Notes* pNotes2)
|
||||
bool CompareNotesPointersByDifficulty(const Notes *pNotes1, const Notes *pNotes2)
|
||||
{
|
||||
Difficulty class1 = pNotes1->m_Difficulty;
|
||||
Difficulty class2 = pNotes2->m_Difficulty;
|
||||
|
||||
if( class1 < class2 )
|
||||
return -1;
|
||||
else if( class1 == class2 )
|
||||
return CompareNotesPointersByMeter( &pNotes1, &pNotes2 );
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CompareNotesPointersByDifficulty2(const void *arg1, const void *arg2)
|
||||
{
|
||||
Notes* pNotes1 = *(Notes**)arg1;
|
||||
Notes* pNotes2 = *(Notes**)arg2;
|
||||
|
||||
return CompareNotesPointersByDifficulty( pNotes1, pNotes2 );
|
||||
if( pNotes1->m_Difficulty < pNotes2->m_Difficulty )
|
||||
return true;
|
||||
if( pNotes1->m_Difficulty > pNotes2->m_Difficulty )
|
||||
return false;
|
||||
return CompareNotesPointersByMeter( pNotes1, pNotes2 );
|
||||
}
|
||||
|
||||
void SortNotesArrayByDifficulty( CArray<Notes*,Notes*> &arraySteps )
|
||||
{
|
||||
qsort( arraySteps.GetData(), arraySteps.GetSize(), sizeof(Notes*), CompareNotesPointersByDifficulty2 );
|
||||
sort( arraySteps.GetData(), arraySteps.GetData()+arraySteps.GetSize(),
|
||||
CompareNotesPointersByDifficulty );
|
||||
}
|
||||
|
||||
|
||||
@@ -63,5 +63,5 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
int CompareNotesPointersByDifficulty(Notes* pNotes1, Notes* pNotes2);
|
||||
bool CompareNotesPointersByDifficulty(const Notes *pNotes1, const Notes *pNotes2);
|
||||
void SortNotesArrayByDifficulty( CArray<Notes*,Notes*> &arrayNotess );
|
||||
|
||||
@@ -673,25 +673,21 @@ bool IsADirectory( const CString &sPath )
|
||||
return (dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CompareCStringsAsc(const void *arg1, const void *arg2)
|
||||
bool CompareCStringsAsc(const CString &str1, const CString &str2)
|
||||
{
|
||||
CString str1 = *(CString *)arg1;
|
||||
CString str2 = *(CString *)arg2;
|
||||
return str1.CompareNoCase( str2 );
|
||||
return str2.CompareNoCase( str1 ) < 0;
|
||||
}
|
||||
|
||||
int CompareCStringsDesc(const void *arg1, const void *arg2)
|
||||
bool CompareCStringsDesc(const CString &str1, const CString &str2)
|
||||
{
|
||||
CString str1 = *(CString *)arg1;
|
||||
CString str2 = *(CString *)arg2;
|
||||
return str2.CompareNoCase( str1 );
|
||||
return str2.CompareNoCase( str1 ) > 0;
|
||||
}
|
||||
|
||||
void SortCStringArray( CStringArray &arrayCStrings, const bool bSortAcsending )
|
||||
void SortCStringArray( CStringArray &arrayCStrings, const bool bSortAscending )
|
||||
{
|
||||
qsort( arrayCStrings.GetData(), arrayCStrings.GetSize(), sizeof(CString), bSortAcsending ? CompareCStringsAsc : CompareCStringsDesc );
|
||||
sort( arrayCStrings.GetData(),
|
||||
arrayCStrings.GetData()+arrayCStrings.GetSize(),
|
||||
bSortAscending?CompareCStringsAsc:CompareCStringsDesc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -172,8 +172,8 @@ bool IsAFile( const CString &sPath );
|
||||
bool IsADirectory( const CString &sPath );
|
||||
DWORD GetFileSizeInBytes( const CString &sFilePath );
|
||||
|
||||
int CompareCStringsAsc(const void *arg1, const void *arg2);
|
||||
int CompareCStringsDesc(const void *arg1, const void *arg2);
|
||||
bool CompareCStringsAsc(const CString &str1, const CString &str2);
|
||||
bool CompareCStringsDesc(const CString &str1, const CString &str2);
|
||||
void SortCStringArray( CStringArray &AddTo, const bool bSortAcsending = true );
|
||||
|
||||
|
||||
|
||||
@@ -548,7 +548,7 @@ void SongManager::GetExtraStageInfo( bool bExtra2, CString sPreferredGroup, cons
|
||||
{
|
||||
Notes* pNotes = apNotes[n];
|
||||
|
||||
if( pExtra1Notes == NULL || CompareNotesPointersByDifficulty(pExtra1Notes,pNotes) == -1 ) // pNotes is harder than pHardestNotes
|
||||
if( pExtra1Notes == NULL || CompareNotesPointersByDifficulty(pExtra1Notes,pNotes) ) // pNotes is harder than pHardestNotes
|
||||
{
|
||||
pExtra1Song = pSong;
|
||||
pExtra1Notes = pNotes;
|
||||
@@ -557,7 +557,7 @@ void SongManager::GetExtraStageInfo( bool bExtra2, CString sPreferredGroup, cons
|
||||
// for extra 2, we don't want to choose the hardest notes possible. So, we'll disgard Notes with meter > 8
|
||||
if( bExtra2 && pNotes->m_iMeter > 8 )
|
||||
continue; // skip
|
||||
if( pExtra2Notes == NULL || CompareNotesPointersByDifficulty(pExtra2Notes,pNotes) == -1 ) // pNotes is harder than pHardestNotes
|
||||
if( pExtra2Notes == NULL || CompareNotesPointersByDifficulty(pExtra2Notes,pNotes) ) // pNotes is harder than pHardestNotes
|
||||
{
|
||||
pExtra2Song = pSong;
|
||||
pExtra2Notes = pNotes;
|
||||
|
||||
Reference in New Issue
Block a user