Skip to content

Commit

Permalink
✨ Also apply the obstruction filter if a sound is obstructed by an actor
Browse files Browse the repository at this point in the history
I think the loop for determining whether a sound belongs to an actor or not should be put into its function. But where? Sound class?
  • Loading branch information
Hiradur committed Oct 1, 2024
1 parent 8025c52 commit 82b19c7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
38 changes: 33 additions & 5 deletions source/main/audio/SoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,39 @@ void SoundManager::updateObstructionFilter(const ALuint hardware_source)
obstacle_was_detected = intersection.first;
}

/*
TODO: Also check if trucks are obstructing the sound.
Trucks shouldn't obstruct their own sound sources since the obstruction is most likely
already contained in the recording.
*/
// Check if an actor is obstructing the sound
const ActorPtrVec& actors = App::GetGameContext()->GetActorManager()->GetActors();
bool soundsource_belongs_to_current_actor = false;
for(const ActorPtr actor : actors)
{
// Trucks shouldn't obstruct their own sound sources since the
// obstruction is most likely already contained in the recording.
for (int soundsource_index = 0; soundsource_index < actor->ar_num_soundsources; ++soundsource_index)
{
const soundsource_t& soundsource = actor->ar_soundsources[soundsource_index];
const int num_sounds = soundsource.ssi->getTemplate()->getNumSounds();
for (int num_sound = 0; num_sound < num_sounds; ++num_sound)
{
if (soundsource.ssi->getSound(num_sound) == corresponding_sound)
{
soundsource_belongs_to_current_actor = true;
}
}
if (soundsource_belongs_to_current_actor) { break; }
}

if (soundsource_belongs_to_current_actor)
{
continue;
}

intersection = direct_path_to_sound.intersects(actor->ar_bounding_box);
if (intersection.first)
{
obstacle_was_detected = true;
break;
}
}

obstruction_filter_has_to_be_applied = obstacle_was_detected;
}
Expand Down
1 change: 1 addition & 0 deletions source/main/audio/SoundManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#pragma once

#include "Actor.h"
#include "Application.h"
#include "Collisions.h"
#include "GameContext.h"
Expand Down

0 comments on commit 82b19c7

Please sign in to comment.