diff --git a/source/main/Application.cpp b/source/main/Application.cpp index f2426ee684..e07c47c2db 100644 --- a/source/main/Application.cpp +++ b/source/main/Application.cpp @@ -217,6 +217,7 @@ CVar* audio_engine_controls_environmental_audio; CVar* audio_efx_reverb_engine; CVar* audio_default_efx_preset; CVar* audio_force_listener_efx_preset; +CVar* audio_force_obstruction_inside_vehicles; CVar* audio_device_name; CVar* audio_doppler_factor; CVar* audio_menu_music; diff --git a/source/main/Application.h b/source/main/Application.h index b4b93e6cac..6b9d06db28 100644 --- a/source/main/Application.h +++ b/source/main/Application.h @@ -454,6 +454,7 @@ extern CVar* io_invert_orbitcam; extern CVar* audio_master_volume; extern CVar* audio_enable_creak; extern CVar* audio_enable_obstruction; +extern CVar* audio_force_obstruction_inside_vehicles; extern CVar* audio_enable_occlusion; extern CVar* audio_enable_directed_sounds; extern CVar* audio_enable_reflection_panning; diff --git a/source/main/audio/SoundManager.cpp b/source/main/audio/SoundManager.cpp index 071771130f..bf82c0b53b 100644 --- a/source/main/audio/SoundManager.cpp +++ b/source/main/audio/SoundManager.cpp @@ -953,8 +953,19 @@ bool SoundManager::IsHardwareSourceObstructed(const int hardware_index) const { if (hardware_sources_map[hardware_index] == -1) { return false; } // no sound assigned to hardware source - const SoundPtr& corresponding_sound = audio_sources[hardware_sources_map[hardware_index]]; - bool obstruction_detected = false; + /* + * There is no simple way to know whether a truck has a closed cabin or not; hence + * provide an option to always force obstruction if the player is inside a vehicle. + */ + if + ( + App::audio_force_obstruction_inside_vehicles->getBool() + && App::GetGameContext()->GetPlayerCharacter()->GetActorCoupling() != nullptr + && App::GetGameContext()->GetPlayerCharacter()->GetActorCoupling()->ar_bounding_box.contains(m_listener_position) + ) + { + return true; + } /* * Perform various line of sight checks until either a collision was detected @@ -962,8 +973,10 @@ bool SoundManager::IsHardwareSourceObstructed(const int hardware_index) const */ std::pair intersection; - const Ogre::Vector3 direction_to_sound = corresponding_sound->getPosition() - m_listener_position; - const Ogre::Ray direct_path_to_sound = Ray(m_listener_position, direction_to_sound); + const SoundPtr& corresponding_sound = audio_sources[hardware_sources_map[hardware_index]]; + const Ogre::Vector3 direction_to_sound = corresponding_sound->getPosition() - m_listener_position; + const Ogre::Ray direct_path_to_sound = Ray(m_listener_position, direction_to_sound); + bool obstruction_detected = false; // perform line of sight check against collision meshes // for this to work correctly, the direction vector of the ray must have diff --git a/source/main/gui/panels/GUI_GameSettings.cpp b/source/main/gui/panels/GUI_GameSettings.cpp index 691638232e..cabd3758a4 100644 --- a/source/main/gui/panels/GUI_GameSettings.cpp +++ b/source/main/gui/panels/GUI_GameSettings.cpp @@ -336,6 +336,10 @@ void GameSettings::DrawAudioSettings() { DrawGCombo(App::audio_efx_reverb_engine, _LC("GameSettings", "OpenAL Reverb engine"), m_combo_items_efx_reverb_engine.c_str()); DrawGCheckbox(App::audio_enable_obstruction, _LC("GameSettings", "Sound obstruction")); + if (App::audio_enable_obstruction->getBool()) + { + DrawGCheckbox(App::audio_force_obstruction_inside_vehicles, _LC("GameSettings", "Force obstruction inside vehicles")); + } DrawGCheckbox(App::audio_enable_occlusion, _LC("GameSettings", "Sound occlusion")); DrawGCheckbox(App::audio_enable_directed_sounds, _LC("GameSettings", "Directed sounds (exhausts etc.)")); if (App::audio_efx_reverb_engine->getEnum() == EfxReverbEngine::EAXREVERB) diff --git a/source/main/system/CVar.cpp b/source/main/system/CVar.cpp index 6fef8fbb3b..6f3b7dd7b1 100644 --- a/source/main/system/CVar.cpp +++ b/source/main/system/CVar.cpp @@ -163,6 +163,7 @@ void Console::cVarSetupBuiltins() App::audio_efx_reverb_engine = this->cVarCreate("audio_efx_reverb_engine", "OpenAL EFX Reverb Engine", CVAR_ARCHIVE | CVAR_TYPE_INT, "2"/*(int)EfxReverbEngine::EAXREVERB*/); App::audio_default_efx_preset = this->cVarCreate("audio_default_efx_preset", "OpenAL default EFX preset", CVAR_ARCHIVE); App::audio_force_listener_efx_preset = this->cVarCreate("audio_force_listener_efx_preset", "OpenAL forced listener EFX preset", CVAR_ARCHIVE); + App::audio_force_obstruction_inside_vehicles = this->cVarCreate("audio_force_obstruction_inside_vehicles", "Force obstruction inside vehicles", CVAR_ARCHIVE | CVAR_TYPE_BOOL, "false"); App::gfx_flares_mode = this->cVarCreate("gfx_flares_mode", "Lights", CVAR_ARCHIVE | CVAR_TYPE_INT, "4"/*(int)GfxFlaresMode::ALL_VEHICLES_ALL_LIGHTS*/); App::gfx_polygon_mode = this->cVarCreate("gfx_polygon_mode", "Polygon mode", CVAR_TYPE_INT, "1"/*(int)Ogre::PM_SOLID*/);