diff --git a/src/java/com/threerings/cast/ActionFrames.java b/src/java/com/threerings/cast/ActionFrames.java index e0fe8bac2..3e43560da 100644 --- a/src/java/com/threerings/cast/ActionFrames.java +++ b/src/java/com/threerings/cast/ActionFrames.java @@ -1,5 +1,5 @@ // -// $Id: ActionFrames.java,v 1.2 2002/05/06 18:08:31 mdb Exp $ +// $Id: ActionFrames.java,v 1.3 2002/05/15 23:54:04 mdb Exp $ package com.threerings.cast; @@ -15,13 +15,13 @@ import com.threerings.util.DirectionCodes; * DirectionCodes#DIRECTION_COUNT} orientations that are used to render a * character sprite. */ -public interface ActionFrames extends MultiFrameImage +public interface ActionFrames { /** - * Updates the orientation that is currently being returned by the - * {@link MultiFrameImage} implementation. + * Returns the multi-frame image that comprises the frames for the + * specified orientation. */ - public void setOrientation (int orient); + public MultiFrameImage getFrames (int orient); /** * Creates a clone of these action frames which will have the supplied diff --git a/src/java/com/threerings/cast/CharacterSprite.java b/src/java/com/threerings/cast/CharacterSprite.java index f0d50e5fe..8fc5f7718 100644 --- a/src/java/com/threerings/cast/CharacterSprite.java +++ b/src/java/com/threerings/cast/CharacterSprite.java @@ -1,5 +1,5 @@ // -// $Id: CharacterSprite.java,v 1.29 2002/05/06 23:24:15 mdb Exp $ +// $Id: CharacterSprite.java,v 1.30 2002/05/15 23:54:04 mdb Exp $ package com.threerings.cast; @@ -111,12 +111,11 @@ public class CharacterSprite extends ImageSprite try { // obtain our animation frames for this action sequence _aframes = _charmgr.getActionFrames(_descrip, action); - _aframes.setOrientation(_orient); // update the sprite render attributes setOrigin(actseq.origin.x, actseq.origin.y); setFrameRate(actseq.framesPerSecond); - setFrames(_aframes); + setFrames(_aframes.getFrames(_orient)); } catch (NoSuchComponentException nsce) { Log.warning("Character sprite references non-existent " + @@ -131,8 +130,7 @@ public class CharacterSprite extends ImageSprite // update the sprite frames to reflect the direction if (_aframes != null) { - _aframes.setOrientation(orient); - setFrames(_aframes); + setFrames(_aframes.getFrames(orient)); } } diff --git a/src/java/com/threerings/cast/CompositedActionFrames.java b/src/java/com/threerings/cast/CompositedActionFrames.java index f9bd4124a..f2fe0784f 100644 --- a/src/java/com/threerings/cast/CompositedActionFrames.java +++ b/src/java/com/threerings/cast/CompositedActionFrames.java @@ -1,15 +1,17 @@ // -// $Id: CompositedActionFrames.java,v 1.3 2002/05/06 18:08:31 mdb Exp $ +// $Id: CompositedActionFrames.java,v 1.4 2002/05/15 23:54:04 mdb Exp $ package com.threerings.cast; import java.awt.Graphics; import java.awt.Image; -import com.threerings.util.DirectionCodes; +import com.threerings.media.sprite.MultiFrameImage; import com.threerings.media.util.Colorization; import com.threerings.media.util.ImageUtil; +import com.threerings.util.DirectionCodes; + /** * An implementation of the {@link MultiFrameImage} interface that is used * to lazily create composited character frames when they are requested. @@ -27,44 +29,46 @@ public class CompositedActionFrames _sources = sources; // the sources must all have the same frame count, so we just use // the count from the first one - _frameCount = _sources[0].getFrameCount(); + _frameCount = _sources[0].getFrames(NORTH).getFrameCount(); _images = new Image[DIRECTION_COUNT][_frameCount]; } - // documentation inherited - public int getFrameCount () - { - return _frameCount; - } - // documentation inherited from interface - public int getWidth (int index) + public MultiFrameImage getFrames (final int orient) { - return getExampleSource().getWidth(index); - } + return new MultiFrameImage() { + // documentation inherited + public int getFrameCount () + { + return _proto.getFrameCount(); + } - // documentation inherited from interface - public int getHeight (int index) - { - return getExampleSource().getHeight(index); - } + // documentation inherited from interface + public int getWidth (int index) + { + return _proto.getWidth(index); + } - // documentation inherited from interface - public void paintFrame (Graphics g, int index, int x, int y) - { - g.drawImage(getFrame(index), x, y, null); - } + // documentation inherited from interface + public int getHeight (int index) + { + return _proto.getHeight(index); + } - // documentation inherited from interface - public boolean hitTest (int index, int x, int y) - { - return ImageUtil.hitTest(getFrame(index), x, y); - } + // documentation inherited from interface + public void paintFrame (Graphics g, int index, int x, int y) + { + g.drawImage(getFrame(orient, index), x, y, null); + } - // documentation inherited from interface - public void setOrientation (int orient) - { - _orient = orient; + // documentation inherited from interface + public boolean hitTest (int index, int x, int y) + { + return ImageUtil.hitTest(getFrame(orient, index), x, y); + } + + protected MultiFrameImage _proto = _sources[0].getFrames(orient); + }; } // documentation inherited from interface @@ -74,18 +78,18 @@ public class CompositedActionFrames } // documentation inherited - protected Image getFrame (int index) + protected Image getFrame (int orient, int index) { // create the frame if we don't already have it - if (_images[_orient] == null) { - _images[_orient] = new Image[_frameCount]; + if (_images[orient] == null) { + _images[orient] = new Image[_frameCount]; } - if (_images[_orient][index] == null) { -// Log.info("Compositing [orient=" + _orient + + if (_images[orient][index] == null) { +// Log.info("Compositing [orient=" + orient + // ", index=" + index + "]."); - _images[_orient][index] = compositeFrames(_orient, index); + _images[orient][index] = compositeFrames(orient, index); } - return _images[_orient][index]; + return _images[orient][index]; } /** @@ -102,20 +106,17 @@ public class CompositedActionFrames // long start = System.currentTimeMillis(); for (int ii = 0; ii < _sources.length; ii++) { + MultiFrameImage source = _sources[ii].getFrames(orient); // create the image now that we know how big it should be if (dest == null) { - dest = ImageUtil.createImage(_sources[ii].getWidth(index), - _sources[ii].getHeight(index)); + dest = ImageUtil.createImage(source.getWidth(index), + source.getHeight(index)); g = dest.getGraphics(); } - // make sure the action frames are configured with the right - // orientation before we render - _sources[ii].setOrientation(orient); - // render the particular action from this component into the // target image - _sources[ii].paintFrame(g, index, 0, 0); + source.paintFrame(g, index, 0, 0); } // clean up after ourselves @@ -130,20 +131,6 @@ public class CompositedActionFrames return dest; } - /** - * When fetching width and height, we can simply use the first - * component's image set since they must all be the same. - */ - protected ActionFrames getExampleSource () - { - ActionFrames source = _sources[0]; - source.setOrientation(_orient); - return source; - } - - /** The orientation we're currently using. */ - protected int _orient; - /** The number of frames in each orientation. */ protected int _frameCount; diff --git a/src/java/com/threerings/cast/bundle/BundledComponentRepository.java b/src/java/com/threerings/cast/bundle/BundledComponentRepository.java index ebc52e77f..de0dae8ba 100644 --- a/src/java/com/threerings/cast/bundle/BundledComponentRepository.java +++ b/src/java/com/threerings/cast/bundle/BundledComponentRepository.java @@ -1,5 +1,5 @@ // -// $Id: BundledComponentRepository.java,v 1.11 2002/05/06 18:08:31 mdb Exp $ +// $Id: BundledComponentRepository.java,v 1.12 2002/05/15 23:54:05 mdb Exp $ package com.threerings.cast.bundle; @@ -30,6 +30,8 @@ import com.threerings.media.ImageManager; import com.threerings.media.util.Colorization; import com.threerings.media.util.ImageUtil; +import com.threerings.media.sprite.MultiFrameImage; + import com.threerings.media.tile.ImageProvider; import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.Tile; @@ -303,78 +305,72 @@ public class BundledComponentRepository _set = set; } - // documentation inherited - public int getFrameCount () - { - return _set.getTileCount() / DIRECTION_COUNT; - } - // documentation inherited from interface - public int getWidth (int index) + public MultiFrameImage getFrames (final int orient) { - Tile tile = getTile(index); - return (tile == null) ? 0 : tile.getWidth(); - } + return new MultiFrameImage() { + // documentation inherited + public int getFrameCount () + { + return _set.getTileCount() / DIRECTION_COUNT; + } - // documentation inherited from interface - public int getHeight (int index) - { - Tile tile = getTile(index); - return (tile == null) ? 0 : tile.getHeight(); - } + // documentation inherited from interface + public int getWidth (int index) + { + Tile tile = getTile(orient, index); + return (tile == null) ? 0 : tile.getWidth(); + } - // documentation inherited from interface - public void paintFrame (Graphics g, int index, int x, int y) - { - Tile tile = getTile(index); - if (tile != null) { - tile.paint(g, x, y); - } - } + // documentation inherited from interface + public int getHeight (int index) + { + Tile tile = getTile(orient, index); + return (tile == null) ? 0 : tile.getHeight(); + } - // documentation inherited from interface - public boolean hitTest (int index, int x, int y) - { - Tile tile = getTile(index); - return (tile != null) ? tile.hitTest(x, y) : false; - } + // documentation inherited from interface + public void paintFrame (Graphics g, int index, int x, int y) + { + Tile tile = getTile(orient, index); + if (tile != null) { + tile.paint(g, x, y); + } + } - // documentation inherited from interface - public void setOrientation (int orient) - { - _orient = orient; + // documentation inherited from interface + public boolean hitTest (int index, int x, int y) + { + Tile tile = getTile(orient, index); + return (tile != null) ? tile.hitTest(x, y) : false; + } + }; } // documentation inherited from interface public ActionFrames cloneColorized (Colorization[] zations) { - TileSet zset = _set.cloneColorized(zations); - TileSetFrameImage cframes = new TileSetFrameImage(zset); - cframes.setOrientation(_orient); - return cframes; + return new TileSetFrameImage(_set.cloneColorized(zations)); } /** * Fetches the requested tile. */ - protected Tile getTile (int index) + protected Tile getTile (int orient, int index) { - int tileIndex = _orient * getFrameCount() + index; + int fcount = _set.getTileCount() / DIRECTION_COUNT; + int tileIndex = orient * fcount + index; try { return _set.getTile(tileIndex); } catch (NoSuchTileException nste) { Log.warning("Can't extract action frame [set=" + _set + - ", orient=" + _orient + ", index=" + index + "]."); + ", orient=" + orient + ", index=" + index + "]."); return null; } } /** The tileset from which we obtain our frame images. */ protected TileSet _set; - - /** The particular orientation for which we are providing - * frames. */ - protected int _orient; } /** We use the image manager to decode and cache images. */