Skip to content
Permalink
Browse files

Add client setting to toggle internet sound streams (#834)

* Add new client audio function isSoundStopped

Helps to determine whether a sound is actually created.

* Add new client setting allow_internet_sound_streams

- When disabled, it disables creation of internet sound streams, and destroys existing streams, keeps sound elements, and triggers "onClientSoundStopped" with "disabled" reason
- When enabled, it enables creation of internet sound streams, and creates missing streams and triggers "onClientSoundStarted" with "enabled" reason
- Adds new reason to "onClientSoundStarted": "enabled", which is returned if setting is changed to true
- Adds new reason to "onClientSoundStopped": "disabled", which is returned if setting is changed to false

* Remove test tip text that was meant to be for the Advanced tab

* Rename internet sound streams setting to external sounds

* Update make_uname.bat

* Remove isSoundStopped

Let's rather make a generic client config getter function.

* Fix crash on stream in if sound was not created due to client setting
  • Loading branch information...
patrikjuvonen committed Sep 2, 2019
1 parent 4dc2335 commit bdb8013029fc22e2d50130516663e14885d0ac4e
@@ -1,6 +1,6 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: core/CClientVariables.cpp
* PURPOSE: Managed storage of client variables (cvars)
@@ -331,6 +331,7 @@ void CClientVariables::LoadDefaults()
DEFAULT("high_detail_peds", 0); // Disable rendering high detail peds all the time
DEFAULT("fast_clothes_loading", 1); // 0-off 1-auto 2-on
DEFAULT("allow_screen_upload", 1); // 0-off 1-on
DEFAULT("allow_external_sounds", 1); // 0-off 1-on
DEFAULT("max_clientscript_log_kb", 5000); // Max size in KB (0-No limit)
DEFAULT("display_fullscreen_style", 0); // 0-standard 1-borderless 2-borderless keep res 3-borderless stretch
DEFAULT("display_windowed", 0); // 0-off 1-on
@@ -376,6 +376,11 @@ void CSettings::CreateGUI()
m_pCheckBoxAllowScreenUpload->GetPosition(vecTemp, false);
m_pCheckBoxAllowScreenUpload->AutoSize(NULL, 20.0f);

m_pCheckBoxAllowExternalSounds = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabMultiplayer, _("Allow external sounds"), true));
m_pCheckBoxAllowExternalSounds->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f));
m_pCheckBoxAllowExternalSounds->GetPosition(vecTemp, false);
m_pCheckBoxAllowExternalSounds->AutoSize(NULL, 20.0f);

m_pCheckBoxCustomizedSAFiles = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabMultiplayer, _("Use customized GTA:SA files"), true));
m_pCheckBoxCustomizedSAFiles->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f));
m_pCheckBoxCustomizedSAFiles->GetPosition(vecTemp, false);
@@ -1213,6 +1218,7 @@ void CSettings::CreateGUI()
m_pComboFxQuality->SetSelectionHandler(GUI_CALLBACK(&CSettings::OnFxQualityChanged, this));
m_pCheckBoxVolumetricShadows->SetClickHandler(GUI_CALLBACK(&CSettings::OnVolumetricShadowsClick, this));
m_pCheckBoxAllowScreenUpload->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowScreenUploadClick, this));
m_pCheckBoxAllowExternalSounds->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowExternalSoundsClick, this));
m_pCheckBoxCustomizedSAFiles->SetClickHandler(GUI_CALLBACK(&CSettings::OnCustomizedSAFilesClick, this));
m_pCheckBoxWindowed->SetClickHandler(GUI_CALLBACK(&CSettings::OnWindowedClick, this));
m_pCheckBoxDPIAware->SetClickHandler(GUI_CALLBACK(&CSettings::OnDPIAwareClick, this));
@@ -1506,6 +1512,11 @@ void CSettings::UpdateVideoTab()
CVARS_GET("allow_screen_upload", bAllowScreenUploadEnabled);
m_pCheckBoxAllowScreenUpload->SetSelected(bAllowScreenUploadEnabled);

// Allow external sounds
bool bAllowExternalSoundsEnabled;
CVARS_GET("allow_external_sounds", bAllowExternalSoundsEnabled);
m_pCheckBoxAllowExternalSounds->SetSelected(bAllowExternalSoundsEnabled);

// Customized sa files
m_pCheckBoxCustomizedSAFiles->SetSelected(GetApplicationSettingInt("customized-sa-files-request") != 0);
m_pCheckBoxCustomizedSAFiles->SetVisible(GetApplicationSettingInt("customized-sa-files-show") != 0);
@@ -3333,6 +3344,10 @@ void CSettings::SaveData()
bool bAllowScreenUploadEnabled = m_pCheckBoxAllowScreenUpload->GetSelected();
CVARS_SET("allow_screen_upload", bAllowScreenUploadEnabled);

// Allow external sounds
bool bAllowExternalSoundsEnabled = m_pCheckBoxAllowExternalSounds->GetSelected();
CVARS_SET("allow_external_sounds", bAllowExternalSoundsEnabled);

// Grass
bool bGrassEnabled = m_pCheckBoxGrass->GetSelected();
CVARS_SET("grass", bGrassEnabled);
@@ -4336,6 +4351,24 @@ bool CSettings::OnAllowScreenUploadClick(CGUIElement* pElement)
return true;
}

