diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index c4b1aa91..447d49e5 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -2720,11 +2720,30 @@ d/snd/d_snd_mgr_unk_9.cpp: .ctors start:0x804DB92C end:0x804DB930 d/snd/d_snd_mgr_unk_10.cpp: - .text start:0x80390A20 end:0x80393DF4 align:16 + .text start:0x80390A20 end:0x80392E38 align:16 + +d/snd/d_snd_source_tg_sound.cpp: + .text start:0x80392E40 end:0x80393008 align:16 + .data start:0x8054D1C0 end:0x8054D3B0 + .sdata start:0x80574810 end:0x80574818 + +d/snd/d_snd_mgr_unk_16.cpp: + .text start:0x80393010 end:0x803934A8 align:16 + +d/snd/d_snd_distant_sound_actor_pool.cpp: + .text start:0x803934B0 end:0x80393DF4 align:16 .ctors start:0x804DB930 end:0x804DB934 + .data start:0x8054D400 end:0x8054D410 + .sbss start:0x80575DD0 end:0x80575DD8 + .sdata2 start:0x8057E398 end:0x8057E3B8 + .bss start:0x805D1018 end:0x805D1030 + +d/snd/d_snd_distant_sound_actor.cpp: + .text start:0x80393E00 end:0x80394208 align:16 + .data start:0x8054D410 end:0x8054D470 d/snd/d_snd_mgr_unk_11.cpp: - .text start:0x80393E00 end:0x8039A848 align:16 + .text start:0x80394210 end:0x8039A848 align:16 .ctors start:0x804DB934 end:0x804DB938 d/snd/d_snd_calc_pitch.cpp: diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 075c8759..cdf2babd 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -19839,9 +19839,9 @@ __dt__Q34nw4r3snd11SoundHandleFv = .text:0x8035A5A0; // type:function size:0x54 __cl__22SoundPropertiesCheckerFRQ34nw4r3snd11SoundHandle = .text:0x8035A600; // type:function size:0x240 scope:weak __dt__11dSndActor_cFv = .text:0x8035A840; // type:function size:0x58 scope:weak __ct__13dSnd3DActor_cFP15dSndSourceParamUc = .text:0x8035A8A0; // type:function size:0xE8 -d_vt_0x34__13dSnd3DActor_cFRCQ34nw4r4math4VEC3 = .text:0x8035A990; // type:function size:0x40 +setPosition__13dSnd3DActor_cFRCQ34nw4r4math4VEC3 = .text:0x8035A990; // type:function size:0x40 resetCachedRelativePositions__13dSnd3DActor_cFv = .text:0x8035A9D0; // type:function size:0x2C -fn_8035AA00 = .text:0x8035AA00; // type:function size:0x30 +setSourceParam__13dSnd3DActor_cFPC15dSndSourceParam = .text:0x8035AA00; // type:function size:0x30 updatePositionRelativeToListener__13dSnd3DActor_cFv = .text:0x8035AA30; // type:function size:0x44 calculatePositionRelativeToListener__13dSnd3DActor_cFv = .text:0x8035AA80; // type:function size:0x28 updateDistanceToListener__13dSnd3DActor_cFv = .text:0x8035AAB0; // type:function size:0x50 @@ -21103,7 +21103,7 @@ fn_80386410 = .text:0x80386410; // type:function size:0x8 fn_80386420 = .text:0x80386420; // type:function size:0x8 fn_80386430 = .text:0x80386430; // type:function size:0x8 fn_80386440 = .text:0x80386440; // type:function size:0x8 -@4@d_vt_0x38__14dSoundSource_cFbi = .text:0x80386450; // type:function size:0x8 +@4@setPause__14dSoundSource_cFbi = .text:0x80386450; // type:function size:0x8 fn_80386460 = .text:0x80386460; // type:function size:0x8 fn_80386470 = .text:0x80386470; // type:function size:0x8 @4@SetupSound__14dSoundSource_cFPQ34nw4r3snd11SoundHandleUlPCQ44nw4r3snd14SoundStartable9StartInfoPv = .text:0x80386480; // type:function size:0x8 @@ -21149,7 +21149,7 @@ vt_0x5C__14dSoundSource_cFv = .text:0x803890C0; // type:function size:0x18 vt_0x58__14dSoundSource_cFv = .text:0x803890E0; // type:function size:0x1C fn_80389100 = .text:0x80389100; // type:function size:0x60 d_s_vt_0x190__14dSoundSource_cFv = .text:0x80389160; // type:function size:0x40 -d_vt_0x38__14dSoundSource_cFbi = .text:0x803891A0; // type:function size:0xB0 +setPause__14dSoundSource_cFbi = .text:0x803891A0; // type:function size:0xB0 vt_0x60__14dSoundSource_cFv = .text:0x80389250; // type:function size:0x30 vt_0x70__14dSoundSource_cFv = .text:0x80389280; // type:function size:0x48 vt_0x64__14dSoundSource_cFv = .text:0x803892D0; // type:function size:0x64 @@ -21201,10 +21201,10 @@ d_s_vt_0x194__14dSoundSource_cFv = .text:0x8038B380; // type:function size:0x8 d_vt_0x58__14dSoundSource_cFv = .text:0x8038B390; // type:function size:0x4 d_s_vt_0x1A0__14dSoundSource_cFv = .text:0x8038B3A0; // type:function size:0x8 d_vt_0x5C__14dSoundSource_cFv = .text:0x8038B3B0; // type:function size:0x4 -d_s_vt_0x1B4__14dSoundSource_cFv = .text:0x8038B3C0; // type:function size:0x54 -d_s_vt_0x1B8__14dSoundSource_cFv = .text:0x8038B420; // type:function size:0x60 -d_s_vt_0x1BC__14dSoundSource_cFv = .text:0x8038B480; // type:function size:0x74 -d_s_vt_0x1C4__14dSoundSource_cFv = .text:0x8038B500; // type:function size:0x84 +attachDistantSound__14dSoundSource_cFP18dSndDistantSound_c = .text:0x8038B3C0; // type:function size:0x54 +detachDistantSound__14dSoundSource_cFP18dSndDistantSound_c = .text:0x8038B420; // type:function size:0x60 +detachAllDistantSounds__14dSoundSource_cFv = .text:0x8038B480; // type:function size:0x74 +pauseAllDistantSounds__14dSoundSource_cFbi = .text:0x8038B500; // type:function size:0x84 fn_8038B590 = .text:0x8038B590; // type:function size:0x24 fn_8038B5C0 = .text:0x8038B5C0; // type:function size:0x24 fn_8038B5F0 = .text:0x8038B5F0; // type:function size:0x60 @@ -21442,11 +21442,11 @@ fn_803932D0 = .text:0x803932D0; // type:function size:0x64 fn_80393340 = .text:0x80393340; // type:function size:0xC8 fn_80393410 = .text:0x80393410; // type:function size:0x64 fn_80393480 = .text:0x80393480; // type:function size:0x28 -fn_803934B0 = .text:0x803934B0; // type:function size:0x78 -fn_80393530 = .text:0x80393530; // type:function size:0x48 -fn_80393580 = .text:0x80393580; // type:function size:0x10 -fn_80393590 = .text:0x80393590; // type:function size:0xA0 -fn_80393630 = .text:0x80393630; // type:function size:0x70 +__dt__45SndMgrDisposer<27dSndDistantSoundActorPool_c>Fv = .text:0x803934B0; // type:function size:0x78 +create__45SndMgrDisposer<27dSndDistantSoundActorPool_c>Fv = .text:0x80393530; // type:function size:0x48 +remove__45SndMgrDisposer<27dSndDistantSoundActorPool_c>Fv = .text:0x80393580; // type:function size:0x10 +__ct__27dSndDistantSoundActorPool_cFv = .text:0x80393590; // type:function size:0xA0 +__dt__23dSndDistantSoundActor_cFv = .text:0x80393630; // type:function size:0x70 fn_803936A0 = .text:0x803936A0; // type:function size:0x7C fn_80393720 = .text:0x80393720; // type:function size:0xBC fn_803937E0 = .text:0x803937E0; // type:function size:0x158 @@ -21459,22 +21459,22 @@ fn_80393B90 = .text:0x80393B90; // type:function size:0x90 fn_80393C20 = .text:0x80393C20; // type:function size:0x98 fn_80393CC0 = .text:0x80393CC0; // type:function size:0x98 fn_80393D60 = .text:0x80393D60; // type:function size:0x60 -fn_80393DC0 = .text:0x80393DC0; // type:function size:0x34 -fn_80393E00 = .text:0x80393E00; // type:function size:0x74 -fn_80393E80 = .text:0x80393E80; // type:function size:0xC -fn_80393E90 = .text:0x80393E90; // type:function size:0x54 -fn_80393EF0 = .text:0x80393EF0; // type:function size:0x18 -fn_80393F10 = .text:0x80393F10; // type:function size:0x28 +__sinit_\d_snd_distant_sound_actor_pool_cpp = .text:0x80393DC0; // type:function size:0x34 scope:local +__ct__23dSndDistantSoundActor_cFv = .text:0x80393E00; // type:function size:0x74 +getSourceParam__27dSndDistantSoundActorPool_cFv = .text:0x80393E80; // type:function size:0xC +initSource__23dSndDistantSoundActor_cFP14dSoundSource_c = .text:0x80393E90; // type:function size:0x54 +setSourceDirectly__23dSndDistantSoundActor_cFP14dSoundSource_c = .text:0x80393EF0; // type:function size:0x18 +updatePosition__23dSndDistantSoundActor_cFv = .text:0x80393F10; // type:function size:0x28 fn_80393F40 = .text:0x80393F40; // type:function size:0x20 fn_80393F60 = .text:0x80393F60; // type:function size:0x20 -fn_80393F80 = .text:0x80393F80; // type:function size:0x98 -fn_80394020 = .text:0x80394020; // type:function size:0x90 -fn_803940B0 = .text:0x803940B0; // type:function size:0x38 -fn_803940F0 = .text:0x803940F0; // type:function size:0x58 -fn_80394150 = .text:0x80394150; // type:function size:0x6C +startSound__23dSndDistantSoundActor_cFUlRCQ34nw4r4math4VEC3PQ34nw4r3snd11SoundHandle = .text:0x80393F80; // type:function size:0x98 +holdSound__23dSndDistantSoundActor_cFUlRCQ34nw4r4math4VEC3PQ34nw4r3snd11SoundHandle = .text:0x80394020; // type:function size:0x90 +loadDefaultParam__23dSndDistantSoundActor_cFv = .text:0x803940B0; // type:function size:0x38 +detachFromSource__23dSndDistantSoundActor_cFv = .text:0x803940F0; // type:function size:0x58 +setPause__23dSndDistantSoundActor_cFbi = .text:0x80394150; // type:function size:0x6C fn_803941C0 = .text:0x803941C0; // type:function size:0x10 fn_803941D0 = .text:0x803941D0; // type:function size:0x24 -fn_80394200 = .text:0x80394200; // type:function size:0x8 +@84@__dt__23dSndDistantSoundActor_cFv = .text:0x80394200; // type:function size:0x8 fn_80394210 = .text:0x80394210; // type:function size:0xA8 fn_803942C0 = .text:0x803942C0; // type:function size:0x14 fn_803942E0 = .text:0x803942E0; // type:function size:0x40 @@ -38092,8 +38092,8 @@ lbl_8054CFC4 = .data:0x8054CFC4; // type:object size:0x1FC lbl_8054D1C0 = .data:0x8054D1C0; // type:object size:0x1F0 lbl_8054D3B0 = .data:0x8054D3B0; // type:object size:0xC lbl_8054D3BC = .data:0x8054D3BC; // type:object size:0x44 -lbl_8054D400 = .data:0x8054D400; // type:object size:0x10 -lbl_8054D410 = .data:0x8054D410; // type:object size:0x60 +__vt__45SndMgrDisposer<27dSndDistantSoundActorPool_c> = .data:0x8054D400; // type:object size:0x10 +__vt__23dSndDistantSoundActor_c = .data:0x8054D410; // type:object size:0x60 lbl_8054D470 = .data:0x8054D470; // type:object size:0x18 lbl_8054D488 = .data:0x8054D488; // type:object size:0x18 lbl_8054D4A0 = .data:0x8054D4A0; // type:object size:0x18 @@ -42296,8 +42296,8 @@ lbl_80575DB8 = .sbss:0x80575DB8; // type:object size:0x8 data:byte lbl_80575DC0 = .sbss:0x80575DC0; // type:object size:0x8 data:4byte lbl_80575DC8 = .sbss:0x80575DC8; // type:object size:0x4 data:4byte lbl_80575DCC = .sbss:0x80575DCC; // type:object size:0x4 data:4byte -lbl_80575DD0 = .sbss:0x80575DD0; // type:object size:0x4 data:4byte -lbl_80575DD4 = .sbss:0x80575DD4; // type:object size:0x4 data:4byte +sInstance__27dSndDistantSoundActorPool_c = .sbss:0x80575DD0; // type:object size:0x4 data:4byte +sDisposer__27dSndDistantSoundActorPool_c = .sbss:0x80575DD4; // type:object size:0x4 data:4byte lbl_80575DD8 = .sbss:0x80575DD8; // type:object size:0x4 data:4byte lbl_80575DDC = .sbss:0x80575DDC; // type:object size:0x4 data:4byte lbl_80575DE0 = .sbss:0x80575DE0; // type:object size:0x4 data:4byte @@ -52194,7 +52194,7 @@ lbl_805D0FB8 = .bss:0x805D0FB8; // type:object size:0x30 align:4 data:float lbl_805D0FE8 = .bss:0x805D0FE8; // type:object size:0x10 lbl_805D0FF8 = .bss:0x805D0FF8; // type:object size:0x10 align:4 data:float lbl_805D1008 = .bss:0x805D1008; // type:object size:0x10 align:4 data:float -lbl_805D1018 = .bss:0x805D1018; // type:object size:0x18 align:4 data:float +sParam__27dSndDistantSoundActorPool_c = .bss:0x805D1018; // type:object size:0x18 align:4 data:float lbl_805D1030 = .bss:0x805D1030; // type:object size:0xC data:4byte lbl_805D103C = .bss:0x805D103C; // type:object size:0x14 data:4byte lbl_805D1050 = .bss:0x805D1050; // type:object size:0x80 data:4byte diff --git a/configure.py b/configure.py index 997ca80a..5fa0e082 100644 --- a/configure.py +++ b/configure.py @@ -761,10 +761,16 @@ config.libs = [ Object(NonMatching, "d/snd/d_snd_source_mgr.cpp"), Object(NonMatching, "d/snd/d_snd_source_group.cpp"), Object(NonMatching, "d/snd/d_snd_source.cpp"), + # sound source subclasses start Object(NonMatching, "d/snd/d_snd_mgr_unk_7.cpp"), Object(NonMatching, "d/snd/d_snd_mgr_unk_8.cpp"), Object(NonMatching, "d/snd/d_snd_mgr_unk_9.cpp"), Object(NonMatching, "d/snd/d_snd_mgr_unk_10.cpp"), + # sound source subclasses end + Object(NonMatching, "d/snd/d_snd_source_tg_sound.cpp"), + Object(NonMatching, "d/snd/d_snd_mgr_unk_16.cpp"), + Object(NonMatching, "d/snd/d_snd_distant_sound_actor_pool.cpp"), + Object(NonMatching, "d/snd/d_snd_distant_sound_actor.cpp"), Object(NonMatching, "d/snd/d_snd_mgr_unk_11.cpp"), Object(NonMatching, "d/snd/d_snd_calc_pitch.cpp"), ], diff --git a/include/d/snd/d_snd_3d_actor.h b/include/d/snd/d_snd_3d_actor.h index 6f3ad6d4..8f00235d 100644 --- a/include/d/snd/d_snd_3d_actor.h +++ b/include/d/snd/d_snd_3d_actor.h @@ -16,9 +16,9 @@ public: return true; } - virtual void d_vt_0x34(const nw4r::math::VEC3 &); + virtual void setPosition(const nw4r::math::VEC3 &); - virtual void d_vt_0x38(bool flag, int fadeFrames) = 0; + virtual void setPause(bool flag, int fadeFrames) = 0; virtual UNKWORD d_vt_0x3C() { return 0; @@ -63,6 +63,11 @@ public: return mDistanceToListener; } + const dSndSourceParam *getSourceParam() const { + return mpSourceParam; + } + void setSourceParam(const dSndSourceParam *param); + bool hasPlayingSounds() const; bool isPlayingSound(u32 id); @@ -74,7 +79,7 @@ protected: /* 0x7D */ u8 a_field_0x7D; /* 0x7E */ u8 a_field_0x7E; /* 0x7F */ u8 a_field_0x7F; - /* 0x80 */ u8 a_field_0x80; + /* 0x80 */ u8 mIsPaused; /* 0x84 */ f32 a_field_0x84; /* 0x88 */ f32 a_field_0x88; /* 0x8C */ f32 a_field_0x8C; diff --git a/include/d/snd/d_snd_distant_sound_actor.h b/include/d/snd/d_snd_distant_sound_actor.h new file mode 100644 index 00000000..ee805f7f --- /dev/null +++ b/include/d/snd/d_snd_distant_sound_actor.h @@ -0,0 +1,53 @@ +#ifndef D_SND_DISTANT_SOUND_ACTOR_H +#define D_SND_DISTANT_SOUND_ACTOR_H + +#include "common.h" +#include "d/snd/d_snd_3d_actor.h" +#include "m/m_vec.h" +#include "nw4r/math/math_types.h" +#include "nw4r/snd/snd_SoundHandle.h" +#include "nw4r/ut/ut_list.h" + +class dSoundSource_c; + +/** + * A sound actor to be borrowed by sound sources when they want to play + * sounds at a specific position. + * + * Sound sources correspond to actors, but e.g. projectile hit effects, grass + * cutting sounds, sword hit effects, ... have to be played where the hit occurred. + * This pool allows sound sources to borrow sound actors for these purposes. + */ +class dSndDistantSoundActor_c : public dSnd3DActor_c { +public: + dSndDistantSoundActor_c(); + virtual void setPause(bool flag, int fadeFrames) override; + virtual void d_vt_0x58() override; + virtual void d_vt_0x5C() override; + + void initSource(dSoundSource_c *pSource); + void setSourceDirectly(dSoundSource_c *pSource); + void loadDefaultParam(); + void detachFromSource(); + + void updatePosition(); + + bool startSound(u32 soundId, const nw4r::math::VEC3 &position, nw4r::snd::SoundHandle *pHandle); + bool holdSound(u32 soundId, const nw4r::math::VEC3 &position, nw4r::snd::SoundHandle *pHandle); + + bool isAttachedSource(dSoundSource_c *source) const { + return mpSoundSource == source; + } + +private: + /* 0x0E4 */ nw4r::ut::Node mDistantLink; + /* 0x0EC */ u8 _0x0EC[0x0F4 - 0x0EC]; + /* 0x0F4 */ UNKWORD field_0x0F4; + /* 0x0F8 */ dSoundSource_c *mpSoundSource; + /* 0x0FC */ nw4r::snd::SoundHandle mSoundHandle; + /* 0x100 */ nw4r::snd::SoundHandle *mpSoundHandle; + /* 0x104 */ u8 field_0x104; + /* 0x105 */ bool mUseSourcePosition; +}; + +#endif diff --git a/include/d/snd/d_snd_distant_sound_actor_pool.h b/include/d/snd/d_snd_distant_sound_actor_pool.h new file mode 100644 index 00000000..303740b4 --- /dev/null +++ b/include/d/snd/d_snd_distant_sound_actor_pool.h @@ -0,0 +1,35 @@ +#ifndef D_SND_DISTANT_SOUND_ACTOR_POOL_H +#define D_SND_DISTANT_SOUND_ACTOR_POOL_H + +#include "common.h" +#include "d/snd/d_snd_misc.h" +#include "d/snd/d_snd_util.h" +#include "d/snd/d_snd_distant_sound_actor.h" +#include "nw4r/ut/ut_list.h" + +SND_DISPOSER_FORWARD_DECL(dSndDistantSoundActorPool_c); + +/** + * A pool for distant sounds actors. Sound sources will borrow + * actors from this pool when they want to play a sound + * at a specific position. + */ +class dSndDistantSoundActorPool_c { + SND_DISPOSER_MEMBERS(dSndDistantSoundActorPool_c); + +public: + dSndDistantSoundActorPool_c(); + + static dSndSourceParam& getSourceParam() { + return sParam; + } + +private: + /* 0x0010 */ dSndDistantSoundActor_c mSounds[64]; + /* 0x4210 */ UNKWORD field_0x4210; + /* 0x4214 */ nw4r::ut::List mList; + + static dSndSourceParam sParam; +}; + +#endif diff --git a/include/d/snd/d_snd_misc.h b/include/d/snd/d_snd_misc.h index f5bfaa7f..3df7709a 100644 --- a/include/d/snd/d_snd_misc.h +++ b/include/d/snd/d_snd_misc.h @@ -11,12 +11,12 @@ struct dSndSourceParam { reset(); } - void reset() { + void reset(f32 value_0x10 = 5000.0f) { field_0x00 = 300.0; field_0x04 = 1000.0f; field_0x08 = 100.0f; field_0x0C = 400.0f; - field_0x10 = 5000.0f; + field_0x10 = value_0x10; } /* 0x00 */ f32 field_0x00; diff --git a/include/d/snd/d_snd_source.h b/include/d/snd/d_snd_source.h index d2db73d0..25d9f5a1 100644 --- a/include/d/snd/d_snd_source.h +++ b/include/d/snd/d_snd_source.h @@ -9,6 +9,7 @@ #include class dSndSourceGroup_c; +class dSndDistantSoundActor_c; /** Manages sound relating to a particular actor. */ /** Size: probably 0x15C */ @@ -46,15 +47,17 @@ public: virtual void d_s_vt_0x1AC(); virtual void d_s_vt_0x1B0(); - virtual void d_s_vt_0x1B4(); - virtual void d_s_vt_0x1B8(); - virtual void d_s_vt_0x1BC(); - virtual void d_s_vt_0x1C0(); - virtual void d_s_vt_0x1C4(bool flag, int fadeFrames); + virtual void attachDistantSound(dSndDistantSoundActor_c *); + virtual void detachDistantSound(dSndDistantSoundActor_c *); + virtual void detachAllDistantSounds(); + virtual bool hasDistantSounds() const { + return nw4r::ut::List_GetFirstConst(&mDistantSoundList) != nullptr; + } + virtual void pauseAllDistantSounds(bool flag, int fadeFrames); virtual void d_s_vt_0x1C8(); virtual void d_s_vt_0x1CC(); - virtual void d_vt_0x38(bool flag, int fadeFrames) override; + virtual void setPause(bool flag, int fadeFrames) override; virtual void d_s_vt_0x1D4(); virtual void d_s_vt_0x1D8(); @@ -101,7 +104,7 @@ private: /* 0x104 */ UNKWORD field_0x104; /* 0x108 */ UNKWORD field_0x108; /* 0x10C */ UNKWORD field_0x10C; - /* 0x110 */ nw4r::ut::List field_0x110; // node offset 0xEC + /* 0x110 */ nw4r::ut::List mDistantSoundList; // node offset 0xEC -> dSndDistantSoundActor_c /* 0x11C */ UNKWORD field_0x11C; /* 0x120 */ nw4r::ut::List field_0x120; // node offset 0x4 /* 0x12C */ nw4r::ut::List field_0x12C; // node offset 0x4 diff --git a/include/d/snd/d_snd_source_enums.h b/include/d/snd/d_snd_source_enums.h index 8ce423dc..d1f29cc8 100644 --- a/include/d/snd/d_snd_source_enums.h +++ b/include/d/snd/d_snd_source_enums.h @@ -58,6 +58,9 @@ enum SoundSourceType_e { // 59: ? (9) SND_SOURCE_59 = 59, + + // dSndDistantSoundActor_c, not a real sound source type + SND_SOURCE_DISTANT = 61, }; enum SoundSourceCategory_e { diff --git a/include/d/snd/d_snd_state_mgr.h b/include/d/snd/d_snd_state_mgr.h index d2c54446..7a5356a4 100644 --- a/include/d/snd/d_snd_state_mgr.h +++ b/include/d/snd/d_snd_state_mgr.h @@ -40,6 +40,10 @@ public: return field_0x11C; } + f32 getField_0x49C() const { + return field_0x49C; + } + void resetStageName() { field_0x098 = "EVENT_NONE"; } 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 @@ -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 + + +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(nw4r::ut::List_GetFirst(&mDistantSoundList)); + while (it != nullptr) { + it->setSourceDirectly(nullptr); + nw4r::ut::List_Remove(&mDistantSoundList, it); + it = static_cast(nw4r::ut::List_GetFirst(&mDistantSoundList)); + } +} + +void dSoundSource_c::pauseAllDistantSounds(bool flag, int fadeFrames) { + for (dSndDistantSoundActor_c *it = static_cast(nw4r::ut::List_GetFirst(&mDistantSoundList)); + it != nullptr; it = static_cast(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;