- sound API

This commit is contained in:
Christoph Oelckers 2021-10-22 18:31:28 +02:00
parent 97b4116f28
commit 07ad50d97c
7 changed files with 25 additions and 41 deletions

View file

@ -207,9 +207,9 @@ void InitPlayerInventory(short nPlayer)
PlayerList[nPlayer].nPlayerColor = pixels[tileWidth(nPlayer + kTile3571) * tileHeight(nPlayer + kTile3571) / 2]; 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; return RunData[pSprite->owner].nObjIndex;
} }

View file

@ -128,11 +128,7 @@ extern DExhumedActor* nNetStartSprite[kMaxPlayers];
extern short nNetStartSprites; extern short nNetStartSprites;
extern short nCurStartSprite; extern short nCurStartSprite;
short GetPlayerFromSprite(short nSprite); short GetPlayerFromActor(DExhumedActor* actor);
short GetPlayerFromActor(DExhumedActor* actor)
{
return GetPlayerFromSprite(actor->GetSpriteIndex());
}
void SetPlayerMummified(int nPlayer, int bIsMummified); void SetPlayerMummified(int nPlayer, int bIsMummified);
int AddAmmo(int nPlayer, int nWeapon, int nAmmoAmount); int AddAmmo(int nPlayer, int nWeapon, int nAmmoAmount);
void ShootStaff(int nPlayer); void ShootStaff(int nPlayer);

View file

@ -437,7 +437,7 @@ int seq_GetFrameSound(int val, int edx)
return FrameSound[SeqBase[val] + 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 assert(nSeq >= 0); // TEMP
@ -446,8 +446,8 @@ void seq_MoveSequence(short nSprite, short nSeq, short bx)
return; return;
} }
if (nSprite > -1) { if (actor) {
D3PlayFX(nSound, nSprite); D3PlayFX(nSound, actor);
} }
else { else {
PlayLocalSound(nSound, 0); PlayLocalSound(nSound, 0);

View file

@ -133,11 +133,7 @@ extern short FrameBase[];
void seq_LoadSequences(); void seq_LoadSequences();
int seq_GetFrameSound(int val, int edx); int seq_GetFrameSound(int val, int edx);
void seq_MoveSequence(short nSprite, short nSeq, short bx); void seq_MoveSequence(DExhumedActor* actor, short nSeq, short bx);
inline void seq_MoveSequence(DExhumedActor* actor, short nSeq, short bx)
{
seq_MoveSequence(actor->GetSpriteIndex(), nSeq, bx);
}
int seq_GetSeqPicnum2(short nSeq, short nFrame); int seq_GetSeqPicnum2(short nSeq, short nFrame);
int seq_GetSeqPicnum(short nSeq, short edx, short ebx); int seq_GetSeqPicnum(short nSeq, short edx, short ebx);

View file

@ -557,23 +557,23 @@ void GameInterface::UpdateSounds()
int soundx, soundy, soundz; int soundx, soundy, soundz;
short soundsect; 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 (!SoundEnabled()) return;
if ((nSound&0x1ff) >= kMaxSounds || !soundEngine->isValidSoundId((nSound & 0x1ff)+1)) 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; return;
} }
bool fullvol = false, hiprio = false; bool fullvol = false, hiprio = false;
if (nSprite >= 0) if (pActor)
{ {
fullvol = (sprflags & 0x2000) != 0; fullvol = (sprflags & 0x2000) != 0;
hiprio = (sprflags & 0x4000) != 0; hiprio = (sprflags & 0x4000) != 0;
soundx = sprite[nSprite].x; soundx = pActor->s().x;
soundy = sprite[nSprite].y; soundy = pActor->s().y;
soundz = sprite[nSprite].z; soundz = pActor->s().z;
} }
int nVolume = 255; int nVolume = 255;
@ -584,7 +584,7 @@ void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanfla
int prio = 0; int prio = 0;
if (forcePlay || midprio) prio = 1000; if (forcePlay || midprio) prio = 1000;
else if (nSprite != -1 && hiprio) prio = 2000; else if (pActor != nullptr && hiprio) prio = 2000;
short v10 = (nSound&0xe00)>>9; short v10 = (nSound&0xe00)>>9;
nSound &= 0x1ff; nSound &= 0x1ff;
@ -602,16 +602,16 @@ void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanfla
{ {
bool res = soundEngine->EnumerateChannels([=](FSoundChan* chan) 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 (prio >= chan->UserData)
{ {
if (chan->SoundID == nSound + 1) if (chan->SoundID == nSound + 1)
{ {
if (!allowMultiple && &sprite[nSprite] == chan->Source) if (!allowMultiple && &pActor->s() == chan->Source)
return 1; return 1;
} }
else if (&sprite[nSprite] == chan->Source) else if (&pActor->s() == chan->Source)
{ {
soundEngine->StopChannel(chan); soundEngine->StopChannel(chan);
return -1; 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) if (chan->SoundID == nSound + 1)
{ {
@ -633,9 +633,9 @@ void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanfla
if (res) return; if (res) return;
} }
FSoundChan* chan = nullptr; 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 else
{ {
@ -648,7 +648,7 @@ void PlayFX2(unsigned short nSound, short nSprite, int sectf, EChanFlags chanfla
} }
// Nuke: added nSprite >= 0 check // 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; nCreepyTimer = kCreepyCount;
} }
@ -664,7 +664,7 @@ void PlayFXAtXYZ(unsigned short ax, int x, int y, int z, int nSector, EChanFlags
soundy = y; soundy = y;
soundz = z; soundz = z;
soundsect = nSector; soundsect = nSector;
PlayFX2(ax, -1, sectf, chanflags); PlayFX2(ax, nullptr, sectf, chanflags);
} }
//========================================================================== //==========================================================================

View file

@ -131,20 +131,12 @@ int LoadSound(const char* sound);
void BendAmbientSound(); void BendAmbientSound();
void CheckAmbience(short nSector); void CheckAmbience(short nSector);
void PlayFX2(unsigned short nSound, short nSprite, int sectf = 0, EChanFlags chanflags = CHANF_NONE, int sprflags = 0); void PlayFX2(unsigned short nSound, DExhumedActor* 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 PlayFXAtXYZ(unsigned short nSound, int x, int y, int z, int nSector, EChanFlags chanflags = CHANF_NONE, int sectf = 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) 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); void StopActorSound(DExhumedActor* actor);

View file

@ -102,7 +102,7 @@ DEFINE_ACTION_FUNCTION(_Exhumed, MoveStatusSequence)
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(s1); PARAM_INT(s1);
PARAM_INT(s2); PARAM_INT(s2);
seq_MoveSequence(-1, nStatusSeqOffset + s1, s2); seq_MoveSequence(nullptr, nStatusSeqOffset + s1, s2);
ACTION_RETURN_INT(SeqSize[nStatusSeqOffset + s1]); ACTION_RETURN_INT(SeqSize[nStatusSeqOffset + s1]);
} }