From 24728ba29148dabf29ef33eca513362bb4d6fcd5 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 23 Jun 2014 02:24:10 +0000 Subject: [PATCH] Allow EVENT_SOUND to return -1 to cancel a sound without printing a warning to the console and log. NOTE: Other negative values are reserved! git-svn-id: https://svn.eduke32.com/eduke32@4520 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/sounds.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index 274b7fd46..acafb913b 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -558,15 +558,19 @@ sound_further_processing: int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos) { - int32_t j = 0; + int32_t j; int32_t sndist, sndang, explosionp; int32_t voice, pitch; const DukePlayer_t *const myps = g_player[myconnectindex].ps; const DukePlayer_t *peekps; - if (G_HaveEvent(EVENT_SOUND)) - num = VM_OnEvent(EVENT_SOUND, i, screenpeek, -1, num); + j = VM_OnEvent(EVENT_SOUND, i, screenpeek, -1, num); + + if (j == -1 && num != -1) // check that the user returned -1, but only if -1 wasn't playing already (in which case, warn) + return -1; + + num = j; if ((unsigned)num > (unsigned)g_maxSoundPos || ud.config.FXDevice < 0 || @@ -584,6 +588,7 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos) if ((voice = S_PlaySound(num)) <= FX_Ok) return -1; + j = 0; while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice != voice) j++; @@ -716,8 +721,12 @@ int32_t S_PlaySound(int32_t num) int32_t pitch; int32_t voice, j; - if (G_HaveEvent(EVENT_SOUND)) - num = VM_OnEvent(EVENT_SOUND, g_player[screenpeek].ps->i, screenpeek, -1, num); + j = VM_OnEvent(EVENT_SOUND, g_player[screenpeek].ps->i, screenpeek, -1, num); + + if (j == -1 && num != -1) // check that the user returned -1, but only if -1 wasn't playing already (in which case, warn) + return -1; + + num = j; if (ud.config.FXDevice < 0) return -1; if (ud.config.SoundToggle==0) return -1;