diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp index 0bfe0a7cbc..8a8075c4c4 100644 --- a/src/scripting/vmthunks_actors.cpp +++ b/src/scripting/vmthunks_actors.cpp @@ -142,6 +142,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_StopSound, NativeStopSound) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_StopAllSounds, S_StopAllActorSounds) +{ + PARAM_SELF_PROLOGUE(AActor); + + S_StopAllActorSounds(self); + return 0; +} + DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_SoundPitch, S_ChangeActorSoundPitch) { PARAM_SELF_PROLOGUE(AActor); diff --git a/src/sound/s_doomsound.cpp b/src/sound/s_doomsound.cpp index 6ca6449e0a..40b4f3d310 100644 --- a/src/sound/s_doomsound.cpp +++ b/src/sound/s_doomsound.cpp @@ -498,6 +498,18 @@ void S_StopSound (AActor *actor, int channel) soundEngine->StopSound(SOURCE_Actor, actor, (compatflags & COMPATF_MAGICSILENCE) ? -1 : channel); } +//========================================================================== +// +// S_StopAllActorSounds +// +// Stops all sounds on an actor. +// +//========================================================================== + +void S_StopAllActorSounds(AActor *actor) +{ + soundEngine->StopAllActorSounds(SOURCE_Actor, actor); +} //========================================================================== // diff --git a/src/sound/s_doomsound.h b/src/sound/s_doomsound.h index 27dd07fb71..cac4c2ee80 100644 --- a/src/sound/s_doomsound.h +++ b/src/sound/s_doomsound.h @@ -35,6 +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); // 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 660925a1a9..f8ef648baa 100644 --- a/src/sound/s_sound.cpp +++ b/src/sound/s_sound.cpp @@ -904,6 +904,29 @@ void SoundEngine::StopSound(int sourcetype, const void* actor, int channel, int } } +//========================================================================== +// +// S_StopAllActorSounds +// +// Stops all sounds on an actor. +// +//========================================================================== + +void SoundEngine::StopAllActorSounds(int sourcetype, const void* actor) +{ + FSoundChan* chan = Channels; + while (chan != nullptr) + { + FSoundChan* next = chan->NextChan; + if (chan->SourceType == sourcetype && + chan->Source == actor) + { + StopChannel(chan); + } + chan = next; + } +} + //========================================================================== // // S_StopAllChannels diff --git a/src/sound/s_soundinternal.h b/src/sound/s_soundinternal.h index 96e46c2565..c8f065cb5d 100644 --- a/src/sound/s_soundinternal.h +++ b/src/sound/s_soundinternal.h @@ -307,6 +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 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 10ef8d84e5..488fcd353a 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -1060,6 +1060,7 @@ 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(); 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); diff --git a/wadsrc/static/zscript/actors/inventory/inventory.zs b/wadsrc/static/zscript/actors/inventory/inventory.zs index 439f0c532f..b4ee7da002 100644 --- a/wadsrc/static/zscript/actors/inventory/inventory.zs +++ b/wadsrc/static/zscript/actors/inventory/inventory.zs @@ -326,7 +326,7 @@ class Inventory : Actor bIsMonster = false; ChangeStatNum(STAT_INVENTORY); // stop all sounds this item is playing. - for(int i = 1;i<=7;i++) A_StopSound(i); + A_StopAllSounds(); SetState (FindState("Held")); }