Use the new LRUHashMap removal observer mechanism.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3672 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2005-08-05 20:26:01 +00:00
parent 237419b179
commit d668c91b9b
2 changed files with 11 additions and 4 deletions
@@ -27,14 +27,12 @@ import java.nio.IntBuffer;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.openal.AL10; import org.lwjgl.openal.AL10;
import com.samskivert.util.LRUHashMap;
import com.samskivert.util.ObserverList; import com.samskivert.util.ObserverList;
/** /**
* Represents a sound that has been loaded into the OpenAL system. * Represents a sound that has been loaded into the OpenAL system.
*/ */
public class ClipBuffer public class ClipBuffer
implements LRUHashMap.LRUItem
{ {
/** Used to notify parties interested in when a clip is loaded. */ /** Used to notify parties interested in when a clip is loaded. */
public static interface Observer public static interface Observer
@@ -164,8 +162,10 @@ public class ClipBuffer
} }
} }
// documentation inherited from interface LRUHashMap.LRUItem /**
public void removedFromMap (LRUHashMap map) * Frees up the internal audio buffers associated with this clip.
*/
public void dispose ()
{ {
if (_bufferId != null) { if (_bufferId != null) {
// we've been given the boot, free up our buffer // we've been given the boot, free up our buffer
@@ -120,6 +120,13 @@ public class SoundManager
return; return;
} }
// configure our LRU map with a removal observer
_clips.setRemovalObserver(new LRUHashMap.RemovalObserver() {
public void removedFromMap (LRUHashMap map, Object item) {
((ClipBuffer)item).dispose();
}
});
// create our loading queue // create our loading queue
_toLoad = new Queue(); _toLoad = new Queue();