//
// AllowExternalSounds
//
bool CSettings::OnAllowExternalSoundsClick(CGUIElement* pElement)
{
if (!m_pCheckBoxAllowExternalSounds->GetSelected() && !m_bShownAllowExternalSoundsMessage)
{
m_bShownAllowExternalSoundsMessage = true;
SString strMessage;
strMessage +=
_("Some scripts may play sounds, such as radio, from the internet."
"\n\nDisabling this setting may decrease network"
"\nbandwidth consumption.\n");
CCore::GetSingleton().ShowMessageBox(_("EXTERNAL SOUNDS"), strMessage, MB_BUTTON_OK | MB_ICON_INFO);
}
return true;
}

//
// CustomizedSAFiles
//
@@ -1,6 +1,6 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: core/CSettings.h
* PURPOSE: Header file for in-game settings window class
@@ -152,6 +152,7 @@ class CSettings
CGUICheckBox* m_pCheckBoxDeviceSelectionDialog;
CGUICheckBox* m_pCheckBoxShowUnsafeResolutions;
CGUICheckBox* m_pCheckBoxAllowScreenUpload;
CGUICheckBox* m_pCheckBoxAllowExternalSounds;
CGUICheckBox* m_pCheckBoxCustomizedSAFiles;
CGUICheckBox* m_pCheckBoxGrass;
CGUICheckBox* m_pCheckBoxHeatHaze;
@@ -377,6 +378,7 @@ class CSettings
bool OnFxQualityChanged(CGUIElement* pElement);
bool OnVolumetricShadowsClick(CGUIElement* pElement);
bool OnAllowScreenUploadClick(CGUIElement* pElement);
bool OnAllowExternalSoundsClick(CGUIElement* pElement);
bool OnCustomizedSAFilesClick(CGUIElement* pElement);
bool ShowUnsafeResolutionsClick(CGUIElement* pElement);
bool OnWindowedClick(CGUIElement* pElement);
@@ -443,6 +445,7 @@ class CSettings
DWORD m_dwFrameCount;
bool m_bShownVolumetricShadowsWarning;
bool m_bShownAllowScreenUploadMessage;
bool m_bShownAllowExternalSoundsMessage;
int m_iMaxAnisotropic;

std::list<SKeyBindSection*> m_pKeyBindSections;
@@ -1,9 +1,8 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* (Shared logic for modifications)
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/shared_logic/CClientSound.cpp
* FILE: mods/deathmatch/logic/CClientSound.cpp
* PURPOSE: Sound entity class
*
*****************************************************************************/
@@ -63,12 +62,15 @@ void CClientSound::DistanceStreamIn()
{
if (!m_pAudio)
{
Create();
m_pSoundManager->OnDistanceStreamIn(this);
// If the sound was successfully created, we stream it in
if (Create())
{
m_pSoundManager->OnDistanceStreamIn(this);

// Call Stream In event
CLuaArguments Arguments;
CallEvent("onClientElementStreamIn", Arguments, true);
// Call Stream In event
CLuaArguments Arguments;
CallEvent("onClientElementStreamIn", Arguments, true);
}
}
}

@@ -104,6 +106,11 @@ bool CClientSound::Create()
if (m_pAudio)
return false;

// If we're not allowed to play a stream, stop here
if (m_bStream)
if (!g_pCore->GetCVars()->GetValue("allow_external_sounds", true))
return false;

// Initial state
if (!m_pBuffer)
m_pAudio = new CBassAudio(m_bStream, m_strPath, m_bLoop, m_bThrottle, m_b3D);
@@ -626,6 +633,35 @@ bool CClientSound::IsFxEffectEnabled(uint uiFxEffect)
////////////////////////////////////////////////////////////
void CClientSound::Process3D(const CVector& vecPlayerPosition, const CVector& vecCameraPosition, const CVector& vecLookAt)
{
// If this is a stream
if (m_bStream)
{
// Check if we're allowed to play streams, otherwise just destroy the stream
// This way we can start the stream without the need to handle this edge case in scripting
if (g_pCore->GetCVars()->GetValue("allow_external_sounds", true))
{
if (!m_pAudio)
{
// call onClientSoundStarted
CLuaArguments Arguments;
Arguments.PushString("enabled"); // Reason
CallEvent("onClientSoundStarted", Arguments, false);
Create();
}
}
else
{
if (m_pAudio)
{
// call onClientSoundStopped
CLuaArguments Arguments;
Arguments.PushString("disabled"); // Reason
CallEvent("onClientSoundStopped", Arguments, false);
Destroy();
}
}
}

// Update 3D things if required
if (m_b3D)
{
@@ -1,6 +1,6 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
* PURPOSE: Scripting function processing
@@ -1,6 +1,6 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/CStaticFunctionDefinitions.h
* PURPOSE: Header for static function definitions class
@@ -1,8 +1,8 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.x
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/shared_logic/luadefs/CLuaAudioDefs.cpp
* FILE: mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp
* PURPOSE: Lua audio definitions class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
@@ -1,8 +1,8 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.x
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/shared_logic/luadefs/CLuaAudioDefs.h
* FILE: mods/deathmatch/logic/luadefs/CLuaAudioDefs.h
* PURPOSE: Lua audio definitions class header
*
* Multi Theft Auto is available from http://www.multitheftauto.com/

0 comments on commit bdb8013

Please sign in to comment.
You can’t perform that action at this time.