The vast and the sweeping. Modified the tile framework such that tiles no

longer provide access to their underlying image (they actually still do,
but not in the normal course of affairs). This will allow us to use
"trimmed" tiles which are trimmed to the smallest rectangle that contains
the non-transparent pixels in a tile image, which will shrink up our
components and other tiles a great deal.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1339 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-05-06 18:08:32 +00:00
parent 1c182d6e36
commit 99c4330646
24 changed files with 517 additions and 306 deletions
@@ -1,5 +1,5 @@
//
// $Id: CompositedActionFrames.java,v 1.2 2002/05/04 19:38:13 mdb Exp $
// $Id: CompositedActionFrames.java,v 1.3 2002/05/06 18:08:31 mdb Exp $
package com.threerings.cast;
@@ -7,8 +7,8 @@ import java.awt.Graphics;
import java.awt.Image;
import com.threerings.util.DirectionCodes;
import com.threerings.media.util.Colorization;
import com.threerings.media.util.ImageUtil;
import com.threerings.cast.util.TileUtil;
/**
* An implementation of the {@link MultiFrameImage} interface that is used
@@ -22,13 +22,9 @@ public class CompositedActionFrames
* source frames and colorization configuration. The actual component
* frame images will not be composited until they are requested.
*/
public CompositedActionFrames (
String action, ActionFrames[] sources, Colorization[][] zations)
public CompositedActionFrames (ActionFrames[] sources)
{
_action = action;
_sources = sources;
_zations = zations;
// the sources must all have the same frame count, so we just use
// the count from the first one
_frameCount = _sources[0].getFrameCount();
@@ -72,8 +68,7 @@ public class CompositedActionFrames
}
// documentation inherited from interface
public void paintColoredFrame (
Graphics g, int index, int x, int y, Colorization[] zations)
public ActionFrames cloneColorized (Colorization[] zations)
{
throw new RuntimeException("What you talkin' about Willis?");
}
@@ -86,14 +81,55 @@ public class CompositedActionFrames
_images[_orient] = new Image[_frameCount];
}
if (_images[_orient][index] == null) {
// Log.info("Compositing [action=" + _action +
// ", orient=" + _orient + ", index=" + index + "].");
_images[_orient][index] =
TileUtil.compositeFrames(_orient, index, _sources, _zations);
// Log.info("Compositing [orient=" + _orient +
// ", index=" + index + "].");
_images[_orient][index] = compositeFrames(_orient, index);
}
return _images[_orient][index];
}
/**
* Renders and returns the <code>index</code>th image from each of the
* supplied source multi-frame images to a newly created buffered
* image. This is used to render a single frame of a composited
* character action, and accordingly, the source image array should be
* already sorted into the proper rendering order.
*/
protected Image compositeFrames (int orient, int index)
{
Image dest = null;
Graphics g = null;
// long start = System.currentTimeMillis();
for (int ii = 0; ii < _sources.length; ii++) {
// 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));
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);
}
// clean up after ourselves
if (g != null) {
g.dispose();
}
// long now = System.currentTimeMillis();
// Log.info("Composited " + sources.length + " frames in " +
// (now-start) + " millis.");
return dest;
}
/**
* When fetching width and height, we can simply use the first
* component's image set since they must all be the same.
@@ -105,8 +141,6 @@ public class CompositedActionFrames
return source;
}
protected String _action;
/** The orientation we're currently using. */
protected int _orient;
@@ -116,9 +150,6 @@ public class CompositedActionFrames
/** Our source action frames. */
protected ActionFrames[] _sources;
/** The colorizations for our source components. */
protected Colorization[][] _zations;
/** The frame images. */
protected Image[][] _images;
}