From 20c0a8e258ac9e27b415a24ebdc6e9918a85c613 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 24 Apr 2024 20:37:46 -0400 Subject: [PATCH] Move the sorting into the C++ so I can make qsort disappear. --- sc2/src/uqm/planets/pstarmap-modern.cpp | 39 +++++++++++++++++++++++++ sc2/src/uqm/planets/pstarmap.c | 35 ---------------------- sc2/src/uqm/starmap.h | 1 - 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/sc2/src/uqm/planets/pstarmap-modern.cpp b/sc2/src/uqm/planets/pstarmap-modern.cpp index d636aa797..56519cb86 100644 --- a/sc2/src/uqm/planets/pstarmap-modern.cpp +++ b/sc2/src/uqm/planets/pstarmap-modern.cpp @@ -17,15 +17,54 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include + #include #include +#include "../gamestr.h" #include "../starmap.h" #include "../menustat.h" #include "../controls.h" #include "../sis.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 DoStarSearch (MENU_STATE *pMS) diff --git a/sc2/src/uqm/planets/pstarmap.c b/sc2/src/uqm/planets/pstarmap.c index 3176ef8c9..adf368514 100644 --- a/sc2/src/uqm/planets/pstarmap.c +++ b/sc2/src/uqm/planets/pstarmap.c @@ -797,41 +797,6 @@ UpdateFuelRequirement (void) 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 SplitStarName (STAR_SEARCH_STATE *pSS) { diff --git a/sc2/src/uqm/starmap.h b/sc2/src/uqm/starmap.h index e7560889f..5409f5bd6 100644 --- a/sc2/src/uqm/starmap.h +++ b/sc2/src/uqm/starmap.h @@ -66,7 +66,6 @@ typedef struct starsearch_state } STAR_SEARCH_STATE; bool DoStarSearch( MENU_STATE * ); -void SortStarsOnName( STAR_SEARCH_STATE * ); BOOLEAN OnStarNameChange( TEXTENTRY_STATE * ); BOOLEAN OnStarNameFrame ( TEXTENTRY_STATE *pTES );