- added GetSoundPos variant taking a reference instead of pointer.

This commit is contained in:
Christoph Oelckers 2022-01-30 16:59:23 +01:00
parent efc832ca5c
commit 4f391e46ce
5 changed files with 26 additions and 17 deletions

View file

@ -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.

View file

@ -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
{

View file

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

View file

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

View file

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