Skip to content

Commit

Permalink
Sector|World|Client: Sector now manages environmental audio updates i…
Browse files Browse the repository at this point in the history
…nternally
  • Loading branch information
danij-deng committed Aug 16, 2013
1 parent c62f7d1 commit ec2590a
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 157 deletions.
27 changes: 0 additions & 27 deletions doomsday/client/include/audio/s_environ.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include "api_uri.h"

class Sector;

enum AudioEnvironmentId
{
AE_NONE = -1,
Expand All @@ -48,31 +46,6 @@ struct AudioEnvironment
int dampingMul;
};

/**
* 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., wall/plane material or plane height changes).
*
* Call S_UpdateReverbForSector() to do the actual calculation.
*
* @param sec Sector to calculate reverb properties of.
*/
void S_MarkSectorReverbDirty(Sector *sec);

/**
* Recalculates reverb properties for a sector. One must first mark the sector
* as needing an update using S_MarkSectorReverbDirty() or this function will do
* nothing.
*
* @param sec Sector in which to update reverb properties.
*/
void S_UpdateReverbForSector(Sector *sec);

/**
* Must be called when the map changes.
*/
void S_ResetReverb();

/**
* Lookup the symbolic name of the identified audio environment.
*/
Expand Down
16 changes: 11 additions & 5 deletions doomsday/client/include/world/sector.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,20 +429,26 @@ class Sector : public de::MapElement
/**
* Perform initialization for environmental audio (reverb). Duties include
* determining the set of BSP leafs which will contribute to the final audio
* characteristics (reverb) of the sector. To be called when initializing
* the map after load.
* characteristics of the sector. To be called when initializing the map after
* loading.
*
* The BspLeaf Blockmap for the owning map must be prepared before calling.
*/
void initReverb();

/**
* Recalculate environmental audio (reverb) for the sector.
* Request re-calculation of the environmental audio (reverb) characteristics
* for the sector (update is deferred until next accessed).
*
* Should be called whenever any of the properties governing reverb properties
* have changed (i.e., wall/plane material changes).
*/
void updateReverb();
void markReverbDirty(bool yes = true);

/**
* Returns the final environmental audio characteristics (reverb) of the sector.
* Provides access to the final environmental audio characteristics (reverb)
* of the sector. Note that if a reverb update is scheduled it will be done
* at this time (@ref markReverbDirty()).
*/
AudioEnvironmentFactors const &reverb() const;

Expand Down
18 changes: 9 additions & 9 deletions doomsday/client/include/world/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ class Surface : public de::MapElement
DENG2_ERROR(MissingMaterialError);

/*
* Observers to be notified when the normal vector changes.
*/
DENG2_DEFINE_AUDIENCE(NormalChange,
void normalChanged(Surface &surface, de::Vector3f oldNormal,
int changedAxes /*bit-field (0x1=X, 0x2=Y, 0x4=Z)*/))
/*
* Observers to be notified when the @em sharp material origin changes.
* Notified when the @em sharp material origin changes.
*/
DENG2_DEFINE_AUDIENCE(MaterialOriginChange,
void materialOriginChanged(Surface &surface, de::Vector2f oldMaterialOrigin,
int changedAxes /*bit-field (0x1=X, 0x2=Y)*/))
/*
* Observers to be notified when the opacity changes.
* Notified when the normal vector changes.
*/
DENG2_DEFINE_AUDIENCE(NormalChange,
void normalChanged(Surface &surface, de::Vector3f oldNormal,
int changedAxes /*bit-field (0x1=X, 0x2=Y, 0x4=Z)*/))
/*
* Notified when the opacity changes.
*/
DENG2_DEFINE_AUDIENCE(OpacityChange,
void opacityChanged(Surface &surface, float oldOpacity))

/*
* Observers to be notified when the tint color changes.
* Notified when the tint color changes.
*/
DENG2_DEFINE_AUDIENCE(TintColorChange,
void tintColorChanged(Surface &sector, de::Vector3f const &oldTintColor,
Expand Down
30 changes: 0 additions & 30 deletions doomsday/client/src/audio/s_environ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@
* 02110-1301 USA</small>
*/

#include <set>

#include "de_base.h"
#include "de_audio.h"
#include "de_play.h"
#include "de_resource.h"

#include "BspLeaf"
#include "Sector"

#include "audio/s_environ.h"
Expand All @@ -43,9 +38,6 @@ static AudioEnvironment envInfo[1 + NUM_AUDIO_ENVIRONMENTS] = {
{"Cloth", 5, 5, 255}
};

typedef std::set<Sector *> ReverbUpdateRequested;
ReverbUpdateRequested reverbUpdateRequested;

char const *S_AudioEnvironmentName(AudioEnvironmentId id)
{
DENG_ASSERT(id >= AE_NONE && id < NUM_AUDIO_ENVIRONMENTS);
Expand Down Expand Up @@ -83,25 +75,3 @@ AudioEnvironmentId S_AudioEnvironmentId(uri_s const *uri)
}
return AE_NONE;
}

void S_ResetReverb()
{
reverbUpdateRequested.clear();
}

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

// If update has been requested for this sector, calculate it now.
if(reverbUpdateRequested.find(sec) != reverbUpdateRequested.end())
{
sec->updateReverb();
reverbUpdateRequested.erase(sec);
}
}

void S_MarkSectorReverbDirty(Sector* sec)
{
reverbUpdateRequested.insert(sec);
}
6 changes: 0 additions & 6 deletions doomsday/client/src/audio/s_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ void S_MapChange(void)

#ifdef __CLIENT__
Sfx_MapChange();

S_ResetReverb();
#endif
}

Expand All @@ -182,10 +180,6 @@ void S_Reset(void)
Sfx_Reset();
#endif
_api_S.StopMusic();

#ifdef __CLIENT__
S_ResetReverb();
#endif
}

void S_StartFrame(void)
Expand Down
4 changes: 1 addition & 3 deletions doomsday/client/src/audio/s_sfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,7 @@ void Sfx_ListenerUpdate()
{
listenerSector = listener->bspLeaf->sectorPtr();

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

// It may be necessary to recalculate the reverb properties...
AudioEnvironmentFactors const &envFactors = listenerSector->reverb();

for(int i = 0; i < NUM_REVERB_DATA; ++i)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/dd_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3028,7 +3028,7 @@ DENG_EXTERN_C void R_SetupMap(int mode, int flags)
sector->updateSoundEmitterOrigin();
#ifdef __CLIENT__
map.updateMissingMaterialsForLinesOfSector(*sector);
S_MarkSectorReverbDirty(sector);
sector->markReverbDirty();
#endif
}

Expand Down
Loading

0 comments on commit ec2590a

Please sign in to comment.