diff options
| author | robojumper <robojumper@gmail.com> | 2025-05-30 22:21:49 +0200 |
|---|---|---|
| committer | robojumper <robojumper@gmail.com> | 2025-05-31 21:21:12 +0200 |
| commit | 83456a9cd8a15b6c27d29f09c72ad1f09bc2ed60 (patch) | |
| tree | 5cf9528a037062eb3b1555c8869d2cf37d80612f /include | |
| parent | 77e17d4c1fb7439914889076b21176242301e7ef (diff) | |
start matching some d/snd things
Diffstat (limited to 'include')
26 files changed, 688 insertions, 159 deletions
diff --git a/include/d/a/d_a_base.h b/include/d/a/d_a_base.h index e293b927..b223b88a 100644 --- a/include/d/a/d_a_base.h +++ b/include/d/a/d_a_base.h @@ -4,6 +4,7 @@ #include "UnknownTypeBelongings.h" #include "common.h" #include "d/d_base.h" +#include "d/snd/d_snd_source.h" #include "m/m_allocator.h" #include "m/m_angle.h" #include "m/m_vec.h" @@ -13,83 +14,9 @@ class dAcBase_c; struct cBgS_PolyInfo; -struct SoundSource { - virtual ~SoundSource() {} -// TODO there's probably multiple inheritance involved and stuff -#define SOUNDSOURCE_VIRTUAL(offset) virtual void vt_##offset(); - - SOUNDSOURCE_VIRTUAL(0x0C); - SOUNDSOURCE_VIRTUAL(0x10); - SOUNDSOURCE_VIRTUAL(0x14); - SOUNDSOURCE_VIRTUAL(0x18); - SOUNDSOURCE_VIRTUAL(0x1C); - SOUNDSOURCE_VIRTUAL(0x20); - SOUNDSOURCE_VIRTUAL(0x24); - SOUNDSOURCE_VIRTUAL(0x28); - SOUNDSOURCE_VIRTUAL(0x2C); - SOUNDSOURCE_VIRTUAL(0x30); - SOUNDSOURCE_VIRTUAL(0x34); - SOUNDSOURCE_VIRTUAL(0x38); - SOUNDSOURCE_VIRTUAL(0x3C); - SOUNDSOURCE_VIRTUAL(0x40); - SOUNDSOURCE_VIRTUAL(0x44); - virtual bool shutdown(); // 0x48 - SOUNDSOURCE_VIRTUAL(0x4C); - SOUNDSOURCE_VIRTUAL(0x50); - SOUNDSOURCE_VIRTUAL(0x54); - SOUNDSOURCE_VIRTUAL(0x58); - SOUNDSOURCE_VIRTUAL(0x5C); - SOUNDSOURCE_VIRTUAL(0x60); - SOUNDSOURCE_VIRTUAL(0x64); - SOUNDSOURCE_VIRTUAL(0x68); - SOUNDSOURCE_VIRTUAL(0x6C); - SOUNDSOURCE_VIRTUAL(0x70); - SOUNDSOURCE_VIRTUAL(0x74); - SOUNDSOURCE_VIRTUAL(0x78); - SOUNDSOURCE_VIRTUAL(0x7C); - SOUNDSOURCE_VIRTUAL(0x80); - SOUNDSOURCE_VIRTUAL(0x84); - SOUNDSOURCE_VIRTUAL(0x88); - SOUNDSOURCE_VIRTUAL(0x8C); - SOUNDSOURCE_VIRTUAL(0x90); - SOUNDSOURCE_VIRTUAL(0x94); - SOUNDSOURCE_VIRTUAL(0x98); - SOUNDSOURCE_VIRTUAL(0x9C); - SOUNDSOURCE_VIRTUAL(0xA0); - SOUNDSOURCE_VIRTUAL(0xA4); - SOUNDSOURCE_VIRTUAL(0xA8); - SOUNDSOURCE_VIRTUAL(0xAC); - SOUNDSOURCE_VIRTUAL(0xB0); - SOUNDSOURCE_VIRTUAL(0xB4); - SOUNDSOURCE_VIRTUAL(0xB8); - SOUNDSOURCE_VIRTUAL(0xBC); - SOUNDSOURCE_VIRTUAL(0xC0); - SOUNDSOURCE_VIRTUAL(0xC4); - SOUNDSOURCE_VIRTUAL(0xC8); - SOUNDSOURCE_VIRTUAL(0xCC); - SOUNDSOURCE_VIRTUAL(0xD0); - SOUNDSOURCE_VIRTUAL(0xD4); - SOUNDSOURCE_VIRTUAL(0xD8); - SOUNDSOURCE_VIRTUAL(0xDC); - SOUNDSOURCE_VIRTUAL(0xE0); - SOUNDSOURCE_VIRTUAL(0xE4); - SOUNDSOURCE_VIRTUAL(0xE8); - SOUNDSOURCE_VIRTUAL(0xEC); - SOUNDSOURCE_VIRTUAL(0xF0); - SOUNDSOURCE_VIRTUAL(0xF4); - SOUNDSOURCE_VIRTUAL(0xF8); - SOUNDSOURCE_VIRTUAL(0xFC); - - virtual bool isReadyMaybe(); // 0x100 - virtual bool load(void *data, const char *name); // 0x104 - virtual void setFrame(f32 frame); // 0x108 - virtual void setRate(f32 frame); // 0x10C - virtual void set_0x164(UNKWORD val); // 0x114 -}; - struct SoundInfo { dAcBase_c *actor; - SoundSource *sound_source; + dSoundSourceIf_c *sound_source; mVec3_c *obj_pos; TListNode<SoundInfo> mLink; }; @@ -143,7 +70,7 @@ public: /* 0x68 */ mHeapAllocator_c heap_allocator; /* 0x84 */ ObjInfo *obj_info; /* 0x88 */ TList<SoundInfo, 12> sound_list; - /* 0x94 */ RaiiPtr<SoundSource> sound_source; + /* 0x94 */ RaiiPtr<dSoundSourceIf_c> sound_source; /* 0x98 */ mVec3_c *obj_pos; /* 0x9C */ mVec3_c pos_copy; /* 0xA8 */ u32 params2; @@ -252,7 +179,7 @@ public: s8 viewClipIdx, ObjInfo *objInfo ); - /* 8002c690 */ SoundSource *FUN_8002c690(); + /* 8002c690 */ dSoundSourceIf_c *FUN_8002c690(); /* 8002c710 */ int initAllocatorWork1Heap(int size, char *name, int align); /* 8002c720 */ int initAllocator(int size, char *name, EGG::Heap *heap, int align); /* 8002c7b0 */ bool addActorToRoom(s32 roomId); @@ -301,7 +228,7 @@ public: /* 8002d810 */ void FUN_8002d810(); /* 8002d830 */ void FUN_8002d830(); /* 8002d860 */ void FUN_8002d860(UNKWORD val); - /* 8002d880 */ SoundSource *getSoundSource(); + /* 8002d880 */ dSoundSourceIf_c *getSoundSource(); // End of SoundSource stuff /* 8002d890 */ void removeSoundInfo(SoundInfo *); diff --git a/include/d/snd/d_snd_3d_actor.h b/include/d/snd/d_snd_3d_actor.h new file mode 100644 index 00000000..6fa7fafa --- /dev/null +++ b/include/d/snd/d_snd_3d_actor.h @@ -0,0 +1,94 @@ +#ifndef D_SND_ACTOR_H +#define D_SND_ACTOR_H + +#include "common.h" +#include "nw4r/math/math_types.h" +#include "nw4r/snd/snd_Sound3DActor.h" +#include "nw4r/snd/snd_SoundHandle.h" + +class dSnd3DActor_c : public nw4r::snd::Sound3DActor { + static const u32 NUM_SOUNDS = 4; + +public: + dSnd3DActor_c(UNKTYPE *, u8); + + virtual ~dSnd3DActor_c() {} + + virtual bool d_vt_0x30() { + return true; + } + + virtual void d_vt_0x34(const nw4r::math::VEC3 &); + + virtual void d_vt_0x38(bool flag, int fadeFrames) = 0; + + virtual UNKWORD d_vt_0x3C() { + return 0; + } + + virtual UNKWORD d_vt_0x40() { + return 0; + } + + virtual UNKWORD d_vt_0x44() { + return 0; + } + + virtual const nw4r::math::VEC3 &getPositionRelativeToPlayer(); + virtual f32 getDistanceToPlayer(); // vt 0x4C + virtual void updatePositionRelativeToPlayer(); // vt 0x50 + virtual void updateDistanceToPlayer(); // vt 0x54 + virtual void d_vt_0x58() = 0; + virtual void d_vt_0x5C() = 0; + + void resetFloats(); + + bool checkFlag(u16 flag) const { + return (mFlags & flag); + } + + bool hasPlayingSounds() const; + bool isPlayingSound(u32 id); + + const char *soundIdToSoundLabel(u32 soundId) const; + u32 soundLabelToSoundId(const char *soundLabel) const; + +protected: + // a_ prefix to prevent multiple inheritance clashes + /* 0x7D */ u8 a_field_0x7D; + /* 0x7E */ u8 a_field_0x7E; + /* 0x7F */ u8 a_field_0x7F; + /* 0x80 */ u8 a_field_0x80; + /* 0x84 */ f32 a_field_0x84; + /* 0x88 */ f32 a_field_0x88; + /* 0x8C */ f32 a_field_0x8C; + /* 0x90 */ f32 a_field_0x90; + /* 0x94 */ f32 a_field_0x94; + /* 0x98 */ f32 a_field_0x98; + /* 0x9C */ f32 a_field_0x9C; + /* 0xA0 */ u8 a_0xA0[0xC8 - 0xA0]; + /* 0xC8 */ UNKTYPE *a_field_0xC8; + /* 0xCC */ u16 mFlags; + /* 0xD0 */ nw4r::math::VEC3 mPositionRelativeToPlayer; + /* 0xDC */ f32 mDistanceToPlayer; + /* 0xE0 */ f32 a_field_0xE0; +}; + +// used at the very least when trying to finish Demise +class IsCurrentSoundIdChecker { +public: + IsCurrentSoundIdChecker(u32 id, bool *pResult) : mSoundId(id), mpResult(pResult) {} + ~IsCurrentSoundIdChecker() {} + + virtual void operator()(nw4r::snd::SoundHandle &pHandle) { + if (mSoundId == pHandle.GetId()) { + *mpResult = true; + } + } + +private: + /* 0x04 */ u32 mSoundId; + /* 0x08 */ bool *mpResult; +}; + +#endif diff --git a/include/d/snd/d_snd_3d_engine.h b/include/d/snd/d_snd_3d_engine.h new file mode 100644 index 00000000..309f169a --- /dev/null +++ b/include/d/snd/d_snd_3d_engine.h @@ -0,0 +1,18 @@ +#ifndef D_SND_3D_ENGINE +#define D_SND_3D_ENGINE + +#include "nw4r/snd/snd_BasicSound.h" +#include "nw4r/snd/snd_Sound3DEngine.h" +#include "nw4r/snd/snd_Sound3DManager.h" + +class dSnd3DEngine_c : public nw4r::snd::Sound3DEngine { +public: + dSnd3DEngine_c(); + + virtual void UpdateAmbientParam( + const nw4r::snd::Sound3DManager *mgr, const nw4r::snd::Sound3DParam *param3d, u32 unk, u32 flags, + nw4r::snd::SoundAmbientParam *paramAmb + ) override; +}; + +#endif diff --git a/include/d/snd/d_snd_3d_manager.h b/include/d/snd/d_snd_3d_manager.h new file mode 100644 index 00000000..b0a86b90 --- /dev/null +++ b/include/d/snd/d_snd_3d_manager.h @@ -0,0 +1,66 @@ +#ifndef D_SND_3D_MANAGER_H +#define D_SND_3D_MANAGER_H + +#include "d/snd/d_snd_3d_engine.h" +#include "d/snd/d_snd_util.h" +#include "egg/gfx/eggCamera.h" +#include "m/m_vec.h" +#include "nw4r/math/math_types.h" +#include "nw4r/snd/snd_Sound3DListener.h" +#include "nw4r/snd/snd_Sound3DManager.h" + +class dSnd3DManager_c; +extern template class SndMgrDisposer<dSnd3DManager_c>; + +class dSnd3DManager_c { +public: + SndMgrDisposer<dSnd3DManager_c> *GetDisposer() { + return &mDisposer; + } + + static dSnd3DManager_c *GetInstance() { + return sInstance; + } + + static dSnd3DManager_c *sInstance; + static SndMgrDisposer<dSnd3DManager_c> *sDisposer; + +private: + SndMgrDisposer<dSnd3DManager_c> mDisposer; + +public: + dSnd3DManager_c(); + + void setup(); + void updateFromCamera(EGG::LookAtCamera &camera); + void setCamDistance(f32 value); + void resetCamDistance(); + void calc(); + void clearState(); + + nw4r::snd::Sound3DManager& getManager() { + return mManager; + } + + const mVec3_c &getListenerPos() const { + return mSoundListenerPosition; + } + +private: + + void updateListenerPos(f32); + /* 0x10 */ bool mIsSetup; + /* 0x11 */ u8 field_0x11; + /* 0x14 */ dSnd3DEngine_c *mpEngine; + /* 0x18 */ nw4r::snd::Sound3DManager mManager; + /* 0x44 */ nw4r::snd::Sound3DListener mListener; + /* 0xB0 */ EGG::LookAtCamera mCamera; + /* 0x138 */ mVec3_c field_0x138; + /* 0x144 */ mVec3_c mSoundListenerPosition; + /* 0x150 */ f32 mCameraPosSqVelocity; + /* 0x154 */ f32 mCameraAtSqVelocity; + /* 0x158 */ f32 mCamDistance; + /* 0x15C */ s16 mTimer; +}; + +#endif diff --git a/include/d/snd/d_snd_actor.h b/include/d/snd/d_snd_actor.h new file mode 100644 index 00000000..5fc2480c --- /dev/null +++ b/include/d/snd/d_snd_actor.h @@ -0,0 +1,12 @@ +#ifndef D_SND_3D_ACTOR_H +#define D_SND_3D_ACTOR_H + +#include "nw4r/snd/snd_SoundActor.h" +#include "nw4r/snd/snd_SoundHandle.h" + +class dSndActor_c : public nw4r::snd::SoundActor { +public: + dSndActor_c(nw4r::snd::SoundArchivePlayer &rPlayer); +}; + +#endif diff --git a/include/d/snd/d_snd_checkers.h b/include/d/snd/d_snd_checkers.h new file mode 100644 index 00000000..c34f881b --- /dev/null +++ b/include/d/snd/d_snd_checkers.h @@ -0,0 +1,22 @@ +#ifndef D_SND_CHECKERS_H +#define D_SND_CHECKERS_H + +#include "nw4r/snd/snd_SoundHandle.h" + +class SoundPropertiesChecker { +public: + virtual void operator()(nw4r::snd::SoundHandle &pHandle); + +private: + /* 0x04 */ u32 mSoundId; + /* 0x08 */ u32 mPlayCounter; + /* 0x0C */ u32 mPauseCounter; + /* 0x10 */ u32 mCounter3; + /* 0x14 */ u32 mCounter4; + /* 0x18 */ u32 *mpPlayCounter; + /* 0x1C */ u32 *mpPauseCounter; + /* 0x20 */ u32 *mpCounter3; + /* 0x24 */ u32 *mpCounter4; +}; + +#endif diff --git a/include/d/snd/d_snd_mgr.h b/include/d/snd/d_snd_mgr.h new file mode 100644 index 00000000..d5606784 --- /dev/null +++ b/include/d/snd/d_snd_mgr.h @@ -0,0 +1,32 @@ +#ifndef D_SND_MGR_H +#define D_SND_MGR_H + +#include "egg/audio/eggAudioMgr.h" +#include "nw4r/snd/snd_SoundArchivePlayer.h" + +class dSndMgr_c : public EGG::SimpleAudioMgr { +public: + dSndMgr_c(); + + virtual void calc() override; + void initialize(EGG::Heap *heap, u32 size); + void initHbm(u32 frame); + + static void restoreEffectsCallback(); + + static dSndMgr_c *GetInstance() { + return sInstance; + } + + static nw4r::snd::SoundArchivePlayer* getPlayer() { + return sInstance->ArcPlayer::getPlayer(); + } + +private: + static dSndMgr_c *sInstance; + + /* 0x6C8 */ u8 _0x6C8[0x6CC - 0x6C8]; + /* 0x6CC */ u8 field_0x6CC; +}; + +#endif diff --git a/include/d/snd/d_snd_player_mgr.h b/include/d/snd/d_snd_player_mgr.h new file mode 100644 index 00000000..2578fcb4 --- /dev/null +++ b/include/d/snd/d_snd_player_mgr.h @@ -0,0 +1,61 @@ +#ifndef D_SND_PLAYER_MGR_H +#define D_SND_PLAYER_MGR_H + +#include "d/snd/d_snd_util.h" +#include "nw4r/snd/snd_MemorySoundArchive.h" +#include "nw4r/snd/snd_SoundArchivePlayer.h" +#include "nw4r/snd/snd_SoundHandle.h" +#include "nw4r/snd/snd_SoundStartable.h" + +class dSndPlayerMgr_c; +extern template class SndMgrDisposer<dSndPlayerMgr_c>; + +class dSndPlayerMgr_c { +public: + SndMgrDisposer<dSndPlayerMgr_c> *GetDisposer() { + return &mDisposer; + } + + static dSndPlayerMgr_c *GetInstance() { + return sInstance; + } + + static dSndPlayerMgr_c *sInstance; + static SndMgrDisposer<dSndPlayerMgr_c> *sDisposer; + +private: + SndMgrDisposer<dSndPlayerMgr_c> mDisposer; + +public: + dSndPlayerMgr_c(); + + void calc(); + + u32 getFreeSize(); + bool loadDemoArchive(const char *demoArchiveName); + const char *getSoundArchivePath(); + u32 convertLabelStringToSoundId(const char *label) const; + nw4r::snd::SoundArchivePlayer &getSoundArchivePlayerForType(u8 type); + + bool checkFlag(u32 mask) const { + return mFlags & mask; + } + +private: + /* 0x010 */ u8 field_0x010; + /* 0x011 */ u8 field_0x011; + /* 0x014 */ s32 field_0x014; + /* 0x018 */ s32 field_0x018; + /* 0x01C */ s32 field_0x01C; + /* 0x020 */ u32 mFlags; + + virtual nw4r::snd::SoundStartable::StartResult + startSound(nw4r::snd::SoundHandle *pHandle, u32 soundId, const nw4r::snd::SoundStartable::StartInfo *pStartInfo); + virtual nw4r::snd::SoundStartable::StartResult + startSound(nw4r::snd::SoundHandle *pHandle, const char *soundLabel, const nw4r::snd::SoundStartable::StartInfo *pStartInfo); + + /* 0x028 */ nw4r::snd::MemorySoundArchive mSoundArchive; + /* 0x178 */ nw4r::snd::SoundArchivePlayer mSoundArchivePlayer; +}; + +#endif diff --git a/include/d/snd/d_snd_source.h b/include/d/snd/d_snd_source.h new file mode 100644 index 00000000..65d8be13 --- /dev/null +++ b/include/d/snd/d_snd_source.h @@ -0,0 +1,167 @@ +#ifndef D_SOUND_SOURCE_H +#define D_SOUND_SOURCE_H + +#include "common.h" +#include "d/snd/d_snd_3d_actor.h" +#include "nw4r/ut/ut_list.h" + + +class dAcBase_c; + +class dSoundSourceIf_c { +public: + virtual ~dSoundSourceIf_c() {} +#define SOUNDSOURCE_VIRTUAL(offset) virtual void vt_##offset() = 0; + SOUNDSOURCE_VIRTUAL(0x0C); + SOUNDSOURCE_VIRTUAL(0x10); + SOUNDSOURCE_VIRTUAL(0x14); + SOUNDSOURCE_VIRTUAL(0x18); + SOUNDSOURCE_VIRTUAL(0x1C); + SOUNDSOURCE_VIRTUAL(0x20); + SOUNDSOURCE_VIRTUAL(0x24); + SOUNDSOURCE_VIRTUAL(0x28); + SOUNDSOURCE_VIRTUAL(0x2C); + SOUNDSOURCE_VIRTUAL(0x30); + SOUNDSOURCE_VIRTUAL(0x34); + SOUNDSOURCE_VIRTUAL(0x38); + SOUNDSOURCE_VIRTUAL(0x3C); + SOUNDSOURCE_VIRTUAL(0x40); + SOUNDSOURCE_VIRTUAL(0x44); + virtual bool hasPlayingSounds() const = 0; // 0x48 + SOUNDSOURCE_VIRTUAL(0x4C); + SOUNDSOURCE_VIRTUAL(0x50); + SOUNDSOURCE_VIRTUAL(0x54); + SOUNDSOURCE_VIRTUAL(0x58); + SOUNDSOURCE_VIRTUAL(0x5C); + SOUNDSOURCE_VIRTUAL(0x60); + SOUNDSOURCE_VIRTUAL(0x64); + SOUNDSOURCE_VIRTUAL(0x68); + SOUNDSOURCE_VIRTUAL(0x6C); + SOUNDSOURCE_VIRTUAL(0x70); + SOUNDSOURCE_VIRTUAL(0x74); + SOUNDSOURCE_VIRTUAL(0x78); + SOUNDSOURCE_VIRTUAL(0x7C); + SOUNDSOURCE_VIRTUAL(0x80); + SOUNDSOURCE_VIRTUAL(0x84); + SOUNDSOURCE_VIRTUAL(0x88); + SOUNDSOURCE_VIRTUAL(0x8C); + SOUNDSOURCE_VIRTUAL(0x90); + SOUNDSOURCE_VIRTUAL(0x94); + SOUNDSOURCE_VIRTUAL(0x98); + SOUNDSOURCE_VIRTUAL(0x9C); + SOUNDSOURCE_VIRTUAL(0xA0); + SOUNDSOURCE_VIRTUAL(0xA4); + SOUNDSOURCE_VIRTUAL(0xA8); + SOUNDSOURCE_VIRTUAL(0xAC); + SOUNDSOURCE_VIRTUAL(0xB0); + SOUNDSOURCE_VIRTUAL(0xB4); + SOUNDSOURCE_VIRTUAL(0xB8); + SOUNDSOURCE_VIRTUAL(0xBC); + SOUNDSOURCE_VIRTUAL(0xC0); + SOUNDSOURCE_VIRTUAL(0xC4); + SOUNDSOURCE_VIRTUAL(0xC8); + SOUNDSOURCE_VIRTUAL(0xCC); + SOUNDSOURCE_VIRTUAL(0xD0); + SOUNDSOURCE_VIRTUAL(0xD4); + SOUNDSOURCE_VIRTUAL(0xD8); + SOUNDSOURCE_VIRTUAL(0xDC); + SOUNDSOURCE_VIRTUAL(0xE0); + SOUNDSOURCE_VIRTUAL(0xE4); + SOUNDSOURCE_VIRTUAL(0xE8); + SOUNDSOURCE_VIRTUAL(0xEC); + SOUNDSOURCE_VIRTUAL(0xF0); + SOUNDSOURCE_VIRTUAL(0xF4); + SOUNDSOURCE_VIRTUAL(0xF8); + SOUNDSOURCE_VIRTUAL(0xFC); + + virtual bool isReadyMaybe() = 0; // 0x100 + virtual bool load(void *data, const char *name) = 0; // 0x104 + virtual void setFrame(f32 frame) = 0; // 0x108 + virtual void setRate(f32 frame) = 0; // 0x10C + virtual void set_0x164(UNKWORD val) = 0; // 0x114 + + SOUNDSOURCE_VIRTUAL(0x118); + SOUNDSOURCE_VIRTUAL(0x11C); +}; + +class dSoundSource_c : public dSoundSourceIf_c, public dSnd3DActor_c { +public: + dSoundSource_c(u8, dAcBase_c *, UNKWORD, UNKWORD); + virtual ~dSoundSource_c(); + + u32 getRemoConSoundVariant(u32 soundId) const; + + // This is where it gets a bit wild and this class starts mixing in overrides between + // new virtual functions, which causes the vtable to list these functions in exactly this + // order. + virtual void d_s_vt_0x17C(); + virtual void d_s_vt_0x180(); + virtual void d_s_vt_0x184(); + virtual void d_s_vt_0x188(); + virtual void d_s_vt_0x18C(); + virtual void d_s_vt_0x190(); + virtual void d_s_vt_0x194(); + + virtual void d_vt_0x58() override; + + virtual void d_s_vt_0x19C(); + virtual void d_s_vt_0x1A0(); + + virtual void d_vt_0x5C() override; + virtual StartResult + SetupSound(nw4r::snd::SoundHandle *pHandle, u32 soundId, const StartInfo *pStartInfo, void *) override; + + 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 d_s_vt_0x1C8(); + virtual void d_s_vt_0x1CC(); + + virtual void d_vt_0x38(bool flag, int fadeFrames) override; + + virtual void d_s_vt_0x1D4(); + virtual void d_s_vt_0x1D8(); + virtual void d_s_vt_0x1DC(); + virtual void d_s_vt_0x1E0(); + virtual void d_s_vt_0x1E4(); + virtual void d_s_vt_0x1E8(); + + // Overrides of dSoundSourceIf_c + virtual bool hasPlayingSounds() const override; + +private: + // at 0x00: dSoundSourceIf_c vtable + // at 0x04: dSnd3DActor_c sub-object + // at 0x58: thunk-vtable + /* 0xE8 */ u8 field_0xE8[0xF0 - 0xE8]; + + /* 0x0F0 */ UNKWORD field_0x0F0; + /* 0x0F4 */ UNKWORD field_0x0F4; + /* 0x0F8 */ dAcBase_c *mpPlayer; + /* 0x0FC */ u8 field_0x0FC; + /* 0x0FD */ u8 field_0x0FD; + /* 0x0FE */ u8 field_0x0FE; + /* 0x0FF */ u8 field_0x0FF; + /* 0x100 */ u8 field_0x100; + /* 0x101 */ u8 field_0x101; + /* 0x102 */ u8 field_0x102; + /* 0x104 */ UNKWORD field_0x104; + /* 0x108 */ UNKWORD field_0x108; + /* 0x10C */ UNKWORD field_0x10C; + /* 0x110 */ nw4r::ut::List field_0x110; // node offset 0xEC + /* 0x11C */ UNKWORD field_0x11C; + /* 0x120 */ nw4r::ut::List field_0x120; // node offset 0x4 + /* 0x12C */ nw4r::ut::List field_0x12C; // node offset 0x4 + /* 0x138 */ nw4r::ut::Node mNode; + /* 0x140 */ UNKWORD field_0x140; + /* 0x144 */ u8 _0x144[0x154 - 0x144]; + /* 0x154 */ UNKWORD field_0x154; + /* 0x158 */ s16 field_0x158; + /* 0x15A */ s16 field_0x15A; +}; + +#endif diff --git a/include/d/snd/d_snd_util.h b/include/d/snd/d_snd_util.h new file mode 100644 index 00000000..164ae3df --- /dev/null +++ b/include/d/snd/d_snd_util.h @@ -0,0 +1,42 @@ +#ifndef D_SND_UTIL_H +#define D_SND_UTIL_H + +#include "common.h" +#include "egg/core/eggDisposer.h" + +// This setup is only inferred. d/snd uses it all over the place. +// This works for dSndPlayerMgr_c, which has a vtable of its own but the Disposer at offset 0. +// It also works for the factory at 0x80399c20, which calls a base class ctor, +// an inline ctor, and has the Disposer at offset 0x18 + +template <typename T> +struct SndMgrDisposer : public EGG::Disposer { + virtual ~SndMgrDisposer(); + + static T *create(); + static void remove(); +}; + +template <typename T> +SndMgrDisposer<T>::~SndMgrDisposer() { + if (this == T::sDisposer) { + remove(); + } +} + +template <typename T> +T *SndMgrDisposer<T>::create() { + if (T::sInstance == nullptr) { + T::sInstance = new T(); + T::sDisposer = T::sInstance->GetDisposer(); + } + return T::sInstance; +} + +template <typename T> +void SndMgrDisposer<T>::remove() { + T::sInstance = nullptr; + T::sDisposer = nullptr; +} + +#endif diff --git a/include/egg/audio/eggAudioArcPlayerMgr.h b/include/egg/audio/eggAudioArcPlayerMgr.h index 49673250..f9b982c0 100644 --- a/include/egg/audio/eggAudioArcPlayerMgr.h +++ b/include/egg/audio/eggAudioArcPlayerMgr.h @@ -26,12 +26,20 @@ public: void stopAllSound(); u32 changeNameToId(const char *name) { - return mOpenSndArchive->ConvertLabelStringToSoundId(name); + u32 id = -1; + if (mOpenSndArchive != nullptr) { + id = mOpenSndArchive->ConvertLabelStringToSoundId(name); + } + return id; } nw4r::snd::SoundArchivePlayer *getPlayer() { return mActiveSndArchivePlayer; } + nw4r::snd::SoundArchive *getArchive() { + return mOpenSndArchive; + } + void setLoadStringLabels(bool bLoad) { mLoadLabelStringData = bLoad; } @@ -65,12 +73,7 @@ public: virtual bool startSound(nw4r::snd::SoundHandle *handle, const char *name) // at 0x40 { - u32 id = -1; - if (mOpenSndArchive) { - id = changeNameToId(name); - } - - return ArcPlayer::startSound(handle, id); + return ArcPlayer::startSound(handle, changeNameToId(name)); } virtual bool prepareSound(nw4r::snd::SoundHandle *handle, u32 id) // at 0x44 @@ -85,12 +88,7 @@ public: virtual bool prepareSound(nw4r::snd::SoundHandle *handle, const char *name) // at 0x4C { - u32 id = -1; - if (mOpenSndArchive) { - id = changeNameToId(name); - } - - return ArcPlayer::prepareSound(handle, id); + return ArcPlayer::prepareSound(handle, changeNameToId(name)); } virtual bool holdSound(nw4r::snd::SoundHandle *handle, u32 id) // at 0x50 @@ -105,12 +103,7 @@ public: virtual bool holdSound(nw4r::snd::SoundHandle *handle, const char *name) // at 0x58 { - u32 id = -1; - if (mOpenSndArchive) { - id = changeNameToId(name); - } - - return ArcPlayer::holdSound(handle, id); + return ArcPlayer::holdSound(handle, changeNameToId(name)); } private: diff --git a/include/egg/audio/eggAudioHeapMgr.h b/include/egg/audio/eggAudioHeapMgr.h index fa8ef361..9fd269cc 100644 --- a/include/egg/audio/eggAudioHeapMgr.h +++ b/include/egg/audio/eggAudioHeapMgr.h @@ -21,9 +21,38 @@ public: ~SoundHeapMgr() { destroySoundHeap(); } - virtual bool loadState(s32 id) {} - virtual int getCurrentLevel() {} - virtual void stateProc() {} + int saveState() { + return mSoundHeap.SaveState(); + } + virtual bool loadState(s32 id) { + s32 level = mSoundHeap.GetCurrentLevel(); + if (id > 0 && level >= id) { + mSoundHeap.LoadState(id); + return true; + } else { + return false; + } + } + virtual int getCurrentLevel() { + return mSoundHeap.GetCurrentLevel(); + } + virtual void stateProc() { + OSMessage msg; + if (OSReceiveMessage(&mQueue1.mQueue, &msg, 0)) { + bool ok = loadState((s32)msg); + OSSendMessage(&mQueue3.mQueue, (OSMessage)ok, 0); + } + + if (OSReceiveMessage(&mQueue2.mQueue, &msg, 0)) { + int ok = mSoundHeap.SaveState(); + OSSendMessage(&mQueue3.mQueue, (OSMessage)ok, 0); + } + + if (OSReceiveMessage(&mQueue, &msg, 0)) { + int level = getCurrentLevel(); + OSSendMessage(&mQueue3.mQueue, (OSMessage)level, 0); + } + } void createSoundHeap(Allocator *allocator, u32 size); void destroySoundHeap(); @@ -34,7 +63,9 @@ public: private: nw4r::snd::SoundHeap mSoundHeap; - u8 unk[0x68 - 0x38]; + // I guess we're not initializing this queue? + OSMessageQueue mQueue; + OSMessage mBuffer[4]; SoundMessageQueue mQueue1; SoundMessageQueue mQueue2; SoundMessageQueue mQueue3; diff --git a/include/egg/audio/eggAudioUtility.h b/include/egg/audio/eggAudioUtility.h index 6a56ea66..7abb95b9 100644 --- a/include/egg/audio/eggAudioUtility.h +++ b/include/egg/audio/eggAudioUtility.h @@ -12,7 +12,7 @@ namespace EGG { struct MultiArcSimpleAudioMgr { u8 field_0x000[0x0FC - 0x000]; s32 field_0x0FC; - ArcPlayer players[]; + ArcPlayer players[1]; nw4r::snd::SoundArchivePlayer *getPlayer(int i) { return players[i].getPlayer(); diff --git a/include/egg/core/eggDvdRipper.h b/include/egg/core/eggDvdRipper.h index 82fd09b2..8f4b4b48 100644 --- a/include/egg/core/eggDvdRipper.h +++ b/include/egg/core/eggDvdRipper.h @@ -6,7 +6,6 @@ #include "egg/core/eggHeap.h" #include "egg/core/eggStreamDecomp.h" - namespace EGG { class DvdRipper { @@ -28,6 +27,29 @@ public: typedef void (*UnkCallback)(void *); public: + // Not sure + struct Arg { + Arg(const char *path, u8 *pOut, Heap *pHeap, EAllocDirection allocDir, u32 offset, u32 *pRead, u32 *fileSize) + : path(path), + pOut(pOut), + pHeap(pHeap), + allocDir(allocDir), + offset(offset), + pRead(pRead), + fileSize(fileSize) {} + const char *path; + u8 *pOut; + Heap *pHeap; + EAllocDirection allocDir; + u32 offset; + u32 *pRead; + u32 *fileSize; + }; + + static u8 *loadToMainRAM(Arg &arg) { + return loadToMainRAM(arg.path, arg.pOut, arg.pHeap, arg.allocDir, arg.offset, arg.pRead, arg.fileSize); + } + static u8 * loadToMainRAM(s32 entryNum, u8 *pOut, Heap *pHeap, EAllocDirection allocDir, u32 offset, u32 *pRead, u32 *fileSize); diff --git a/include/egg/gfx/eggCamera.h b/include/egg/gfx/eggCamera.h index c3104fb7..67c3853d 100644 --- a/include/egg/gfx/eggCamera.h +++ b/include/egg/gfx/eggCamera.h @@ -35,6 +35,15 @@ protected: class LookAtCamera : public BaseCamera { public: LookAtCamera() : mPos(0.0f, 10.0f, 0.0f), mAt(0.0f, 0.0f, 0.0f), mUp(0.0f, 1.0f, 0.0f) {} + + LookAtCamera& operator=(const LookAtCamera &other) { + mViewMtx.copyFrom(other.mViewMtx); + mOtherMtx.copyFrom(other.mOtherMtx); + mPos = other.mPos; + mAt = other.mAt; + mUp = other.mUp; + return *this; + } // Which way around? virtual Matrix34f &getViewMatrix() override { return mViewMtx; @@ -53,7 +62,15 @@ public: virtual void doDraw() override; virtual Matrix34f &getViewMatrixOld() override; -protected: + Vector3f getDirection() const { + return mAt - mPos; + } + + Vector3f getOtherDirection() const { + return mPos - mAt; + } + +public: /* 0x64 */ Vector3f mPos; /* 0x70 */ Vector3f mAt; /* 0x7C */ Vector3f mUp; diff --git a/include/egg/math/eggMatrix.h b/include/egg/math/eggMatrix.h index a99a0698..d16f2865 100644 --- a/include/egg/math/eggMatrix.h +++ b/include/egg/math/eggMatrix.h @@ -4,6 +4,7 @@ #include "common.h" #include "egg/math/eggQuat.h" #include "egg/math/eggVector.h" +#include "nw4r/math/math_types.h" namespace EGG { @@ -55,6 +56,14 @@ struct Matrix34f { void multiplyTo(const Matrix34f &m2, Matrix34f &to) const; void dump(); + operator nw4r::math::MTX34 *() { + return (nw4r::math::MTX34 *)this; + } + + operator const nw4r::math::MTX34 *() const { + return (nw4r::math::MTX34 *)this; + } + public: void concat(const Matrix34f &, Matrix34f &) const; void rotate(const Vector3f &rpy) const; diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index dd988c4b..543065fb 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -2,11 +2,11 @@ #define NW4R_LYT_LAYOUT_H #include "common.h" -#include "new.h" #include "nw4r/lyt/lyt_animation.h" #include "nw4r/lyt/lyt_types.h" #include "rvl/MEM/mem_allocator.h" +#include <new> namespace nw4r { namespace lyt { diff --git a/include/nw4r/snd/snd_BasicSound.h b/include/nw4r/snd/snd_BasicSound.h index 8fc57508..b3629b19 100644 --- a/include/nw4r/snd/snd_BasicSound.h +++ b/include/nw4r/snd/snd_BasicSound.h @@ -327,40 +327,40 @@ namespace nw4r { namespace snd { namespace detail ExternalSoundPlayer *mExtSoundPlayer; // size 0x04, offset 0x18 AmbientInfo mAmbientInfo; // size 0x14, offset 0x1c SoundParam mAmbientParam; // size 0x24, offset 0x30 - SoundActorParam mActorParam; // size 0x0c, offset 0x54 - MoveValue<f32, int> mFadeVolume; // size 0x10, offset 0x60 - MoveValue<f32, int> mPauseFadeVolume; // size 0x10, offset 0x70 - bool mStartFlag; // size 0x01, offset 0x80 - bool mStartedFlag; // size 0x01, offset 0x81 - bool mAutoStopFlag; // size 0x01, offset 0x82 - bool mFadeOutFlag; // size 0x01, offset 0x83 - PauseState mPauseState; // size 0x04, offset 0x84 - bool mUnPauseFlag; // size 0x01, offset 0x88 + SoundActorParam mActorParam; // size 0x0c, offset 0x58 + MoveValue<f32, int> mFadeVolume; // size 0x10, offset 0x64 + MoveValue<f32, int> mPauseFadeVolume; // size 0x10, offset 0x74 + bool mStartFlag; // size 0x01, offset 0x84 + bool mStartedFlag; // size 0x01, offset 0x85 + bool mAutoStopFlag; // size 0x01, offset 0x86 + bool mFadeOutFlag; // size 0x01, offset 0x87 + PauseState mPauseState; // size 0x04, offset 0x88 + bool mUnPauseFlag; // size 0x01, offset 0x8c /* 3 bytes padding */ - s32 mAutoStopCounter; // size 0x04, offset 0x8c - u32 mUpdateCounter; // size 0x04, offset 0x90 - u8 mPriority; // size 0x01, offset 0x94 - u8 mVoiceOutCount; // size 0x01, offset 0x95 - u8 mBiquadFilterType; // size 0x01, offset 0x96 + s32 mAutoStopCounter; // size 0x04, offset 0x90 + u32 mUpdateCounter; // size 0x04, offset 0x94 + u8 mPriority; // size 0x01, offset 0x98 + u8 mVoiceOutCount; // size 0x01, offset 0x99 + u8 mBiquadFilterType; // size 0x01, offset 0x9a /* 1 byte padding */ - u32 mId; // size 0x04, offset 0x98 - MoveValue<f32, int> mExtMoveVolume; // size 0x10, offset 0x9c - f32 mInitVolume; // size 0x04, offset 0xac - f32 mExtPan; // size 0x04, offset 0xb0 - f32 mExtSurroundPan; // size 0x04, offset 0xb4 - f32 mExtPitch; // size 0x04, offset 0xb8 - f32 mLpfFreq; // size 0x04, offset 0xbc - f32 mBiquadFilterValue; // size 0x04, offset 0xc0 - int mOutputLineFlag; // size 0x04, offset 0xc4 - f32 mMainOutVolume; // size 0x04, offset 0xc8 - f32 mMainSend; // size 0x04, offset 0xcc - f32 mFxSend[AUX_BUS_NUM]; // size 0x0c, offset 0xd0 - f32 mRemoteOutVolume[4]; // size 0x10, offset 0xdc + u32 mId; // size 0x04, offset 0x9c + MoveValue<f32, int> mExtMoveVolume; // size 0x10, offset 0xa0 + f32 mInitVolume; // size 0x04, offset 0xb0 + f32 mExtPan; // size 0x04, offset 0xb4 + f32 mExtSurroundPan; // size 0x04, offset 0xb8 + f32 mExtPitch; // size 0x04, offset 0xbc + f32 mLpfFreq; // size 0x04, offset 0xc0 + f32 mBiquadFilterValue; // size 0x04, offset 0xc4 + int mOutputLineFlag; // size 0x04, offset 0xc8 + f32 mMainOutVolume; // size 0x04, offset 0xcc + f32 mMainSend; // size 0x04, offset 0xd0 + f32 mFxSend[AUX_BUS_NUM]; // size 0x0c, offset 0xd4 + f32 mRemoteOutVolume[4]; // size 0x10, offset 0xe0 public: - ut::LinkListNode mPriorityLink; // size 0x08, offset 0xe0 - ut::LinkListNode mSoundPlayerPlayLink; // size 0x08, offset 0xe8 - ut::LinkListNode mSoundPlayerPriorityLink; // size 0x08, offset 0xf0 - ut::LinkListNode mExtSoundPlayerPlayLink; // size 0x08, offset 0xf8 + ut::LinkListNode mPriorityLink; // size 0x08, offset 0xf0 + ut::LinkListNode mSoundPlayerPlayLink; // size 0x08, offset 0xf8 + ut::LinkListNode mSoundPlayerPriorityLink; // size 0x08, offset 0x100 + ut::LinkListNode mExtSoundPlayerPlayLink; // size 0x08, offset 0x108 // friends private: diff --git a/include/nw4r/snd/snd_Sound3DActor.h b/include/nw4r/snd/snd_Sound3DActor.h index a748bddd..168fafa6 100644 --- a/include/nw4r/snd/snd_Sound3DActor.h +++ b/include/nw4r/snd/snd_Sound3DActor.h @@ -21,8 +21,15 @@ public: // AmbientArgUpdateCallback virtual void at_0x0c(void *arg, detail::BasicSound* sound) override; + const nw4r::math::VEC3 &GetPosition() const { + return mPosition; + } void SetPosition(const math::VEC3 &rPosition); + void SetUserParam(u32 userParam) { + mUserParam = userParam; + } + private: static void ClearUpdateCallback(SoundHandle &rHandle); diff --git a/include/nw4r/snd/snd_Sound3DEngine.h b/include/nw4r/snd/snd_Sound3DEngine.h index e643d5f5..abab43f6 100644 --- a/include/nw4r/snd/snd_Sound3DEngine.h +++ b/include/nw4r/snd/snd_Sound3DEngine.h @@ -19,7 +19,7 @@ public: virtual void UpdateAmbientParam(const Sound3DManager*, const Sound3DParam*, u32, int, SoundAmbientParam*); virtual s32 GetAmbientPriority(const Sound3DManager*, const Sound3DParam*, u32); virtual s32 GetRequiredVoiceOutCount(const Sound3DManager*, const Sound3DParam*, u32); - virtual void UpdateAmbientParam(const Sound3DManager*, const Sound3DParam*, u32, u32, SoundAmbientParam*); + virtual void UpdateAmbientParam(const Sound3DManager*, const Sound3DParam*, u32, u32 flags, SoundAmbientParam*); private: Sound3DCalculator::CalcPanParam mPanParam; // at 0x04 diff --git a/include/nw4r/snd/snd_Sound3DManager.h b/include/nw4r/snd/snd_Sound3DManager.h index 9bfa470c..1c370eef 100644 --- a/include/nw4r/snd/snd_Sound3DManager.h +++ b/include/nw4r/snd/snd_Sound3DManager.h @@ -68,10 +68,18 @@ public: return field_0x20; } + void SetField0x20(f32 value) { + field_0x20 = value; + } + f32 GetField0x24() const { return field_0x24; } + void SetField0x24(f32 value) { + field_0x24 = value; + } + void SetEngine(Sound3DEngine *engine); enum ParamDecayCurve { diff --git a/include/nw4r/snd/snd_SoundHandle.h b/include/nw4r/snd/snd_SoundHandle.h index e400a441..cf1ed317 100644 --- a/include/nw4r/snd/snd_SoundHandle.h +++ b/include/nw4r/snd/snd_SoundHandle.h @@ -39,6 +39,10 @@ namespace nw4r { namespace snd mSound->Stop(0); } + bool IsPause() const { + return IsAttachedSound() && mSound->IsPause(); + } + u32 GetId() const { if (IsAttachedSound()) diff --git a/include/sized_string.h b/include/sized_string.h index dc711238..44e26ebe 100644 --- a/include/sized_string.h +++ b/include/sized_string.h @@ -5,6 +5,7 @@ #include "common.h" #include "string.h" #include "wstring.h" +#include "printf.h" extern "C" bool strequals(const char *a, const char *b); diff --git a/include/sound_mgrs/sound_audio_manager.h b/include/sound_mgrs/sound_audio_manager.h deleted file mode 100644 index 1bfe885c..00000000 --- a/include/sound_mgrs/sound_audio_manager.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef SOUND_AUDIO_MANAGER_H -#define SOUND_AUDIO_MANAGER_H - -#include "common.h" -#include "egg/audio/eggAudioMgr.h" - - -// Size: 0x6d0 -class SndAudioMgr : public EGG::SimpleAudioMgr { -public: -}; - -#endif diff --git a/include/toBeSorted/d_d3d.h b/include/toBeSorted/d_d3d.h index 07e9505d..76cbd010 100644 --- a/include/toBeSorted/d_d3d.h +++ b/include/toBeSorted/d_d3d.h @@ -91,14 +91,14 @@ public: return create2(ac, mdlFile, mdlName, anmName, callback, bufferOption); } - void setSoundSource(SoundSource *pSource); + void setSoundSource(dSoundSourceIf_c *pSource); protected: bool loadSounds(const char *name); void syncAnmFrame(); void setSoundRate(f32 rate); - /* 0x68 */ SoundSource *mpSoundSource; + /* 0x68 */ dSoundSourceIf_c *mpSoundSource; /* 0x6C */ void *mpSoundData; }; diff --git a/include/toBeSorted/music_mgrs.h b/include/toBeSorted/music_mgrs.h index 476c1293..aad42969 100644 --- a/include/toBeSorted/music_mgrs.h +++ b/include/toBeSorted/music_mgrs.h @@ -2,16 +2,18 @@ #define MUSIC_MGRS_H #include "common.h" +#include "d/snd/d_snd_player_mgr.h" -class BgmMgr; +class dSndPlayerMgr_c; -extern "C" BgmMgr *BGM_MGR; +#define BGM_MGR (dSndPlayerMgr_c::GetInstance()) extern "C" void fn_8035E000(); -extern "C" void fn_8035E860(BgmMgr *); -extern "C" void fn_8035E310(BgmMgr *); -extern "C" void fn_8035E820(BgmMgr *); -extern "C" void fn_8035E880(BgmMgr *); -extern "C" void fn_8035E790(BgmMgr *, UNKWORD, void *); +extern "C" void fn_8035E860(dSndPlayerMgr_c *); +extern "C" void fn_8035E310(dSndPlayerMgr_c *); +extern "C" void fn_8035E820(dSndPlayerMgr_c *); +extern "C" void fn_8035E880(dSndPlayerMgr_c *); +extern "C" void fn_8035E790(dSndPlayerMgr_c *, UNKWORD, void *); +extern "C" bool fn_8035ED90(dSndPlayerMgr_c *, u8); extern "C" void *ENEMY_SOUND_MGR; extern "C" void fn_80362150(void *, u16); @@ -21,6 +23,8 @@ extern "C" void fn_80362730(void *); extern "C" void fn_80365D20(void *); extern "C" void fn_803624F0(void *); extern "C" void fn_80364FD0(void *, s32); +extern "C" bool fn_80364DA0(void *); +extern "C" void fn_80364D00(void*, s32); extern "C" void *ENEMY_BGM_RELATED_MGR; extern "C" void fn_80384570(void *, bool); @@ -28,5 +32,10 @@ extern "C" void fn_803858D0(void *); extern "C" void *FANFARE_SOUND_MGR; extern "C" void AnotherSoundMgr__playSound(void *, s32); +extern "C" bool fn_803721F0(void *, u32); +extern "C" bool fn_803720E0(void *, u32); +extern "C" bool fn_80372070(void *, u32); +extern "C" bool fn_803734C0(void *, u32); +extern "C" bool fn_80373550(void *, u32); #endif |
