From c3ede69d16065e2d2d3f0f03106131ef9e1ac882 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 12 Dec 2019 18:30:11 +0200 Subject: [PATCH] - fixed linked sound resolving Hash indices and sound ids were used interchangeably but they are different entities https://forum.zdoom.org/viewtopic.php?t=66618 --- src/sound/s_doomsound.cpp | 10 +++++----- src/sound/s_sound.cpp | 18 ++++++++++-------- src/sound/s_soundinternal.h | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/sound/s_doomsound.cpp b/src/sound/s_doomsound.cpp index 9f7bd6acd7..b5b4fbb741 100644 --- a/src/sound/s_doomsound.cpp +++ b/src/sound/s_doomsound.cpp @@ -88,7 +88,7 @@ class DoomSoundEngine : public SoundEngine bool ValidatePosVel(int sourcetype, const void* source, const FVector3& pos, const FVector3& vel); TArray ReadSound(int lumpnum); int PickReplacement(int refid); - int ResolveSound(const void *ent, int type, sfxinfo_t *sfx, float &attenuation); + FSoundID ResolveSound(const void *ent, int type, FSoundID soundid, float &attenuation) override; public: DoomSoundEngine() = default; @@ -305,16 +305,16 @@ DEFINE_ACTION_FUNCTION(DObject, S_Sound) // //========================================================================== -int DoomSoundEngine::ResolveSound(const void * ent, int type, sfxinfo_t *sfx, float &attenuation) +FSoundID DoomSoundEngine::ResolveSound(const void * ent, int type, FSoundID soundid, float &attenuation) { - if (isPlayerReserve(sfx->index)) + if (isPlayerReserve(soundid)) { AActor *src; if (type != SOURCE_Actor) src = nullptr; else src = (AActor*)ent; - return S_FindSkinnedSound(src, sfx->index); + return S_FindSkinnedSound(src, soundid); } - return SoundEngine::ResolveSound(ent, type, sfx, attenuation); + return SoundEngine::ResolveSound(ent, type, soundid, attenuation); } //========================================================================== diff --git a/src/sound/s_sound.cpp b/src/sound/s_sound.cpp index 4141202220..1f90c3707c 100644 --- a/src/sound/s_sound.cpp +++ b/src/sound/s_sound.cpp @@ -350,17 +350,19 @@ bool SoundEngine::ValidatePosVel(const FSoundChan* const chan, const FVector3& p // //========================================================================== -int SoundEngine::ResolveSound(const void *, int, sfxinfo_t *sfx, float &attenuation) +FSoundID SoundEngine::ResolveSound(const void *, int, FSoundID soundid, float &attenuation) { - if (sfx->bRandomHeader) + const sfxinfo_t &sfx = S_sfx[soundid]; + + 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); + attenuation *= sfx.Attenuation; + return PickReplacement (soundid); } else { - return sfx->link; + return sfx.link; } } @@ -422,9 +424,9 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source, // Resolve player sounds, random sounds, and aliases while (sfx->link != sfxinfo_t::NO_LINK) { - auto newid = ResolveSound(source, type, sfx, attenuation); - if (newid < 0) return nullptr; - auto newsfx = &S_sfx[newid]; + sound_id = ResolveSound(source, type, sound_id, attenuation); + if (sound_id < 0) return nullptr; + auto newsfx = &S_sfx[sound_id]; if (newsfx != sfx) { if (near_limit < 0) diff --git a/src/sound/s_soundinternal.h b/src/sound/s_soundinternal.h index 13150e6308..38502d1926 100644 --- a/src/sound/s_soundinternal.h +++ b/src/sound/s_soundinternal.h @@ -264,7 +264,7 @@ private: bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel); virtual TArray ReadSound(int lumpnum) = 0; protected: - virtual int ResolveSound(const void *ent, int srctype, sfxinfo_t *sfx, float &attenuation); + virtual FSoundID ResolveSound(const void *ent, int srctype, FSoundID soundid, float &attenuation); public: virtual ~SoundEngine() = default;