From 81abfe0d306bbea1b18ce000ed0fc6593d19b957 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 14 Apr 2011 20:33:28 +0000 Subject: [PATCH] - Keep the current/desired state of the sound up to date and add a method to check if a sound is pending, (ie. set to play but hasn't finished buffering) git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1160 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../java/com/threerings/openal/Sound.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/threerings/openal/Sound.java b/src/main/java/com/threerings/openal/Sound.java index 9e445390..1446df05 100644 --- a/src/main/java/com/threerings/openal/Sound.java +++ b/src/main/java/com/threerings/openal/Sound.java @@ -265,10 +265,9 @@ public class Sound */ public void pause () { + _stateDesired = AL10.AL_PAUSED; if (_source != null) { _source.pause(); - } else { - _stateDesired = AL10.AL_PAUSED; } } @@ -278,10 +277,9 @@ public class Sound */ public void stop () { + _stateDesired = AL10.AL_STOPPED; if (_source != null) { _source.stop(); - } else { - _stateDesired = AL10.AL_STOPPED; } } @@ -293,6 +291,14 @@ public class Sound return _source != null && _source.isPlaying(); } + /** + * Called to check if this sound wants to start playing. + */ + public boolean isPending () + { + return _stateDesired == AL10.AL_PLAYING; + } + protected Sound (SoundGroup group, ClipBuffer buffer) { _group = group; @@ -306,6 +312,7 @@ public class Sound if (obs != null) { obs.soundStarted(null); } + _stateDesired = AL10.AL_INVALID; return false; } @@ -332,6 +339,7 @@ public class Sound // left hanging if (obs != null && _stateDesired != AL10.AL_STOPPED) { obs.soundStarted(Sound.this); + _stateDesired = AL10.AL_INVALID; } } }); @@ -341,6 +349,7 @@ public class Sound if (obs != null) { obs.soundStarted(null); } + _stateDesired = AL10.AL_INVALID; return false; } } @@ -354,6 +363,7 @@ public class Sound if (_source == null) { _source = _group.acquireSource(this); if (_source == null) { + _stateDesired = AL10.AL_INVALID; return false; } @@ -424,7 +434,7 @@ public class Sound protected Source _source; /** The desired state of the sound (stopped, playing, paused) after resolution. */ - protected int _stateDesired; + protected int _stateDesired = AL10.AL_INVALID; /** Whether or not looping is desired after resolution. */ protected boolean _loopDesired;