From 423b57a5015df80ee258f610e7d3d4a419a4add8 Mon Sep 17 00:00:00 2001 From: AMS21 Date: Wed, 8 Nov 2023 22:12:12 +0100 Subject: [PATCH] xrSound: Allow engine to run with no sound devices available --- src/xrGame/GamePersistent.cpp | 2 +- src/xrGame/script_sound.cpp | 2 +- src/xrGame/ui/UIGameTutorial.cpp | 2 +- src/xrGame/ui/UIGameTutorialSimpleItem.cpp | 2 +- src/xrGame/ui/UIGameTutorialVideoItem.cpp | 2 +- src/xrSound/Sound.h | 2 ++ src/xrSound/SoundRender_Core.cpp | 6 ++++++ src/xrSound/SoundRender_Core.h | 2 ++ src/xrSound/SoundRender_CoreA.cpp | 4 ++-- 9 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/xrGame/GamePersistent.cpp b/src/xrGame/GamePersistent.cpp index 5eb2bb968fd..fc3d9b24313 100644 --- a/src/xrGame/GamePersistent.cpp +++ b/src/xrGame/GamePersistent.cpp @@ -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 diff --git a/src/xrGame/script_sound.cpp b/src/xrGame/script_sound.cpp index e221e4be82f..0a050b4a3b0 100644 --- a/src/xrGame/script_sound.cpp +++ b/src/xrGame/script_sound.cpp @@ -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); diff --git a/src/xrGame/ui/UIGameTutorial.cpp b/src/xrGame/ui/UIGameTutorial.cpp index 509b67e1632..a826da72766 100644 --- a/src/xrGame/ui/UIGameTutorial.cpp +++ b/src/xrGame/ui/UIGameTutorial.cpp @@ -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, ""); diff --git a/src/xrGame/ui/UIGameTutorialSimpleItem.cpp b/src/xrGame/ui/UIGameTutorialSimpleItem.cpp index 4d9f6304d8b..b8a4a229bbb 100644 --- a/src/xrGame/ui/UIGameTutorialSimpleItem.cpp +++ b/src/xrGame/ui/UIGameTutorialSimpleItem.cpp @@ -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); diff --git a/src/xrGame/ui/UIGameTutorialVideoItem.cpp b/src/xrGame/ui/UIGameTutorialVideoItem.cpp index b01c8b2b69d..d877a6a803a 100644 --- a/src/xrGame/ui/UIGameTutorialVideoItem.cpp +++ b/src/xrGame/ui/UIGameTutorialVideoItem.cpp @@ -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); diff --git a/src/xrSound/Sound.h b/src/xrSound/Sound.h index 7431823cb9e..53862a23739 100644 --- a/src/xrSound/Sound.h +++ b/src/xrSound/Sound.h @@ -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; diff --git a/src/xrSound/SoundRender_Core.cpp b/src/xrSound/SoundRender_Core.cpp index fcbb0db110c..b90dd30056a 100644 --- a/src/xrSound/SoundRender_Core.cpp +++ b/src/xrSound/SoundRender_Core.cpp @@ -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; +} diff --git a/src/xrSound/SoundRender_Core.h b/src/xrSound/SoundRender_Core.h index a743f4bcc47..1e3f2f5af3f 100644 --- a/src/xrSound/SoundRender_Core.h +++ b/src/xrSound/SoundRender_Core.h @@ -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; diff --git a/src/xrSound/SoundRender_CoreA.cpp b/src/xrSound/SoundRender_CoreA.cpp index ae37ab407b9..5d9dc792010 100644 --- a/src/xrSound/SoundRender_CoreA.cpp +++ b/src/xrSound/SoundRender_CoreA.cpp @@ -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; } }