Move the sorting into the C++ so I can make qsort disappear.
This commit is contained in:
@@ -17,15 +17,54 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "../gamestr.h"
|
||||||
#include "../starmap.h"
|
#include "../starmap.h"
|
||||||
#include "../menustat.h"
|
#include "../menustat.h"
|
||||||
#include "../controls.h"
|
#include "../controls.h"
|
||||||
#include "../sis.h"
|
#include "../sis.h"
|
||||||
#include "../sounds.h"
|
#include "../sounds.h"
|
||||||
|
|
||||||
|
static int
|
||||||
|
compStarName (const void *ptr1, const void *ptr2)
|
||||||
|
{
|
||||||
|
int index1;
|
||||||
|
int index2;
|
||||||
|
|
||||||
|
index1 = *(const int *) ptr1;
|
||||||
|
index2 = *(const int *) ptr2;
|
||||||
|
if (star_array[index1].Postfix != star_array[index2].Postfix)
|
||||||
|
{
|
||||||
|
return utf8StringCompare (GAME_STRING (star_array[index1].Postfix),
|
||||||
|
GAME_STRING (star_array[index2].Postfix));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (star_array[index1].Prefix < star_array[index2].Prefix)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (star_array[index1].Prefix > star_array[index2].Prefix)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
SortStarsOnName (STAR_SEARCH_STATE *pSS)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int *sorted = pSS->SortedStars;
|
||||||
|
|
||||||
|
for (i = 0; i < GetStarCount(); i++)
|
||||||
|
sorted[i] = i;
|
||||||
|
|
||||||
|
std::qsort (sorted, GetStarCount(), sizeof (int), compStarName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" bool
|
extern "C" bool
|
||||||
DoStarSearch (MENU_STATE *pMS)
|
DoStarSearch (MENU_STATE *pMS)
|
||||||
|
|||||||
@@ -797,41 +797,6 @@ UpdateFuelRequirement (void)
|
|||||||
DrawStatusMessage (buf);
|
DrawStatusMessage (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
compStarName (const void *ptr1, const void *ptr2)
|
|
||||||
{
|
|
||||||
int index1;
|
|
||||||
int index2;
|
|
||||||
|
|
||||||
index1 = *(const int *) ptr1;
|
|
||||||
index2 = *(const int *) ptr2;
|
|
||||||
if (star_array[index1].Postfix != star_array[index2].Postfix)
|
|
||||||
{
|
|
||||||
return utf8StringCompare (GAME_STRING (star_array[index1].Postfix),
|
|
||||||
GAME_STRING (star_array[index2].Postfix));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (star_array[index1].Prefix < star_array[index2].Prefix)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (star_array[index1].Prefix > star_array[index2].Prefix)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SortStarsOnName (STAR_SEARCH_STATE *pSS)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int *sorted = pSS->SortedStars;
|
|
||||||
|
|
||||||
for (i = 0; i < GetStarCount(); i++)
|
|
||||||
sorted[i] = i;
|
|
||||||
|
|
||||||
qsort (sorted, GetStarCount(), sizeof (int), compStarName);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
SplitStarName (STAR_SEARCH_STATE *pSS)
|
SplitStarName (STAR_SEARCH_STATE *pSS)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ typedef struct starsearch_state
|
|||||||
} STAR_SEARCH_STATE;
|
} STAR_SEARCH_STATE;
|
||||||
|
|
||||||
bool DoStarSearch( MENU_STATE * );
|
bool DoStarSearch( MENU_STATE * );
|
||||||
void SortStarsOnName( STAR_SEARCH_STATE * );
|
|
||||||
BOOLEAN OnStarNameChange( TEXTENTRY_STATE * );
|
BOOLEAN OnStarNameChange( TEXTENTRY_STATE * );
|
||||||
BOOLEAN OnStarNameFrame ( TEXTENTRY_STATE *pTES );
|
BOOLEAN OnStarNameFrame ( TEXTENTRY_STATE *pTES );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user