d_snd_small_effect_mgr OK

This commit is contained in:
robojumper
2025-07-20 22:10:38 +02:00
parent ac846aea3e
commit 1be399e999
7 changed files with 169 additions and 57 deletions
+99 -9
View File
@@ -1,6 +1,7 @@
#include "d/snd/d_snd_small_effect_mgr.h"
#include "common.h"
#include "d/snd/d_snd_area_sound_effect_mgr.h"
#include "d/snd/d_snd_bgm_harp_data.h"
#include "d/snd/d_snd_bgm_mgr.h"
#include "d/snd/d_snd_bgm_sound.h"
@@ -109,13 +110,64 @@ void dSndSmallEffectMgr_c::stopAllSoundExceptEffectOrLink(s32 fadeFrames) {
}
bool dSndSmallEffectMgr_c::playSoundInternalChecked(u32 soundId, nw4r::snd::SoundHandle *pHandle) {
// TODO
return false;
if (dSndStateMgr_c::GetInstance()->getField_0x064()) {
return false;
}
if (field_0x10 > 0) {
return false;
}
if (dSndStateMgr_c::GetInstance()->checkFlag0x10(dSndStateMgr_c::FLAG0x10_0x08)) {
return false;
}
return playSoundInternal(soundId, pHandle);
}
bool dSndSmallEffectMgr_c::playSoundInternal(u32 soundId, nw4r::snd::SoundHandle *pHandle) {
// TODO
return false;
u32 userParam = dSndPlayerMgr_c::GetInstance()->getSomeUserParam(soundId);
if (userParam & 2) {
for (u32 i = dSndPlayerMgr_c::PLAYER_SMALL_IMPORTANT; i <= dSndPlayerMgr_c::PLAYER_EVENT; i++) {
if (isPlayingSound(i, soundId)) {
return false;
}
}
} else if (userParam & 1) {
stopSounds(soundId, 2);
}
if (userParam & 0x80000000) {
return false;
}
nw4r::snd::SoundHandle tmpHandle;
if (pHandle == nullptr) {
pHandle = &tmpHandle;
}
nw4r::snd::SoundStartable::StartResult res = dSndPlayerMgr_c::GetInstance()->startSound(pHandle, soundId, nullptr);
if (res == nw4r::snd::SoundStartable::START_SUCCESS) {
if (userParam & 8) {
if (EGG::AudioRmtSpeakerMgr::getWpadVolume() != 0) {
pHandle->SetOutputLineFlag(nw4r::snd::OUTPUT_LINE_REMOTE_1);
}
} else if (userParam & 4) {
pHandle->SetOutputLineFlag(nw4r::snd::OUTPUT_LINE_MAIN | nw4r::snd::OUTPUT_LINE_REMOTE_1);
}
if (userParam & 0x10 && EGG::AudioRmtSpeakerMgr::getWpadVolume() != 0) {
u32 rcVariant = dSndPlayerMgr_c::GetInstance()->getRemoConSoundVariant(soundId);
if (rcVariant != -1) {
nw4r::snd::SoundHandle rcHandle;
dSndMgr_c::GetInstance()->getPlayer().StartSound(&rcHandle, rcVariant);
if (EGG::AudioRmtSpeakerMgr::getWpadVolume() != 0) {
rcHandle.SetOutputLineFlag(nw4r::snd::OUTPUT_LINE_REMOTE_1);
}
}
}
}
return res == nw4r::snd::SoundStartable::START_SUCCESS;
}
bool dSndSmallEffectMgr_c::playSound(u32 soundId) {
@@ -228,8 +280,41 @@ bool dSndSmallEffectMgr_c::playSoundWithPan(u32 soundId, f32 pan) {
return ok;
}
bool dSndSmallEffectMgr_c::doSideEffects(u32 soundId) {
if (soundId == SE_S_FS2_SELECT_START || soundId == SE_S_NE_SELECT_OK) {
dSndBgmMgr_c::GetInstance()->stopAllBgm(15);
dSndAreaSoundEffectMgr_c::GetInstance()->stopSounds(15);
}
u32 userParam = dSndPlayerMgr_c::GetInstance()->getSomeUserParam(soundId);
if ((userParam & 0x80) && dSndStateMgr_c::GetInstance()->isInEvent()) {
return false;
}
if (userParam & 2) {
for (u32 i = dSndPlayerMgr_c::PLAYER_SMALL_IMPORTANT; i <= dSndPlayerMgr_c::PLAYER_SMALL_NORMAL; i++) {
if (isPlayingSound(i, soundId)) {
return false;
}
}
} else if (userParam & 1) {
stopSounds(soundId, 2);
}
return true;
}
bool dSndSmallEffectMgr_c::playSoundInternal(u32 soundId) {
// TODO
u32 userParam = dSndPlayerMgr_c::GetInstance()->getSomeUserParam(soundId);
// Why is this flag weird
if ((userParam >> 31) != 0) {
return false;
}
// Bunch of code duplication between doSideEffects and playSoundInternal
if (doSideEffects(soundId)) {
return playSoundInternal(soundId, &mNormalSound);
}
return false;
}
@@ -491,6 +576,14 @@ bool dSndSmallEffectMgr_c::playSkbSound(u32 soundId) {
return playSound(soundId);
}
bool dSndSmallEffectMgr_c::playDemoSound(u32 soundId, nw4r::snd::SoundHandle *pHandle) {
nw4r::snd::SoundHandle tmpHandle;
return dSndPlayerMgr_c::GetInstance()->startDemoSound(
pHandle == nullptr ? &tmpHandle : pHandle, soundId, nullptr
) == nw4r::snd::SoundStartable::START_SUCCESS;
}
void dSndSmallEffectMgr_c::stopSounds(u32 playerIdx, u32 soundId, s32 fadeFrames) {
SoundStopper stopper(soundId, fadeFrames);
dSndControlPlayerMgr_c::GetInstance()->getPlayer1(playerIdx)->ForEachSound(stopper, false);
@@ -661,7 +754,6 @@ bool dSndSmallEffectMgr_c::playBattleHitSound(BattleHitSound_e type, dSoundSourc
// One bit set, get the value (using a slightly convoluted method
// due to inline complexity) without rejecting it when it equals
// the previously picked value
// TODO - unnecessary reload of count here.
varIdx = set->getRandomIdxWithBitSet();
field_0x40 = set->getVal(varIdx);
} else {
@@ -733,9 +825,7 @@ bool dSndSmallEffectMgr_c::playBattleHitSound(BattleHitSound_e type, dSoundSourc
return ok;
}
void dSndSmallEffectMgr_c::setBitsIfAdjacent(
dSndBgmDataHarpVarSetBase_c *set, s32 count, s32 target, u32 *pMask
) {
void dSndSmallEffectMgr_c::setBitsIfAdjacent(dSndBgmDataHarpVarSetBase_c *set, s32 count, s32 target, u32 *pMask) {
for (int i = 0; i < count; i++) {
s32 val = set->getVal(i);
if (val == target + 1 || val == target - 1) {
+16 -16
View File
@@ -42,7 +42,7 @@ dSndStateMgr_c::dSndStateMgr_c()
mLayer(0),
mRoomId(-1),
field_0x060(0),
field_0x064(0),
field_0x064(false),
field_0x065(false),
mHasChangedTgSndAreaFlags(false),
mHasChangedTgSndAreaMgFlags(false),
@@ -110,8 +110,8 @@ void dSndStateMgr_c::onStageOrLayerUpdate() {
bool unk_0x065 = field_0x065;
onFlag0x10(0x2);
field_0x064 = 0;
onFlag0x10(FLAG0x10_0x02);
field_0x064 = false;
if (!streq(mStageName, dScGame_c::currentSpawnInfo.getStageName())) {
mNeedsGroupsReload = true;
@@ -248,7 +248,7 @@ void dSndStateMgr_c::onRestartScene(s32 fadeFrames) {
dSndAreaSoundEffectMgr_c::GetInstance()->stopSounds(fadeFrames);
} else {
onGotoStage(fadeFrames);
onFlag0x10(0x01);
onFlag0x10(FLAG0x10_0x01);
return;
}
}
@@ -256,10 +256,10 @@ void dSndStateMgr_c::onRestartScene(s32 fadeFrames) {
dSndSmallEffectMgr_c::GetInstance()->stopAllSoundExceptEvent(fadeFrames);
dSndBgmMgr_c::GetInstance()->prepareBgm();
dSndHarpSongMgr_c::GetInstance()->deactivate();
onFlag0x10(0x01);
onFlag0x10(FLAG0x10_0x01);
dSndBgmMgr_c::GetInstance()->setField_0x306(1);
offFlag0x10(0x4);
offFlag0x10(0x10);
offFlag0x10(FLAG0x10_0x04);
offFlag0x10(FLAG0x10_0x10);
}
void dSndStateMgr_c::loadStageSound() {
@@ -488,14 +488,14 @@ void dSndStateMgr_c::setEvent(const char *eventName) {
dSndPlayerMgr_c::GetInstance()->leaveCaution();
}
if (field_0x064 == 0) {
if (!field_0x064) {
if (streq(mEventName, "DefaultSkip")) {
onSkipEvent();
mPrevEventName = mEventName;
return;
}
if (!checkFlag0x18(0x20) || !checkFlag0x10(0x04)) {
if (!checkFlag0x18(0x20) || !checkFlag0x10(FLAG0x10_0x04)) {
SizedString<64> prevEvent = mEventName;
if (isInEvent()) {
field_0x23C = 1;
@@ -523,7 +523,7 @@ void dSndStateMgr_c::setEvent(const char *eventName) {
mpStbEventName = nullptr;
}
if (!checkFlag0x10(0x04)) {
if (!checkFlag0x10(FLAG0x10_0x04)) {
if (mpUnkCallback != nullptr) {
mpUnkCallback();
}
@@ -531,11 +531,11 @@ void dSndStateMgr_c::setEvent(const char *eventName) {
dSndBgmMgr_c::GetInstance()->setField_0x306(1);
dSndBgmMgr_c::GetInstance()->prepareBgm();
onEventFlag(EVENT_0x04);
onFlag0x10(0x04);
onFlag0x10(FLAG0x10_0x04);
dSndControlPlayerMgr_c::GetInstance()->unmuteScenePlayers(30);
}
bool b2 = checkEventFlag(EVENT_0x800) && dSndBgmMgr_c::GetInstance()->isPlayingBgmSound();
if (checkEventFlag(EVENT_0x800) && field_0x064 == 0) {
if (checkEventFlag(EVENT_0x800) && !field_0x064) {
// TODO - constness or direct access
offEventFlag(0x800);
}
@@ -846,8 +846,8 @@ void dSndStateMgr_c::onMsgWaitEnd() {
}
void dSndStateMgr_c::onLinkDie() {
if (!checkFlag0x10(0x8)) {
onFlag0x10(0x8);
if (!checkFlag0x10(FLAG0x10_0x08)) {
onFlag0x10(FLAG0x10_0x08);
dSndBgmMgr_c::GetInstance()->stopAllBgm(15);
dSndSmallEffectMgr_c::GetInstance()->stopAllSoundExceptEffectOrLink(15);
if (field_0x065 == 0) {
@@ -861,7 +861,7 @@ void dSndStateMgr_c::setStbEventName(const char *eventName) {
}
void dSndStateMgr_c::calcRoomId() {
if (checkFlag0x10(4)) {
if (checkFlag0x10(FLAG0x10_0x04)) {
if (field_0x060 > 0) {
field_0x060--;
} else {
@@ -871,7 +871,7 @@ void dSndStateMgr_c::calcRoomId() {
s32 newRoom = dSndSourceMgr_c::GetInstance()->getPlayerSourceRoomId();
if (mRoomId != newRoom) {
setRoomId(newRoom);
} else if (newRoom != -1 && !checkFlag0x10(0x10)) {
} else if (newRoom != -1 && !checkFlag0x10(FLAG0x10_0x10)) {
setRoomId(newRoom);
}
}