- made the sound resolving a virtual method

This way the player sounds can be done in the proper place without infesting the core.
This commit is contained in:
Christoph Oelckers 2019-12-12 01:31:41 +01:00
parent cc7807bb10
commit 165d9951aa
3 changed files with 52 additions and 28 deletions

View File

@ -88,6 +88,7 @@ class DoomSoundEngine : public SoundEngine
bool ValidatePosVel(int sourcetype, const void* source, const FVector3& pos, const FVector3& vel);
TArray<uint8_t> ReadSound(int lumpnum);
int PickReplacement(int refid);
int ResolveSound(const void *ent, int type, sfxinfo_t *sfx, float &attenuation);
public:
DoomSoundEngine() = default;
@ -298,6 +299,24 @@ DEFINE_ACTION_FUNCTION(DObject, S_Sound)
return 0;
}
//==========================================================================
//
//
//
//==========================================================================
int DoomSoundEngine::ResolveSound(const void * ent, int type, sfxinfo_t *sfx, float &attenuation)
{
if (isPlayerReserve(sfx->index))
{
AActor *src;
if (type != SOURCE_Actor) src = nullptr;
else src = (AActor*)ent;
return S_FindSkinnedSound(src, sfx->index);
}
return SoundEngine::ResolveSound(ent, type, sfx, attenuation);
}
//==========================================================================
//
// Common checking code for the actor sound functions
@ -317,12 +336,6 @@ static bool VerifyActorSound(AActor* ent, FSoundID& sound_id, int& channel)
}
}
if (soundEngine->isPlayerReserve(sound_id))
{
sound_id = FSoundID(S_FindSkinnedSound(ent, sound_id));
if (sound_id <= 0) return false;
}
if (compatflags & COMPATF_MAGICSILENCE)
{ // For people who just can't play without a silent BFG.
channel = CHAN_WEAPON;

View File

@ -344,6 +344,26 @@ bool SoundEngine::ValidatePosVel(const FSoundChan* const chan, const FVector3& p
return ValidatePosVel(chan->SourceType, chan->Source, pos, vel);
}
//==========================================================================
//
//
//
//==========================================================================
int SoundEngine::ResolveSound(const void *, int, sfxinfo_t *sfx, float &attenuation)
{
if (sfx->bRandomHeader)
{
// Random sounds attenuate based on the original (random) sound as well as the chosen one.
attenuation *= sfx->Attenuation;
return PickReplacement (sfx->index);
}
else
{
return sfx->link;
}
}
//==========================================================================
//
// S_StartSound
@ -402,35 +422,24 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
// Resolve player sounds, random sounds, and aliases
while (sfx->link != sfxinfo_t::NO_LINK)
{
if (sfx->bRandomHeader)
auto newid = ResolveSound(source, type, sfx, attenuation);
if (newid < 0) return nullptr;
auto newsfx = &S_sfx[newid];
if (newsfx != sfx)
{
// Random sounds attenuate based on the original (random) sound as well as the chosen one.
attenuation *= sfx->Attenuation;
sound_id = FSoundID(PickReplacement (sound_id));
if (near_limit < 0)
if (near_limit < 0)
{
near_limit = S_sfx[sound_id].NearLimit;
limit_range = S_sfx[sound_id].LimitRange;
near_limit = newsfx->NearLimit;
limit_range = newsfx->LimitRange;
}
if (rolloff->MinDistance == 0)
{
rolloff = &S_sfx[sound_id].Rolloff;
rolloff = &newsfx->Rolloff;
}
sfx = newsfx;
}
else
{
sound_id = FSoundID(sfx->link);
if (near_limit < 0)
{
near_limit = S_sfx[sound_id].NearLimit;
limit_range = S_sfx[sound_id].LimitRange;
}
if (rolloff->MinDistance == 0)
{
rolloff = &S_sfx[sound_id].Rolloff;
}
}
sfx = &S_sfx[sound_id];
else return nullptr; // nothing got replaced, prevent an endless loop,
}
// Attenuate the attenuation based on the sound.

View File

@ -263,6 +263,8 @@ private:
bool CheckSingular(int sound_id);
bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel);
virtual TArray<uint8_t> ReadSound(int lumpnum) = 0;
protected:
virtual int ResolveSound(const void *ent, int srctype, sfxinfo_t *sfx, float &attenuation);
public:
virtual ~SoundEngine() = default;