diff --git a/docs/rh-log.txt b/docs/rh-log.txt index c3c5da73d..6b6bac33a 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,7 @@ +December 17, 2009 +- Replaced sprite sorting with a stable sort. Performance at the start of + nuts.wad seems the same. + December 16, 2009 (Changes by Graf Zahl) - Fixed: Morphed players tried endlessly to switch to a weapon they picked up. - fixed: P_DamageMobj just set an ice corpse's velocity to 0 to make it shatter. diff --git a/src/r_things.cpp b/src/r_things.cpp index 155c84353..869d73a6a 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -23,6 +23,7 @@ #include #include +#include #include "templates.h" #include "doomdef.h" @@ -1883,13 +1884,9 @@ void R_DrawRemainingPlayerSprites() // gain compared to the old function. // // Sort vissprites by depth, far to near -static int STACK_ARGS sv_compare (const void *arg1, const void *arg2) +static bool sv_compare(vissprite_t *a, vissprite_t *b) { - int diff = (*(vissprite_t **)arg2)->idepth - (*(vissprite_t **)arg1)->idepth; - // If two sprites are the same distance, then the higher one gets precedence - if (diff == 0) - return (*(vissprite_t **)arg2)->gzt - (*(vissprite_t **)arg1)->gzt; - return diff; + return a->idepth > b->idepth; } #if 0 @@ -2023,7 +2020,7 @@ void R_SplitVisSprites () } #endif -void R_SortVisSprites (int (STACK_ARGS *compare)(const void *, const void *), size_t first) +void R_SortVisSprites (bool (*compare)(vissprite_t *, vissprite_t *), size_t first) { int i; vissprite_t **spr; @@ -2046,7 +2043,7 @@ void R_SortVisSprites (int (STACK_ARGS *compare)(const void *, const void *), si spritesorter[i] = *spr; } - qsort (spritesorter, vsprcount, sizeof (vissprite_t *), compare); + std::stable_sort(&spritesorter[0], &spritesorter[vsprcount], compare); }