diff options
| author | robojumper <robojumper@gmail.com> | 2025-06-04 23:47:43 +0200 |
|---|---|---|
| committer | robojumper <robojumper@gmail.com> | 2025-06-04 23:47:43 +0200 |
| commit | 35ae04fdf94b0210446ccdebef2d66171095a124 (patch) | |
| tree | 64303d75e9fcffdc1af80182362a29d4c80c7a78 /include | |
| parent | e9935e62330417c89601d11c5f92d6a11bc18926 (diff) | |
Refactoring
Diffstat (limited to 'include')
| -rw-r--r-- | include/d/snd/d_snd_3d_actor.h | 2 | ||||
| -rw-r--r-- | include/d/snd/d_snd_3d_manager.h | 23 | ||||
| -rw-r--r-- | include/d/snd/d_snd_area_sound.h | 38 | ||||
| -rw-r--r-- | include/d/snd/d_snd_area_sound_effect_mgr.h | 39 | ||||
| -rw-r--r-- | include/d/snd/d_snd_control_player_mgr.h | 20 | ||||
| -rw-r--r-- | include/d/snd/d_snd_player_mgr.h | 17 | ||||
| -rw-r--r-- | include/d/snd/d_snd_small_effect_mgr.h | 31 | ||||
| -rw-r--r-- | include/d/snd/d_snd_sound.h | 14 | ||||
| -rw-r--r-- | include/d/snd/d_snd_util.h | 29 | ||||
| -rw-r--r-- | include/d/snd/d_snd_wzsound.h (renamed from include/toBeSorted/small_sound_mgr.h) | 19 | ||||
| -rw-r--r-- | include/nw4r/snd/snd_SoundHandle.h | 7 |
11 files changed, 162 insertions, 77 deletions
diff --git a/include/d/snd/d_snd_3d_actor.h b/include/d/snd/d_snd_3d_actor.h index dd33d42d..5c8642f1 100644 --- a/include/d/snd/d_snd_3d_actor.h +++ b/include/d/snd/d_snd_3d_actor.h @@ -52,8 +52,6 @@ public: void updatePositionRelativeToListener(); void updateDistanceToListener(); - void resetFloats(); - bool checkFlag(u16 flag) const { return (mFlags & flag); } diff --git a/include/d/snd/d_snd_3d_manager.h b/include/d/snd/d_snd_3d_manager.h index 09b127fb..679e7963 100644 --- a/include/d/snd/d_snd_3d_manager.h +++ b/include/d/snd/d_snd_3d_manager.h @@ -9,24 +9,10 @@ #include "nw4r/snd/snd_Sound3DListener.h" #include "nw4r/snd/snd_Sound3DManager.h" -class dSnd3DManager_c; -extern template class SndMgrDisposer<dSnd3DManager_c>; +SND_DISPOSER_FORWARD_DECL(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; + SND_DISPOSER_MEMBERS(dSnd3DManager_c); public: dSnd3DManager_c(); @@ -37,8 +23,8 @@ public: void resetCamDistance(); void calc(); void clearState(); - - nw4r::snd::Sound3DManager& getManager() { + + nw4r::snd::Sound3DManager &getManager() { return mManager; } @@ -59,7 +45,6 @@ public: } private: - void updateListenerPos(f32); /* 0x10 */ bool mIsSetup; /* 0x11 */ bool mCalculationsFresh; diff --git a/include/d/snd/d_snd_area_sound.h b/include/d/snd/d_snd_area_sound.h new file mode 100644 index 00000000..963fefeb --- /dev/null +++ b/include/d/snd/d_snd_area_sound.h @@ -0,0 +1,38 @@ +#ifndef D_SND_AREA_SOUND_H +#define D_SND_AREA_SOUND_H + +#include "common.h" +#include "d/snd/d_snd_sound.h" + +/** A sound class used for dSndAreaSoundEffectMgr */ +class dSndAreaSound_c : public dSndSound_c { +public: + dSndAreaSound_c(); + + virtual void cancel() override; // 0x08 + virtual void calc() override; // 0x0C + virtual void fadeIn(u32 id, s32 fadeFrames) override; // 0x10 + + virtual void initCallback(u32 id); // 0x28 + + typedef void (*Callback)(dSndAreaSound_c &sound); + + using dSndSound_c::pause; + + void pause(s32 fadeFrames); + void unpause(s32 fadeFrames); + +private: + bool isFadingOut() const { + return mIsFadingOut && IsAttachedSound(); + } + + /* 0x0F0 */ bool field_0xF0; + /* 0x0F4 */ Callback mpCalcCallback; + /* 0x0F8 */ UNKWORD field_0xF8; + /* 0x0FC */ UNKWORD field_0xFC; + /* 0x100 */ UNKWORD field_0x100; + /* 0x104 */ UNKWORD field_0x104; +}; + +#endif diff --git a/include/d/snd/d_snd_area_sound_effect_mgr.h b/include/d/snd/d_snd_area_sound_effect_mgr.h new file mode 100644 index 00000000..aa4f7f72 --- /dev/null +++ b/include/d/snd/d_snd_area_sound_effect_mgr.h @@ -0,0 +1,39 @@ +#ifndef D_SND_AREA_SOUND_EFFECT_MGR_H +#define D_SND_AREA_SOUND_EFFECT_MGR_H + +#include "common.h" +#include "d/snd/d_snd_actor.h" +#include "d/snd/d_snd_area_sound.h" +#include "d/snd/d_snd_util.h" + +SND_DISPOSER_FORWARD_DECL(dSndAreaSoundEffectMgr_c); + +/** + * A singleton sound actor for playing persistent environmental background + * sound effects. Turn this off and the Faron birds will stop singing. + * + * Plays sounds like SE_A_F100 (hence the name, not sure if it's the real meaning). + */ +class dSndAreaSoundEffectMgr_c { + SND_DISPOSER_MEMBERS(dSndAreaSoundEffectMgr_c) + +public: + dSndAreaSoundEffectMgr_c(); + + bool startSound(u32 soundId, u32 handleIdx); + void calc(); + void stopSounds(s32 fadeFrames); + +private: + bool isPlayingAnySound() const; + bool isPlayingSound(u32 soundId) const; + + /* 0x010 */ dSndAreaSound_c mSounds[3]; + /* 0x328 */ UNKWORD field_0x328; + /* 0x32C */ f32 field_0x32C; + /* 0x330 */ f32 field_0x330; + /* 0x334 */ dSndActor_c mActor; + /* 0x388 */ f32 field_0x388; +}; + +#endif diff --git a/include/d/snd/d_snd_control_player_mgr.h b/include/d/snd/d_snd_control_player_mgr.h index 057f2e81..d3b7654e 100644 --- a/include/d/snd/d_snd_control_player_mgr.h +++ b/include/d/snd/d_snd_control_player_mgr.h @@ -32,24 +32,10 @@ Notes on player groups: 17: TgSound */ -class dSndControlPlayerMgr_c; -extern template class SndMgrDisposer<dSndControlPlayerMgr_c>; +SND_DISPOSER_FORWARD_DECL(dSndControlPlayerMgr_c); class dSndControlPlayerMgr_c { -public: - SndMgrDisposer<dSndControlPlayerMgr_c> *GetDisposer() { - return &mDisposer; - } - - static dSndControlPlayerMgr_c *GetInstance() { - return sInstance; - } - - static dSndControlPlayerMgr_c *sInstance; - static SndMgrDisposer<dSndControlPlayerMgr_c> *sDisposer; - -private: - SndMgrDisposer<dSndControlPlayerMgr_c> mDisposer; + SND_DISPOSER_MEMBERS(dSndControlPlayerMgr_c); public: enum PlayerCtrl_e { @@ -87,7 +73,7 @@ private: void unlinkCtrl(dSndControlPlayer_c *); void setControlValue(PlayerCtrl_e ctrlType, u32 playerIdx, f32 value, s32 frames); f32 getAppliedPlayerVolume(u32 playerIdx) const; - f32 getControlVolumeTarget(PlayerCtrl_e ctrlType, u32 playerIdx) const; + f32 getControlTarget(PlayerCtrl_e ctrlType, u32 playerIdx) const; /* 0x10 */ dSndControlPlayer_c *mpCtrls[CTRL_MAX]; /* 0x1C */ f32 *mpTargetVolumes; diff --git a/include/d/snd/d_snd_player_mgr.h b/include/d/snd/d_snd_player_mgr.h index f80a07af..81ea7e61 100644 --- a/include/d/snd/d_snd_player_mgr.h +++ b/include/d/snd/d_snd_player_mgr.h @@ -7,8 +7,7 @@ #include "nw4r/snd/snd_SoundHandle.h" #include "nw4r/snd/snd_SoundStartable.h" -class dSndPlayerMgr_c; -extern template class SndMgrDisposer<dSndPlayerMgr_c>; +SND_DISPOSER_FORWARD_DECL(dSndPlayerMgr_c); /** * The main interface for managing sound stuff. Will delegate to dSndMgr_c for @@ -16,19 +15,7 @@ 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; + SND_DISPOSER_MEMBERS(dSndPlayerMgr_c); public: dSndPlayerMgr_c(); diff --git a/include/d/snd/d_snd_small_effect_mgr.h b/include/d/snd/d_snd_small_effect_mgr.h new file mode 100644 index 00000000..84ebbfb1 --- /dev/null +++ b/include/d/snd/d_snd_small_effect_mgr.h @@ -0,0 +1,31 @@ +#ifndef D_SND_SMALL_EFFECT_MGR_H +#define D_SND_SMALL_EFFECT_MGR_H + +#include "d/snd/d_snd_util.h" +#include "d/snd/d_snd_wzsound.h" // IWYU pragma: export +#include "nw4r/snd/snd_SoundHandle.h" + + +SND_DISPOSER_FORWARD_DECL(dSndSmallEffectMgr_c); + +/** + * An interface for playing the SE_S ("sound effect, small"?) sounds. + */ +class dSndSmallEffectMgr_c { + SND_DISPOSER_MEMBERS(dSndSmallEffectMgr_c) + +public: + dSndSmallEffectMgr_c(); + + void playSound(u32 soundId); + void playSoundWithPitch(u32 soundId, f32 pitch); + void playButtonPressSoundWhenAdvancingTextBoxes(f32); + +private: + /* 0x10 */ void *field_0x10; + /* 0x14 */ void *field_0x14; + /* 0x18 */ void *field_0x18; + /* 0x1C */ nw4r::snd::SoundHandle mHandles[3]; +}; + +#endif diff --git a/include/d/snd/d_snd_sound.h b/include/d/snd/d_snd_sound.h index 78d95398..c2b865da 100644 --- a/include/d/snd/d_snd_sound.h +++ b/include/d/snd/d_snd_sound.h @@ -136,14 +136,14 @@ public: dSndSound_c(); ~dSndSound_c(); - virtual void cancel(); // 0x08 - virtual void executeCtrls(); // 0x0C - virtual void fadeIn(u32 id, s32 fadeFrames); // 0x10 + virtual void cancel(); // 0x08 + virtual void calc(); // 0x0C + virtual void fadeIn(u32 id, s32 fadeFrames); // 0x10 virtual nw4r::snd::SoundStartable::StartResult prepareSound(u32 soundId, u32 startOffset); // 0x14 virtual nw4r::snd::SoundStartable::StartResult prepareSound(const char *label, u32 startOffset); // 0x18 - virtual void onPreparing(u32 soundId, u32 startOffset); // 0x1C - virtual void stop(s32 fadeFrames); // 0x20 - virtual void pause(bool pauseFlag, s32 fadeFrames); // 0x24 + virtual void onPreparing(u32 soundId, u32 startOffset); // 0x1C + virtual void stop(s32 fadeFrames); // 0x20 + virtual void pause(bool pauseFlag, s32 fadeFrames); // 0x24 bool isStrmSound(); bool isWaveSound(); @@ -173,7 +173,7 @@ public: void linkCtrl(dSndControlSound_c *); void unlinkCtrl(dSndControlSound_c *); -private: +protected: bool cannotStart() const { return mIsRunning && !mIsFadingOut && IsAttachedSound(); } diff --git a/include/d/snd/d_snd_util.h b/include/d/snd/d_snd_util.h index 164ae3df..5040fa50 100644 --- a/include/d/snd/d_snd_util.h +++ b/include/d/snd/d_snd_util.h @@ -39,4 +39,33 @@ void SndMgrDisposer<T>::remove() { T::sDisposer = nullptr; } +#define SND_DISPOSER_FORWARD_DECL(class_name) \ + class class_name; \ + extern template class SndMgrDisposer<class_name>; + +#define SND_DISPOSER_DEFINE(class_name) \ + template class SndMgrDisposer<class_name>; \ + class_name *class_name::sInstance; \ + SndMgrDisposer<class_name> *class_name::sDisposer; + +#define SND_DISPOSER_MEMBERS(class_name) \ +public: \ + SndMgrDisposer<class_name> *GetDisposer() { \ + return &mDisposer; \ + } \ + \ + static class_name *GetInstance() { \ + return sInstance; \ + } \ + \ + static void create() { \ + SndMgrDisposer<class_name>::create(); \ + } \ + \ + static class_name *sInstance; \ + static SndMgrDisposer<class_name> *sDisposer; \ + \ +private: \ + SndMgrDisposer<class_name> mDisposer; + #endif diff --git a/include/toBeSorted/small_sound_mgr.h b/include/d/snd/d_snd_wzsound.h index 06978ad1..63da34c9 100644 --- a/include/toBeSorted/small_sound_mgr.h +++ b/include/d/snd/d_snd_wzsound.h @@ -1,9 +1,8 @@ -#ifndef SMALL_SOUND_MGR_H -#define SMALL_SOUND_MGR_H +#ifndef D_SND_WZSOUND_H +#define D_SND_WZSOUND_H // Thanks kiwi! https://gist.github.com/kiwi515/47bb17b07ed502bdfa7faa60bc48a3c7 -#include "common.h" enum WZSound { /* 0x0000 */ SE_L_FLIPED, /* 0x0001 */ SE_L_FS_START, @@ -6469,18 +6468,4 @@ enum WZSound { /* 0x193D */ LABEL_SOUND_END }; -class SmallSoundManager { -public: - void playSound(WZSound id); - void playSoundWithPitch(WZSound id, f32 pitch); - void playButtonPressSoundWhenAdvancingTextBoxes(f32); - - static SmallSoundManager *GetInstance() { - return sInstance; - } - -private: - static SmallSoundManager *sInstance; -}; - #endif diff --git a/include/nw4r/snd/snd_SoundHandle.h b/include/nw4r/snd/snd_SoundHandle.h index 5c969c1c..bca2c59a 100644 --- a/include/nw4r/snd/snd_SoundHandle.h +++ b/include/nw4r/snd/snd_SoundHandle.h @@ -64,6 +64,13 @@ namespace nw4r { namespace snd return IsAttachedSound() && mSound->IsPause(); } + int GetRemainingFadeFrames() const { + if (IsAttachedSound()) + return mSound->GetRemainingFadeFrames(); + + return 0; + } + u32 GetId() const { if (IsAttachedSound()) |
