X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsound.c;h=29d5a981f3d2836356d397f7160a2e49da7bb482;hb=5eeeb4703415b1fbad7910c2a3bf2c5af13916f8;hp=faa9a49d598344a6e8da3cf99f35e93c2136235d;hpb=8932f698c0831ab0e4ae2e03d64a48be1aeee82a;p=rocksndiamonds.git diff --git a/src/libgame/sound.c b/src/libgame/sound.c index faa9a49d..29d5a981 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -38,7 +38,7 @@ static int playing_sounds = 0; static struct SoundControl playlist[MAX_SOUNDS_PLAYING]; static struct SoundControl emptySoundControl = { - -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE, 0,0L,0L,NULL + -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE, 0,0L,0L,NULL }; #if defined(PLATFORM_UNIX) @@ -135,7 +135,7 @@ static boolean ForkAudioProcess(void) return FALSE; } - if (audio.soundserver_pid == 0) /* we are child */ + if (audio.soundserver_pid == 0) /* we are child process */ { SoundServer(); @@ -168,7 +168,7 @@ void UnixCloseAudio(void) if (audio.device_fd) close(audio.device_fd); - if (audio.soundserver_pid) + if (audio.soundserver_pid > 0) /* we are parent process */ kill(audio.soundserver_pid, SIGTERM); } #endif /* PLATFORM_UNIX */ @@ -227,6 +227,22 @@ void SoundServer(void) != sizeof(snd_ctrl)) Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); + if (snd_ctrl.reload_sounds || snd_ctrl.reload_music) + { + for(i=0;i= 0) @@ -910,6 +926,15 @@ 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 20 /* size of WAV file header */ @@ -1080,21 +1105,10 @@ int LoadMusic(void) { char *filename = dir_entry->d_name; - if (strlen(filename) > 4 && - strcmp(&filename[strlen(filename) - 4], ".wav") == 0) - { - if (LoadSoundExt(filename, TRUE)) - num_wav_music++; - } - else if (strlen(filename) > 4 && - (strcmp(&filename[strlen(filename) - 4], ".mod") == 0 || - strcmp(&filename[strlen(filename) - 4], ".MOD") == 0 || - strncmp(filename, "mod.", 4) == 0 || - strncmp(filename, "MOD.", 4) == 0)) - { - if (LoadMod(filename)) - num_mod_music++; - } + if (FileIsSound(filename) && LoadSoundExt(filename, TRUE)) + num_wav_music++; + else if (FileIsMusic(filename) && LoadMod(filename)) + num_mod_music++; } closedir(dir); @@ -1180,6 +1194,9 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop) Mix_Volume(-1, SOUND_MAX_VOLUME); Mix_PlayChannel(-1, Sound[nr].mix_chunk, (loop ? -1 : 0)); #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) { Error(ERR_WARN, "cannot pipe to child process -- no sounds"); @@ -1285,6 +1302,9 @@ void StopSoundExt(int nr, int method) #else #if !defined(PLATFORM_MSDOS) + if (audio.soundserver_pid == 0) /* we are child process */ + return; + if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0) { Error(ERR_WARN, "cannot pipe to child process -- no sounds"); @@ -1297,6 +1317,58 @@ void StopSoundExt(int nr, int method) #endif } +void InitReloadSounds(char *set_name) +{ + struct SoundControl snd_ctrl = emptySoundControl; + + if (!audio.sound_available) + return; + + snd_ctrl.reload_sounds = TRUE; + +#if defined(TARGET_SDL) + ReloadSounds(); +#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) + { + 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) +{ + 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; + + 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 FreeSounds(int num_sounds) { int i;