From 4cf7c6351dcedf8b746dbf864fa9b07b1011d2cb Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Sun, 1 Mar 2020 12:35:19 -0600 Subject: [PATCH] Added A_StopSounds(int chanmin, int chanmax). - If both channels are 0, completely silences the actor. - Adapted A_StopAllSounds to call A_StopSounds(0,0); --- src/scripting/vmthunks_actors.cpp | 7 ++++--- src/sound/s_doomsound.cpp | 4 ++-- src/sound/s_doomsound.h | 2 +- src/sound/s_sound.cpp | 13 +++++++++++-- src/sound/s_soundinternal.h | 2 +- wadsrc/static/zscript/actors/actor.zs | 3 ++- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp index 8a8075c4c4..12cd27676b 100644 --- a/src/scripting/vmthunks_actors.cpp +++ b/src/scripting/vmthunks_actors.cpp @@ -142,11 +142,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_StopSound, NativeStopSound) return 0; } -DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_StopAllSounds, S_StopAllActorSounds) +DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_StopSounds, S_StopActorSounds) { PARAM_SELF_PROLOGUE(AActor); - - S_StopAllActorSounds(self); + PARAM_INT(chanmin); + PARAM_INT(chanmax); + S_StopActorSounds(self, chanmin, chanmax); return 0; } diff --git a/src/sound/s_doomsound.cpp b/src/sound/s_doomsound.cpp index 40b4f3d310..bec5fff8ba 100644 --- a/src/sound/s_doomsound.cpp +++ b/src/sound/s_doomsound.cpp @@ -506,9 +506,9 @@ void S_StopSound (AActor *actor, int channel) // //========================================================================== -void S_StopAllActorSounds(AActor *actor) +void S_StopActorSounds(AActor *actor, int chanmin, int chanmax) { - soundEngine->StopAllActorSounds(SOURCE_Actor, actor); + soundEngine->StopActorSounds(SOURCE_Actor, actor, chanmin, chanmax); } //========================================================================== diff --git a/src/sound/s_doomsound.h b/src/sound/s_doomsound.h index cac4c2ee80..5a1a8fa090 100644 --- a/src/sound/s_doomsound.h +++ b/src/sound/s_doomsound.h @@ -35,7 +35,7 @@ void S_PlaySound(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, void S_StopSound (AActor *ent, int channel); void S_StopSound (const sector_t *sec, int channel); void S_StopSound (const FPolyObj *poly, int channel); -void S_StopAllActorSounds(AActor *actor); +void S_StopActorSounds(AActor *actor, int chanmin, int chanmax); // Moves all sounds from one mobj to another void S_RelinkSound (AActor *from, AActor *to); diff --git a/src/sound/s_sound.cpp b/src/sound/s_sound.cpp index f8ef648baa..9c15c47b52 100644 --- a/src/sound/s_sound.cpp +++ b/src/sound/s_sound.cpp @@ -912,14 +912,23 @@ void SoundEngine::StopSound(int sourcetype, const void* actor, int channel, int // //========================================================================== -void SoundEngine::StopAllActorSounds(int sourcetype, const void* actor) +void SoundEngine::StopActorSounds(int sourcetype, const void* actor, int chanmin, int chanmax) { + const bool all = (chanmin == 0 && chanmax == 0); + if (!all && chanmax > chanmin) + { + const int temp = chanmax; + chanmax = chanmin; + chanmin = temp; + } + FSoundChan* chan = Channels; while (chan != nullptr) { FSoundChan* next = chan->NextChan; if (chan->SourceType == sourcetype && - chan->Source == actor) + chan->Source == actor && + (all || (chan->EntChannel >= chanmin && chan->EntChannel <= chanmax))) { StopChannel(chan); } diff --git a/src/sound/s_soundinternal.h b/src/sound/s_soundinternal.h index c8f065cb5d..4dc978ed37 100644 --- a/src/sound/s_soundinternal.h +++ b/src/sound/s_soundinternal.h @@ -307,7 +307,7 @@ public: void StopSoundID(int sound_id); void StopSound(int channel, int sound_id = -1); void StopSound(int sourcetype, const void* actor, int channel, int sound_id = -1); - void StopAllActorSounds(int sourcetype, const void* actor); + void StopActorSounds(int sourcetype, const void* actor, int chanmin, int chanmax); void RelinkSound(int sourcetype, const void* from, const void* to, const FVector3* optpos); void ChangeSoundVolume(int sourcetype, const void* source, int channel, double dvolume); diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 488fcd353a..55b90edcbe 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -1060,7 +1060,8 @@ class Actor : Thinker native native void A_SoundPitch(int slot, double pitch); deprecated("2.3") void A_PlayWeaponSound(sound whattoplay) { A_StartSound(whattoplay, CHAN_WEAPON); } native void A_StopSound(int slot = CHAN_VOICE); // Bad default but that's what is originally was... - native void A_StopAllSounds(); + void A_StopAllSounds() { A_StopSounds(0,0); } + native void A_StopSounds(int chanmin, int chanmax); deprecated("2.3") native void A_PlaySoundEx(sound whattoplay, name slot, bool looping = false, int attenuation = 0); deprecated("2.3") native void A_StopSoundEx(name slot); native clearscope bool IsActorPlayingSound(int channel, Sound snd = 0);