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);
This commit is contained in:
Major Cooke 2020-03-01 12:35:19 -06:00 committed by Christoph Oelckers
parent 55284d46bf
commit 4cf7c6351d
6 changed files with 21 additions and 10 deletions

View file

@ -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;
}

View file

@ -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);
}
//==========================================================================

View file

@ -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);

View file

@ -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);
}

View file

@ -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);

View file

@ -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);