From ae0910c3223faf69f7638780ff8e49cf08bbb554 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 24 Apr 2002 03:59:35 +0200 Subject: [PATCH] rnd-20020424-2-src --- src/init.c | 36 +++++++++ src/libgame/sound.c | 182 ++++++++++++++++++++++++++++++------------- src/libgame/sound.h | 9 ++- src/libgame/system.c | 7 ++ src/libgame/system.h | 5 ++ src/timestamp.h | 2 +- 6 files changed, 184 insertions(+), 57 deletions(-) diff --git a/src/init.c b/src/init.c index eee87022..0a52cc63 100644 --- a/src/init.c +++ b/src/init.c @@ -151,20 +151,56 @@ void InitNetworkServer() #endif } +static void ReloadCustomSounds() +{ + int i; + + printf("DEBUG: reloading sounds '%s' [%d] ...\n", + artwork.sounds_set_current, audio.soundserver_pid); + +#if 1 + FreeAllSounds(); + + InitSoundList(NUM_SOUNDS); + for(i=0; iname); + InitReloadMusic(artwork.mus_current->name); +#endif } void InitTileClipmasks() diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 744c4bd8..57e61c70 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -227,16 +227,82 @@ void SoundServer(void) if (snd_ctrl.reload_sounds || snd_ctrl.reload_music) { - for(i=0; ifullpath != NULL) + free(leveldir_current->fullpath); + printf("B.3 ['%s']\n", ti->basepath); +#if 0 + if (ti->basepath != NULL) + free(ti->basepath); +#endif + printf("B.4\n"); + if (ti->fullpath != NULL) + free(ti->fullpath); + printf("B.5\n"); + + printf("C\n"); + + if (read(audio.soundserver_pipe[0], set_name, + snd_ctrl.data_len) != snd_ctrl.data_len || + read(audio.soundserver_pipe[0], leveldir_current, + sizeof(TreeInfo)) != sizeof(TreeInfo) || + read(audio.soundserver_pipe[0], ti, + sizeof(TreeInfo)) != sizeof(TreeInfo) || + read(audio.soundserver_pipe[0], &str_size1, + sizeof(unsigned long)) != sizeof(unsigned long) || + read(audio.soundserver_pipe[0], &str_size2, + sizeof(unsigned long)) != sizeof(unsigned long) || + read(audio.soundserver_pipe[0], &str_size3, + sizeof(unsigned long)) != sizeof(unsigned long)) + Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); + + printf("D\n"); + + leveldir_current->fullpath = checked_calloc(str_size1); + ti->basepath = checked_calloc(str_size2); + ti->fullpath = checked_calloc(str_size3); + + if (read(audio.soundserver_pipe[0], leveldir_current->fullpath, + str_size1) != str_size1 || + read(audio.soundserver_pipe[0], ti->basepath, + str_size2) != str_size2 || + read(audio.soundserver_pipe[0], ti->fullpath, + str_size3) != str_size3) + Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); + + printf("E\n"); + + InitPlaylist(); close(audio.device_fd); + printf("X\n"); + if (snd_ctrl.reload_sounds) - ReloadSounds(); + { + artwork.sounds_set_current = set_name; + audio.func_reload_sounds(); + } else - ReloadMusic(); + { + artwork.music_set_current = set_name; + audio.func_reload_music(); + } + + free(set_name); continue; } @@ -317,9 +383,9 @@ void SoundServer(void) if (snd_ctrl.active) /* new sound has arrived */ SoundServer_InsertNewSound(snd_ctrl); - while(playing_sounds && - select(audio.soundserver_pipe[0] + 1, - &sound_fdset, NULL, NULL, &delay) < 1) + while (playing_sounds && + select(audio.soundserver_pipe[0] + 1, + &sound_fdset, NULL, NULL, &delay) < 1) { FD_SET(audio.soundserver_pipe[0], &sound_fdset); @@ -442,9 +508,9 @@ void SoundServer(void) { playing_sounds = 1; - while(playing_sounds && - select(audio.soundserver_pipe[0] + 1, - &sound_fdset, NULL, NULL, &delay) < 1) + while (playing_sounds && + select(audio.soundserver_pipe[0] + 1, + &sound_fdset, NULL, NULL, &delay) < 1) { FD_SET(audio.soundserver_pipe[0], &sound_fdset); @@ -956,16 +1022,6 @@ static int ulaw_to_linear(unsigned char ulawbyte) /* ========================================================================= */ /* THE STUFF BELOW IS ONLY USED BY THE MAIN PROCESS */ -void ReloadSounds() -{ - printf("reloading sounds ...\n"); -} - -void ReloadMusic() -{ - printf("reloading music ...\n"); -} - #define CHUNK_ID_LEN 4 /* IFF style chunk id length */ #define WAV_HEADER_SIZE 16 /* size of WAV file header */ @@ -1097,6 +1153,8 @@ SoundInfo *LoadCustomSound(char *basename) return FALSE; } + printf("-> '%s'\n", filename); + return Load_WAV(filename); } @@ -1372,8 +1430,8 @@ void StopSoundExt(int nr, int method) Mix_HaltMusic(); } -#else -#if !defined(PLATFORM_MSDOS) +#elif !defined(PLATFORM_MSDOS) + if (audio.soundserver_pid == 0) /* we are child process */ return; @@ -1386,59 +1444,75 @@ void StopSoundExt(int nr, int method) #else sound_handler(snd_ctrl); #endif -#endif } -void InitReloadSounds(char *set_name) +static void InitReloadSoundsOrMusic(char *set_name, int type) { struct SoundControl snd_ctrl = emptySoundControl; + TreeInfo *ti = + (type == SND_RELOAD_SOUNDS ? artwork.snd_current : artwork.mus_current); + unsigned long str_size1 = strlen(leveldir_current->fullpath) + 1; + unsigned long str_size2 = strlen(ti->basepath) + 1; + unsigned long str_size3 = strlen(ti->fullpath) + 1; if (!audio.sound_available) return; - snd_ctrl.reload_sounds = TRUE; + if (leveldir_current == NULL) + Error(ERR_EXIT, "leveldir_current == NULL"); -#if defined(TARGET_SDL) - ReloadSounds(); + snd_ctrl.reload_sounds = (type == SND_RELOAD_SOUNDS); + snd_ctrl.reload_music = (type == SND_RELOAD_MUSIC); + snd_ctrl.data_len = strlen(set_name) + 1; + +#if defined(TARGET_SDL) || defined(TARGET_ALLEGRO) + if (type == SND_RELOAD_SOUNDS) + audio.audio.func_reload_sounds(); + else + audio.audio.func_reload_music(); #elif defined(PLATFORM_UNIX) if (audio.soundserver_pid == 0) /* we are child process */ return; - if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0) + if (write(audio.soundserver_pipe[1], &snd_ctrl, + sizeof(snd_ctrl)) < 0 || + write(audio.soundserver_pipe[1], set_name, + snd_ctrl.data_len) < 0 || + write(audio.soundserver_pipe[1], leveldir_current, + sizeof(TreeInfo)) < 0 || + write(audio.soundserver_pipe[1], ti, + sizeof(TreeInfo)) < 0 || + write(audio.soundserver_pipe[1], &str_size1, + sizeof(unsigned long)) < 0 || + write(audio.soundserver_pipe[1], &str_size2, + sizeof(unsigned long)) < 0 || + write(audio.soundserver_pipe[1], &str_size3, + sizeof(unsigned long)) < 0 || + write(audio.soundserver_pipe[1], leveldir_current->fullpath, + str_size1) < 0 || + write(audio.soundserver_pipe[1], ti->basepath, + str_size2) < 0 || + write(audio.soundserver_pipe[1], ti->fullpath, + str_size3) < 0) { Error(ERR_WARN, "cannot pipe to child process -- no sounds"); audio.sound_available = audio.sound_enabled = FALSE; return; } -#elif defined(PLATFORM_MSDOS) - sound_handler(snd_ctrl); + + printf("A\n"); + #endif } -void InitReloadMusic(char *set_name) +void InitReloadSounds(char *set_name) { - struct SoundControl snd_ctrl = emptySoundControl; - - if (!audio.sound_available) - return; - - snd_ctrl.reload_music = TRUE; - -#if defined(TARGET_SDL) - ReloadMusic(); -#elif defined(PLATFORM_UNIX) - if (audio.soundserver_pid == 0) /* we are child process */ - return; + InitReloadSoundsOrMusic(set_name, SND_RELOAD_SOUNDS); +} - if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0) - { - Error(ERR_WARN, "cannot pipe to child process -- no sounds"); - audio.sound_available = audio.sound_enabled = FALSE; - return; - } -#elif defined(PLATFORM_MSDOS) - sound_handler(snd_ctrl); -#endif +void InitReloadMusic(char *set_name) +{ + InitReloadSoundsOrMusic(set_name, SND_RELOAD_MUSIC); } void FreeSound(SoundInfo *sound) @@ -1493,6 +1567,7 @@ void FreeAllSounds() FreeSound(Sound[i]); free(Sound); + Sound = NULL; } void FreeAllMusic() @@ -1506,6 +1581,7 @@ void FreeAllMusic() FreeMusic(Music[i]); free(Music); + Music = NULL; } /* THE STUFF ABOVE IS ONLY USED BY THE MAIN PROCESS */ diff --git a/src/libgame/sound.h b/src/libgame/sound.h index 896bef06..ebca45f5 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -133,6 +133,9 @@ #define SSND_MUSIC (SSND_FADE_MUSIC | SSND_STOP_MUSIC) #define SSND_ALL (SSND_FADE_ALL | SSND_STOP_ALL) +#define SND_RELOAD_SOUNDS 1 +#define SND_RELOAD_MUSIC 2 + #define SND_TYPE_NONE 0 #define SND_TYPE_WAV 1 @@ -207,7 +210,7 @@ struct SoundControl int playingtime; long playingpos; - long data_len; + unsigned long data_len; byte *data_ptr; #if defined(PLATFORM_MSDOS) @@ -225,8 +228,8 @@ void StartSoundserver(void); void SoundServer(void); /* sound client functions */ -void ReloadSounds(void); -void ReloadMusic(void); +void ReloadSounds(char *); +void ReloadMusic(char *); SoundInfo *LoadCustomSound(char *); void InitSoundList(int); void LoadSoundToList(char *, int); diff --git a/src/libgame/system.c b/src/libgame/system.c index 98b16c42..916d92f1 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -780,6 +780,13 @@ inline void SetAudioMode(boolean enabled) audio.sound_enabled = enabled; } +inline void SetAudioReloadFunctions(void (*func_reload_sounds)(void), + void (*func_reload_music)(void)) +{ + audio.func_reload_sounds = func_reload_sounds; + audio.func_reload_music = func_reload_music; +} + /* ========================================================================= */ /* event functions */ diff --git a/src/libgame/system.h b/src/libgame/system.h index 316de68e..4d8940d1 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -236,6 +236,9 @@ struct AudioSystemInfo boolean sound_enabled; boolean sound_deactivated; /* for temporarily disabling sound */ + void (*func_reload_sounds)(void); + void (*func_reload_music)(void); + int soundserver_pipe[2]; int soundserver_pid; char *device_name; @@ -477,6 +480,8 @@ void ReloadCustomImage(Bitmap *, char *); inline void OpenAudio(void); inline void CloseAudio(void); inline void SetAudioMode(boolean); +inline void SetAudioReloadFunctions(void (*func_reload_sounds)(void), + void (*func_reload_music)(void)); inline void InitEventFilter(EventFilter); inline boolean PendingEvent(void); diff --git a/src/timestamp.h b/src/timestamp.h index 427ae052..9f01cb6d 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-04-23 22:56]" +#define COMPILE_DATE_STRING "[2002-04-24 03:21]" -- 2.34.1