- deal with QAV::nIndex.

This was totally redundant. Since the player already gets passed as 'Data', we can just make that pointer a PLAYER type and use it instead to retrieve the playing actor for sound purposes.
This commit is contained in:
Christoph Oelckers 2021-09-04 22:48:28 +02:00
parent 70cd4d9466
commit 7204b8e026
6 changed files with 8 additions and 15 deletions

View file

@ -38,7 +38,6 @@ void CChoke::init(int a1, void(*a2)(PLAYER*))
qav = getQAV(a1);
if (!qav)
I_Error("Could not load QAV %d\n", a1);
qav->nSprite = -1;
qav->x = x;
qav->y = y;
duration = qav->duration;

View file

@ -60,7 +60,6 @@ CGameMenuItemQAV::CGameMenuItemQAV(int a3, int a4, const char* name, bool widesc
data = getQAV(fileSystem.GetResourceId(fileSystem.FindFile(name)));
if (data)
{
data->nSprite = -1;
data->x = a3;
data->y = a4;
duration = data->duration;

View file

@ -7364,7 +7364,6 @@ void playerQavScenePlay(PLAYER* pPlayer)
if (pQavScene->qavResrc != NULL)
{
QAV* pQAV = pQavScene->qavResrc;
pQAV->nSprite = pPlayer->pSprite->index;
int nTicks = pQAV->duration - pPlayer->weaponTimer;
pQAV->Play(nTicks - 4, nTicks, pPlayer->qavCallback, pPlayer);
}

View file

@ -203,8 +203,9 @@ void QAV::Draw(double x, double y, int ticks, int stat, int shade, int palnum, b
}
void QAV::Play(int start, int end, int nCallback, void *pData)
void QAV::Play(int start, int end, int nCallback, PLAYER *pData)
{
auto pActor = pData ? pData->actor() : nullptr;
assert(ticksPerFrame > 0);
int frame;
int ticks;
@ -227,10 +228,10 @@ void QAV::Play(int start, int end, int nCallback, void *pData)
SOUNDINFO* pSound2 = &pFrame2->sound;
if (pSound2->sound != 0) {
if (pSound->sndFlags != kFlagSoundKillAll && pSound2->priority != pSound->priority) continue;
else if (nSprite >= 0) {
else if (pActor) {
// We need stop all sounds in a range
for (int a = 0; a <= pSound2->sndRange; a++)
sfxKill3DSound(&sprite[nSprite], -1, pSound2->sound + a);
sfxKill3DSound(pActor, -1, pSound2->sound + a);
} else {
sndKillAllSounds();
}
@ -245,8 +246,8 @@ void QAV::Play(int start, int end, int nCallback, void *pData)
if (pSound->sndRange > 0 && !VanillaMode())
sound += Random((pSound->sndRange == 1) ? 2 : pSound->sndRange);
if (nSprite == -1) sndStartSample(sound, -1, -1, 0);
else sfxPlay3DSound(&sprite[nSprite], sound, 16+pSound->priority, 6);
if (pActor == nullptr) sndStartSample(sound, -1, -1, 0);
else sfxPlay3DSound(pActor, sound, 16+pSound->priority, 6);
}
if (pFrame->nCallbackId > 0 && nCallback != -1) {
@ -345,7 +346,7 @@ QAV* getQAV(int res_id)
qavdata->duration = fr.ReadInt32();
qavdata->x = fr.ReadInt32();
qavdata->y = fr.ReadInt32();
qavdata->nSprite = fr.ReadInt32();
/*qavdata->nSprite =*/ fr.ReadInt32();
for (int i = 0; i < 4; i++) fr.ReadUInt8();
// Read FRAMEINFO data.

View file

@ -227,14 +227,11 @@ struct QAV
int duration; // 10
int x; // 14
int y; // 18
int nSprite; // 1c
//SPRITE *pSprite; // 1c
char pad3[2]; // 20
unsigned short res_id;
FRAMEINFO frames[1]; // 24
void Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool to3dview, double const smoothratio = 65536);
void Draw(int ticks, int stat, int shade, int palnum, bool to3dview, double const smoothratio = 65536) { Draw(x, y, ticks, stat, shade, palnum, to3dview, smoothratio); }
void Play(int, int, int, void *);
void Play(int, int, int, PLAYER *);
void Precache(int palette = 0);
};

View file

@ -235,7 +235,6 @@ void WeaponInit(void)
auto pQAV = getQAV(i);
if (!pQAV)
I_Error("Could not load QAV %d\n", i);
pQAV->nSprite = -1;
}
};
@ -288,7 +287,6 @@ void WeaponPlay(PLAYER *pPlayer)
if (pPlayer->weaponQav == kQAVNone)
return;
auto pQAV = getQAV(pPlayer->weaponQav);
pQAV->nSprite = pPlayer->pSprite->index;
int nTicks = pQAV->duration - pPlayer->weaponTimer;
pQAV->Play(nTicks-4, nTicks, pPlayer->qavCallback, pPlayer);
}