Class SoundCache

java.lang.Object
com.blackrook.gloop.openal.util.system.SoundCache
All Implemented Interfaces:
AutoCloseable

public class SoundCache extends Object implements AutoCloseable
A Buffer cache used for caching often-used buffers so that they don't need to be reloaded.
  • Field Details

    • NAME_COMPARATOR

      protected static final Comparator<SoundCache.Node> NAME_COMPARATOR
      Comparator for resource names.
    • SIZE_COMPARATOR

      protected static final Comparator<SoundCache.Node> SIZE_COMPARATOR
      Comparator for buffer sizes.
    • maxByteSize

      protected int maxByteSize
    • currBytes

      protected int currBytes
  • Constructor Details

    • SoundCache

      public SoundCache(int maxByteSize)
      Creates a new buffer cache with a set amount of byte capacity.
      Parameters:
      maxByteSize - the maximum bytes of this cache.
  • Method Details

    • addBuffer

      public void addBuffer(SoundData sound, OALBuffer buffer)
      Adds a buffer to the cache.
      Parameters:
      sound - the sound definition to map.
      buffer - the created buffer to store.
    • getBuffer

      public OALBuffer getBuffer(SoundData resource)
      Gets an existing buffer. Null if not found.
      Parameters:
      resource - the sound resource.
      Returns:
      the buffer that contains the sound data.
    • removeLargestBuffer

      public OALBuffer removeLargestBuffer()
      Removes the largest buffer.
      Returns:
      the buffer removed. It is NOT freed.
    • destroy

      public void destroy()
      Destroys all buffers and stuff.
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception