Skip to content

Commit

Permalink
Optimize|SFX: Further improvements for sector reverb calculations
Browse files Browse the repository at this point in the history
Only the sector where the listener is in is ever needed for the SFX
playback. It is therefore unnecessary to update the reverb properties
until the listener arrives in a particular sector.

This makes it possible to keep the updates always on even when 3D SFX
is disabled, so that there are no glitches when switching 3D SFX on
and off.
  • Loading branch information
skyjake committed Aug 30, 2012
1 parent 920b36c commit db98ec2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
22 changes: 14 additions & 8 deletions doomsday/engine/portable/include/s_environ.h
Expand Up @@ -30,15 +30,17 @@ extern "C" {
#endif

/**
* Re-calculate the reverb properties of the given sector. Should be called
* whenever any of the properties governing reverb properties have changed
* (i.e. hedge/plane texture or plane height changes).
* Requests re-calculation of the reverb properties of the given sector. Should
* be called whenever any of the properties governing reverb properties have
* changed (i.e. hedge/plane texture or plane height changes).
*
* PRE: BspLeaf attributors must have been determined first.
* Call S_UpdateReverbForSector() to do the actual calculation.
*
* @param sec Ptr to the sector to calculate reverb properties of.
* @pre BspLeaf attributors must have been determined first.
*
* @param sec Sector to calculate reverb properties of.
*/
void S_CalcSectorReverb(Sector* sec);
void S_MarkSectorReverbDirty(Sector* sec);

/**
* Called during map init to determine which BSP leafs affect the reverb
Expand All @@ -49,9 +51,13 @@ void S_CalcSectorReverb(Sector* sec);
void S_DetermineBspLeafsAffectingSectorReverb(GameMap* map);

/**
* Recalculate reverb properties in the sectors where update has been requested.
* Recalculates reverb properties for a sector. One must first mark the sector
* eligible for update using S_MarkSectorReverbDirty() or this function will do
* nothing.
*
* @param sec Sector in which to update reverb properties.
*/
void S_UpdateReverb(void);
void S_UpdateReverbForSector(Sector* sec);

/**
* Must be called when the map changes.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/r_world.c
Expand Up @@ -1806,7 +1806,7 @@ boolean R_UpdateSector(Sector* sec, boolean forceUpdate)
{
Sector_UpdateBaseOrigin(sec);
R_UpdateLinedefsOfSector(sec);
S_CalcSectorReverb(sec);
S_MarkSectorReverbDirty(sec);
changed = true;
}

Expand Down
20 changes: 8 additions & 12 deletions doomsday/engine/portable/src/s_environ.cpp
Expand Up @@ -399,23 +399,19 @@ void S_ResetReverb(void)
reverbUpdateRequested.clear();
}

void S_UpdateReverb(void)
void S_UpdateReverbForSector(Sector* sec)
{
if(sfx3D)
{
if(reverbUpdateRequested.empty()) return;
if(reverbUpdateRequested.empty()) return;

for(ReverbUpdateRequested::iterator i = reverbUpdateRequested.begin(); i != reverbUpdateRequested.end(); ++i)
{
Sector_CalculateReverb(*i);
}
// If update has been requested for this sector, calculate it now.
if(reverbUpdateRequested.find(sec) != reverbUpdateRequested.end())
{
Sector_CalculateReverb(sec);
reverbUpdateRequested.erase(sec);
}
reverbUpdateRequested.clear();
}

void S_CalcSectorReverb(Sector* sec)
void S_MarkSectorReverbDirty(Sector* sec)
{
if(!sfx3D) return;

reverbUpdateRequested.insert(sec);
}
1 change: 0 additions & 1 deletion doomsday/engine/portable/src/s_main.c
Expand Up @@ -200,7 +200,6 @@ BEGIN_PROF( PROF_SOUND_STARTFRAME );

Sfx_StartFrame();
Mus_StartFrame();
S_UpdateReverb();

// Remove stopped sounds from the LSM.
Sfx_PurgeLogical();
Expand Down
5 changes: 5 additions & 0 deletions doomsday/engine/portable/src/s_sfx.c
Expand Up @@ -565,11 +565,16 @@ void Sfx_ListenerUpdate(void)
{
listenerSector = listener->bspLeaf->sector;

// It may be necessary to recalculate the reverb properties.
S_UpdateReverbForSector(listenerSector);

for(i = 0; i < NUM_REVERB_DATA; ++i)
{
vec[i] = listenerSector->reverb[i];
if(i == SRD_VOLUME)
{
vec[i] *= sfxReverbStrength;
}
}

AudioDriver_SFX()->Listenerv(SFXLP_REVERB, vec);
Expand Down

0 comments on commit db98ec2

Please sign in to comment.