diff options
| author | robojumper <robojumper@gmail.com> | 2025-06-13 16:20:06 +0200 |
|---|---|---|
| committer | robojumper <robojumper@gmail.com> | 2025-09-13 10:49:06 +0200 |
| commit | f56b72a2e0a938f95e2a5c3a14767bdfd0e2d54a (patch) | |
| tree | de4bf641ecaa7cba55d3cbea7f797a6e81c10493 /src | |
| parent | f9e95f9bb03b9474bbee85b03121c9b4e158aea4 (diff) | |
let's go with the distant sound name for now
Diffstat (limited to 'src')
| -rw-r--r-- | src/d/snd/d_snd_3d_actor.cpp | 7 | ||||
| -rw-r--r-- | src/d/snd/d_snd_distant_sound_actor.cpp | 95 | ||||
| -rw-r--r-- | src/d/snd/d_snd_distant_sound_actor_pool.cpp | 17 | ||||
| -rw-r--r-- | src/d/snd/d_snd_mgr.cpp | 14 | ||||
| -rw-r--r-- | src/d/snd/d_snd_source.cpp | 47 |
5 files changed, 162 insertions, 18 deletions
diff --git a/src/d/snd/d_snd_3d_actor.cpp b/src/d/snd/d_snd_3d_actor.cpp index e304d296..51199b48 100644 --- a/src/d/snd/d_snd_3d_actor.cpp +++ b/src/d/snd/d_snd_3d_actor.cpp @@ -5,6 +5,7 @@ #include "d/snd/d_snd_3d_manager.h" #include "d/snd/d_snd_checkers.h" #include "d/snd/d_snd_player_mgr.h" +#include "d/snd/d_snd_state_mgr.h" #include "nw4r/math/math_types.h" #include <cmath> @@ -16,7 +17,7 @@ dSnd3DActor_c::dSnd3DActor_c(dSndSourceParam *pSourceParam, u8 sourceType) a_field_0x7D(0), a_field_0x7E(0), a_field_0x7F(0), - a_field_0x80(0), + mIsPaused(0), a_field_0x84(0.0f), a_field_0x88(0.0f), a_field_0x8C(0.0f), @@ -36,9 +37,9 @@ dSnd3DActor_c::dSnd3DActor_c(dSndSourceParam *pSourceParam, u8 sourceType) } } -void dSnd3DActor_c::d_vt_0x34(const nw4r::math::VEC3 &rPosition) { +void dSnd3DActor_c::setPosition(const nw4r::math::VEC3 &rPosition) { SetPosition(rPosition); - // TODO - 0xE0 + a_field_0xE0 = dSndStateMgr_c::GetInstance()->getField_0x49C(); mFlags = 0; } diff --git a/src/d/snd/d_snd_distant_sound_actor.cpp b/src/d/snd/d_snd_distant_sound_actor.cpp new file mode 100644 index 00000000..c06c96af --- /dev/null +++ b/src/d/snd/d_snd_distant_sound_actor.cpp @@ -0,0 +1,95 @@ + + +#include "d/snd/d_snd_distant_sound_actor.h" + +#include "common.h" +#include "d/snd/d_snd_3d_actor.h" +#include "d/snd/d_snd_distant_sound_actor_pool.h" +#include "d/snd/d_snd_source.h" +#include "d/snd/d_snd_source_enums.h" + +dSndDistantSoundActor_c::dSndDistantSoundActor_c() + : dSnd3DActor_c(&dSndDistantSoundActorPool_c::GetInstance()->getSourceParam(), SND_SOURCE_DISTANT), + field_0x0F4(0), + mpSoundSource(nullptr), + mpSoundHandle(&mSoundHandle), + field_0x104(0), + mUseSourcePosition(false) {} + +void dSndDistantSoundActor_c::initSource(dSoundSource_c *pSource) { + resetCachedRelativePositions(); + loadDefaultParam(); + setSourceDirectly(pSource); + mUseSourcePosition = false; +} + +void dSndDistantSoundActor_c::setSourceDirectly(dSoundSource_c *pSource) { + mpSoundSource = pSource; + if (mpSoundSource != nullptr) { + setSourceParam(pSource->getSourceParam()); + } +} + +void dSndDistantSoundActor_c::updatePosition() { + if (mpSoundSource != nullptr && mUseSourcePosition) { + dSnd3DActor_c::setPosition(mpSoundSource->GetPosition()); + } else { + dSnd3DActor_c::setPosition(GetPosition()); + } +} + +bool dSndDistantSoundActor_c::startSound( + u32 soundId, const nw4r::math::VEC3 &position, nw4r::snd::SoundHandle *pHandle +) { + if (a_field_0x7E) { + return false; + } + + if (pHandle == nullptr) { + pHandle = &mSoundHandle; + } else { + mpSoundHandle = pHandle; + } + + SetPosition(position); + return StartSound(pHandle, soundId); +} + +bool dSndDistantSoundActor_c::holdSound( + u32 soundId, const nw4r::math::VEC3 &position, nw4r::snd::SoundHandle *pHandle +) { + if (a_field_0x7E) { + return false; + } + + if (pHandle == nullptr) { + pHandle = &mSoundHandle; + } else { + mpSoundHandle = pHandle; + } + + SetPosition(position); + return HoldSound(pHandle, soundId); +} + +void dSndDistantSoundActor_c::loadDefaultParam() { + setSourceParam(&dSndDistantSoundActorPool_c::GetInstance()->getSourceParam()); +} + +void dSndDistantSoundActor_c::detachFromSource() { + if (mpSoundSource != nullptr) { + mpSoundSource->detachDistantSound(this); + } + mpSoundSource = nullptr; + field_0x0F4 = 0; +} + +void dSndDistantSoundActor_c::setPause(bool flag, int fadeFrames) { + if (mIsPaused && !flag) { + PauseAllSound(flag, fadeFrames); + mIsPaused = 0; + } else if (!mIsPaused && flag) { + PauseAllSound(flag, fadeFrames); + mIsPaused = 1; + } +} diff --git a/src/d/snd/d_snd_distant_sound_actor_pool.cpp b/src/d/snd/d_snd_distant_sound_actor_pool.cpp new file mode 100644 index 00000000..bc34276a --- /dev/null +++ b/src/d/snd/d_snd_distant_sound_actor_pool.cpp @@ -0,0 +1,17 @@ +#include "d/snd/d_snd_distant_sound_actor_pool.h" + +#include "nw4r/ut/ut_list.h" + +#include <cmath> + + +SND_DISPOSER_DEFINE(dSndDistantSoundActorPool_c); + +dSndSourceParam dSndDistantSoundActorPool_c::sParam; + +dSndDistantSoundActorPool_c::dSndDistantSoundActorPool_c() { + field_0x4210 = 0; + // TODO offsetof + nw4r::ut::List_Init(&mList, 0xE4); + sParam.reset(INFINITY); +} diff --git a/src/d/snd/d_snd_mgr.cpp b/src/d/snd/d_snd_mgr.cpp index b2ee2279..15efb6e5 100644 --- a/src/d/snd/d_snd_mgr.cpp +++ b/src/d/snd/d_snd_mgr.cpp @@ -2,17 +2,17 @@ #include "d/snd/d_snd_3d_manager.h" #include "d/snd/d_snd_area_sound_effect_mgr.h" +#include "d/snd/d_snd_bgm_mgr.h" #include "d/snd/d_snd_control_player_mgr.h" +#include "d/snd/d_snd_distant_sound_actor_pool.h" #include "d/snd/d_snd_player_mgr.h" #include "d/snd/d_snd_small_effect_mgr.h" #include "d/snd/d_snd_source_mgr.h" +#include "d/snd/d_snd_state_mgr.h" #include "egg/audio/eggAudioRmtSpeakerMgr.h" #include "egg/audio/eggAudioUtility.h" -extern "C" void initEnemySoundMgr(); -extern "C" void initFanfareSoundMgr(); extern "C" void initSomeUnusedSoundMgr(); -extern "C" void fn_80393530(); extern "C" void fn_80394830(); extern "C" void fn_8037F940(); extern "C" void fn_80399600(); @@ -20,18 +20,18 @@ extern "C" void fn_80399C20(); dSndMgr_c *dSndMgr_c::sInstance; -dSndMgr_c::dSndMgr_c(): field_0x6CC(0) { +dSndMgr_c::dSndMgr_c() : field_0x6CC(0) { sInstance = this; dSndPlayerMgr_c::create(); dSndControlPlayerMgr_c::create(); - initEnemySoundMgr(); + dSndStateMgr_c::create(); dSnd3DManager_c::create(); - initFanfareSoundMgr(); + dSndBgmMgr_c::create(); initSomeUnusedSoundMgr(); dSndSmallEffectMgr_c::create(); dSndAreaSoundEffectMgr_c::create(); dSndSourceMgr_c::create(); - fn_80393530(); + dSndDistantSoundActorPool_c::create(); fn_80394830(); fn_8037F940(); fn_80399600(); diff --git a/src/d/snd/d_snd_source.cpp b/src/d/snd/d_snd_source.cpp index 76a25b44..7085108e 100644 --- a/src/d/snd/d_snd_source.cpp +++ b/src/d/snd/d_snd_source.cpp @@ -4,6 +4,7 @@ #include "d/a/d_a_base.h" #include "d/snd/d_snd_3d_actor.h" #include "d/snd/d_snd_3d_manager.h" +#include "d/snd/d_snd_distant_sound_actor.h" #include "d/snd/d_snd_mgr.h" #include "d/snd/d_snd_player_mgr.h" #include "d/snd/d_snd_source_group.h" @@ -46,7 +47,7 @@ dSoundSource_c::dSoundSource_c(u8 sourceType, dAcBase_c *actor, const char *name field_0x15A(-1) { mSourceCategory = dSndSourceMgr_c::getSourceCategoryForSourceType(sourceType, name); // TODO: Offsetof - nw4r::ut::List_Init(&field_0x110, 0xEC); + nw4r::ut::List_Init(&mDistantSoundList, 0xEC); nw4r::ut::List_Init(&field_0x120, 0x04); nw4r::ut::List_Init(&field_0x12C, 0x04); pOwnerGroup->registerSource(this); @@ -55,7 +56,7 @@ dSoundSource_c::dSoundSource_c(u8 sourceType, dAcBase_c *actor, const char *name dSoundSource_c::~dSoundSource_c() { SetUserParam(0); vt_0x44(); - d_s_vt_0x1BC(); + detachAllDistantSounds(); dSndSourceMgr_c::GetInstance()->unregisterSource(this); mpOwnerGroup->unregisterSource(this); } @@ -76,15 +77,15 @@ bool dSoundSource_c::isPlayingSound(const char *soundId) { return isPlayingSound(soundLabelToSoundId(soundId)); } -void dSoundSource_c::d_vt_0x38(bool flag, int fadeFrames) { - if (flag == 0) { +void dSoundSource_c::setPause(bool flag, int fadeFrames) { + if (!flag) { PauseAllSound(flag, fadeFrames); - d_s_vt_0x1C4(flag, fadeFrames); - a_field_0x80 = 0; + pauseAllDistantSounds(flag, fadeFrames); + mIsPaused = 0; } else if (a_field_0x7E == 0) { PauseAllSound(flag, fadeFrames); - d_s_vt_0x1C4(flag, fadeFrames); - a_field_0x80 = 1; + pauseAllDistantSounds(flag, fadeFrames); + mIsPaused = 1; } } @@ -106,6 +107,36 @@ void dSoundSource_c::d_vt_0x5C() { // noop } +void dSoundSource_c::attachDistantSound(dSndDistantSoundActor_c *sound) { + if (sound != nullptr) { + sound->setSourceDirectly(this); + nw4r::ut::List_Append(&mDistantSoundList, sound); + } +} + +void dSoundSource_c::detachDistantSound(dSndDistantSoundActor_c *sound) { + if (sound != nullptr && sound->isAttachedSource(this)) { + sound->setSourceDirectly(nullptr); + nw4r::ut::List_Remove(&mDistantSoundList, sound); + } +} + +void dSoundSource_c::detachAllDistantSounds() { + dSndDistantSoundActor_c *it = static_cast<dSndDistantSoundActor_c *>(nw4r::ut::List_GetFirst(&mDistantSoundList)); + while (it != nullptr) { + it->setSourceDirectly(nullptr); + nw4r::ut::List_Remove(&mDistantSoundList, it); + it = static_cast<dSndDistantSoundActor_c *>(nw4r::ut::List_GetFirst(&mDistantSoundList)); + } +} + +void dSoundSource_c::pauseAllDistantSounds(bool flag, int fadeFrames) { + for (dSndDistantSoundActor_c *it = static_cast<dSndDistantSoundActor_c *>(nw4r::ut::List_GetFirst(&mDistantSoundList)); + it != nullptr; it = static_cast<dSndDistantSoundActor_c *>(nw4r::ut::List_GetNext(&mDistantSoundList, it))) { + it->PauseAllSound(flag, fadeFrames); + } +} + u32 dSoundSource_c::getCharacterTalkSoundId(u32 baseSoundId, dSoundSource_c *source) { if (baseSoundId != -1 && source != nullptr) { SizedString<64> label; |
