Provided hooks for a disk-based cache for composited action animations.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@956 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// $Id: ActionCache.java,v 1.1 2002/02/07 03:20:29 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
import com.threerings.media.sprite.MultiFrameImage;
|
||||
|
||||
/**
|
||||
* A mechanism for caching composited character action animations on disk.
|
||||
*/
|
||||
public interface ActionCache
|
||||
{
|
||||
/**
|
||||
* Fetches from the cache a composited set of images for a particular
|
||||
* character for a particular action.
|
||||
*/
|
||||
public MultiFrameImage[] getActionFrames (
|
||||
CharacterDescriptor descrip, String action);
|
||||
|
||||
/**
|
||||
* Requests that the specified set of action frames for the specified
|
||||
* character be cached.
|
||||
*/
|
||||
public void cacheActionFrames (
|
||||
CharacterDescriptor descrip, String action, MultiFrameImage[] frames);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: CharacterManager.java,v 1.11 2001/12/17 03:33:40 mdb Exp $
|
||||
// $Id: CharacterManager.java,v 1.12 2002/02/07 03:20:29 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
@@ -59,6 +59,15 @@ public class CharacterManager
|
||||
_charClass = charClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the character manager to use the provided cache for
|
||||
* composited action animations.
|
||||
*/
|
||||
public void setActionCache (ActionCache cache)
|
||||
{
|
||||
_acache = cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link CharacterSprite} representing the character
|
||||
* described by the given {@link CharacterDescriptor}, or
|
||||
@@ -105,15 +114,29 @@ public class CharacterManager
|
||||
CharacterDescriptor descrip, String action)
|
||||
throws NoSuchComponentException
|
||||
{
|
||||
// the cache is keyed on both values
|
||||
// first check the in-memory cache; which is keyed on both values
|
||||
Tuple key = new Tuple(descrip, action);
|
||||
MultiFrameImage[] frames = (MultiFrameImage[])_frames.get(key);
|
||||
|
||||
// next check the disk cache
|
||||
if (frames == null && _acache != null) {
|
||||
frames = getActionFrames(descrip, action);
|
||||
// cache the result in memory
|
||||
_frames.put(key, frames);
|
||||
}
|
||||
|
||||
// if that failed, we'll just have to generate the danged things
|
||||
if (frames == null) {
|
||||
// do the compositing
|
||||
frames = createCompositeFrames(descrip, action);
|
||||
// cache the result
|
||||
// cache the result on disk if we've got such a cache
|
||||
if (_acache != null) {
|
||||
_acache.cacheActionFrames(descrip, action, frames);
|
||||
}
|
||||
// cache the result in memory as well
|
||||
_frames.put(key, frames);
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
@@ -162,4 +185,7 @@ public class CharacterManager
|
||||
|
||||
/** The character class to be created. */
|
||||
protected Class _charClass = CharacterSprite.class;
|
||||
|
||||
/** The action animation cache, if we have one. */
|
||||
protected ActionCache _acache;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user