From fd4d3e0c3498e2a4f0a1a52c5ad16b1dd70b0652 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 2 Nov 2021 13:13:03 +0200 Subject: [PATCH] Allow to change sound driver from ingame (ryzom/ryzomcore#63) --- .../src/interface_v3/action_handler_game.cpp | 116 ++++++++++++++++++ ryzom/client/src/main_loop_utilities.cpp | 13 +- 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/ryzom/client/src/interface_v3/action_handler_game.cpp b/ryzom/client/src/interface_v3/action_handler_game.cpp index 75c9ef0e3..2b55f2c78 100644 --- a/ryzom/client/src/interface_v3/action_handler_game.cpp +++ b/ryzom/client/src/interface_v3/action_handler_game.cpp @@ -95,6 +95,8 @@ #include "nel/gui/ctrl_button.h" #include "../global.h" +#include "nel/sound/u_audio_mixer.h" + using namespace std; using namespace NL3D; using namespace NLMISC; @@ -2984,6 +2986,10 @@ static vector VideoModes; #define GAME_CONFIG_ANISOTROPIC_COMBO "ui:interface:game_config:content:fx:anisotropic_gr:anisotropic" #define GAME_CONFIG_ANISOTROPIC_DB "UI:TEMP:ANISOTROPIC" +// Sound driver +#define GAME_CONFIG_SOUND_DRIVER_COMBO "ui:interface:game_config:content:sound:driver_gr:driver" +#define GAME_CONFIG_SOUND_DRIVER_DB "UI:TEMP:SOUND_DRIVER" + // The 3 possible modes editable (NB: do not allow client.cfg HDEntityTexture==1 and DivideTextureSizeBy2=2 enum TTextureMode {LowTextureMode= 0, NormalTextureMode= 1, HighTextureMode= 2}; @@ -3031,6 +3037,77 @@ void updateVRDevicesComboUI(bool enable) } } +// *************************************************************************** +void updateSoundDriverComboUI() +{ + CDBGroupComboBox *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_SOUND_DRIVER_COMBO)); + if (!pCB) + { + nlwarning("Sound driver UI element '%s' not found", GAME_CONFIG_SOUND_DRIVER_COMBO); + return; + } + + pCB->resetTexts(); + + uint32 selected = 0; + + NLSOUND::UAudioMixer::TDriver cfgDriverId = NLSOUND::UAudioMixer::DriverAuto; + if(ClientCfg.DriverSound==CClientConfig::SoundDrvFMod) + cfgDriverId = NLSOUND::UAudioMixer::DriverFMod; + else if(ClientCfg.DriverSound==CClientConfig::SoundDrvOpenAL) + cfgDriverId = NLSOUND::UAudioMixer::DriverOpenAl; + else if(ClientCfg.DriverSound==CClientConfig::SoundDrvDirectSound) + cfgDriverId = NLSOUND::UAudioMixer::DriverDSound; + else if(ClientCfg.DriverSound==CClientConfig::SoundDrvXAudio2) + cfgDriverId = NLSOUND::UAudioMixer::DriverXAudio2; + + std::vector drivers = NLSOUND::UAudioMixer::getDrivers(); + + // add AUTO for ingame selection, if one is not already in list + bool found = false; + for(uint i = 0; i < drivers.size(); ++i) + { + if (drivers[i].ID == NLSOUND::UAudioMixer::DriverAuto) + { + found = true; + break; + } + } + if (!found) + drivers.insert(drivers.begin(), 1, NLSOUND::UAudioMixer::TDriverInfo(NLSOUND::UAudioMixer::DriverAuto, "Auto")); + + for(uint i = 0; i < drivers.size(); ++i) + { + switch(drivers[i].ID) + { + case NLSOUND::UAudioMixer::DriverAuto: + pCB->addText("Auto"); + break; + case NLSOUND::UAudioMixer::DriverFMod: + pCB->addText("FMod"); + break; + case NLSOUND::UAudioMixer::DriverDSound: + pCB->addText("DirectSound"); + break; + case NLSOUND::UAudioMixer::DriverOpenAl: + pCB->addText("OpenAL"); + break; + case NLSOUND::UAudioMixer::DriverXAudio2: + pCB->addText("XAudio2"); + break; + default: + pCB->addText(drivers[i].Name); + break; + } + + if (cfgDriverId == drivers[i].ID) + selected = i; + } + + NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_SOUND_DRIVER_DB)->setValue32(-1); + NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_SOUND_DRIVER_DB)->setValue32(selected); +} + // *************************************************************************** class CHandlerGameConfigInit : public IActionHandler { @@ -3083,6 +3160,8 @@ public: } CAHManager::getInstance()->runActionHandler("game_config_change_vid_fullscreen",NULL); + updateSoundDriverComboUI(); + // **** Init Texture Size Modes // init the combo box, according to Texture Installed or not pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_TEXTURE_MODE_COMBO )); @@ -3439,6 +3518,32 @@ class CHandlerGameConfigVRDevice : public IActionHandler }; REGISTER_ACTION_HANDLER (CHandlerGameConfigVRDevice, "game_config_change_vr_device"); +// *************************************************************************** +class CHandlerGameConfigSoundDriver : public IActionHandler +{ + virtual void execute (CCtrlBase * pCaller, const string &/* Params */) + { + sint oldDriver = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_SOUND_DRIVER_DB)->getOldValue32(); + sint newDriver = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_SOUND_DRIVER_DB)->getValue32(); + + if (oldDriver != -1 && newDriver != oldDriver) + { + CDBGroupComboBox *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_SOUND_DRIVER_COMBO)); + if (!pCB) + { + nlwarning("Unable to change sound driver. UI '%s' not found.", GAME_CONFIG_SOUND_DRIVER_COMBO); + return; + } + + CDDXManager *pDM = CDDXManager::getInstance(); + CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX); + if(pDDX) + pDDX->validateApplyButton(); + } + } +}; +REGISTER_ACTION_HANDLER (CHandlerGameConfigSoundDriver, "game_config_change_sound_driver"); + // *************************************************************************** class CHandlerGameConfigApply : public IActionHandler { @@ -3545,6 +3650,17 @@ class CHandlerGameConfigApply : public IActionHandler ClientCfg.writeString("VRDisplayDeviceId", VRDeviceCache[deviceIdx].second); } + sint sndDriver = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_SOUND_DRIVER_DB)->getValue32(); + if (sndDriver != -1) + { + CDBGroupComboBox *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_SOUND_DRIVER_COMBO)); + if (pCB) + { + std::string drv = pCB->getText(sndDriver); + ClientCfg.writeString("DriverSound", drv); + } + } + bool requestReboot = false; // **** Apply the texture mode diff --git a/ryzom/client/src/main_loop_utilities.cpp b/ryzom/client/src/main_loop_utilities.cpp index 95dcf82c8..ceccc80af 100644 --- a/ryzom/client/src/main_loop_utilities.cpp +++ b/ryzom/client/src/main_loop_utilities.cpp @@ -324,8 +324,19 @@ void updateFromClientCfg() bool mustReloadSoundMngrContinent= false; // disable/enable sound? - if (ClientCfg.SoundOn != LastClientCfg.SoundOn) + if (ClientCfg.SoundOn != LastClientCfg.SoundOn || ClientCfg.DriverSound != LastClientCfg.DriverSound) { + // changing sound driver + if (ClientCfg.DriverSound != LastClientCfg.DriverSound) + { + if (SoundMngr) + { + nlwarning("Changing sound driver..."); + delete SoundMngr; + SoundMngr = NULL; + } + } + if (SoundMngr && !ClientCfg.SoundOn) { nlwarning("Deleting sound manager...");