- Duke: refactored sound API to receive its position by reference.

This commit is contained in:
Christoph Oelckers 2022-01-30 23:20:00 +01:00
parent b4e18e8255
commit f97bae8d23
6 changed files with 44 additions and 55 deletions

View file

@ -550,7 +550,7 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa
if ((krand() & 255) < 4)
{
vec3_t v{ hit.hitpos.X, hit.hitpos.Y, hit.hitpos.Z };
S_PlaySound3D(PISTOL_RICOCHET, spark, &v);
S_PlaySound3D(PISTOL_RICOCHET, spark, v);
}
}

View file

@ -447,7 +447,7 @@ static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa
if ((krand() & 255) < 10)
{
vec3_t v{ hit.hitpos.X, hit.hitpos.Y, hit.hitpos.Z };
S_PlaySound3D(PISTOL_RICOCHET, spark, &v);
S_PlaySound3D(PISTOL_RICOCHET, spark, v);
}
}

View file

@ -501,17 +501,17 @@ bool checkhitswitch_d(int snum, walltype* wwal, DDukeActor *act)
if (picnum == ALIENSWITCH || picnum == ALIENSWITCH + 1)
{
if (act)
S_PlaySound3D(ALIEN_SWITCH1, act, &v);
else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].GetActor(), &v);
S_PlaySound3D(ALIEN_SWITCH1, act, v);
else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].GetActor(), v);
}
else
{
if (act)
S_PlaySound3D(SWITCH_ON, act, &v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v);
S_PlaySound3D(SWITCH_ON, act, v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), v);
}
if (numdips != correctdips) break;
S_PlaySound3D(END_OF_LEVEL_WARN, ps[snum].GetActor(), &v);
S_PlaySound3D(END_OF_LEVEL_WARN, ps[snum].GetActor(), v);
}
[[fallthrough]];
case DIPSWITCH2:
@ -591,15 +591,15 @@ bool checkhitswitch_d(int snum, walltype* wwal, DDukeActor *act)
if (hitag == 0 && fi.isadoorwall(picnum) == 0)
{
if (act)
S_PlaySound3D(SWITCH_ON, act, &v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v);
S_PlaySound3D(SWITCH_ON, act, v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), v);
}
else if (hitag != 0)
{
auto flags = S_GetUserFlags(hitag);
if (act && (flags & SF_TALK) == 0)
S_PlaySound3D(hitag, act, &v);
S_PlaySound3D(hitag, act, v);
else
S_PlayActorSound(hitag, ps[snum].GetActor());
}

View file

