Provide a means of overriding the base gain at the group level.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@981 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Andrzej Kapolka
2010-08-12 22:01:08 +00:00
parent 1be717f362
commit d8cda89ab3
3 changed files with 31 additions and 6 deletions
+1 -1
View File
@@ -393,7 +393,7 @@ public class Sound
protected void updateSourceGain ()
{
if (_source != null) {
_source.setGain(_gain * _group.getBaseGain());
_source.setGain(_gain * _group.getInheritedBaseGain());
}
}
+25 -3
View File
@@ -35,6 +35,25 @@ import static com.threerings.openal.Log.log;
*/
public class SoundGroup
{
/**
* Sets the base gain for this group, or -1 to inherit from the manager (the default).
*/
public void setBaseGain (float gain)
{
if (_baseGain != gain) {
_baseGain = gain;
baseGainChanged();
}
}
/**
* Returns the base gain for this group, or -1 if inherited from the manager.
*/
public float getBaseGain ()
{
return _baseGain;
}
/**
* Queues up the specified sound clip for pre-loading into the cache.
*/
@@ -140,15 +159,15 @@ public class SoundGroup
/**
* Used to pass the base gain through to sound effects.
*/
protected float getBaseGain ()
protected float getInheritedBaseGain ()
{
return _manager.getBaseGain();
return (_baseGain < 0f) ? _manager.getBaseGain() : _baseGain;
}
/**
* Called by the manager when the base gain has changed.
*/
protected void baseGainChanged (float gain)
protected void baseGainChanged ()
{
// notify any sound currently holding a source
for (int ii = 0, nn = _sources.size(); ii < nn; ii++) {
@@ -170,4 +189,7 @@ public class SoundGroup
protected ClipProvider _provider;
protected ArrayList<PooledSource> _sources = Lists.newArrayList();
/** The base gain, or -1 to inherit from the manager. */
protected float _baseGain = -1f;
}
@@ -120,9 +120,12 @@ public class SoundManager
}
_baseGain = gain;
// alert the groups
// alert the groups that inherite the gain
for (int ii = 0, nn = _groups.size(); ii < nn; ii++) {
_groups.get(ii).baseGainChanged(gain);
SoundGroup group = _groups.get(ii);
if (group.getBaseGain() < 0f) {
group.baseGainChanged();
}
}
}