- cleaned up the parameters of A_StartSound.

There were two booleans that could be merged into the flag word.
This also fixes a bug with CHAN_NOSTOP not working for local sounds because it checked the wrong sound source for the playing sound.
This commit is contained in:
Christoph Oelckers 2020-01-04 13:27:50 +01:00
parent 651dfbc49f
commit b7e1a35e6f
9 changed files with 32 additions and 40 deletions

View file

@ -5911,14 +5911,9 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound)
if (sid != 0) 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. // 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) if (local) chan |= CHANF_LOCAL;
{ if (looping) chan |= CHANF_LOOP | CHANF_NOSTOP;
S_PlaySound(spot, chan&7, EChanFlags::FromInt(chan&~7), sid, vol, atten, !!local); S_PlaySound(spot, chan&7, EChanFlags::FromInt(chan&~7), sid, vol, atten);
}
else if (!S_IsActorPlayingSomething(spot, chan & 7, sid))
{
S_PlaySound(spot, chan&7, EChanFlags::FromInt(chan & ~7)|CHANF_LOOP, sid, vol, atten, !!local);
}
} }
} }
} }

View file

@ -181,11 +181,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_StartSound, A_StartSound)
PARAM_INT(channel); PARAM_INT(channel);
PARAM_INT(flags); PARAM_INT(flags);
PARAM_FLOAT(volume); PARAM_FLOAT(volume);
PARAM_BOOL(looping);
PARAM_FLOAT(attenuation); PARAM_FLOAT(attenuation);
PARAM_BOOL(local);
PARAM_FLOAT(pitch); 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; return 0;
} }

View file

@ -27,6 +27,7 @@ enum EChanFlag
CHANF_VIRTUAL = 2048, // internal: Channel is currently virtual CHANF_VIRTUAL = 2048, // internal: Channel is currently virtual
CHANF_NOSTOP = 4096, // only for A_PlaySound. Does not start if channel is playing something. 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_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<EChanFlag> EChanFlags; typedef TFlags<EChanFlag> EChanFlags;

View file

@ -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) if (a == nullptr || a->Sector->Flags & SECF_SILENT || a->Level != primaryLevel)
return; 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 else
{ {
if (a->CheckLocalView()) 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) S_PlaySoundPitch(self, channel, EChanFlags::FromInt(flags), soundid, (float)volume, (float)attenuation, (float)pitch);
{
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);
}
}
} }
void A_PlaySound(AActor* self, int soundid, int channel, double volume, int looping, double attenuation, int local, double 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);
} }

View file

@ -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); void S_SoundPitchActor (AActor *ent, int channel, EChanFlags flags, FSoundID sfxid, float volume, float attenuation, float pitch);
// [Nash] Used by ACS and DECORATE // [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_PlaySound(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, float atten);
void S_PlaySoundPitch(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol, float atten, bool local, float pitch);
// Stops a sound emanating from one of an emitter's channels. // Stops a sound emanating from one of an emitter's channels.
void S_StopSound (AActor *ent, int channel); 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 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_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); static void S_SetListener(AActor *listenactor);
void S_SoundReset(); void S_SoundReset();
void S_ResumeSound(bool state); void S_ResumeSound(bool state);

View file

@ -1054,8 +1054,8 @@ class Actor : Thinker native
deprecated("2.3") native void A_BulletAttack(); 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<Actor> pufftype = "BulletPuff"); 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<Actor> 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); 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); 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_SoundVolume(int slot, double volume);
native void A_SoundPitch(int slot, double pitch); native void A_SoundPitch(int slot, double pitch);
deprecated("2.3") void A_PlayWeaponSound(sound whattoplay) { A_StartSound(whattoplay, CHAN_WEAPON); } deprecated("2.3") void A_PlayWeaponSound(sound whattoplay) { A_StartSound(whattoplay, CHAN_WEAPON); }

View file

@ -124,7 +124,7 @@ class Lightning : Actor
if ((!thing.player && !thing.bBoss) || !(Level.maptime & 1)) if ((!thing.player && !thing.bBoss) || !(Level.maptime & 1))
{ {
thing.DamageMobj(self, target, 3, 'Electric'); 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) if (thing.bIsMonster && random[LightningHit]() < 64)
{ {
thing.Howl (); thing.Howl ();

View file

@ -1074,7 +1074,7 @@ class Inventory : Actor
chan = CHAN_ITEM; chan = CHAN_ITEM;
flags = CHANF_MAYBE_LOCAL; flags = CHANF_MAYBE_LOCAL;
} }
toucher.A_StartSound(PickupSound, chan, flags, 1, false, atten); toucher.A_StartSound(PickupSound, chan, flags, 1, atten);
} }
//=========================================================================== //===========================================================================

View file

@ -430,6 +430,10 @@ enum ESoundFlags
CHANF_LOOP = 256, CHANF_LOOP = 256,
CHANF_NOSTOP = 4096, CHANF_NOSTOP = 4096,
CHANF_OVERLAP = 8192, CHANF_OVERLAP = 8192,
CHANF_LOCAL = 16384,
CHANF_LOOPING = CHANF_LOOP | CHANF_NOSTOP, // convenience value for replicating the old 'looping' boolean.
}; };