Revamped component action animation support so that we're not passing

around arrays of multi-frame images but instead pass around one object
that knows how to render any action frame in any orientation. This
apparently fixed some horrible bug that we had introduced in doing JITC
and now the whole thing is super fast, just like I always thought it would
be. Once we introduce trimmed images, it will blaze!


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1336 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-05-04 19:38:14 +00:00
parent 47e38b4fa8
commit 37a1167fb5
9 changed files with 237 additions and 175 deletions
+17 -86
View File
@@ -1,5 +1,5 @@
//
// $Id: TileUtil.java,v 1.13 2002/05/04 06:57:24 mdb Exp $
// $Id: TileUtil.java,v 1.14 2002/05/04 19:38:14 mdb Exp $
package com.threerings.cast.util;
@@ -7,76 +7,17 @@ import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import com.threerings.media.sprite.MultiFrameImage;
import com.threerings.media.util.ImageUtil;
import com.threerings.util.DirectionCodes;
import com.threerings.cast.Log;
import com.threerings.cast.ActionFrames;
import com.threerings.cast.Colorization;
/**
* Miscellaneous tile-related utility functions.
*/
public class TileUtil
implements DirectionCodes
{
// /**
// * Renders each of the given <code>src</code> component frames into
// * the corresponding frames of <code>dest</code>, allocating blank
// * image frames for <code>dest</code> if none yet exist. If
// * <code>zations</code> is not null, the provided list of
// * colorizations will be applied as well.
// *
// * @throws IllegalArgumentException if the frame count of the source
// * and destination images don't match.
// */
// public static void compositeFrames (
// MultiFrameImage[] dest, MultiFrameImage[] src,
// Colorization[] zations)
// {
// for (int orient = 0; orient < DIRECTION_COUNT; orient++) {
// MultiFrameImage sframes = src[orient];
// MultiFrameImage dframes = dest[orient];
// // create blank destination frames if needed
// if (dframes == null) {
// dframes = (dest[orient] = new BlankFrameImage(sframes));
// }
// // sanity check
// int dsize = dframes.getFrameCount();
// int ssize = sframes.getFrameCount();
// if (dsize != ssize) {
// String errmsg = "Can't composite images with inequal " +
// "frame counts [dest=" + dsize + ", src=" + ssize + "].";
// throw new IllegalArgumentException(errmsg);
// }
// // slap the images together
// for (int ii = 0; ii < dsize; ii++) {
// Image dimg = dframes.getFrame(ii);
// BufferedImage simg = (BufferedImage)sframes.getFrame(ii);
// // recolor the source image
// if (zations != null) {
// for (int i = 0; i < zations.length; i++) {
// Colorization cz = zations[i];
// if (zations[i] != null) {
// simg = ImageUtil.recolorImage(
// simg, cz.rootColor, cz.range, cz.offsets);
// }
// }
// }
// // now splat the recolored image onto the target
// Graphics g = dimg.getGraphics();
// g.drawImage(simg, 0, 0, null);
// g.dispose();
// }
// }
// }
/**
* Renders and returns the <code>index</code>th image from each of the
* supplied source multi-frame images to a newly created buffered
@@ -85,36 +26,29 @@ public class TileUtil
* already sorted into the proper rendering order.
*/
public static Image compositeFrames (
int index, MultiFrameImage[] sources, Colorization[][] zations)
int orient, int index, ActionFrames[] sources,
Colorization[][] zations)
{
Image dest = null;
Graphics g = null;
// long start = System.currentTimeMillis();
long start = System.currentTimeMillis();
for (int ii = 0; ii < sources.length; ii++) {
BufferedImage simg = (BufferedImage)sources[ii].getFrame(index);
// create the image now that we know how big it should be
if (dest == null) {
dest = ImageUtil.createImage(
simg.getWidth(null), simg.getHeight(null));
dest = ImageUtil.createImage(sources[ii].getWidth(index),
sources[ii].getHeight(index));
g = dest.getGraphics();
}
// recolor the source image
if (zations != null) {
int zcount = zations[ii].length;
for (int zz = 0; zz < zcount; zz++) {
Colorization cz = zations[ii][zz];
if (cz != null) {
simg = ImageUtil.recolorImage(
simg, cz.rootColor, cz.range, cz.offsets);
}
}
}
// make sure the action frames are configured with the right
// orientation before we render
sources[ii].setOrientation(orient);
// now splat the recolored image onto the target
g.drawImage(simg, 0, 0, null);
// render the particular action from this component into the
// target image
Colorization[] cz = (zations != null) ? zations[ii] : null;
sources[ii].paintColoredFrame(g, index, 0, 0, cz);
}
// clean up after ourselves
@@ -122,13 +56,10 @@ public class TileUtil
g.dispose();
}
long now = System.currentTimeMillis();
Log.info("Composited " + sources.length + " frames in " +
(now-start) + " millis.");
// long now = System.currentTimeMillis();
// Log.info("Composited " + sources.length + " frames in " +
// (now-start) + " millis.");
return dest;
}
/** The image file name suffix appended to component image file names. */
protected static final String IMAGE_SUFFIX = ".png";
}