From: Holger Schemel Date: Wed, 12 Apr 2023 12:36:58 +0000 (+0200) Subject: added reading unconfigured music files from already existing list X-Git-Tag: 4.3.6.0~30 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=d9c8ce45df9d28dfe8061b67f10677d63b804f0a;p=rocksndiamonds.git added reading unconfigured music files from already existing list 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. --- diff --git a/src/files.c b/src/files.c index a22098da..ee42c990 100644 --- a/src/files.c +++ b/src/files.c @@ -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); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 177992d7..473850dd 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -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(); diff --git a/src/libgame/sound.h b/src/libgame/sound.h index 9f6c754c..20852138 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -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);