From 16f742feb1fc01d452cc09ad00cdf822d36bfd2f Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Mon, 4 Dec 2023 23:26:18 +0500 Subject: [PATCH] xrSound: final polishing refactoring --- src/xrSound/Sound.cpp | 7 +++++ src/xrSound/Sound.h | 33 ++++++++++---------- src/xrSound/SoundRender_Core.cpp | 7 ----- src/xrSound/SoundRender_Core.h | 1 - src/xrSound/SoundRender_Emitter_streamer.cpp | 6 ++-- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/xrSound/Sound.cpp b/src/xrSound/Sound.cpp index f26d697a69e..b4707943095 100644 --- a/src/xrSound/Sound.cpp +++ b/src/xrSound/Sound.cpp @@ -73,3 +73,10 @@ SoundEnvironment_LIB* CSoundManager::get_env_library() const { return soundEnvironment; } + +void CSoundManager::refresh_env_library() +{ + env_unload(); + env_load(); + SoundRender->env_apply(); +} diff --git a/src/xrSound/Sound.h b/src/xrSound/Sound.h index 2a7271246f1..46792fd06f1 100644 --- a/src/xrSound/Sound.h +++ b/src/xrSound/Sound.h @@ -22,7 +22,7 @@ constexpr pcstr SNDENV_FILENAME = "sEnvironment.xr"; // refs class IGameObject; -class CSound; +struct CSound; struct resptrcode_sound; class ISoundScene; class XRSOUND_API CSound_params; @@ -241,7 +241,7 @@ inline ISoundScene::~ISoundScene() = default; class XRSOUND_API XR_NOVTABLE ISoundManager { protected: - friend class CSound; + friend struct CSound; friend struct resptrcode_sound; virtual CSound* create(pcstr fName, esound_type sound_type, int game_type, bool replaceWithNoSound = true) = 0; @@ -271,7 +271,6 @@ class XRSOUND_API XR_NOVTABLE ISoundManager virtual const Fvector& listener_position() = 0; - virtual void refresh_env_library() = 0; virtual void refresh_sources() = 0; }; @@ -288,11 +287,13 @@ class XRSOUND_API CSoundManager void Create(); void Destroy(); + [[nodiscard]] bool IsSoundEnabled() const; - SoundEnvironment_LIB* get_env_library() const; void env_load(); void env_unload(); + void refresh_env_library(); + SoundEnvironment_LIB* get_env_library() const; }; class CSound_UserDataVisitor; @@ -307,7 +308,7 @@ class CSound_UserData : public xr_resource using CSound_UserDataPtr = resptr_core>; -class CSound : public xr_resource +struct CSound : public xr_resource { public: //shared_str nm; @@ -323,9 +324,6 @@ class CSound : public xr_resource u32 dwBytesTotal{}; float fTimeTotal{}; - - ~CSound() override { GEnv.Sound->destroy(*this); } - float get_length_sec() const { return fTimeTotal; } }; /*! \class ref_sound @@ -355,7 +353,7 @@ struct resptrcode_sound : public resptr_base [[nodiscard]] ICF CSound_UserDataPtr _g_userdata() const { VERIFY(p_); return p_ ? p_->g_userdata : nullptr; } - bool create(pcstr name, esound_type sound_type, int game_type, bool replaceWithNoSound = true) + ICF bool create(pcstr name, esound_type sound_type, int game_type, bool replaceWithNoSound = true) { VerSndUnlocked(); _set(GEnv.Sound->create(name, sound_type, game_type, replaceWithNoSound)); @@ -364,11 +362,14 @@ struct resptrcode_sound : public resptr_base ICF void destroy() { + if (!p_) + return; VerSndUnlocked(); + GEnv.Sound->destroy(*p_); _set(nullptr); } - void attach_tail(pcstr name) const + ICF void attach_tail(pcstr name) const { VerSndUnlocked(); if (!p_) @@ -390,7 +391,7 @@ struct resptrcode_sound : public resptr_base p_->s_type = sound_type; } - void play(IGameObject* O, u32 flags = 0, float delay = 0.f) + ICF void play(IGameObject* O, u32 flags = 0, float delay = 0.f) { if (!p_ || !DefaultSoundScene) return; @@ -398,7 +399,7 @@ struct resptrcode_sound : public resptr_base DefaultSoundScene->play(static_cast(*this), O, flags, delay); } - void play_at_pos(IGameObject* O, const Fvector& pos, u32 flags = 0, float delay = 0.f) + ICF void play_at_pos(IGameObject* O, const Fvector& pos, u32 flags = 0, float delay = 0.f) { if (!p_ || !DefaultSoundScene) return; @@ -406,7 +407,7 @@ struct resptrcode_sound : public resptr_base DefaultSoundScene->play_at_pos(static_cast(*this), O, pos, flags, delay); } - void play_no_feedback(IGameObject* O, u32 flags = 0, float delay = 0.f, Fvector* pos = nullptr, float* vol = nullptr, float* freq = nullptr, Fvector2* range = nullptr) + ICF void play_no_feedback(IGameObject* O, u32 flags = 0, float delay = 0.f, Fvector* pos = nullptr, float* vol = nullptr, float* freq = nullptr, Fvector2* range = nullptr) { if (!p_ || !DefaultSoundScene) return; @@ -431,7 +432,7 @@ struct resptrcode_sound : public resptr_base return _feedback() ? _feedback()->get_params() : nullptr; } - void set_params(CSound_params* p) const + ICF void set_params(CSound_params* p) const { VerSndUnlocked(); if (CSound_emitter* const feedback = _feedback()) @@ -444,9 +445,9 @@ struct resptrcode_sound : public resptr_base } [[nodiscard]] - ICF float get_length_sec() const { return p_ ? p_->get_length_sec() : 0.0f; } + ICF float get_length_sec() const { return p_ ? p_->fTimeTotal : 0.0f; } - IC static void VerSndUnlocked() + static void VerSndUnlocked() { VERIFY(!GEnv.Sound->i_locked()); } diff --git a/src/xrSound/SoundRender_Core.cpp b/src/xrSound/SoundRender_Core.cpp index 910363d4a78..5fd9127597c 100644 --- a/src/xrSound/SoundRender_Core.cpp +++ b/src/xrSound/SoundRender_Core.cpp @@ -220,13 +220,6 @@ void CSoundRender_Core::update_listener(const Fvector& P, const Fvector& D, cons m_effects->commit(); } -void CSoundRender_Core::refresh_env_library() -{ - Parent.env_unload(); - Parent.env_load(); - env_apply(); -} - void CSoundRender_Core::refresh_sources() { stop_emitters(); diff --git a/src/xrSound/SoundRender_Core.h b/src/xrSound/SoundRender_Core.h index a33df9e0e7d..4b38eaa3281 100644 --- a/src/xrSound/SoundRender_Core.h +++ b/src/xrSound/SoundRender_Core.h @@ -101,7 +101,6 @@ class CSoundRender_Core : public ISoundManager // virtual const Fvector& listener_position ( )=0; virtual void update_listener(const Fvector& P, const Fvector& D, const Fvector& N, float dt) = 0; - void refresh_env_library() override; void refresh_sources() override; public: diff --git a/src/xrSound/SoundRender_Emitter_streamer.cpp b/src/xrSound/SoundRender_Emitter_streamer.cpp index 7f41274858d..59f55354898 100644 --- a/src/xrSound/SoundRender_Emitter_streamer.cpp +++ b/src/xrSound/SoundRender_Emitter_streamer.cpp @@ -153,12 +153,10 @@ void CSoundRender_Emitter::fill_block(void* ptr, u32 size) u32 CSoundRender_Emitter::get_bytes_total() const { - u32 res = owner_data->dwBytesTotal; - return res; + return owner_data->dwBytesTotal; } float CSoundRender_Emitter::get_length_sec() const { - float res = owner_data->get_length_sec(); - return res; + return owner_data->fTimeTotal; }