Hey, let's not just completely break locking and unlocking sounds

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@645 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Charlie Groves
2008-08-22 02:38:57 +00:00
parent 329bedd523
commit 135b25516e
@@ -108,24 +108,25 @@ public class OpenALSoundPlayer extends SoundPlayer
public void lock (String pkgPath, String... keys) public void lock (String pkgPath, String... keys)
{ {
for (String key : keys) { for (String key : keys) {
final String path = pkgPath + key; for (final String path : getPaths(pkgPath, key)) {
getSoundQueue().postRunnable(new Runnable() { getSoundQueue().postRunnable(new Runnable() {
public void run () { public void run () {
if (_locked.containsKey(path)) { if (_locked.containsKey(path)) {
return; return;
} }
_alSoundManager.loadClip(OpenALSoundPlayer.this, path, _alSoundManager.loadClip(OpenALSoundPlayer.this, path,
new ClipBuffer.Observer() { new ClipBuffer.Observer() {
public void clipFailed (ClipBuffer buffer) { public void clipFailed (ClipBuffer buffer) {
log.warning("Unable to load sound", "path", path); log.warning("Unable to load sound", "path", path);
} }
public void clipLoaded (ClipBuffer buffer) { public void clipLoaded (ClipBuffer buffer) {
_locked.put(path, buffer); _locked.put(path, buffer);
} }
}); });
} }
}); });
}
} }
} }
@@ -135,7 +136,9 @@ public class OpenALSoundPlayer extends SoundPlayer
for (final String key : keys) { for (final String key : keys) {
getSoundQueue().postRunnable(new Runnable() { getSoundQueue().postRunnable(new Runnable() {
public void run () { public void run () {
_locked.remove(pkgPath + key); for (String path : getPaths(pkgPath, key)) {
_locked.remove(path);
}
} }
}); });
} }
@@ -241,6 +244,24 @@ public class OpenALSoundPlayer extends SoundPlayer
} }
} }
/**
* Returns bundle:path for all sounds under key in pkgPath.
*/
protected String[] getPaths (String pkgPath, String key)
{
String bundle = _loader.getBundle(pkgPath);
Preconditions.checkNotNull(bundle,
"Unable to find the bundle name for a package [package=%s, key=%s]", pkgPath, key);
String[] names = _loader.getPaths(pkgPath, key);
Preconditions.checkNotNull(bundle, "No such sound [package=%s, key=%s]", pkgPath, key);
String[] paths = new String[names.length];
for (int ii = 0; ii < paths.length; ii++) {
paths[ii] = bundle + ":" + names[ii];
}
return paths;
}
/** /**
* Extends sound manager to allow sounds to be pulled out of the locked map. * Extends sound manager to allow sounds to be pulled out of the locked map.
*/ */
@@ -310,12 +331,8 @@ public class OpenALSoundPlayer extends SoundPlayer
public SoundGrabber (String pkgPath, String key) public SoundGrabber (String pkgPath, String key)
{ {
String bundle = _loader.getBundle(pkgPath); String[] paths = getPaths(pkgPath, key);
Preconditions.checkNotNull(bundle, path = paths[RandomUtil.getInt(paths.length)];
"Unable to find the bundle name for a package [package=%s, key=%s]", pkgPath, key);
String[] names = _loader.getPaths(pkgPath, key);
Preconditions.checkNotNull(bundle, "No such sound [package=%s, key=%s]", pkgPath, key);
path = bundle + ":" + names[RandomUtil.getInt(names.length)];
} }
public void run () public void run ()