From f0ddc063b0419255a551985a89c90b164ee794ae Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 13 Mar 2021 13:11:03 +0100 Subject: [PATCH] - do not sort level names in the statistics output when saving. Instead do this when creating the data to avoid trashing manual edits. The old sorter resorted all data loaded from the old file as well. --- src/gamedata/statistics.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gamedata/statistics.cpp b/src/gamedata/statistics.cpp index 2258a2565..589c2b46f 100644 --- a/src/gamedata/statistics.cpp +++ b/src/gamedata/statistics.cpp @@ -205,14 +205,6 @@ int compare_episode_names(const void *a, const void *b) return strnatcasecmp(A->epi_header, B->epi_header); } -int compare_level_names(const void *a, const void *b) -{ - FLevelStatistics *A = (FLevelStatistics*)a; - FLevelStatistics *B = (FLevelStatistics*)b; - - return strnatcasecmp(A->name, B->name); -} - int compare_dates(const void *a, const void *b) { FLevelStatistics *A = (FLevelStatistics*)a; @@ -275,8 +267,6 @@ static void SaveStatistics(const char *fn, TArray &statlist) { fw->Printf("\t{\n"); - qsort(&ls[0], ls.Size(), sizeof(ls[0]), compare_level_names); - for(unsigned k=0;kPrintf("\t\t%-8s \"%-33s\" %02d:%02d:%02d\n", ls[k].name, ls[k].info, @@ -390,6 +380,15 @@ void STAT_StartNewGame(const char *mapname) // //========================================================================== +int compare_level_names(const void* a, const void* b) +{ + OneLevel* A = (OneLevel*)a; + OneLevel* B = (OneLevel*)b; + + return strnatcasecmp(A->Levelname, B->Levelname); +} + + static void StoreLevelStats(FLevelLocals *Level) { unsigned int i; @@ -427,6 +426,8 @@ static void StoreLevelStats(FLevelLocals *Level) } if (mc == 0) LevelData[i].killcount = LevelData[i].totalkills; } + // sort level names alphabetically to bring the newly added level to its proper place when playing a hub. + qsort(&LevelData[0], LevelData.Size(), sizeof(LevelData[0]), compare_level_names); } //==========================================================================