diff --git a/src/java/com/threerings/cast/ActionCache.java b/src/java/com/threerings/cast/ActionCache.java new file mode 100644 index 000000000..4250f45cf --- /dev/null +++ b/src/java/com/threerings/cast/ActionCache.java @@ -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); +} diff --git a/src/java/com/threerings/cast/CharacterManager.java b/src/java/com/threerings/cast/CharacterManager.java index 15ea4e8f3..c08d25453 100644 --- a/src/java/com/threerings/cast/CharacterManager.java +++ b/src/java/com/threerings/cast/CharacterManager.java @@ -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; }