From ecf5b527e6148d21074440593b300ef333a086e8 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sun, 3 Apr 2022 18:26:40 +0600 Subject: [PATCH] - fix insertion sort implementation in gamesnd --- src_rebuild/Game/C/gamesnd.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src_rebuild/Game/C/gamesnd.c b/src_rebuild/Game/C/gamesnd.c index 1ed5e8a0..585e8235 100644 --- a/src_rebuild/Game/C/gamesnd.c +++ b/src_rebuild/Game/C/gamesnd.c @@ -1005,20 +1005,19 @@ void DoDopplerSFX(void) } } - // sort cars by distance distance - for (i = 0; i < num_noisy_cars - 1; i++) + // sort cars by distance + for (i = 1; i < num_noisy_cars; i++) { - for (j = i + 1; j < num_noisy_cars; j++) - { - int tmpi; - tmpi = indexlist[i]; + int tmpi; + tmpi = indexlist[i]; - if (car_dist[indexlist[j]] < car_dist[tmpi]) - { - indexlist[i] = indexlist[j]; - indexlist[j] = tmpi; - } + j = i - 1; + while (j >= 0 && car_dist[indexlist[j]] > car_dist[tmpi]) + { + indexlist[j + 1] = indexlist[j]; + j = j - 1; } + indexlist[j + 1] = tmpi; } car_flags = 0;