Index: binaries/data/config/default.cfg =================================================================== --- binaries/data/config/default.cfg +++ binaries/data/config/default.cfg @@ -517,6 +517,7 @@ ambientgain = 0.6 actiongain = 0.7 uigain = 0.7 +maxdistance = 400 [sound.notify] nick = true ; Play a sound when someone mentions your name in the lobby or game Index: source/soundmanager/SoundManager.h =================================================================== --- source/soundmanager/SoundManager.h +++ source/soundmanager/SoundManager.h @@ -81,6 +81,7 @@ int m_BufferCount; bool m_SoundEnabled; bool m_MusicEnabled; + float m_RollOffMaxDist = 400.f; bool m_MusicPaused; bool m_AmbientPaused; @@ -158,6 +159,8 @@ void RunHardwareDetection(); + float GetRollOffMaxDist() const; + void SetAmbientItem(ISoundItem* anItem); void SetMasterGain(float gain); Index: source/soundmanager/SoundManager.cpp =================================================================== --- source/soundmanager/SoundManager.cpp +++ source/soundmanager/SoundManager.cpp @@ -245,11 +245,15 @@ m_RunningPlaylist(false), m_PlayingPlaylist(false), m_LoopingPlaylist(false), m_PlaylistGap(0), m_DistressErrCount(0), m_DistressTime(0) { - CFG_GET_VAL("sound.mastergain", m_Gain); - CFG_GET_VAL("sound.musicgain", m_MusicGain); - CFG_GET_VAL("sound.ambientgain", m_AmbientGain); - CFG_GET_VAL("sound.actiongain", m_ActionGain); - CFG_GET_VAL("sound.uigain", m_UIGain); +#define LINK_TO_CONF(conf, x) \ + g_ConfigDB.RegisterHookAndCall(conf, [this](){ CFG_GET_VAL(conf, x); }) + LINK_TO_CONF("sound.mastergain", m_Gain); + LINK_TO_CONF("sound.musicgain", m_MusicGain); + LINK_TO_CONF("sound.ambientgain", m_AmbientGain); + LINK_TO_CONF("sound.actiongain", m_ActionGain); + LINK_TO_CONF("sound.uigain", m_UIGain); + LINK_TO_CONF("sound.maxdistance", m_RollOffMaxDist); +#undef LINK_TO_CONF AlcInit(); @@ -821,6 +825,11 @@ } } +float CSoundManager::GetRollOffMaxDist() const +{ + return m_RollOffMaxDist; +} + void CSoundManager::RunHardwareDetection() { // OpenAL alGetString might not return anything interesting on certain platforms Index: source/soundmanager/items/CSoundBase.h =================================================================== --- source/soundmanager/items/CSoundBase.h +++ source/soundmanager/items/CSoundBase.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -58,7 +58,7 @@ void EnsurePlay(); void SetGain(ALfloat gain); - void SetRollOff(ALfloat gain); + void SetRollOff(ALfloat gain, ALfloat maxDist); void SetPitch(ALfloat pitch); void SetDirection(const CVector3D& direction); void SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain); Index: source/soundmanager/items/CSoundBase.cpp =================================================================== --- source/soundmanager/items/CSoundBase.cpp +++ source/soundmanager/items/CSoundBase.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -127,14 +127,14 @@ } } -void CSoundBase::SetRollOff(ALfloat rolls) +void CSoundBase::SetRollOff(ALfloat rolls, ALfloat maxDist) { if ( m_ALSource ) { std::lock_guard lock(m_ItemMutex); - alSourcef(m_ALSource, AL_REFERENCE_DISTANCE, 70.0f); + alSourcef(m_ALSource, AL_REFERENCE_DISTANCE, 1.0f); AL_CHECK; - alSourcef(m_ALSource, AL_MAX_DISTANCE, 200.0); + alSourcef(m_ALSource, AL_MAX_DISTANCE, maxDist); AL_CHECK; alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls); AL_CHECK; Index: source/soundmanager/items/ISoundItem.h =================================================================== --- source/soundmanager/items/ISoundItem.h +++ source/soundmanager/items/ISoundItem.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -59,7 +59,7 @@ virtual void SetPitch(float pitch) = 0; virtual void SetGain(float gain) = 0; virtual void SetLocation(const CVector3D& position) = 0; - virtual void SetRollOff(float gain) = 0; + virtual void SetRollOff(float gain, float maxDist) = 0; virtual void Pause() = 0; virtual void Resume() = 0; Index: source/soundmanager/scripting/SoundGroup.cpp =================================================================== --- source/soundmanager/scripting/SoundGroup.cpp +++ source/soundmanager/scripting/SoundGroup.cpp @@ -218,7 +218,7 @@ LOGWARNING("OpenAL: stereo sounds can't be positioned: %s", sndData->GetFileName().string8()); hSound->SetLocation(CVector3D(itemDist * sin(offset), 0, -itemDist * cos(offset))); - hSound->SetRollOff(itemRollOff); + hSound->SetRollOff(itemRollOff, static_cast(g_SoundManager)->GetRollOffMaxDist()); } CmpPtr cmpVisual(*g_Game->GetSimulation2(), source);