Exploratory house cleaning

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@611 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Charlie Groves
2008-08-07 18:11:31 +00:00
parent 3122ae7e65
commit 1949014c76
6 changed files with 38 additions and 35 deletions
@@ -131,7 +131,7 @@ public class ClipBuffer
_state = LOADED; _state = LOADED;
_manager.restoreClip(this); _manager.restoreClip(this);
} }
// if we're already loaded, this is easy // if we're already loaded, this is easy
if (_state == LOADED) { if (_state == LOADED) {
if (observer != null) { if (observer != null) {
@@ -182,7 +182,7 @@ public class ClipBuffer
_state = UNLOADING; _state = UNLOADING;
return; return;
} }
// free up our buffer // free up our buffer
AL10.alDeleteBuffers(_bufferId); AL10.alDeleteBuffers(_bufferId);
_bufferId = null; _bufferId = null;
@@ -255,12 +255,12 @@ public class ClipBuffer
/** /**
* Notifies the buffer that a source has been bound to it. * Notifies the buffer that a source has been bound to it.
*/ */
protected void sourceBound () protected void sourceBound ()
{ {
_bound++; _bound++;
} }
/** /**
* Notifies the buffer that a source has been unbound from it. * Notifies the buffer that a source has been unbound from it.
*/ */
@@ -271,15 +271,15 @@ public class ClipBuffer
dispose(); dispose();
} }
} }
protected SoundManager _manager; protected SoundManager _manager;
protected ClipProvider _provider; protected ClipProvider _provider;
protected String _path; protected String _path;
protected int _state; protected int _state;
protected IntBuffer _bufferId; protected IntBuffer _bufferId;
protected int _size; protected int _size;
protected ObserverList _observers = protected ObserverList<Observer> _observers =
new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY); new ObserverList<Observer>(ObserverList.FAST_UNSAFE_NOTIFY);
protected int _bound; protected int _bound;
protected static final int UNLOADED = 0; protected static final int UNLOADED = 0;
@@ -58,19 +58,19 @@ public class FileStream extends Stream
_queue.add(new QueuedFile(file, loop)); _queue.add(new QueuedFile(file, loop));
} }
// documentation inherited @Override
protected int getFormat () protected int getFormat ()
{ {
return _decoder.getFormat(); return _decoder.getFormat();
} }
// documentation inherited @Override
protected int getFrequency () protected int getFrequency ()
{ {
return _decoder.getFrequency(); return _decoder.getFrequency();
} }
// documentation inherited @Override
protected int populateBuffer (ByteBuffer buf) protected int populateBuffer (ByteBuffer buf)
throws IOException throws IOException
{ {
@@ -39,7 +39,7 @@ import javazoom.jl.decoder.SampleBuffer;
*/ */
public class Mp3StreamDecoder extends StreamDecoder public class Mp3StreamDecoder extends StreamDecoder
{ {
// documentation inherited @Override
public void init (InputStream in) public void init (InputStream in)
throws IOException throws IOException
{ {
@@ -52,19 +52,19 @@ public class Mp3StreamDecoder extends StreamDecoder
_decoder = new Decoder(); _decoder = new Decoder();
} }
// documentation inherited @Override
public int getFormat () public int getFormat ()
{ {
return AL10.AL_FORMAT_STEREO16; return AL10.AL_FORMAT_STEREO16;
} }
// documentation inherited @Override
public int getFrequency () public int getFrequency ()
{ {
return _header.frequency(); return _header.frequency();
} }
// documentation inherited @Override
public int read (ByteBuffer buf) public int read (ByteBuffer buf)
throws IOException throws IOException
{ {
@@ -43,7 +43,7 @@ import com.jcraft.jorbis.Info;
*/ */
public class OggStreamDecoder extends StreamDecoder public class OggStreamDecoder extends StreamDecoder
{ {
// documentation inherited @Override
public void init (InputStream in) public void init (InputStream in)
throws IOException throws IOException
{ {
@@ -84,19 +84,19 @@ public class OggStreamDecoder extends StreamDecoder
_offsets = new int[_info.channels]; _offsets = new int[_info.channels];
} }
// documentation inherited @Override
public int getFormat () public int getFormat ()
{ {
return (_info.channels == 1) ? AL10.AL_FORMAT_MONO16 : AL10.AL_FORMAT_STEREO16; return (_info.channels == 1) ? AL10.AL_FORMAT_MONO16 : AL10.AL_FORMAT_STEREO16;
} }
// documentation inherited @Override
public int getFrequency () public int getFrequency ()
{ {
return _info.rate; return _info.rate;
} }
// documentation inherited @Override
public int read (ByteBuffer buf) public int read (ByteBuffer buf)
throws IOException throws IOException
{ {
@@ -21,14 +21,13 @@
package com.threerings.openal; package com.threerings.openal;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.WeakHashMap;
import org.lwjgl.openal.AL; import org.lwjgl.openal.AL;
import org.lwjgl.openal.AL10; import org.lwjgl.openal.AL10;
import com.google.common.collect.Maps;
import com.samskivert.util.LRUHashMap; import com.samskivert.util.LRUHashMap;
import com.samskivert.util.Queue; import com.samskivert.util.Queue;
import com.samskivert.util.RunQueue; import com.samskivert.util.RunQueue;
@@ -121,7 +120,7 @@ public class SoundManager
{ {
return _streams; return _streams;
} }
/** /**
* Updates all of the streams controlled by the manager. This should be called once per frame * Updates all of the streams controlled by the manager. This should be called once per frame
* by the application. * by the application.
@@ -183,7 +182,7 @@ public class SoundManager
}); });
// create our loading queue // create our loading queue
_toLoad = new Queue(); _toLoad = new Queue<ClipBuffer>();
// start up the background loader thread // start up the background loader thread
_loader.setDaemon(true); _loader.setDaemon(true);
@@ -250,7 +249,7 @@ public class SoundManager
{ {
_clips.put(buffer.getKey(), buffer); _clips.put(buffer.getKey(), buffer);
} }
/** /**
* Adds a stream to the list maintained by the manager. Called by streams when they are * Adds a stream to the list maintained by the manager. Called by streams when they are
* created. * created.
@@ -259,7 +258,7 @@ public class SoundManager
{ {
_streams.add(stream); _streams.add(stream);
} }
/** /**
* Removes a stream from the list maintained by the manager. Called by streams when they are * Removes a stream from the list maintained by the manager. Called by streams when they are
* disposed. * disposed.
@@ -268,12 +267,13 @@ public class SoundManager
{ {
_streams.remove(stream); _streams.remove(stream);
} }
/** The thread that loads up sound clips in the background. */ /** The thread that loads up sound clips in the background. */
protected Thread _loader = new Thread("SoundManager.Loader") { protected Thread _loader = new Thread("SoundManager.Loader") {
@Override
public void run () { public void run () {
while (true) { while (true) {
final ClipBuffer buffer = (ClipBuffer)_toLoad.get(); final ClipBuffer buffer = _toLoad.get();
try { try {
log.debug("Loading " + buffer.getKey() + "."); log.debug("Loading " + buffer.getKey() + ".");
final Clip clip = buffer.load(); final Clip clip = buffer.load();
@@ -308,18 +308,18 @@ public class SoundManager
protected float _baseGain = 1; protected float _baseGain = 1;
/** Contains a mapping of all currently-loading clips. */ /** Contains a mapping of all currently-loading clips. */
protected HashMap<Comparable,ClipBuffer> _loading = new HashMap<Comparable,ClipBuffer>(); protected HashMap<Comparable,ClipBuffer> _loading = Maps.newHashMap();
/** Contains a mapping of all loaded clips. */ /** Contains a mapping of all loaded clips. */
protected LRUHashMap<Comparable,ClipBuffer> _clips = protected LRUHashMap<Comparable,ClipBuffer> _clips =
new LRUHashMap<Comparable,ClipBuffer>(DEFAULT_CACHE_SIZE, _sizer); new LRUHashMap<Comparable,ClipBuffer>(DEFAULT_CACHE_SIZE, _sizer);
/** Contains a queue of clip buffers waiting to be loaded. */ /** Contains a queue of clip buffers waiting to be loaded. */
protected Queue _toLoad; protected Queue<ClipBuffer> _toLoad;
/** The list of active streams. */ /** The list of active streams. */
protected ArrayList<Stream> _streams = new ArrayList<Stream>(); protected ArrayList<Stream> _streams = new ArrayList<Stream>();
/** The one and only sound manager, here for an exclusive performance by special request. /** The one and only sound manager, here for an exclusive performance by special request.
* Available for all your sound playing needs. */ * Available for all your sound playing needs. */
protected static SoundManager _soundmgr; protected static SoundManager _soundmgr;
@@ -30,6 +30,8 @@ import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import com.google.common.collect.Maps;
import static com.threerings.openal.Log.log; import static com.threerings.openal.Log.log;
/** /**
@@ -40,7 +42,7 @@ public abstract class StreamDecoder
/** /**
* Registers a class of {@link StreamDecoder} for the specified file extension. * Registers a class of {@link StreamDecoder} for the specified file extension.
*/ */
public static void registerExtension (String extension, Class clazz) public static void registerExtension (String extension, Class<? extends StreamDecoder> clazz)
{ {
_extensions.put(extension, clazz); _extensions.put(extension, clazz);
} }
@@ -58,7 +60,7 @@ public abstract class StreamDecoder
return null; return null;
} }
String extension = path.substring(idx+1); String extension = path.substring(idx+1);
Class clazz = _extensions.get(extension); Class<? extends StreamDecoder> clazz = _extensions.get(extension);
if (clazz == null) { if (clazz == null) {
log.warning("No decoder registered for extension [extension=" + extension + log.warning("No decoder registered for extension [extension=" + extension +
", file=" + path + "]."); ", file=" + path + "].");
@@ -66,7 +68,7 @@ public abstract class StreamDecoder
} }
StreamDecoder decoder; StreamDecoder decoder;
try { try {
decoder = (StreamDecoder)clazz.newInstance(); decoder = clazz.newInstance();
} catch (Exception e) { } catch (Exception e) {
log.warning("Error instantiating decoder [file=" + path + ", error=" + e + "]."); log.warning("Error instantiating decoder [file=" + path + ", error=" + e + "].");
return null; return null;
@@ -101,7 +103,8 @@ public abstract class StreamDecoder
throws IOException; throws IOException;
/** Maps file extensions to decoder classes. */ /** Maps file extensions to decoder classes. */
protected static HashMap<String, Class> _extensions = new HashMap<String, Class>(); protected static HashMap<String, Class<? extends StreamDecoder>> _extensions =
Maps.newHashMap();
static { static {
registerExtension("ogg", OggStreamDecoder.class); registerExtension("ogg", OggStreamDecoder.class);
registerExtension("mp3", Mp3StreamDecoder.class); registerExtension("mp3", Mp3StreamDecoder.class);