@ -700,17 +700,17 @@ bool checkhitswitch_r(int snum, walltype* wwal, DDukeActor* act)
if (picnum == ALIENSWITCH || picnum == ALIENSWITCH + 1)
{
if (act)
S_PlaySound3D(ALIEN_SWITCH1, act, &v);
else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].GetActor(), &v);
S_PlaySound3D(ALIEN_SWITCH1, act, v);
else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].GetActor(), v);
}
else
{
if (act)
S_PlaySound3D(SWITCH_ON, act, &v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v);
S_PlaySound3D(SWITCH_ON, act, v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), v);
}
if (numdips != correctdips) break;
S_PlaySound3D(END_OF_LEVEL_WARN, ps[snum].GetActor(), &v);
S_PlaySound3D(END_OF_LEVEL_WARN, ps[snum].GetActor(), v);
}
goto goOn2;
case MULTISWITCH2:
@ -788,7 +788,7 @@ bool checkhitswitch_r(int snum, walltype* wwal, DDukeActor* act)
{
DDukeActor* switches[3];
int switchcount = 0, j;
S_PlaySound3D(SWITCH_ON, act, &v);
S_PlaySound3D(SWITCH_ON, act, v);
DukeSpriteIterator itr;
while (auto actt = itr.Next())
{
@ -810,7 +810,7 @@ bool checkhitswitch_r(int snum, walltype* wwal, DDukeActor* act)
if (switches[0]->GetIndex() > switches[2]->GetIndex()) std::swap(switches[0], switches[2]);
if (switches[1]->GetIndex() > switches[2]->GetIndex()) std::swap(switches[1], switches[2]);
S_PlaySound3D(78, act, &v);
S_PlaySound3D(78, act, v);
for (j = 0; j < switchcount; j++)
{
switches[j]->spr.hitag = 0;
@ -880,15 +880,15 @@ bool checkhitswitch_r(int snum, walltype* wwal, DDukeActor* act)
if (hitag == 0 && fi.isadoorwall(picnum) == 0)
{
if (act)
S_PlaySound3D(SWITCH_ON, act, &v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v);
S_PlaySound3D(SWITCH_ON, act, v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), v);
}
else if (hitag != 0)
{
auto flags = S_GetUserFlags(hitag);
if (act && (flags & SF_TALK) == 0)
S_PlaySound3D(hitag, act, &v);
S_PlaySound3D(hitag, act, v);
else
S_PlayActorSound(hitag, ps[snum].GetActor());
}

View file

@ -252,7 +252,7 @@ inline bool S_IsAmbientSFX(DDukeActor* actor)
//==========================================================================
static int GetPositionInfo(DDukeActor* actor, int soundNum, sectortype* sect,
const vec3_t *cam, const vec3_t *pos, int *distPtr, FVector3 *sndPos)
const vec3_t *cam, const vec3_t &pos, int *distPtr, FVector3 *sndPos)
{
// There's a lot of hackery going on here that could be mapped to rolloff and attenuation parameters.
// However, ultimately rolloff would also just reposition the sound source so this can remain as it is.
@ -310,18 +310,18 @@ static int GetPositionInfo(DDukeActor* actor, int soundNum, sectortype* sect,
//
//==========================================================================
void S_GetCamera(vec3_t** c, int32_t* ca, sectortype** cs)
void S_GetCamera(vec3_t* c, int32_t* ca, sectortype** cs)
{
if (ud.cameraactor == nullptr)
{
auto p = &ps[screenpeek];
if (c) *c = &p->pos;
if (c) *c = p->pos;
if (cs) *cs = p->cursector;
if (ca) *ca = p->angle.ang.asbuild();
}
else
{
if (c) *c = &ud.cameraactor->spr.pos;
if (c) *c = ud.cameraactor->spr.pos;
if (cs) *cs = ud.cameraactor->sector();
if (ca) *ca = ud.cameraactor->spr.ang;
}
@ -339,7 +339,7 @@ void DukeSoundEngine::CalcPosVel(int type, const void* source, const float pt[3]
{
if (pos != nullptr)
{
vec3_t* campos;
vec3_t campos;
sectortype* camsect;
S_GetCamera(&campos, nullptr, &camsect);
@ -356,7 +356,7 @@ void DukeSoundEngine::CalcPosVel(int type, const void* source, const float pt[3]
auto aactor = (DDukeActor*)source;
if (aactor != nullptr)
{
GetPositionInfo(aactor, chanSound - 1, camsect, campos, &aactor->spr.pos, nullptr, pos);
GetPositionInfo(aactor, chanSound - 1, camsect, &campos, aactor->spr.pos, nullptr, pos);
/*
if (vel) // DN3D does not properly maintain this.
{
@ -367,9 +367,9 @@ void DukeSoundEngine::CalcPosVel(int type, const void* source, const float pt[3]
*/
}
}
if ((chanflags & CHANF_LISTENERZ) && campos != nullptr && type != SOURCE_None)
if ((chanflags & CHANF_LISTENERZ) && type != SOURCE_None)
{
pos->Y = campos->Z / 256.f;
pos->Y = campos.Z / 256.f;
}
}
}
@ -384,7 +384,7 @@ void DukeSoundEngine::CalcPosVel(int type, const void* source, const float pt[3]
void GameInterface::UpdateSounds(void)
{
SoundListener listener;
vec3_t* c;
vec3_t c;
int32_t ca;
sectortype* cs;
@ -393,27 +393,16 @@ void GameInterface::UpdateSounds(void)
S_GetCamera(&c, &ca, &cs);
if (c != nullptr)
{
listener.angle = -float(ca * BAngRadian); // Build uses a period of 2048.
listener.velocity.Zero();
listener.position = GetSoundPos(c);
listener.underwater = false;
// This should probably use a real environment instead of the pitch hacking in S_PlaySound3D.
// listenactor->waterlevel == 3;
//assert(primaryLevel->Zones.Size() > listenactor->Sector->ZoneNumber);
listener.Environment = 0;// primaryLevel->Zones[listenactor->Sector->ZoneNumber].Environment;
listener.valid = true;
}
else
{
listener.angle = 0;
listener.position.Zero();
listener.velocity.Zero();
listener.underwater = false;
listener.Environment = nullptr;
listener.valid = false;
}
listener.angle = -float(ca * BAngRadian); // Build uses a period of 2048.
listener.velocity.Zero();
listener.position = GetSoundPos(c);
listener.underwater = false;
// This should probably use a real environment instead of the pitch hacking in S_PlaySound3D.
// listenactor->waterlevel == 3;
//assert(primaryLevel->Zones.Size() > listenactor->Sector->ZoneNumber);
listener.Environment = 0;// primaryLevel->Zones[listenactor->Sector->ZoneNumber].Environment;
listener.valid = true;
listener.ListenerObject = ud.cameraactor == nullptr ? nullptr : ud.cameraactor.Get();
soundEngine->SetListener(listener);
}
@ -425,7 +414,7 @@ void GameInterface::UpdateSounds(void)
//
//==========================================================================
int S_PlaySound3D(int sndnum, DDukeActor* actor, const vec3_t* pos, int channel, EChanFlags flags)
int S_PlaySound3D(int sndnum, DDukeActor* actor, const vec3_t& pos, int channel, EChanFlags flags)
{
auto const pl = &ps[myconnectindex];
if (!soundEngine->isValidSoundId(sndnum+1) || !SoundEnabled() || actor == nullptr || !playrunning() ||
@ -463,11 +452,11 @@ int S_PlaySound3D(int sndnum, DDukeActor* actor, const vec3_t* pos, int channel,
int32_t sndist;
FVector3 sndpos; // this is in sound engine space.
vec3_t* campos;
vec3_t campos;
sectortype* camsect;
S_GetCamera(&campos, nullptr, &camsect);
GetPositionInfo(actor, sndnum, camsect, campos, pos, &sndist, &sndpos);
GetPositionInfo(actor, sndnum, camsect, &campos, pos, &sndist, &sndpos);
int pitch = S_GetPitch(sndnum);
bool explosion = ((userflags & (SF_GLOBAL | SF_DTAG)) == (SF_GLOBAL | SF_DTAG)) || ((sndnum == PIPEBOMB_EXPLODE || sndnum == LASERTRIP_EXPLODE || sndnum == RPG_EXPLODE));
@ -547,7 +536,7 @@ int S_PlaySound(int sndnum, int channel, EChanFlags flags, float vol)
int S_PlayActorSound(int soundNum, DDukeActor* actor, int channel, EChanFlags flags)
{
return (actor == nullptr ? S_PlaySound(soundNum, channel, flags) :
S_PlaySound3D(soundNum, actor, &actor->spr.pos, channel, flags));
S_PlaySound3D(soundNum, actor, actor->spr.pos, channel, flags));
}
void S_StopSound(int sndNum, DDukeActor* actor, int channel)

View file

@ -40,7 +40,7 @@ int S_DefineSound(unsigned index, const char* filename, int ps, int pe, int pr,
void S_WorldTourMappingsForOldSounds();
int S_PlaySound(int num, int channel = CHAN_AUTO, EChanFlags flags = 0, float vol =0.8f);
int S_PlaySound3D(int num, DDukeActor* spriteNum, const vec3_t* pos, int channel = CHAN_AUTO, EChanFlags flags = 0);
int S_PlaySound3D(int num, DDukeActor* spriteNum, const vec3_t& pos, int channel = CHAN_AUTO, EChanFlags flags = 0);
int S_PlayActorSound(int soundNum, DDukeActor* spriteNum, int channel = CHAN_AUTO, EChanFlags flags = 0);
void S_MenuSound(void);