diff --git a/src/playsim/p_acs.cpp b/src/playsim/p_acs.cpp index df54741ff..dca86a7c8 100644 --- a/src/playsim/p_acs.cpp +++ b/src/playsim/p_acs.cpp @@ -5911,14 +5911,9 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) if (sid != 0) { // What a mess. I think it's a given that this was used with sound flags so it will forever be restricted to the original 8 channels. - if (!looping) - { - S_PlaySound(spot, chan&7, EChanFlags::FromInt(chan&~7), sid, vol, atten, !!local); - } - else if (!S_IsActorPlayingSomething(spot, chan & 7, sid)) - { - S_PlaySound(spot, chan&7, EChanFlags::FromInt(chan & ~7)|CHANF_LOOP, sid, vol, atten, !!local); - } + if (local) chan |= CHANF_LOCAL; + if (looping) chan |= CHANF_LOOP | CHANF_NOSTOP; + S_PlaySound(spot, chan&7, EChanFlags::FromInt(chan&~7), sid, vol, atten); } } } diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp index ef82eb657..0bfe0a7cb 100644 --- a/src/scripting/vmthunks_actors.cpp +++ b/src/scripting/vmthunks_actors.cpp @@ -181,11 +181,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_StartSound, A_StartSound) PARAM_INT(channel); PARAM_INT(flags); PARAM_FLOAT(volume); - PARAM_BOOL(looping); PARAM_FLOAT(attenuation); - PARAM_BOOL(local); PARAM_FLOAT(pitch); - A_StartSound(self, soundid, channel, flags, volume, looping, attenuation, local, pitch); + A_StartSound(self, soundid, channel, flags, volume, attenuation, pitch); return 0; } diff --git a/src/sound/backend/i_soundinternal.h b/src/sound/backend/i_soundinternal.h index 35e00f52b..1651d518d 100644 --- a/src/sound/backend/i_soundinternal.h +++ b/src/sound/backend/i_soundinternal.h @@ -27,6 +27,7 @@ enum EChanFlag CHANF_VIRTUAL = 2048, // internal: Channel is currently virtual CHANF_NOSTOP = 4096, // only for A_PlaySound. Does not start if channel is playing something. CHANF_OVERLAP = 8192, // [MK] Does not stop any sounds in the channel and instead plays over them. + CHANF_LOCAL = 16384, // only plays locally for the calling actor }; typedef TFlags EChanFlags; diff --git a/src/sound/s_doomsound.cpp b/src/sound/s_doomsound.cpp index 12ec59cf1..d6b16e61c 100644 --- a/src/sound/s_doomsound.cpp +++ b/src/sound/s_doomsound.cpp @@ -443,50 +443,45 @@ void S_Sound (const sector_t *sec, int channel, EChanFlags flags, FSoundID sfxid // //========================================================================== -void S_PlaySoundPitch(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, float atten, bool local, float pitch) +void S_PlaySoundPitch(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, float atten, float pitch) { if (a == nullptr || a->Sector->Flags & SECF_SILENT || a->Level != primaryLevel) return; - if (!local) + if (!(flags & CHANF_LOCAL)) { - S_SoundPitchActor(a, chan, flags, sid, vol, atten, pitch); + if (!(flags & (CHANF_NOSTOP) || !S_IsActorPlayingSomething(a, chan, sid))) + { + S_SoundPitchActor(a, chan, flags, sid, vol, atten, pitch); + } } else { if (a->CheckLocalView()) { - S_SoundPitch(chan, flags, sid, vol, ATTN_NONE, pitch); + if (!(flags & (CHANF_NOSTOP) || !soundEngine->IsSourcePlayingSomething(SOURCE_None, nullptr, chan, sid))) + { + S_SoundPitch(chan, flags, sid, vol, ATTN_NONE, pitch); + } } } } -void S_PlaySound(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, float atten, bool local) +void S_PlaySound(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, float atten) { - S_PlaySoundPitch(a, chan, flags, sid, vol, atten, local, 0.f); + S_PlaySoundPitch(a, chan, flags, sid, vol, atten, 0.f); } -void A_StartSound(AActor *self, int soundid, int channel, int flags, double volume, int looping, double attenuation, int local, double pitch) +void A_StartSound(AActor *self, int soundid, int channel, int flags, double volume, double attenuation, double pitch) { - if (!looping) - { - if (!(flags & CHANF_NOSTOP) || !S_IsActorPlayingSomething(self, channel, soundid)) - { - S_PlaySoundPitch(self, channel, EChanFlags::FromInt(flags), soundid, (float)volume, (float)attenuation, local, (float)pitch); - } - } - else - { - if (!S_IsActorPlayingSomething(self, channel, soundid)) - { - S_PlaySoundPitch(self, channel, EChanFlags::FromInt(flags) | CHANF_LOOP, soundid, (float)volume, (float)attenuation, local, (float)pitch); - } - } + S_PlaySoundPitch(self, channel, EChanFlags::FromInt(flags), soundid, (float)volume, (float)attenuation, (float)pitch); } void A_PlaySound(AActor* self, int soundid, int channel, double volume, int looping, double attenuation, int local, double pitch) { - A_StartSound(self, soundid, channel & 7, channel & ~7, volume, looping, attenuation, local, pitch); + if (looping) channel |= CHANF_LOOP | CHANF_NOSTOP; + if (local) channel |= CHANF_LOCAL; + A_StartSound(self, soundid, channel & 7, channel & ~7, volume, attenuation, pitch); } diff --git a/src/sound/s_doomsound.h b/src/sound/s_doomsound.h index d1b3e197d..27dd07fb7 100644 --- a/src/sound/s_doomsound.h +++ b/src/sound/s_doomsound.h @@ -29,8 +29,7 @@ void S_Sound(FLevelLocals *Level, const DVector3 &pos, int channel, EChanFlags f void S_SoundPitchActor (AActor *ent, int channel, EChanFlags flags, FSoundID sfxid, float volume, float attenuation, float pitch); // [Nash] Used by ACS and DECORATE -void S_PlaySound(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, float atten, bool local); -void S_PlaySoundPitch(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, float atten, bool local, float pitch); +void S_PlaySound(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, float atten); // Stops a sound emanating from one of an emitter's channels. void S_StopSound (AActor *ent, int channel); @@ -57,7 +56,7 @@ void S_ChangeActorSoundPitch(AActor *actor, int channel, double pitch); void S_SerializeSounds(FSerializer &arc); void A_PlaySound(AActor *self, int soundid, int channel, double volume, int looping, double attenuation, int local, double pitch); -void A_StartSound(AActor* self, int soundid, int flags, int channel, double volume, int looping, double attenuation, int local, double pitch); +void A_StartSound(AActor* self, int soundid, int channel, int flags, double volume, double attenuation, double pitch); static void S_SetListener(AActor *listenactor); void S_SoundReset(); void S_ResumeSound(bool state); diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index be4fd430b..8d56d92c0 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -1054,8 +1054,8 @@ class Actor : Thinker native deprecated("2.3") native void A_BulletAttack(); native void A_WolfAttack(int flags = 0, sound whattoplay = "weapons/pistol", double snipe = 1.0, int maxdamage = 64, int blocksize = 128, int pointblank = 2, int longrange = 4, double runspeed = 160.0, class pufftype = "BulletPuff"); - /*deprecated("4.3")*/ native clearscope void A_PlaySound(sound whattoplay = "weapons/pistol", int slot = CHAN_BODY, double volume = 1.0, bool looping = false, double attenuation = ATTN_NORM, bool local = false, double pitch = 0.0); - native clearscope void A_StartSound(sound whattoplay, int slot, int flags = 0, double volume = 1.0, bool looping = false, double attenuation = ATTN_NORM, bool local = false, double pitch = 0.0); + deprecated("4.3") native clearscope void A_PlaySound(sound whattoplay = "weapons/pistol", int slot = CHAN_BODY, double volume = 1.0, bool looping = false, double attenuation = ATTN_NORM, bool local = false, double pitch = 0.0); + native clearscope void A_StartSound(sound whattoplay, int slot, int flags = 0, double volume = 1.0, double attenuation = ATTN_NORM, double pitch = 0.0); native void A_SoundVolume(int slot, double volume); native void A_SoundPitch(int slot, double pitch); deprecated("2.3") void A_PlayWeaponSound(sound whattoplay) { A_StartSound(whattoplay, CHAN_WEAPON); } diff --git a/wadsrc/static/zscript/actors/hexen/magelightning.zs b/wadsrc/static/zscript/actors/hexen/magelightning.zs index f68defe9d..d079a8797 100644 --- a/wadsrc/static/zscript/actors/hexen/magelightning.zs +++ b/wadsrc/static/zscript/actors/hexen/magelightning.zs @@ -124,7 +124,7 @@ class Lightning : Actor if ((!thing.player && !thing.bBoss) || !(Level.maptime & 1)) { thing.DamageMobj(self, target, 3, 'Electric'); - A_StartSound(AttackSound, CHAN_WEAPON, CHANF_NOSTOP, 1, false); + A_StartSound(AttackSound, CHAN_WEAPON, CHANF_NOSTOP, 1); if (thing.bIsMonster && random[LightningHit]() < 64) { thing.Howl (); diff --git a/wadsrc/static/zscript/actors/inventory/inventory.zs b/wadsrc/static/zscript/actors/inventory/inventory.zs index ca6d48de2..99ca77425 100644 --- a/wadsrc/static/zscript/actors/inventory/inventory.zs +++ b/wadsrc/static/zscript/actors/inventory/inventory.zs @@ -1074,7 +1074,7 @@ class Inventory : Actor chan = CHAN_ITEM; flags = CHANF_MAYBE_LOCAL; } - toucher.A_StartSound(PickupSound, chan, flags, 1, false, atten); + toucher.A_StartSound(PickupSound, chan, flags, 1, atten); } //=========================================================================== diff --git a/wadsrc/static/zscript/constants.zs b/wadsrc/static/zscript/constants.zs index 8c91efb09..d1e073274 100644 --- a/wadsrc/static/zscript/constants.zs +++ b/wadsrc/static/zscript/constants.zs @@ -430,6 +430,10 @@ enum ESoundFlags CHANF_LOOP = 256, CHANF_NOSTOP = 4096, CHANF_OVERLAP = 8192, + CHANF_LOCAL = 16384, + + + CHANF_LOOPING = CHANF_LOOP | CHANF_NOSTOP, // convenience value for replicating the old 'looping' boolean. };