From 221d9fe28ebae06119676a5cf598409a5f558b3d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 Nov 2021 10:31:15 +0100 Subject: [PATCH] - adapted Duke's and Exhumed's sound code to directly work with actors. This was already wrapped so all that needed to be done was removing the wrapper. --- source/games/duke/src/sounds.cpp | 26 +++++++------------------- source/games/exhumed/src/sound.cpp | 6 +++--- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index 221dda5f9..73818dccf 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -54,18 +54,6 @@ CVAR(Bool, wt_commentary, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) BEGIN_DUKE_NS -// These are needed until real objects can be used for actors. -inline void* sndActor(DDukeActor* actor) -{ - return actor ? actor->s : nullptr; -} - -inline DDukeActor* getSndActor(const void* source) -{ - // transitional conversation voodoo - return source ? &hittype[((spritetype*)source) - sprite] : nullptr; -} - static FSoundID currentCommentarySound; static DDukeActor* currentCommentarySprite; // todo: GC this once actors become objects @@ -368,7 +356,7 @@ void DukeSoundEngine::CalcPosVel(int type, const void* source, const float pt[3] } else if (type == SOURCE_Actor) { - auto aactor = getSndActor(source); + auto aactor = (DDukeActor*)source; auto aspr = aactor ? aactor->s : nullptr; assert(aspr != nullptr); if (aspr != nullptr) @@ -525,7 +513,7 @@ int S_PlaySound3D(int sndnum, DDukeActor* actor, const vec3_t* pos, int channel, if (userflags & SF_LOOP) flags |= CHANF_LOOP; float vol = attenuation == ATTN_NONE ? 0.8f : 1.f; if (currentCommentarySound != 0) vol *= 0.25f; - auto chan = soundEngine->StartSound(SOURCE_Actor, sndActor(actor), &sndpos, CHAN_AUTO, flags, sndnum+1, vol, attenuation, nullptr, S_ConvertPitch(pitch)); + auto chan = soundEngine->StartSound(SOURCE_Actor, actor, &sndpos, CHAN_AUTO, flags, sndnum+1, vol, attenuation, nullptr, S_ConvertPitch(pitch)); if (chan) chan->UserData = (currentCommentarySound != 0); return chan ? 0 : -1; } @@ -570,7 +558,7 @@ int S_PlayActorSound(int soundNum, DDukeActor* actor, int channel, EChanFlags fl void S_RelinkActorSound(DDukeActor* from, DDukeActor* to) { FVector3 pos = GetSoundPos(&from->s->pos); - soundEngine->RelinkSound(SOURCE_Actor, sndActor(from), sndActor(to), &pos); + soundEngine->RelinkSound(SOURCE_Actor, from, to, &pos); } void S_StopSound(int sndNum, DDukeActor* actor, int channel) @@ -580,7 +568,7 @@ void S_StopSound(int sndNum, DDukeActor* actor, int channel) if (!actor) soundEngine->StopSoundID(sndNum+1); else { - if (channel == -1) soundEngine->StopSound(SOURCE_Actor, sndActor(actor), -1, sndNum + 1); + if (channel == -1) soundEngine->StopSound(SOURCE_Actor, actor, -1, sndNum + 1); else soundEngine->StopSound(SOURCE_Actor, actor, channel, -1); // StopSound kills the actor reference so this cannot be delayed until ChannelEnded gets called. At that point the actor may also not be valid anymore. @@ -600,7 +588,7 @@ void S_ChangeSoundPitch(int soundNum, DDukeActor* actor, int pitchoffset) } else { - soundEngine->ChangeSoundPitch(SOURCE_Actor, sndActor(actor), CHAN_AUTO, expitch, soundNum+1); + soundEngine->ChangeSoundPitch(SOURCE_Actor, actor, CHAN_AUTO, expitch, soundNum+1); } } @@ -615,14 +603,14 @@ int S_CheckActorSoundPlaying(DDukeActor* actor, int soundNum, int channel) soundNum = GetReplacementSound(soundNum); if (actor == nullptr) return soundEngine->GetSoundPlayingInfo(SOURCE_Any, nullptr, soundNum+1); - return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, sndActor(actor), channel, soundNum+1); + return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, actor, channel, soundNum+1); } // Check if actor is playing any sound. int S_CheckAnyActorSoundPlaying(DDukeActor* actor) { if (!actor) return false; - return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, sndActor(actor), CHAN_AUTO, 0); + return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, actor, CHAN_AUTO, 0); } int S_CheckSoundPlaying(int soundNum) diff --git a/source/games/exhumed/src/sound.cpp b/source/games/exhumed/src/sound.cpp index ae790fba7..7ef8b5af8 100644 --- a/source/games/exhumed/src/sound.cpp +++ b/source/games/exhumed/src/sound.cpp @@ -474,11 +474,11 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3], } else if (type == SOURCE_Actor) { - auto actor = (spritetype*)source; + auto actor = (DExhumedActor*)source; assert(actor != nullptr); if (actor != nullptr) { - *pos = GetSoundPos(&actor->pos); + *pos = GetSoundPos(&actor->s().pos); } } if ((chanflags & CHANF_LISTENERZ) && type != SOURCE_None) @@ -631,7 +631,7 @@ void PlayFX2(unsigned int nSound, DExhumedActor* pActor, int sectf, EChanFlags c FSoundChan* chan = nullptr; if (pActor != nullptr) { - chan = soundEngine->StartSound(SOURCE_Actor, &pActor->s(), nullptr, CHAN_BODY, chanflags| CHANF_OVERLAP, nSound+1, nVolume / 255.f,fullvol? 0.5f : ATTN_NORM, nullptr, (11025 + nPitch) / 11025.f); + chan = soundEngine->StartSound(SOURCE_Actor, pActor, nullptr, CHAN_BODY, chanflags| CHANF_OVERLAP, nSound+1, nVolume / 255.f,fullvol? 0.5f : ATTN_NORM, nullptr, (11025 + nPitch) / 11025.f); } else {