From 07ad50d97cd2bf58ea8862dbffc809176ff452cf Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 22 Oct 2021 18:31:28 +0200 Subject: [PATCH] - sound API --- source/games/exhumed/src/player.cpp | 4 ++-- source/games/exhumed/src/player.h | 6 +----- source/games/exhumed/src/sequence.cpp | 6 +++--- source/games/exhumed/src/sequence.h | 6 +----- source/games/exhumed/src/sound.cpp | 30 +++++++++++++-------------- source/games/exhumed/src/sound.h | 12 ++--------- source/games/exhumed/src/status.cpp | 2 +- 7 files changed, 25 insertions(+), 41 deletions(-) diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index eb2264c55..09fd38ef0 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -207,9 +207,9 @@ void InitPlayerInventory(short nPlayer) PlayerList[nPlayer].nPlayerColor = pixels[tileWidth(nPlayer + kTile3571) * tileHeight(nPlayer + kTile3571) / 2]; } -short GetPlayerFromSprite(short nSprite) +short GetPlayerFromActor(DExhumedActor* pActor) { - auto pSprite = &sprite[nSprite]; + auto pSprite = &pActor->s(); return RunData[pSprite->owner].nObjIndex; } diff --git a/source/games/exhumed/src/player.h b/source/games/exhumed/src/player.h index 238c469db..1b214d043 100644 --- a/source/games/exhumed/src/player.h +++ b/source/games/exhumed/src/player.h @@ -128,11 +128,7 @@ extern DExhumedActor* nNetStartSprite[kMaxPlayers]; extern short nNetStartSprites; extern short nCurStartSprite; -short GetPlayerFromSprite(short nSprite); -short GetPlayerFromActor(DExhumedActor* actor) -{ - return GetPlayerFromSprite(actor->GetSpriteIndex()); -} +short GetPlayerFromActor(DExhumedActor* actor); void SetPlayerMummified(int nPlayer, int bIsMummified); int AddAmmo(int nPlayer, int nWeapon, int nAmmoAmount); void ShootStaff(int nPlayer); diff --git a/source/games/exhumed/src/sequence.cpp b/source/games/exhumed/src/sequence.cpp index 6f42d9438..e227434f1 100644 --- a/source/games/exhumed/src/sequence.cpp +++ b/source/games/exhumed/src/sequence.cpp @@ -437,7 +437,7 @@ int seq_GetFrameSound(int val, int edx) return FrameSound[SeqBase[val] + edx]; } -void seq_MoveSequence(short nSprite, short nSeq, short bx) +void seq_MoveSequence(DExhumedActor* actor, short nSeq, short bx) { assert(nSeq >= 0); // TEMP @@ -446,8 +446,8 @@ void seq_MoveSequence(short nSprite, short nSeq, short bx) return; } - if (nSprite > -1) { - D3PlayFX(nSound, nSprite); + if (actor) { + D3PlayFX(nSound, actor); } else { PlayLocalSound(nSound, 0); diff --git a/source/games/exhumed/src/sequence.h b/source/games/exhumed/src/sequence.h index 25aa80f05..5aa673b89 100644 --- a/source/games/exhumed/src/sequence.h +++ b/source/games/exhumed/src/sequence.h @@ -133,11 +133,7 @@ extern short FrameBase[]; void seq_LoadSequences(); int seq_GetFrameSound(int val, int edx); -void seq_MoveSequence(short nSprite, short nSeq, short bx); -inline void seq_MoveSequence(DExhumedActor* actor, short nSeq, short bx) -{ - seq_MoveSequence(actor->GetSpriteIndex(), nSeq, bx); -} +void seq_MoveSequence(DExhumedActor* actor, short nSeq, short bx); int seq_GetSeqPicnum2(short nSeq, short nFrame); int seq_GetSeqPicnum(short nSeq, short edx, short ebx); diff --git a/source/games/exhumed/src/sound.cpp b/source/games/exhumed/src/sound.cpp index 613705c01..68dd4d550 100644 --- a/source/games/exhumed/src/sound.cpp +++ b/source/games/exhumed/src/sound.cpp @@ -557,23 +557,23 @@ void GameInterface::UpdateSounds() int soundx, soundy, soundz; short soundsect; -void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanflags, int sprflags) +void PlayFX2(unsigned short nSound, DExhumedActor* pActor, int sectf, EChanFlags chanflags, int sprflags) { if (!SoundEnabled()) return; if ((nSound&0x1ff) >= kMaxSounds || !soundEngine->isValidSoundId((nSound & 0x1ff)+1)) { - Printf("PlayFX2: Invalid sound nSound == %i, nSprite == %i\n", nSound, nSprite); + Printf("PlayFX2: Invalid sound nSound == %i\n", nSound); return; } bool fullvol = false, hiprio = false; - if (nSprite >= 0) + if (pActor) { fullvol = (sprflags & 0x2000) != 0; hiprio = (sprflags & 0x4000) != 0; - soundx = sprite[nSprite].x; - soundy = sprite[nSprite].y; - soundz = sprite[nSprite].z; + soundx = pActor->s().x; + soundy = pActor->s().y; + soundz = pActor->s().z; } int nVolume = 255; @@ -584,7 +584,7 @@ void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanfla int prio = 0; if (forcePlay || midprio) prio = 1000; - else if (nSprite != -1 && hiprio) prio = 2000; + else if (pActor != nullptr && hiprio) prio = 2000; short v10 = (nSound&0xe00)>>9; nSound &= 0x1ff; @@ -602,16 +602,16 @@ void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanfla { bool res = soundEngine->EnumerateChannels([=](FSoundChan* chan) { - if (chan->SourceType == SOURCE_Actor && nSprite != -1) + if (chan->SourceType == SOURCE_Actor && pActor != nullptr) { if (prio >= chan->UserData) { if (chan->SoundID == nSound + 1) { - if (!allowMultiple && &sprite[nSprite] == chan->Source) + if (!allowMultiple && &pActor->s() == chan->Source) return 1; } - else if (&sprite[nSprite] == chan->Source) + else if (&pActor->s() == chan->Source) { soundEngine->StopChannel(chan); return -1; @@ -619,7 +619,7 @@ void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanfla } } - else if (chan->SourceType == SOURCE_Unattached && nSprite == -1) + else if (chan->SourceType == SOURCE_Unattached && pActor != nullptr) { if (chan->SoundID == nSound + 1) { @@ -633,9 +633,9 @@ void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanfla if (res) return; } FSoundChan* chan = nullptr; - if (nSprite >= 0) + if (pActor != nullptr) { - chan = soundEngine->StartSound(SOURCE_Actor, &sprite[nSprite], 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->s(), nullptr, CHAN_BODY, chanflags| CHANF_OVERLAP, nSound+1, nVolume / 255.f,fullvol? 0.5f : ATTN_NORM, nullptr, (11025 + nPitch) / 11025.f); } else { @@ -648,7 +648,7 @@ void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanfla } // Nuke: added nSprite >= 0 check - if (nSprite != PlayerList[nLocalPlayer].Actor()->GetSpriteIndex() && nSprite >= 0 && (sprite[nSprite].cstat&257)) + if (pActor != PlayerList[nLocalPlayer].Actor() && pActor != nullptr && (pActor->s().cstat&257)) nCreepyTimer = kCreepyCount; } @@ -664,7 +664,7 @@ void PlayFXAtXYZ(unsigned short ax, int x, int y, int z, int nSector, EChanFlags soundy = y; soundz = z; soundsect = nSector; - PlayFX2(ax, -1, sectf, chanflags); + PlayFX2(ax, nullptr, sectf, chanflags); } //========================================================================== diff --git a/source/games/exhumed/src/sound.h b/source/games/exhumed/src/sound.h index 2ebc02302..fdd6310f2 100644 --- a/source/games/exhumed/src/sound.h +++ b/source/games/exhumed/src/sound.h @@ -131,20 +131,12 @@ int LoadSound(const char* sound); void BendAmbientSound(); void CheckAmbience(short nSector); -void PlayFX2(unsigned short nSound, short nSprite, int sectf = 0, EChanFlags chanflags = CHANF_NONE, int sprflags = 0); -inline void PlayFX2(unsigned short nSound, DExhumedActor* actor, int sectf = 0, EChanFlags chanflags = CHANF_NONE, int sprflags = 0) -{ - PlayFX2(nSound, actor->GetSpriteIndex(), sectf, chanflags, sprflags); -} +void PlayFX2(unsigned short nSound, DExhumedActor* nSprite, int sectf = 0, EChanFlags chanflags = CHANF_NONE, int sprflags = 0); void PlayFXAtXYZ(unsigned short nSound, int x, int y, int z, int nSector, EChanFlags chanflags = CHANF_NONE, int sectf = 0); -inline void D3PlayFX(unsigned short nSound, short nSprite, short flags = 0) -{ - PlayFX2(nSound, nSprite, 0, CHANF_NONE, flags); -} inline void D3PlayFX(unsigned short nSound, DExhumedActor* actor, short flags = 0) { - PlayFX2(nSound, actor->GetSpriteIndex(), 0, CHANF_NONE, flags); + PlayFX2(nSound, actor, 0, CHANF_NONE, flags); } void StopActorSound(DExhumedActor* actor); diff --git a/source/games/exhumed/src/status.cpp b/source/games/exhumed/src/status.cpp index 8305c74a8..44bfe6858 100644 --- a/source/games/exhumed/src/status.cpp +++ b/source/games/exhumed/src/status.cpp @@ -102,7 +102,7 @@ DEFINE_ACTION_FUNCTION(_Exhumed, MoveStatusSequence) PARAM_PROLOGUE; PARAM_INT(s1); PARAM_INT(s2); - seq_MoveSequence(-1, nStatusSeqOffset + s1, s2); + seq_MoveSequence(nullptr, nStatusSeqOffset + s1, s2); ACTION_RETURN_INT(SeqSize[nStatusSeqOffset + s1]); }