added reading unconfigured music files from already existing list
authorHolger Schemel <info@artsoft.org>
Wed, 12 Apr 2023 12:36:58 +0000 (14:36 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 12 Apr 2023 12:41:40 +0000 (14:41 +0200)
Before, the list of unconfigured music files was read from the music
directory (in function "LoadMusicInfo()" in "src/files.c") instead
of using the already existing list from the sound sub-system (read
exactly the same way in function "LoadCustomMusic_NoConf()" in
"src/libgame/sound.c"). Now, the code just uses this existing list.

src/files.c
src/libgame/sound.c
src/libgame/sound.h

index a22098da1628d872cd5b9d5692b2ba9cd58f90e0..ee42c99071149d56b57ac3293f64ed5b28032cfa 100644 (file)
@@ -12951,15 +12951,10 @@ static boolean checkLevelSetHasMusic_NoConf(void)
 
 void LoadMusicInfo(void)
 {
-  char *music_directory = getCustomMusicDirectory_NoConf();
   int num_music = getMusicListSize();
-  int num_music_noconf = 0;
   int num_sounds = getSoundListSize();
-  Directory *dir = NULL;
-  DirectoryEntry *dir_entry;
   struct FileInfo *music, *sound;
   struct MusicFileInfo *next, **new;
-  boolean read_music_from_directory = TRUE;
   int i;
 
   while (music_file_info != NULL)
@@ -12985,6 +12980,7 @@ void LoadMusicInfo(void)
 
   new = &music_file_info;
 
+  // get music file info for all configured music files
   for (i = 0; i < num_music; i++)
   {
     music = getMusicListEntry(i);
@@ -13008,66 +13004,31 @@ void LoadMusicInfo(void)
     }
   }
 
-  // if all levels have game music configured, do not read music from directory
-  if (!checkLevelSetHasMusic_NoConf())
-  {
-    read_music_from_directory = FALSE;
-  }
-  else if (music_directory == NULL)
+  // if some levels have no game music configured, use unconfigured music
+  if (checkLevelSetHasMusic_NoConf())
   {
-    Warn("cannot find music directory with unconfigured music");
+    int num_music_noconf = getMusicListSize_NoConf();
 
-    read_music_from_directory = FALSE;
-  }
-  else if ((dir = openDirectory(music_directory)) == NULL)
-  {
-    Warn("cannot read music directory '%s'", music_directory);
-
-    read_music_from_directory = FALSE;
-  }
-
-  while (read_music_from_directory &&
-        (dir_entry = readDirectory(dir)) != NULL)      // loop all entries
-  {
-    char *basename = dir_entry->basename;
-    boolean music_already_used = FALSE;
-    int i;
-
-    // skip all music files that are configured in music config file
-    for (i = 0; i < num_music; i++)
+    // get music file info for all unconfigured music files
+    for (i = 0; i < num_music_noconf; i++)
     {
-      music = getMusicListEntry(i);
+      int music_nr_noconf = MAP_NOCONF_MUSIC(i);
+      char *basename = getMusicInfoEntryFilename(music_nr_noconf);
 
-      if (music->filename == NULL)
+      if (basename == NULL)
        continue;
 
-      if (strEqual(basename, music->filename))
+      if (!music_info_listed(music_file_info, basename))
       {
-       music_already_used = TRUE;
-       break;
-      }
-    }
-
-    if (music_already_used)
-      continue;
-
-    if (!FileIsMusic(dir_entry->filename))
-      continue;
-
-    if (!music_info_listed(music_file_info, basename))
-    {
-      *new = get_music_file_info(basename, MAP_NOCONF_MUSIC(num_music_noconf));
+       *new = get_music_file_info(basename, music_nr_noconf);
 
-      if (*new != NULL)
-       new = &(*new)->next;
+       if (*new != NULL)
+         new = &(*new)->next;
+      }
     }
-
-    num_music_noconf++;
   }
 
-  if (dir != NULL)
-    closeDirectory(dir);
-
+  // get sound file info for all configured sound files
   for (i = 0; i < num_sounds; i++)
   {
     sound = getSoundListEntry(i);
index 177992d74199a28c248609c20f14153570788f80..473850ddaa729d7121aeaaf5873d658703df51e4 100644 (file)
@@ -690,6 +690,11 @@ int getMusicListSize(void)
          music_info->num_dynamic_file_list_entries);
 }
 
+int getMusicListSize_NoConf(void)
+{
+  return num_music_noconf;
+}
+
 struct FileInfo *getSoundListEntry(int pos)
 {
   int num_sounds = getSoundListSize();
index 9f6c754c0e37f2d04e5bd1a71d12c718fc558204..20852138ca194d9d34b35dd4fcf9a4bad8e28007 100644 (file)
@@ -122,6 +122,7 @@ void ExpireSoundLoops(boolean);
 
 int getSoundListSize(void);
 int getMusicListSize(void);
+int getMusicListSize_NoConf(void);
 struct FileInfo *getSoundListEntry(int);
 struct FileInfo *getMusicListEntry(int);
 char *getSoundInfoEntryFilename(int);