From 4f391e46ce6f5561adea8f96efb21144bcb94a51 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 30 Jan 2022 16:59:23 +0100 Subject: [PATCH] - added GetSoundPos variant taking a reference instead of pointer. --- source/core/actorlist.cpp | 2 +- source/core/raze_sound.h | 9 +++++++++ source/games/blood/src/sfx.cpp | 10 +++++----- source/games/exhumed/src/sound.cpp | 18 +++++++++--------- source/games/sw/src/sounds.cpp | 4 ++-- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/source/core/actorlist.cpp b/source/core/actorlist.cpp index 7d93e0d69..7d8ce67b6 100644 --- a/source/core/actorlist.cpp +++ b/source/core/actorlist.cpp @@ -366,7 +366,7 @@ DCoreActor* InsertActor(PClass* type, sectortype* sector, int stat, bool tail) void DCoreActor::OnDestroy() { - FVector3 pos = GetSoundPos(&spr.pos); + FVector3 pos = GetSoundPos(spr.pos); soundEngine->RelinkSound(SOURCE_Actor, this, nullptr, &pos); // also scan all other sounds if they have this actor as source. If so, null the source and stop looped sounds. diff --git a/source/core/raze_sound.h b/source/core/raze_sound.h index 0b8a267a9..819839a6e 100644 --- a/source/core/raze_sound.h +++ b/source/core/raze_sound.h @@ -13,6 +13,15 @@ inline FVector3 GetSoundPos(const vec3_t *pos) return { pos->X* xmul, pos->Z* zmul, pos->Y* ymul }; } +inline FVector3 GetSoundPos(const vec3_t& pos) +{ + // converts a Build coordinate to a sound system coordinate + const float xmul = 1 / 16.f; + const float ymul = -1 / 16.f; + const float zmul = -1 / 256.f; + return { pos.X * xmul, pos.Z * zmul, pos.Y * ymul }; +} + enum { diff --git a/source/games/blood/src/sfx.cpp b/source/games/blood/src/sfx.cpp index 7537237af..78d214f29 100644 --- a/source/games/blood/src/sfx.cpp +++ b/source/games/blood/src/sfx.cpp @@ -75,7 +75,7 @@ void BloodSoundEngine::CalcPosVel(int type, const void* source, const float pt[3 { FVector3 camera; - if (gMe && gMe->actor) camera = GetSoundPos(&gMe->actor->spr.pos); + if (gMe && gMe->actor) camera = GetSoundPos(gMe->actor->spr.pos); else camera = { 0, 0, 0 }; // don't crash if there is no player. if (vel) vel->Zero(); @@ -93,7 +93,7 @@ void BloodSoundEngine::CalcPosVel(int type, const void* source, const float pt[3 // Engine expects velocity in units per second, not units per tic. if (vel) *vel = { actor->vel.X * (30 / 65536.f), actor->vel.Z * (-30 / 65536.f), actor->vel.Y * (-30 / 65536.f) }; - *pos = GetSoundPos(&actor->spr.pos); + *pos = GetSoundPos(actor->spr.pos); } else if (type == SOURCE_Ambient) { @@ -120,7 +120,7 @@ void GameInterface::UpdateSounds() { listener.angle = -gMe->actor->spr.ang * float(BAngRadian); // Build uses a period of 2048. listener.velocity.Zero(); - listener.position = GetSoundPos(&gMe->actor->spr.pos); + listener.position = GetSoundPos(gMe->actor->spr.pos); listener.valid = true; } else @@ -171,7 +171,7 @@ void sfxPlay3DSound(int x, int y, int z, int soundId, sectortype* pSector) if (sid == 0) return; vec3_t xyz = { x, y, z }; - auto svec = GetSoundPos(&xyz); + auto svec = GetSoundPos(xyz); float attenuation; int pitch = -1; @@ -197,7 +197,7 @@ void sfxPlay3DSoundCP(DBloodActor* pActor, int soundId, int playchannel, int pla auto sid = soundEngine->FindSoundByResID(soundId); if (sid == 0) return; - auto svec = GetSoundPos(&pActor->spr.pos); + auto svec = GetSoundPos(pActor->spr.pos); float attenuation; sid = getSfx(sid, attenuation, pitch, volume); diff --git a/source/games/exhumed/src/sound.cpp b/source/games/exhumed/src/sound.cpp index ffbd7a519..92f438bb9 100644 --- a/source/games/exhumed/src/sound.cpp +++ b/source/games/exhumed/src/sound.cpp @@ -435,7 +435,7 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3], { campos = { initx, inity, initz }; } - auto fcampos = GetSoundPos(&campos); + auto fcampos = GetSoundPos(campos); if (vel) vel->Zero(); @@ -477,7 +477,7 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3], assert(actor != nullptr); if (actor != nullptr) { - *pos = GetSoundPos(&actor->spr.pos); + *pos = GetSoundPos(actor->spr.pos); } } if ((chanflags & CHANF_LISTENERZ) && type != SOURCE_None) @@ -511,11 +511,11 @@ void GameInterface::UpdateSounds() pos = { initx, inity, initz }; ang = inita; } - auto fv = GetSoundPos(&pos); + auto fv = GetSoundPos(pos); SoundListener listener; listener.angle = float(-ang * BAngRadian); // Build uses a period of 2048. listener.velocity.Zero(); - listener.position = GetSoundPos(&pos); + listener.position = GetSoundPos(pos); listener.underwater = false; // This should probably use a real environment instead of the pitch hacking in S_PlaySound3D. // listenactor->waterlevel == 3; @@ -589,7 +589,7 @@ void PlayFX2(int nSound, DExhumedActor* pActor, int sectf, EChanFlags chanflags, GetSpriteSoundPitch(&nVolume, &nPitch); vec3_t v = { soundx, soundy, soundz }; - FVector3 vv = GetSoundPos(&v); + FVector3 vv = GetSoundPos(v); // Check if this sound is allowed to play or if it must stop some other sound. if (!forcePlay) @@ -676,7 +676,7 @@ void CheckAmbience(sectortype* sect) if (!soundEngine->IsSourcePlayingSomething(SOURCE_Ambient, &amb, 0)) { vec3_t v = { pWall->wall_int_pos().X, pWall->wall_int_pos().Y, pSector2->floorz }; - amb = GetSoundPos(&v); + amb = GetSoundPos(v); soundEngine->StartSound(SOURCE_Ambient, &amb, nullptr, CHAN_BODY, CHANF_TRANSIENT, sect->Sound + 1, 1.f, ATTN_NORM); return; } @@ -686,12 +686,12 @@ void CheckAmbience(sectortype* sect) { if (sect == pSector2) { - amb = GetSoundPos(&PlayerList[0].pActor->spr.pos); + amb = GetSoundPos(PlayerList[0].pActor->spr.pos); } else { vec3_t v = { pWall->wall_int_pos().X, pWall->wall_int_pos().Y, pSector2->floorz }; - amb = GetSoundPos(&v); + amb = GetSoundPos(v); } return 1; } @@ -732,7 +732,7 @@ void UpdateCreepySounds() vax = -vax; auto sp = PlayerList[nLocalPlayer].pActor->spr.pos + vec3_t({ vdx, vax, 0 }); - creepy = GetSoundPos(&sp); + creepy = GetSoundPos(sp); if ((vsi & 0x1ff) >= kMaxSounds || !soundEngine->isValidSoundId((vsi & 0x1ff) + 1)) { diff --git a/source/games/sw/src/sounds.cpp b/source/games/sw/src/sounds.cpp index a909a6e00..a85fa7497 100644 --- a/source/games/sw/src/sounds.cpp +++ b/source/games/sw/src/sounds.cpp @@ -519,7 +519,7 @@ void SWSoundEngine::CalcPosVel(int type, const void* source, const float pt[3], if (pos != nullptr) { PLAYER* pp = Player + screenpeek; - FVector3 campos = GetSoundPos(&pp->pos); + FVector3 campos = GetSoundPos(pp->pos); vec3_t *vpos = nullptr; if (vel) vel->Zero(); @@ -607,7 +607,7 @@ void GameInterface::UpdateSounds(void) listener.angle = float(-tang.asrad()); listener.velocity.Zero(); - listener.position = GetSoundPos(&pp->pos); + listener.position = GetSoundPos(pp->pos); listener.underwater = false; // This should probably use a real environment instead of the pitch hacking in S_PlaySound3D. // listenactor->waterlevel == 3;