added sorting unconfigured music files by filename
authorHolger Schemel <info@artsoft.org>
Wed, 12 Apr 2023 11:57:20 +0000 (13:57 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 12 Apr 2023 11:57:25 +0000 (13:57 +0200)
Before, unconfigured music files were played in the order they were
stored in the file system (that is, in unpredictable order). This
change adds sorting them by filename.

src/libgame/sound.c

index 2b1ccd873560fe89e5bdee24dc68601eefd25d5f..177992d74199a28c248609c20f14153570788f80 100644 (file)
@@ -587,6 +587,14 @@ static void *Load_WAV_or_MOD(char *filename)
     return NULL;
 }
 
+static int compareMusicInfo(const void *object1, const void *object2)
+{
+  const MusicInfo *mi1 = *((MusicInfo **)object1);
+  const MusicInfo *mi2 = *((MusicInfo **)object2);
+
+  return strcmp(mi1->source_filename, mi2->source_filename);
+}
+
 static void LoadCustomMusic_NoConf(void)
 {
   static boolean draw_init_text = TRUE;                // only draw at startup
@@ -664,6 +672,9 @@ static void LoadCustomMusic_NoConf(void)
 
   closeDirectory(dir);
 
+  // sort music files by filename
+  qsort(Music_NoConf, num_music_noconf, sizeof(MusicInfo *), compareMusicInfo);
+
   draw_init_text = FALSE;
 }