Skip to content

Commit

Permalink
xrSound: final polishing refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Dec 4, 2023
1 parent dfa50c2 commit 16f742f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
7 changes: 7 additions & 0 deletions src/xrSound/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
33 changes: 17 additions & 16 deletions src/xrSound/Sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};

Expand All @@ -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;
Expand All @@ -307,7 +308,7 @@ class CSound_UserData : public xr_resource

using CSound_UserDataPtr = resptr_core<CSound_UserData, resptr_base<CSound_UserData>>;

class CSound : public xr_resource
struct CSound : public xr_resource
{
public:
//shared_str nm;
Expand All @@ -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
Expand Down Expand Up @@ -355,7 +353,7 @@ struct resptrcode_sound : public resptr_base<CSound>
[[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));
Expand All @@ -364,11 +362,14 @@ struct resptrcode_sound : public resptr_base<CSound>

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_)
Expand All @@ -390,23 +391,23 @@ struct resptrcode_sound : public resptr_base<CSound>
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;
VerSndUnlocked();
DefaultSoundScene->play(static_cast<ref_sound&>(*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;
VerSndUnlocked();
DefaultSoundScene->play_at_pos(static_cast<ref_sound&>(*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;
Expand All @@ -431,7 +432,7 @@ struct resptrcode_sound : public resptr_base<CSound>
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())
Expand All @@ -444,9 +445,9 @@ struct resptrcode_sound : public resptr_base<CSound>
}

[[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());
}
Expand Down
7 changes: 0 additions & 7 deletions src/xrSound/SoundRender_Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/xrSound/SoundRender_Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions src/xrSound/SoundRender_Emitter_streamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 16f742f

Please sign in to comment.