From: Holger Schemel Date: Fri, 10 May 2002 15:17:50 +0000 (+0200) Subject: rnd-20020510-7-src X-Git-Tag: 2.1.0^2~26 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=71a1616f11627ab005c19fc6fc06ba23f6b4b633;p=rocksndiamonds.git rnd-20020510-7-src --- diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 5e93bd7a..ac814e90 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -179,6 +179,29 @@ void UnixCloseAudio(void) kill(audio.mixer_pid, SIGTERM); } +static void WriteSoundControlToPipe(struct SoundControl snd_ctrl) +{ + if (audio.mixer_pid == 0) /* we are child process */ + return; + + if (write(audio.mixer_pipe[1], &snd_ctrl, sizeof(struct SoundControl)) < 0) + { + Error(ERR_WARN, "cannot pipe to child process -- no sounds"); + audio.sound_available = audio.sound_enabled = FALSE; + return; + } +} + +static void ReadSoundControlFromPipe(struct SoundControl *snd_ctrl) +{ + if (audio.mixer_pid != 0) /* we are parent process */ + return; + + if (read(audio.mixer_pipe[0], snd_ctrl, sizeof(struct SoundControl)) + != sizeof(struct SoundControl)) + Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); +} + static void WriteReloadInfoToPipe(char *set_name, int type) { struct SoundControl snd_ctrl; @@ -517,6 +540,20 @@ static void HandleSoundRequest(struct SoundControl snd_ctrl) { int i; +#if defined(PLATFORM_MSDOS) + for (i=0; idata_ptr, (state & SND_CTRL_LOOP ? -1 : 0)); } #elif defined(PLATFORM_UNIX) - if (audio.mixer_pid == 0) /* we are child process */ - return; - if (write(audio.mixer_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; - } + WriteSoundControlToPipe(snd_ctrl); + #elif defined(PLATFORM_MSDOS) - sound_handler(snd_ctrl); + + HandleSoundRequest(snd_ctrl); + #endif } @@ -1677,17 +1688,12 @@ void StopSoundExt(int nr, int state) #elif !defined(PLATFORM_MSDOS) - if (audio.mixer_pid == 0) /* we are child process */ - return; + WriteSoundControlToPipe(snd_ctrl); - if (write(audio.mixer_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; - } #else /* PLATFORM_MSDOS */ - sound_handler(snd_ctrl); + + HandleSoundRequest(snd_ctrl); + #endif }