Skip to content

Commit

Permalink
✨ Add option to force obstruction filter when inside an actor
Browse files Browse the repository at this point in the history
There is no simple way to tell whether a truck has a closed cabin or not. This option exists to force the obstruction filter inside an actor if desired.

Since the check if the listener is inside the player's coupled actor is based on the actor's AAB, the obstruction filter might get enabled if the listener is close to but not inside the actor.

Future work: it might be better to perform line of sight checks against the mesh of a vehicle, which could solve both problems.
  • Loading branch information
Hiradur committed Dec 21, 2024
1 parent 7c7ae43 commit 470eb85
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions source/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 17 additions & 4 deletions source/main/audio/SoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,17 +953,30 @@ 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
* and the filter has to be applied or no obstruction was detected.
*/

std::pair<bool, Ogre::Real> 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
Expand Down
4 changes: 4 additions & 0 deletions source/main/gui/panels/GUI_GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>() == EfxReverbEngine::EAXREVERB)
Expand Down
1 change: 1 addition & 0 deletions source/main/system/CVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*/);
Expand Down

0 comments on commit 470eb85

Please sign in to comment.