diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index dee9eb4f..9a03474b 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -21137,27 +21137,27 @@ shutdown__14dSoundSource_cFv = .text:0x80388CD0; // type:function size:0x9C fn_80388D70 = .text:0x80388D70; // type:function size:0x80 getListenerPosition__14dSoundSource_cCFv = .text:0x80388DF0; // type:function size:0xC calc__14dSoundSource_cFRCQ34nw4r4math4VEC3 = .text:0x80388E00; // type:function size:0x88 -d_s_vt_0x184__14dSoundSource_cFv = .text:0x80388E90; // type:function size:0x84 -d_s_vt_0x18C__14dSoundSource_cFv = .text:0x80388F20; // type:function size:0x4 +preCalc__14dSoundSource_cFv = .text:0x80388E90; // type:function size:0x84 +postCalc__14dSoundSource_cFv = .text:0x80388F20; // type:function size:0x4 hasPlayingSounds__14dSoundSource_cCFv = .text:0x80388F30; // type:function size:0x8 isPlayingSound__14dSoundSource_cFUl = .text:0x80388F40; // type:function size:0x8 isPlayingSound__14dSoundSource_cFPCc = .text:0x80388F50; // type:function size:0x48 initVolumeFade__14dSoundSource_cFv = .text:0x80388FA0; // type:function size:0x14 setVolumeFade__14dSoundSource_cFfUl = .text:0x80388FC0; // type:function size:0x84 calcVolumeFade__14dSoundSource_cFv = .text:0x80389050; // type:function size:0x68 -setUnkSeWord__14dSoundSource_cFi = .text:0x803890C0; // type:function size:0x18 -setUnkSeFloat__14dSoundSource_cFf = .text:0x803890E0; // type:function size:0x1C +setCtxInt__14dSoundSource_cFl = .text:0x803890C0; // type:function size:0x18 +setCtxFloat__14dSoundSource_cFf = .text:0x803890E0; // type:function size:0x1C isInaudible__14dSoundSource_cFv = .text:0x80389100; // type:function size:0x60 d_s_vt_0x190__14dSoundSource_cFv = .text:0x80389160; // type:function size:0x40 setPause__14dSoundSource_cFbi = .text:0x803891A0; // type:function size:0xB0 startSound__14dSoundSource_cFUl = .text:0x80389250; // type:function size:0x30 startSound__14dSoundSource_cFPCc = .text:0x80389280; // type:function size:0x48 -startSoundWithUnkSeWord__14dSoundSource_cFUli = .text:0x803892D0; // type:function size:0x64 -startSoundWithUnkSeWord__14dSoundSource_cFPCci = .text:0x80389340; // type:function size:0x58 -startSoundWithUnkSeFloat__14dSoundSource_cFUlf = .text:0x803893A0; // type:function size:0x60 -startSoundWithUnkSeFloat__14dSoundSource_cFPCcf = .text:0x80389400; // type:function size:0x58 -startSoundWithUnkSe__14dSoundSource_cFUlfi = .text:0x80389460; // type:function size:0x88 -startSoundWithUnkSe__14dSoundSource_cFPCcfi = .text:0x803894F0; // type:function size:0x68 +startSoundWithIntParam__14dSoundSource_cFUll = .text:0x803892D0; // type:function size:0x64 +startSoundWithIntParam__14dSoundSource_cFPCcl = .text:0x80389340; // type:function size:0x58 +startSoundWithFloatParam__14dSoundSource_cFUlf = .text:0x803893A0; // type:function size:0x60 +startSoundWithFloatParam__14dSoundSource_cFPCcf = .text:0x80389400; // type:function size:0x58 +startSoundWithParams__14dSoundSource_cFUlfl = .text:0x80389460; // type:function size:0x88 +startSoundWithParams__14dSoundSource_cFPCcfl = .text:0x803894F0; // type:function size:0x68 vt_0xA0__14dSoundSource_cFv = .text:0x80389560; // type:function size:0x94 startRemoConSound__14dSoundSource_cFUl = .text:0x80389600; // type:function size:0x74 startSound__14dSoundSource_cFUlPQ34nw4r3snd11SoundHandle = .text:0x80389680; // type:function size:0x40 @@ -21179,16 +21179,16 @@ stopSounds__14dSoundSource_cFUll = .text:0x8038A310; // type:function size:0xB8 stopSounds__14dSoundSource_cFPCcl = .text:0x8038A3D0; // type:function size:0x58 holdSound__14dSoundSource_cFUl = .text:0x8038A430; // type:function size:0x30 holdSound__14dSoundSource_cFPCc = .text:0x8038A460; // type:function size:0x48 -vt_0xB0__14dSoundSource_cFv = .text:0x8038A4B0; // type:function size:0x64 -vt_0xC0__14dSoundSource_cFv = .text:0x8038A520; // type:function size:0x58 -vt_0xB4__14dSoundSource_cFv = .text:0x8038A580; // type:function size:0x60 -vt_0xC4__14dSoundSource_cFv = .text:0x8038A5E0; // type:function size:0x58 -vt_0xB8__14dSoundSource_cFv = .text:0x8038A640; // type:function size:0x88 -vt_0xC8__14dSoundSource_cFv = .text:0x8038A6D0; // type:function size:0x68 +holdSoundWithIntParam__14dSoundSource_cFUll = .text:0x8038A4B0; // type:function size:0x64 +holdSoundWithIntParam__14dSoundSource_cFPCcl = .text:0x8038A520; // type:function size:0x58 +holdSoundWithFloatParam__14dSoundSource_cFUlf = .text:0x8038A580; // type:function size:0x60 +holdSoundWithFloatParam__14dSoundSource_cFPCcf = .text:0x8038A5E0; // type:function size:0x58 +holdSoundWithParams__14dSoundSource_cFUlfl = .text:0x8038A640; // type:function size:0x88 +holdSoundWithParams__14dSoundSource_cFPCcfl = .text:0x8038A6D0; // type:function size:0x68 holdSound__14dSoundSource_cFUlPQ34nw4r3snd11SoundHandle = .text:0x8038A740; // type:function size:0x1E8 continueHoldingSound__14dSoundSource_cFP14dSndSeSound2_cUlP23dSndDistantSoundActor_cPCQ34nw4r4math4VEC3 = .text:0x8038A930; // type:function size:0x1D0 -vt_0xCC__14dSoundSource_cFv = .text:0x8038AB00; // type:function size:0x258 -vt_0xD0__14dSoundSource_cFv = .text:0x8038AD60; // type:function size:0x58 +holdSoundAtPosition__14dSoundSource_cFUlPCQ34nw4r4math4VEC3 = .text:0x8038AB00; // type:function size:0x258 +holdSoundAtPosition__14dSoundSource_cFPCcPCQ34nw4r4math4VEC3 = .text:0x8038AD60; // type:function size:0x58 SetupSound__14dSoundSource_cFPQ34nw4r3snd11SoundHandleUlPCQ44nw4r3snd14SoundStartable9StartInfoPv = .text:0x8038ADC0; // type:function size:0xAC d_s_vt_0x1AC__14dSoundSource_cFv = .text:0x8038AE70; // type:function size:0x98 setupSound__14dSoundSource_cFPQ34nw4r3snd11SoundHandleUlPCQ44nw4r3snd14SoundStartable9StartInfoPvb = .text:0x8038AF10; // type:function size:0x254 @@ -21476,14 +21476,14 @@ updateSome3DField__23dSndDistantSoundActor_cFv = .text:0x803941C0; // type:funct d_vt_0x3C__23dSndDistantSoundActor_cFv = .text:0x803941D0; // type:function size:0x24 @84@__dt__23dSndDistantSoundActor_cFv = .text:0x80394200; // type:function size:0x8 scope:weak __ct__13dSndSeSound_cFv = .text:0x80394210; // type:function size:0xA8 -__ct__16UnkSeSoundStructFv = .text:0x803942C0; // type:function size:0x14 scope:weak -__dt__16UnkSeSoundStructFv = .text:0x803942E0; // type:function size:0x40 scope:weak +__ct__17dSndSoundCtxParamFv = .text:0x803942C0; // type:function size:0x14 scope:weak +__dt__17dSndSoundCtxParamFv = .text:0x803942E0; // type:function size:0x40 scope:weak __dt__13dSndSeSound_cFv = .text:0x80394320; // type:function size:0x78 setSource__13dSndSeSound_cFP14dSoundSource_cUl = .text:0x803943A0; // type:function size:0x80 clear__13dSndSeSound_cFv = .text:0x80394420; // type:function size:0x40 calc__13dSndSeSound_cFP14dSoundSource_c = .text:0x80394460; // type:function size:0x9C -shiftPair__13dSndSeSound_cFPC16UnkSeSoundStruct = .text:0x80394500; // type:function size:0xA8 -shiftValue__13dSndSeSound_cFf = .text:0x803945B0; // type:function size:0x78 +shiftParam__13dSndSeSound_cFPC17dSndSoundCtxParam = .text:0x80394500; // type:function size:0xA8 +shiftFloatParam__13dSndSeSound_cFf = .text:0x803945B0; // type:function size:0x78 onStart__13dSndSeSound_cFP14dSoundSource_c = .text:0x80394630; // type:function size:0x1C onCalc__13dSndSeSound_cFP14dSoundSource_c = .text:0x80394650; // type:function size:0x1C __ct__14dSndSeSound1_cFv = .text:0x80394670; // type:function size:0x44 diff --git a/include/d/snd/d_snd_distant_sound_actor.h b/include/d/snd/d_snd_distant_sound_actor.h index 017e928c..dd91806b 100644 --- a/include/d/snd/d_snd_distant_sound_actor.h +++ b/include/d/snd/d_snd_distant_sound_actor.h @@ -52,10 +52,18 @@ public: // not sure if this combination makes sense void resetHandle() { - field_0x0F4 = 0; + mpHoldSoundHandle = nullptr; mpSoundHandle = &mSoundHandle; } + dSndSeSound2_c *getHoldSoundHandle() const { + return mpHoldSoundHandle; + } + + void setHoldSoundHandle(dSndSeSound2_c *handle) { + mpHoldSoundHandle = handle; + } + bool isActive() const { return mIsActive; } @@ -73,7 +81,7 @@ public: private: /* 0x0E4 */ nw4r::ut::Node mPoolLink; // sound actor pool link /* 0x0EC */ nw4r::ut::Node mSourceLink; // sound source link - /* 0x0F4 */ UNKWORD field_0x0F4; + /* 0x0F4 */ dSndSeSound2_c *mpHoldSoundHandle; /* 0x0F8 */ dSoundSource_c *mpSoundSource; /* 0x0FC */ nw4r::snd::SoundHandle mSoundHandle; /* 0x100 */ nw4r::snd::SoundHandle *mpSoundHandle; diff --git a/include/d/snd/d_snd_se_sound.h b/include/d/snd/d_snd_se_sound.h index 8efb1758..ee7fa727 100644 --- a/include/d/snd/d_snd_se_sound.h +++ b/include/d/snd/d_snd_se_sound.h @@ -8,23 +8,32 @@ #include "nw4r/ut/ut_list.h" /** - * This seems to be a generic way of passing parameters from callers of dSoundSource_c - * startSound/holdSound to the callbacks that sound sources will register - * on those handlers. E.g. at 80397a40 the chandelier swing hold sound will - * occasionally create additional sounds based on historical params (swinging angle) passed - * to holdSound by the chandelier (see dAcOChandelier_c::executeState_Wait / 80ebc814 in Ghidra) - * In yet other cases the callback itself will keep pushing new values and the caller doesn't - * do anything, e.g. caller at 80228814 for SE_L_ROPE_WIND_LV does not push values, but - * handler at 80394fb0 will keep pushing values. + * Examples: + * * Chandelier hold sound. Game code (dAcOChandelier_c::executeState_Wait) will + * push the current swing angle, callback (80397a40) will play additional sounds + * when chandelier swing speed exceeds certain values. + * * SE_L_ROPE_WIND_LV: callback (80228814) will read and write values to create a feedback + * loop for certain parameters. */ -struct UnkSeSoundStruct { - UnkSeSoundStruct() : field_0x00(0), field_0x04(0.0f) {} - ~UnkSeSoundStruct() {} +struct dSndSoundCtxParam { + dSndSoundCtxParam() : intParam(0), floatParam(0.0f) {} + ~dSndSoundCtxParam() {} - /* 0x00 */ UNKWORD field_0x00; - /* 0x04 */ f32 field_0x04; + /* 0x00 */ s32 intParam; + /* 0x04 */ f32 floatParam; }; +/** + * A sound effect handle. Typically acquired by sound sources from a pool. + * This allows sound sources to play sounds with no pre-determined limit + * on the number of sounds. It also allows the source to handle the statefulness + * of holdSound without requiring users to manage handles. + * + * Additionally, some sound sources will register callbacks to customize + * sound parameters (pitch, volume, ...). These callbacks can additionally + * write and read context parameters (see above). The game will shift these + * parameters with each call, so a lot of this is obviously frame-rate dependent. + */ class dSndSeSound_c { public: dSndSeSound_c(); @@ -45,8 +54,8 @@ public: void clear(); // not sure what this does - void shiftPair(const UnkSeSoundStruct *p); - void shiftValue(f32 value); + void shiftParam(const dSndSoundCtxParam *p); + void shiftFloatParam(f32 value); typedef void Callback(dSndSeSound_c *sound, dSoundSource_c *source, nw4r::snd::SoundHandle &handle); @@ -106,7 +115,7 @@ protected: /* 0x10C */ Type_e mHandleType; /* 0x110 */ u32 mSoundId; /* 0x114 */ s32 field_0x114; - /* 0x118 */ UnkSeSoundStruct *mpUnk; + /* 0x118 */ dSndSoundCtxParam *mpUnk; /* 0x11C */ u8 field_0x11C; /* 0x11D */ u8 field_0x11D; /* 0x11E */ u8 field_0x11E; diff --git a/include/d/snd/d_snd_source.h b/include/d/snd/d_snd_source.h index baf86487..cd022b30 100644 --- a/include/d/snd/d_snd_source.h +++ b/include/d/snd/d_snd_source.h @@ -30,10 +30,10 @@ public: return mpName; } // 0x17C virtual void d_s_vt_0x180(); // 0x180 - virtual void d_s_vt_0x184(); // 0x184 + virtual void preCalc(); // 0x184 virtual void d_s_vt_0x188(); // 0x188 - virtual void d_s_vt_0x18C(); // 0x18C - virtual void d_s_vt_0x190(); // 0x190 + virtual void postCalc(); // 0x18C + virtual bool d_s_vt_0x190(); // 0x190 virtual u32 d_s_vt_0x194(u32 soundId); // 0x194 virtual void postStartSound(nw4r::snd::SoundHandle &handle, dSndSeSound_c *pSound, u32 id) override; // 0x198 @@ -105,23 +105,31 @@ public: virtual bool hasPlayingSounds() const override; // 0x048 virtual bool isPlayingSound(u32 soundId) override; // 0x04C virtual bool isPlayingSound(const char *soundId) override; // 0x050 - virtual void setUnkSe(const UnkSeSoundStruct *arg) override { - mpUnkSe = arg; + virtual void setCtxParam(const dSndSoundCtxParam *arg) override { + mpCtxParam = arg; } // 0x054 - virtual void setUnkSeFloat(f32 value) override; // 0x058 - virtual void setUnkSeWord(UNKWORD value) override; // 0x05C - virtual bool startSound(u32 soundId) override; // 0x060 - virtual bool startSoundWithUnkSeWord(u32 soundId, UNKWORD value) override; // 0x064 - virtual bool startSoundWithUnkSeFloat(u32 soundId, f32 value) override; // 0x068 - virtual bool startSoundWithUnkSe(u32 soundId, f32 fValue, UNKWORD value) override; // 0x06C - virtual bool startSound(const char *label) override; // 0x070 - virtual bool startSoundWithUnkSeWord(const char *label, UNKWORD value) override; // 0x074 - virtual bool startSoundWithUnkSeFloat(const char *label, f32 value) override; // 0x078 - virtual bool startSoundWithUnkSe(const char *label, f32 fValue, UNKWORD value) override; // 0x07C - virtual void stopSounds(u32 soundId, s32 fadeFrames) override; // 0x0A4 - virtual void stopSounds(const char *label, s32 fadeFrames) override; // 0x0A8 - virtual bool holdSound(u32 soundId) override; // 0x0AC - virtual bool holdSound(const char *label) override; // 0x0BC + virtual void setCtxFloat(f32 value) override; // 0x058 + virtual void setCtxInt(s32 value) override; // 0x05C + virtual bool startSound(u32 soundId) override; // 0x060 + virtual bool startSoundWithIntParam(u32 soundId, s32 value) override; // 0x064 + virtual bool startSoundWithFloatParam(u32 soundId, f32 value) override; // 0x068 + virtual bool startSoundWithParams(u32 soundId, f32 fValue, s32 value) override; // 0x06C + virtual bool startSound(const char *label) override; // 0x070 + virtual bool startSoundWithIntParam(const char *label, s32 value) override; // 0x074 + virtual bool startSoundWithFloatParam(const char *label, f32 value) override; // 0x078 + virtual bool startSoundWithParams(const char *label, f32 fValue, s32 value) override; // 0x07C + virtual void stopSounds(u32 soundId, s32 fadeFrames) override; // 0x0A4 + virtual void stopSounds(const char *label, s32 fadeFrames) override; // 0x0A8 + virtual bool holdSound(u32 soundId) override; // 0x0AC + virtual bool holdSoundWithIntParam(u32 soundId, s32 value) override; // 0x0B0 + virtual bool holdSoundWithFloatParam(u32 soundId, f32 value) override; // 0x0B4 + virtual bool holdSoundWithParams(u32 soundId, f32 fValue, s32 value) override; // 0x0B8 + virtual bool holdSound(const char *label) override; // 0x0BC + virtual bool holdSoundWithIntParam(const char *label, s32 value) override; // 0x0C0 + virtual bool holdSoundWithFloatParam(const char *label, f32 value) override; // 0x0C4 + virtual bool holdSoundWithParams(const char *label, f32 fValue, s32 value) override; // 0x0C8 + virtual bool holdSoundAtPosition(u32 soundId, const nw4r::math::VEC3 *position) override; // 0x0CC + virtual bool holdSoundAtPosition(const char *label, const nw4r::math::VEC3 *position) override; // 0x0D0 virtual bool isReadyMaybe() override { return false; @@ -194,7 +202,7 @@ private: /* 0x102 */ u8 field_0x102; /* 0x104 */ UNKWORD field_0x104; /* 0x108 */ UNKWORD field_0x108; - /* 0x10C */ const UnkSeSoundStruct *mpUnkSe; + /* 0x10C */ const dSndSoundCtxParam *mpCtxParam; /* 0x110 */ nw4r::ut::List mDistantSoundList; // node offset 0xEC -> dSndDistantSoundActor_c /* 0x11C */ UNKWORD field_0x11C; /* 0x120 */ nw4r::ut::List mHandleType1List; // node offset 0x4 -> dSndSeSound_c diff --git a/include/d/snd/d_snd_source_if.h b/include/d/snd/d_snd_source_if.h index 6bf20d09..99975b3d 100644 --- a/include/d/snd/d_snd_source_if.h +++ b/include/d/snd/d_snd_source_if.h @@ -20,28 +20,28 @@ public: virtual bool isSourceType(s32 type) const = 0; // 0x01C SOUNDSOURCE_VIRTUAL(0x20); SOUNDSOURCE_VIRTUAL(0x24); - virtual const nw4r::math::VEC3 &getListenerPosition() const = 0; // 0x028 - virtual void calc(const nw4r::math::VEC3 &) = 0; // 0x02C - virtual void onFlag1(u32 mask) = 0; // 0x030 - virtual void offFlag1(u32 mask) = 0; // 0x034 - virtual bool checkFlag(u32 mask) const = 0; // 0x038 - virtual void onFlag2(u32 mask) = 0; // 0x03C - virtual void stopAllSound(s32 fadeFrames) = 0; // 0x040 - virtual void shutdown() = 0; // 0x044 - virtual bool hasPlayingSounds() const = 0; // 0x048 - virtual bool isPlayingSound(u32 soundId) = 0; // 0x04C - virtual bool isPlayingSound(const char *soundId) = 0; // 0x050 - virtual void setUnkSe(const UnkSeSoundStruct *) = 0; // 0x054 - virtual void setUnkSeFloat(f32 value) = 0; // 0x058 - virtual void setUnkSeWord(UNKWORD value) = 0; // 0x05C - virtual bool startSound(u32 soundId) = 0; // 0x060 - virtual bool startSoundWithUnkSeWord(u32 soundId, UNKWORD value) = 0; // 0x064 - virtual bool startSoundWithUnkSeFloat(u32 soundId, f32 value) = 0; // 0x068 - virtual bool startSoundWithUnkSe(u32 soundId, f32 fValue, UNKWORD value) = 0; // 0x06C - virtual bool startSound(const char *label) = 0; // 0x070 - virtual bool startSoundWithUnkSeWord(const char *label, UNKWORD value) = 0; // 0x074 - virtual bool startSoundWithUnkSeFloat(const char *label, f32 value) = 0; // 0x078 - virtual bool startSoundWithUnkSe(const char *label, f32 fValue, UNKWORD value) = 0; // 0x07C + virtual const nw4r::math::VEC3 &getListenerPosition() const = 0; // 0x028 + virtual void calc(const nw4r::math::VEC3 &) = 0; // 0x02C + virtual void onFlag1(u32 mask) = 0; // 0x030 + virtual void offFlag1(u32 mask) = 0; // 0x034 + virtual bool checkFlag(u32 mask) const = 0; // 0x038 + virtual void onFlag2(u32 mask) = 0; // 0x03C + virtual void stopAllSound(s32 fadeFrames) = 0; // 0x040 + virtual void shutdown() = 0; // 0x044 + virtual bool hasPlayingSounds() const = 0; // 0x048 + virtual bool isPlayingSound(u32 soundId) = 0; // 0x04C + virtual bool isPlayingSound(const char *soundId) = 0; // 0x050 + virtual void setCtxParam(const dSndSoundCtxParam *) = 0; // 0x054 + virtual void setCtxFloat(f32 value) = 0; // 0x058 + virtual void setCtxInt(s32 value) = 0; // 0x05C + virtual bool startSound(u32 soundId) = 0; // 0x060 + virtual bool startSoundWithIntParam(u32 soundId, s32 value) = 0; // 0x064 + virtual bool startSoundWithFloatParam(u32 soundId, f32 value) = 0; // 0x068 + virtual bool startSoundWithParams(u32 soundId, f32 fValue, s32 value) = 0; // 0x06C + virtual bool startSound(const char *label) = 0; // 0x070 + virtual bool startSoundWithIntParam(const char *label, s32 value) = 0; // 0x074 + virtual bool startSoundWithFloatParam(const char *label, f32 value) = 0; // 0x078 + virtual bool startSoundWithParams(const char *label, f32 fValue, s32 value) = 0; // 0x07C SOUNDSOURCE_VIRTUAL(0x80); SOUNDSOURCE_VIRTUAL(0x84); SOUNDSOURCE_VIRTUAL(0x88); @@ -51,18 +51,18 @@ public: SOUNDSOURCE_VIRTUAL(0x98); SOUNDSOURCE_VIRTUAL(0x9C); SOUNDSOURCE_VIRTUAL(0xA0); - virtual void stopSounds(u32 soundId, s32 fadeFrames) = 0; // 0x0A4 - virtual void stopSounds(const char *label, s32 fadeFrames) = 0; // 0x0A8 - virtual bool holdSound(u32 soundId) = 0; // 0x0AC - SOUNDSOURCE_VIRTUAL(0xB0); - SOUNDSOURCE_VIRTUAL(0xB4); - SOUNDSOURCE_VIRTUAL(0xB8); - virtual bool holdSound(const char *label) = 0; // 0x0BC - SOUNDSOURCE_VIRTUAL(0xC0); - SOUNDSOURCE_VIRTUAL(0xC4); - SOUNDSOURCE_VIRTUAL(0xC8); - SOUNDSOURCE_VIRTUAL(0xCC); - SOUNDSOURCE_VIRTUAL(0xD0); + virtual void stopSounds(u32 soundId, s32 fadeFrames) = 0; // 0x0A4 + virtual void stopSounds(const char *label, s32 fadeFrames) = 0; // 0x0A8 + virtual bool holdSound(u32 soundId) = 0; // 0x0AC + virtual bool holdSoundWithIntParam(u32 soundId, s32 value) = 0; // 0x0B0 + virtual bool holdSoundWithFloatParam(u32 soundId, f32 value) = 0; // 0x0B4 + virtual bool holdSoundWithParams(u32 soundId, f32 fValue, s32 value) = 0; // 0x0B8 + virtual bool holdSound(const char *label) = 0; // 0x0BC + virtual bool holdSoundWithIntParam(const char *label, s32 value) = 0; // 0x0C0 + virtual bool holdSoundWithFloatParam(const char *label, f32 value) = 0; // 0x0C4 + virtual bool holdSoundWithParams(const char *label, f32 fValue, s32 value) = 0; // 0x0C8 + virtual bool holdSoundAtPosition(u32 soundId, const nw4r::math::VEC3 *position) = 0; // 0x0CC + virtual bool holdSoundAtPosition(const char *label, const nw4r::math::VEC3 *position) = 0; // 0x0D0 SOUNDSOURCE_VIRTUAL(0xD4); SOUNDSOURCE_VIRTUAL(0xD8); SOUNDSOURCE_VIRTUAL(0xDC); diff --git a/include/d/snd/d_snd_source_mgr.h b/include/d/snd/d_snd_source_mgr.h index b11fa616..5e5101f5 100644 --- a/include/d/snd/d_snd_source_mgr.h +++ b/include/d/snd/d_snd_source_mgr.h @@ -28,6 +28,10 @@ public: return GetInstance()->mpBoomerangSource; } + u8 getField_0x0012() const { + return field_0x0012; + } + u8 getField_0x0013() const { return field_0x0013; } diff --git a/include/d/snd/d_snd_types.h b/include/d/snd/d_snd_types.h index e09bc7fa..d86a940f 100644 --- a/include/d/snd/d_snd_types.h +++ b/include/d/snd/d_snd_types.h @@ -10,7 +10,7 @@ class dSndDistantSoundActor_c; class dSndSound_c; -class UnkSeSoundStruct; +class dSndSoundCtxParam; class dSndSeSound_c; class dSndSeSound1_c; diff --git a/src/d/snd/d_snd_distant_sound_actor.cpp b/src/d/snd/d_snd_distant_sound_actor.cpp index 49724be7..88c2a9ca 100644 --- a/src/d/snd/d_snd_distant_sound_actor.cpp +++ b/src/d/snd/d_snd_distant_sound_actor.cpp @@ -11,7 +11,7 @@ dSndDistantSoundActor_c::dSndDistantSoundActor_c() : dSnd3DActor_c(&dSndDistantSoundActorPool_c::GetInstance()->getSourceParam(), SND_SOURCE_DISTANT), - field_0x0F4(0), + mpHoldSoundHandle(nullptr), mpSoundSource(nullptr), mpSoundHandle(&mSoundHandle), mIsActive(false), @@ -95,7 +95,7 @@ void dSndDistantSoundActor_c::detachFromSource() { mpSoundSource->detachDistantSound(this); } mpSoundSource = nullptr; - field_0x0F4 = 0; + mpHoldSoundHandle = nullptr; } void dSndDistantSoundActor_c::setPause(bool flag, int fadeFrames) { diff --git a/src/d/snd/d_snd_se_sound.cpp b/src/d/snd/d_snd_se_sound.cpp index 3ab0a0ff..22620f31 100644 --- a/src/d/snd/d_snd_se_sound.cpp +++ b/src/d/snd/d_snd_se_sound.cpp @@ -14,7 +14,7 @@ dSndSeSound_c::dSndSeSound_c() field_0x11E(0), mpStartCallback(nullptr), mpCalcCallback(nullptr) { - mpUnk = new UnkSeSoundStruct[10]; + mpUnk = new dSndSoundCtxParam[10]; } dSndSeSound_c::~dSndSeSound_c() { @@ -25,10 +25,10 @@ void dSndSeSound_c::setSource(dSoundSource_c *source, u32 soundId) { clear(); mSoundId = soundId; field_0x114 = 0; - UnkSeSoundStruct* s = mpUnk; + dSndSoundCtxParam* s = mpUnk; while (s < &mpUnk[10]) { - s->field_0x00 = 0; - s->field_0x04 = 0.0f; + s->intParam = 0; + s->floatParam = 0.0f; s++; } @@ -57,7 +57,7 @@ void dSndSeSound_c::calc(dSoundSource_c *source) { field_0x114++; } -void dSndSeSound_c::shiftPair(const UnkSeSoundStruct *pUnk) { +void dSndSeSound_c::shiftParam(const dSndSoundCtxParam *pUnk) { if (pUnk == nullptr) { return; } @@ -68,11 +68,11 @@ void dSndSeSound_c::shiftPair(const UnkSeSoundStruct *pUnk) { mpUnk[0] = *pUnk; } -void dSndSeSound_c::shiftValue(f32 value) { +void dSndSeSound_c::shiftFloatParam(f32 value) { for (int i = 9; i > 0; i--) { - mpUnk[i].field_0x04 = mpUnk[i - 1].field_0x04; + mpUnk[i].floatParam = mpUnk[i - 1].floatParam; } - mpUnk[0].field_0x04 = value; + mpUnk[0].floatParam = value; } void dSndSeSound_c::onStart(dSoundSource_c *source) { diff --git a/src/d/snd/d_snd_source.cpp b/src/d/snd/d_snd_source.cpp index 731eac06..8c3ab0fa 100644 --- a/src/d/snd/d_snd_source.cpp +++ b/src/d/snd/d_snd_source.cpp @@ -11,6 +11,7 @@ #include "d/snd/d_snd_mgr.h" #include "d/snd/d_snd_player_mgr.h" #include "d/snd/d_snd_se_sound.h" +#include "d/snd/d_snd_se_sound_2.h" #include "d/snd/d_snd_se_sound_pool.h" #include "d/snd/d_snd_source_enums.h" #include "d/snd/d_snd_source_group.h" @@ -24,7 +25,7 @@ #include "nw4r/ut/ut_list.h" #include "sized_string.h" -static UnkSeSoundStruct sSeStruct; +static dSndSoundCtxParam sCtxParams; bool dSoundSource_c::sIsStartingBaseSound; const char *help_i_need_data() { @@ -44,7 +45,7 @@ dSoundSource_c::dSoundSource_c(u8 sourceType, dAcBase_c *actor, const char *name field_0x102(0), field_0x104(0), field_0x108(0), - mpUnkSe(nullptr), + mpCtxParam(nullptr), field_0x11C(0), mpOwnerGroup(pOwnerGroup), field_0x154(0), @@ -122,14 +123,34 @@ const nw4r::math::VEC3 &dSoundSource_c::getListenerPosition() const { } void dSoundSource_c::calc(const nw4r::math::VEC3 &pos) { - d_s_vt_0x184(); + preCalc(); setPosition(pos); calcHandles(); calcVolumeFade(); - d_s_vt_0x18C(); + postCalc(); field_0x108 = 0; } +void dSoundSource_c::preCalc() { + if (field_0x100 != 0) { + return; + } + + if (dSndSourceMgr_c::GetInstance()->getField_0x0012() != 0) { + return; + } + + if (!mIsPaused && !mpActor->isBasePropertyFlag(dBase_c::BASE_PROP_0x4)) { + setPause(true, 3); + } else if (mIsPaused && mpActor->isBasePropertyFlag(dBase_c::BASE_PROP_0x4)) { + setPause(false, 3); + } +} + +void dSoundSource_c::postCalc() { + // noop +} + bool dSoundSource_c::hasPlayingSounds() const { return dSnd3DActor_c::hasPlayingSounds(); } @@ -192,14 +213,14 @@ void dSoundSource_c::calcVolumeFade() { SoundActor::SetVolume(nextVolume); } -void dSoundSource_c::setUnkSeWord(UNKWORD value) { - sSeStruct.field_0x00 = value; - setUnkSe(&sSeStruct); +void dSoundSource_c::setCtxInt(s32 value) { + sCtxParams.intParam = value; + setCtxParam(&sCtxParams); } -void dSoundSource_c::setUnkSeFloat(f32 value) { - sSeStruct.field_0x04 = value; - setUnkSe(&sSeStruct); +void dSoundSource_c::setCtxFloat(f32 value) { + sCtxParams.floatParam = value; + setCtxParam(&sCtxParams); } bool dSoundSource_c::isInaudible() { @@ -230,35 +251,35 @@ bool dSoundSource_c::startSound(const char *label) { return startSound(soundLabelToSoundId(label)); } -bool dSoundSource_c::startSoundWithUnkSeWord(u32 soundId, UNKWORD value) { - setUnkSeWord(value); +bool dSoundSource_c::startSoundWithIntParam(u32 soundId, s32 value) { + setCtxInt(value); return startSound(soundId, nullptr) != nullptr; } -bool dSoundSource_c::startSoundWithUnkSeWord(const char *label, UNKWORD value) { +bool dSoundSource_c::startSoundWithIntParam(const char *label, s32 value) { u32 soundId = soundLabelToSoundId(label); - return startSoundWithUnkSeWord(soundId, value); + return startSoundWithIntParam(soundId, value); } -bool dSoundSource_c::startSoundWithUnkSeFloat(u32 soundId, f32 value) { - setUnkSeFloat(value); +bool dSoundSource_c::startSoundWithFloatParam(u32 soundId, f32 value) { + setCtxFloat(value); return startSound(soundId, nullptr) != nullptr; } -bool dSoundSource_c::startSoundWithUnkSeFloat(const char *label, f32 value) { +bool dSoundSource_c::startSoundWithFloatParam(const char *label, f32 value) { u32 soundId = soundLabelToSoundId(label); - return startSoundWithUnkSeFloat(soundId, value); + return startSoundWithFloatParam(soundId, value); } -bool dSoundSource_c::startSoundWithUnkSe(u32 soundId, f32 fValue, UNKWORD value) { - setUnkSeWord(value); - setUnkSeFloat(fValue); +bool dSoundSource_c::startSoundWithParams(u32 soundId, f32 fValue, s32 value) { + setCtxInt(value); + setCtxFloat(fValue); return startSound(soundId, nullptr) != nullptr; } -bool dSoundSource_c::startSoundWithUnkSe(const char *label, f32 fValue, UNKWORD value) { +bool dSoundSource_c::startSoundWithParams(const char *label, f32 fValue, s32 value) { u32 soundId = soundLabelToSoundId(label); - return startSoundWithUnkSe(soundId, fValue, value); + return startSoundWithParams(soundId, fValue, value); } bool dSoundSource_c::startRemoConSound(u32 soundId) { @@ -289,7 +310,7 @@ dSoundSource_c::startSound(u32 soundId, nw4r::snd::SoundHandle *handle, nw4r::sn return START_ERR_USER; } - seHandle->shiftPair(mpUnkSe); + seHandle->shiftParam(mpCtxParam); if (handle != nullptr) { seHandle->setHandle(handle); } else { @@ -339,7 +360,7 @@ dSoundSource_c::startSoundAtPosition(u32 soundId, const nw4r::math::VEC3 *positi } seHandle->setAcquiredMaybe(true); - seHandle->shiftPair(mpUnkSe); + seHandle->shiftParam(mpCtxParam); if (handle != nullptr) { seHandle->setHandle(handle); } else { @@ -382,6 +403,37 @@ bool dSoundSource_c::holdSound(const char *label) { return holdSound(soundLabelToSoundId(label)); } +bool dSoundSource_c::holdSoundWithIntParam(u32 soundId, s32 value) { + setCtxInt(value); + return holdSound(soundId, nullptr) != nullptr; +} + +bool dSoundSource_c::holdSoundWithIntParam(const char *label, s32 value) { + u32 soundId = soundLabelToSoundId(label); + return holdSoundWithIntParam(soundId, value); +} + +bool dSoundSource_c::holdSoundWithFloatParam(u32 soundId, f32 value) { + setCtxFloat(value); + return holdSound(soundId, nullptr) != nullptr; +} + +bool dSoundSource_c::holdSoundWithFloatParam(const char *label, f32 value) { + u32 soundId = soundLabelToSoundId(label); + return holdSoundWithFloatParam(soundId, value); +} + +bool dSoundSource_c::holdSoundWithParams(u32 soundId, f32 fValue, s32 value) { + setCtxInt(value); + setCtxFloat(fValue); + return holdSound(soundId, nullptr) != nullptr; +} + +bool dSoundSource_c::holdSoundWithParams(const char *label, f32 fValue, s32 value) { + u32 soundId = soundLabelToSoundId(label); + return holdSoundWithParams(soundId, fValue, value); +} + nw4r::snd::SoundHandle *dSoundSource_c::holdSound(u32 soundId, nw4r::snd::SoundHandle *handle) { if (soundId == -1) { return nullptr; @@ -395,7 +447,7 @@ nw4r::snd::SoundHandle *dSoundSource_c::holdSound(u32 soundId, nw4r::snd::SoundH return nullptr; } - seHandle->shiftPair(mpUnkSe); + seHandle->shiftParam(mpCtxParam); if (handle != nullptr) { seHandle->setHandle(handle); @@ -444,7 +496,7 @@ nw4r::snd::SoundHandle *dSoundSource_c::continueHoldingSound( } } nw4r::snd::SoundHandle *handle = seHandle->getHandle(); - seHandle->shiftPair(mpUnkSe); + seHandle->shiftParam(mpCtxParam); field_0x11C |= 0x80000000; bool ok; if (distant != nullptr && position != nullptr) { @@ -465,6 +517,61 @@ nw4r::snd::SoundHandle *dSoundSource_c::continueHoldingSound( return handle; } +bool dSoundSource_c::holdSoundAtPosition(u32 soundId, const nw4r::math::VEC3 *position) { + dSndSeSound2_c *seHandle; + nw4r::snd::SoundHandle *handle; + + if (position != nullptr) { + dSndDistantSoundActor_c *actor = dSndDistantSoundActorPool_c::GetInstance()->findActiveActor(soundId, this); + if (actor != nullptr) { + seHandle = actor->getHoldSoundHandle(); + seHandle->setAcquiredMaybe(1); + handle = continueHoldingSound(seHandle, soundId, actor, position); + } else { + if (d_s_vt_0x190()) { + d_s_vt_0x1C8(); + return false; + } + if (isInaudible()) { + d_s_vt_0x1C8(); + return false; + } + actor = dSndDistantSoundActorPool_c::GetInstance()->acquireActor(soundId, position, this); + if (actor == nullptr) { + d_s_vt_0x1C8(); + return false; + } + seHandle = dSndSeSoundPool_c::GetInstance()->acquireSoundType2(this, soundId); + if (seHandle == nullptr) { + d_s_vt_0x1C8(); + return false; + } + seHandle->shiftParam(mpCtxParam); + handle = seHandle->getHandle(); + if (actor->holdSound(soundId, *position, handle)) { + addSeHandleType2(seHandle); + postHoldSound(*handle, seHandle, soundId, 0); + postSetupSound(handle->GetId(), soundId, seHandle); + seHandle->onStart(this); + seHandle->onCalc(this); + actor->setHoldSoundHandle(seHandle); + } else { + dSndSeSoundPool_c::GetInstance()->releaseSoundType2(seHandle); + handle = nullptr; + } + } + + } else { + handle = holdSound(soundId, nullptr); + } + d_s_vt_0x1C8(); + return handle != nullptr; +} + +bool dSoundSource_c::holdSoundAtPosition(const char *label, const nw4r::math::VEC3 *position) { + return holdSoundAtPosition(soundLabelToSoundId(label), position); +} + nw4r::snd::SoundStartable::StartResult dSoundSource_c::SetupSound(nw4r::snd::SoundHandle *pHandle, u32 soundId, const StartInfo *pStartInfo, void *arg) { bool holdFlag = *(bool *)arg;