2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-05-01 02:00:39 +00:00
|
|
|
|
2022-07-30 13:05:27 +00:00
|
|
|
void SfxSource_InitAll(PlayState* play) {
|
|
|
|
SfxSource* sources = &play->sfxSources[0];
|
2020-05-01 02:00:39 +00:00
|
|
|
s32 i;
|
|
|
|
|
|
|
|
// clang-format off
|
2022-07-30 13:05:27 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(play->sfxSources); i++) { sources[i].countdown = 0; }
|
2020-05-01 02:00:39 +00:00
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
2022-07-30 13:05:27 +00:00
|
|
|
void SfxSource_UpdateAll(PlayState* play) {
|
|
|
|
SfxSource* source = &play->sfxSources[0];
|
2020-05-01 02:00:39 +00:00
|
|
|
s32 i;
|
|
|
|
|
2022-07-30 13:05:27 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(play->sfxSources); i++) {
|
2020-05-01 02:00:39 +00:00
|
|
|
if (source->countdown != 0) {
|
|
|
|
if (DECR(source->countdown) == 0) {
|
2022-01-11 01:31:53 +00:00
|
|
|
Audio_StopSfxByPos(&source->projectedPos);
|
2020-05-01 02:00:39 +00:00
|
|
|
} else {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkinMatrix_Vec3fMtxFMultXYZ(&play->viewProjectionMtxF, &source->worldPos, &source->projectedPos);
|
2020-05-01 02:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
source++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-30 13:05:27 +00:00
|
|
|
void SfxSource_PlaySfxAtFixedWorldPos(PlayState* play, Vec3f* worldPos, s32 duration, u16 sfxId) {
|
2020-05-01 02:00:39 +00:00
|
|
|
s32 countdown;
|
2022-07-30 13:05:27 +00:00
|
|
|
SfxSource* source;
|
2021-02-14 00:49:40 +00:00
|
|
|
s32 smallestCountdown = 0xFFFF;
|
2022-07-30 13:05:27 +00:00
|
|
|
SfxSource* backupSource;
|
2020-05-01 02:00:39 +00:00
|
|
|
s32 i;
|
|
|
|
|
2022-07-30 13:05:27 +00:00
|
|
|
source = &play->sfxSources[0];
|
|
|
|
for (i = 0; i < ARRAY_COUNT(play->sfxSources); i++) {
|
2020-05-01 02:00:39 +00:00
|
|
|
if (source->countdown == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-07-30 13:05:27 +00:00
|
|
|
// Store the sfx source with the smallest remaining countdown
|
2020-05-01 02:00:39 +00:00
|
|
|
countdown = source->countdown;
|
|
|
|
if (countdown < smallestCountdown) {
|
|
|
|
smallestCountdown = countdown;
|
|
|
|
backupSource = source;
|
|
|
|
}
|
|
|
|
source++;
|
|
|
|
}
|
|
|
|
|
2022-07-30 13:05:27 +00:00
|
|
|
// If no sfx source is available, replace the sfx source with the smallest remaining countdown
|
|
|
|
if (i >= ARRAY_COUNT(play->sfxSources)) {
|
2020-05-01 02:00:39 +00:00
|
|
|
source = backupSource;
|
2022-01-11 01:31:53 +00:00
|
|
|
Audio_StopSfxByPos(&source->projectedPos);
|
2020-05-01 02:00:39 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 01:31:53 +00:00
|
|
|
source->worldPos = *worldPos;
|
2020-05-01 02:00:39 +00:00
|
|
|
source->countdown = duration;
|
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
SkinMatrix_Vec3fMtxFMultXYZ(&play->viewProjectionMtxF, &source->worldPos, &source->projectedPos);
|
2022-07-30 13:05:27 +00:00
|
|
|
Audio_PlaySfxGeneral(sfxId, &source->projectedPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale,
|
|
|
|
&gSfxDefaultReverb);
|
2020-05-01 02:00:39 +00:00
|
|
|
}
|