2022-03-21 21:51:23 -04:00
|
|
|
#include "global.h"
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
void SoundSource_InitAll(PlayState* play) {
|
|
|
|
SoundSource* sources = &play->soundSources[0];
|
2022-03-21 21:51:23 -04:00
|
|
|
s32 i;
|
|
|
|
|
|
|
|
// clang-format off
|
2022-11-06 03:24:34 -05:00
|
|
|
for (i = 0; i < ARRAY_COUNT(play->soundSources); i++) { sources[i].countdown = 0; }
|
2022-03-21 21:51:23 -04:00
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
void SoundSource_UpdateAll(PlayState* play) {
|
|
|
|
SoundSource* source = &play->soundSources[0];
|
2022-03-21 21:51:23 -04:00
|
|
|
s32 i;
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
for (i = 0; i < ARRAY_COUNT(play->soundSources); i++) {
|
2022-03-21 21:51:23 -04:00
|
|
|
if (source->countdown != 0) {
|
|
|
|
if (DECR(source->countdown) == 0) {
|
|
|
|
Audio_StopSfxByPos(&source->projectedPos);
|
|
|
|
} else {
|
2022-11-06 03:24:34 -05:00
|
|
|
SkinMatrix_Vec3fMtxFMultXYZ(&play->viewProjectionMtxF, &source->worldPos, &source->projectedPos);
|
2022-03-21 21:51:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
source++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
void SoundSource_PlaySfxAtFixedWorldPos(PlayState* play, Vec3f* worldPos, s32 duration, u16 sfxId) {
|
2022-03-21 21:51:23 -04:00
|
|
|
s32 countdown;
|
|
|
|
SoundSource* source;
|
|
|
|
s32 smallestCountdown = 0xFFFF;
|
|
|
|
SoundSource* backupSource;
|
|
|
|
s32 i;
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
source = &play->soundSources[0];
|
|
|
|
for (i = 0; i < ARRAY_COUNT(play->soundSources); i++) {
|
2022-03-21 21:51:23 -04:00
|
|
|
if (source->countdown == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the sound source with the smallest remaining countdown
|
|
|
|
countdown = source->countdown;
|
|
|
|
if (countdown < smallestCountdown) {
|
|
|
|
smallestCountdown = countdown;
|
|
|
|
backupSource = source;
|
|
|
|
}
|
|
|
|
source++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no sound source is available, replace the sound source with the smallest remaining countdown
|
2022-11-06 03:24:34 -05:00
|
|
|
if (i >= ARRAY_COUNT(play->soundSources)) {
|
2022-03-21 21:51:23 -04:00
|
|
|
source = backupSource;
|
|
|
|
Audio_StopSfxByPos(&source->projectedPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
source->worldPos = *worldPos;
|
|
|
|
source->countdown = duration;
|
|
|
|
|
2022-11-06 03:24:34 -05:00
|
|
|
SkinMatrix_Vec3fMtxFMultXYZ(&play->viewProjectionMtxF, &source->worldPos, &source->projectedPos);
|
2022-03-21 21:51:23 -04:00
|
|
|
Audio_PlaySoundGeneral(sfxId, &source->projectedPos, 4, &D_801333E0, &D_801333E0, &D_801333E8);
|
|
|
|
}
|