From: Holger Schemel Date: Mon, 22 Apr 2002 00:20:05 +0000 (+0200) Subject: rnd-20020422-1-src X-Git-Tag: 2.1.0^2~54 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=f1685723f2d920b7d7349c57e902c7adfaffdb1c;p=rocksndiamonds.git rnd-20020422-1-src --- diff --git a/src/init.c b/src/init.c index 69008db6..5923322a 100644 --- a/src/init.c +++ b/src/init.c @@ -171,7 +171,7 @@ void InitSound() } } - num_bg_loops = LoadMusic(); + num_bg_loops = LoadCustomMusic(); StartSoundserver(); } diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 32c8f265..fefe33df 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -422,6 +422,41 @@ char *getCustomSoundFilename(char *basename) return NULL; /* cannot find image file */ } +char *getCustomMusicDirectory(void) +{ + static char *directory = NULL; + + if (directory != NULL) + free(directory); + + /* 1st try: look for special artwork in current level series directory */ + directory = getPath2(getCurrentLevelDir(), MUSIC_DIRECTORY); + if (fileExists(directory)) + return directory; + + /* 2nd try: look for special artwork in private artwork directory */ + directory = getStringCopy(getUserMusicDir()); + if (fileExists(directory)) + return directory; + + /* 3rd try: look for special artwork in configured artwork directory */ + directory = getStringCopy(getSetupArtworkDir(artwork.mus_current)); + if (fileExists(directory)) + return directory; + + /* 4th try: look for default artwork in new default artwork directory */ + directory = getStringCopy(getDefaultMusicDir(MUSIC_SUBDIR)); + if (fileExists(directory)) + return directory; + + /* 5th try: look for default artwork in old default artwork directory */ + directory = getStringCopy(options.music_directory); + if (fileExists(directory)) + return directory; + + return NULL; /* cannot find image file */ +} + void InitTapeDirectory(char *level_subdir) { createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE); diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 48419782..4a9fa66b 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -142,6 +142,7 @@ char *getSetupFilename(void); char *getImageFilename(char *); char *getCustomImageFilename(char *); char *getCustomSoundFilename(char *); +char *getCustomMusicDirectory(void); void InitTapeDirectory(char *); void InitScoreDirectory(char *); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index e5aa69e2..52fdcbfb 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -940,10 +940,9 @@ void ReloadMusic() #define CHUNK_ID_LEN 4 /* IFF style chunk id length */ #define WAV_HEADER_SIZE 16 /* size of WAV file header */ -static boolean LoadSoundExt(char *sound_name, boolean is_music) +static boolean Load_WAV(char *filename) { struct SampleInfo *snd_info; - char *filename; #if !defined(TARGET_SDL) && !defined(PLATFORM_MSDOS) byte sound_header_buffer[WAV_HEADER_SIZE]; char chunk_name[CHUNK_ID_LEN + 1]; @@ -961,21 +960,12 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) snd_info = &Sound[num_sounds - 1]; snd_info->data_len = 0; snd_info->data_ptr = NULL; -#if 0 - snd_info->name = sound_name; -#endif - - if (is_music) - filename = getPath2(options.music_directory, sound_name); - else - filename = getStringCopy(sound_name); #if defined(TARGET_SDL) if ((snd_info->mix_chunk = Mix_LoadWAV(filename)) == NULL) { Error(ERR_WARN, "cannot read sound file '%s'", filename); - free(filename); return FALSE; } @@ -984,7 +974,6 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) if ((file = fopen(filename, MODE_READ)) == NULL) { Error(ERR_WARN, "cannot open sound file '%s'", filename); - free(filename); return FALSE; } @@ -994,7 +983,6 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename); fclose(file); - free(filename); return FALSE; } @@ -1004,7 +992,6 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "missing 'WAVE' type ID of sound file '%s'", filename); fclose(file); - free(filename); return FALSE; } @@ -1035,7 +1022,6 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN,"cannot read 'data' chunk of sound file '%s'",filename); fclose(file); - free(filename); return FALSE; } @@ -1052,7 +1038,6 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) if (snd_info->data_ptr == NULL) { Error(ERR_WARN, "missing 'data' chunk of sound file '%s'", filename); - free(filename); return FALSE; } @@ -1070,16 +1055,9 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) #endif - free(filename); - return TRUE; } -boolean LoadSound(char *sound_name) -{ - return LoadSoundExt(sound_name, FALSE); -} - boolean LoadCustomSound(char *basename) { char *filename = getCustomSoundFilename(basename); @@ -1090,10 +1068,10 @@ boolean LoadCustomSound(char *basename) return FALSE; } - return LoadSound(filename); + return Load_WAV(filename); } -boolean LoadMod(char *mod_name) +static boolean Load_MOD(char *mod_name) { #if defined(TARGET_SDL) struct SampleInfo *mod_info; @@ -1122,8 +1100,9 @@ boolean LoadMod(char *mod_name) #endif } -int LoadMusic(void) +int LoadCustomMusic(void) { + char *music_directory = getCustomMusicDirectory(); DIR *dir; struct dirent *dir_entry; int num_wav_music = 0; @@ -1132,22 +1111,23 @@ int LoadMusic(void) if (!audio.sound_available) return 0; - if ((dir = opendir(options.music_directory)) == NULL) + if ((dir = opendir(music_directory)) == NULL) { - Error(ERR_WARN, "cannot read music directory '%s'", - options.music_directory); + Error(ERR_WARN, "cannot read music directory '%s'", music_directory); audio.music_available = FALSE; return 0; } while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */ { - char *filename = dir_entry->d_name; + char *filename = getPath2(music_directory, dir_entry->d_name); - if (FileIsSound(filename) && LoadSoundExt(filename, TRUE)) + if (FileIsSound(filename) && Load_WAV(filename)) num_wav_music++; - else if (FileIsMusic(filename) && LoadMod(filename)) + else if (FileIsMusic(filename) && Load_MOD(filename)) num_mod_music++; + + free(filename); } closedir(dir); diff --git a/src/libgame/sound.h b/src/libgame/sound.h index 6ca5f975..aef0aa2e 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -160,9 +160,6 @@ struct SoundHeader_8SVX struct SampleInfo { -#if 0 - char *name; -#endif byte *data_ptr; long data_len; @@ -210,10 +207,8 @@ void SoundServer(void); /* sound client functions */ void ReloadSounds(void); void ReloadMusic(void); -boolean LoadSound(char *); boolean LoadCustomSound(char *); -boolean LoadMod(char *); -int LoadMusic(void); +int LoadCustomMusic(void); void PlayMusic(int); void PlaySound(int); void PlaySoundStereo(int, int); diff --git a/src/timestamp.h b/src/timestamp.h index 4d75abfe..d672394d 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-04-21 21:51]" +#define COMPILE_DATE_STRING "[2002-04-22 02:18]"