Skip to content

Commit

Permalink
xrSound: Allow engine to run with no sound devices available
Browse files Browse the repository at this point in the history
  • Loading branch information
AMS21 committed Nov 25, 2023
1 parent a501d11 commit 423b57a
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/xrGame/GamePersistent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void CGamePersistent::WeathersUpdate()
snd.play_at_pos(nullptr, pos);

#ifdef DEBUG
if (!snd._handle() && strstr(Core.Params, "-nosound"))
if (!snd._handle() && !GEnv.Sound->is_enabled())
continue;
#endif // DEBUG

Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/script_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

CScriptSound::CScriptSound(LPCSTR caSoundName, ESoundTypes sound_type)
{
m_bIsNoSound = strstr(Core.Params, "-nosound");
m_bIsNoSound = !GEnv.Sound->is_enabled();
m_caSoundToPlay = caSoundName;
string_path l_caFileName;
VERIFY(GEnv.Sound);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/ui/UIGameTutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool CUISequencer::Start(LPCSTR tutor_name)
if (snd_name && snd_name[0])
{
m_global_sound.create(snd_name, st_Effect, sg_Undefined);
VERIFY(m_global_sound._handle() || strstr(Core.Params, "-nosound"));
VERIFY(m_global_sound._handle() || !GEnv.Sound->is_enabled());
}
m_start_lua_function = uiXml.Read("function_on_start", 0, "");
m_stop_lua_function = uiXml.Read("function_on_stop", 0, "");
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/ui/UIGameTutorialSimpleItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void CUISequenceSimpleItem::Load(CUIXml* xml, int idx)
if (m_snd_name && m_snd_name[0])
{
m_sound.create(m_snd_name, st_Effect, sg_Undefined);
VERIFY(m_sound._handle() || strstr(Core.Params, "-nosound"));
VERIFY(m_sound._handle() || !GEnv.Sound->is_enabled());
}
m_time_length = xml->ReadFlt("length_sec", 0, 0);
m_desired_cursor_pos.x = xml->ReadAttribFlt("cursor_pos", 0, "x", 0);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/ui/UIGameTutorialVideoItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void CUISequenceVideoItem::Load(CUIXml* xml, int idx)
m_sound[0] = one;
}

VERIFY(m_sound[0]._handle() || strstr(Core.Params, "-nosound"));
VERIFY(m_sound[0]._handle() || !GEnv.Sound->is_enabled());
}

xml->SetLocalRoot(_stored_root);
Expand Down
2 changes: 2 additions & 0 deletions src/xrSound/Sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ class XRSOUND_API XR_NOVTABLE ISoundManager
virtual void refresh_sources() = 0;
virtual void set_environment(u32 id, CSound_environment** dst_env) = 0;
virtual void set_environment_size(CSound_environment* src_env, CSound_environment** dst_env) = 0;

virtual bool is_enabled() const = 0;
};

class CSound_UserDataVisitor;
Expand Down
6 changes: 6 additions & 0 deletions src/xrSound/SoundRender_Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,9 @@ void CSoundRender_Core::set_environment(u32 id, CSound_environment** dst_env)
#endif
}*/
}

[[nodiscard]] bool CSoundRender_Core::is_enabled() const
{
static bool no_sound = strstr(Core.Params, "-nosound") != nullptr;
return bPresent && !no_sound;
}
2 changes: 2 additions & 0 deletions src/xrSound/SoundRender_Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class CSoundRender_Core : public ISoundManager
bool bUserEnvironment;
bool bReady;

[[nodiscard]] bool is_enabled() const override;

CTimer Timer;
CTimer TimerPersistent; // time-factor is always 1.0f
float fTimer_Value;
Expand Down
4 changes: 2 additions & 2 deletions src/xrSound/SoundRender_CoreA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void CSoundRender_CoreA::_initialize_devices_list()

if (0 == pDeviceList->GetNumDevices())
{
CHECK_OR_EXIT(0, "OpenAL: Can't create sound device.");
xr_delete(pDeviceList);
Log("! SOUND: OpenAL: No sound devices found.");
bPresent = false;
}
}

Expand Down

0 comments on commit 423b57a

Please sign in to comment.