Bundles! Have component bundles largely working. Wrote test code and ANT
tasks and XML parsing rule sets all the good stuff. Rewired up all the cast code to be amenable to bundling and did some other revamping. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@640 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
//
|
||||
// $Id: TileUtil.java,v 1.3 2001/11/18 04:09:21 mdb Exp $
|
||||
// $Id: TileUtil.java,v 1.4 2001/11/27 08:09:35 mdb Exp $
|
||||
|
||||
package com.threerings.cast.util;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.threerings.media.sprite.*;
|
||||
import com.threerings.media.tile.*;
|
||||
import com.threerings.media.sprite.MultiFrameImage;
|
||||
import com.threerings.media.sprite.Sprite;
|
||||
// import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.cast.Log;
|
||||
import com.threerings.cast.*;
|
||||
// import com.threerings.cast.*;
|
||||
|
||||
/**
|
||||
* Miscellaneous tile-related utility functions.
|
||||
@@ -18,126 +19,105 @@ import com.threerings.cast.*;
|
||||
public class TileUtil
|
||||
{
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* @throws IllegalArgumentException if the frame count of the source
|
||||
* and destination images don't match.
|
||||
*/
|
||||
public static void compositeFrames (
|
||||
MultiFrameImage[][] dest, MultiFrameImage[][] src)
|
||||
MultiFrameImage[] dest, MultiFrameImage[] src)
|
||||
{
|
||||
for (int ii = 0; ii < dest.length; ii++) {
|
||||
for (int orient = 0; orient < Sprite.NUM_DIRECTIONS; orient++) {
|
||||
// create blank destination frames if needed
|
||||
if (dest[ii][orient] == null) {
|
||||
dest[ii][orient] = createBlankFrames(src[ii][orient]);
|
||||
}
|
||||
for (int orient = 0; orient < Sprite.NUM_DIRECTIONS; orient++) {
|
||||
MultiFrameImage sframes = src[orient];
|
||||
MultiFrameImage dframes = dest[orient];
|
||||
|
||||
// slap the images together
|
||||
compositeFrames(dest[ii][orient], src[ii][orient]);
|
||||
// create blank destination frames if needed
|
||||
if (dframes == null) {
|
||||
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);
|
||||
Image simg = sframes.getFrame(ii);
|
||||
dimg.getGraphics().drawImage(simg, 0, 0, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@link MultiFrameImage} that has empty images in
|
||||
* all frames. The number of frames in the resulting multi frame
|
||||
* image is the same as the frame count for <code>src</code>.
|
||||
*/
|
||||
public static MultiFrameImage createBlankFrames (MultiFrameImage src)
|
||||
{
|
||||
// TODO: for now, just use the first frame from the source to
|
||||
// get the width and height for all of the blank frames. fix
|
||||
// this hack soon.
|
||||
Image img = src.getFrame(0);
|
||||
int wid = img.getWidth(null), hei = img.getHeight(null);
|
||||
return new BlankFrameImage(wid, hei, src.getFrameCount());
|
||||
}
|
||||
// /**
|
||||
// * Returns a two-dimensional array of multi frame images containing
|
||||
// * the frames of animation used to render the sprite while standing or
|
||||
// * walking in each of the directions it may face.
|
||||
// */
|
||||
// public static MultiFrameImage[][] getComponentFrames (
|
||||
// String imagedir, CharacterComponent c)
|
||||
// {
|
||||
// ActionSequence seqs[] = c.getActionSequences();
|
||||
// MultiFrameImage frames[][] =
|
||||
// new MultiFrameImage[seqs.length][Sprite.NUM_DIRECTIONS];
|
||||
|
||||
/**
|
||||
* Returns a two-dimensional array of multi frame images
|
||||
* containing the frames of animation used to render the sprite
|
||||
* while standing or walking in each of the directions it may
|
||||
* face.
|
||||
*/
|
||||
public static MultiFrameImage[][] getComponentFrames (
|
||||
String imagedir, CharacterComponent c)
|
||||
{
|
||||
ActionSequence seqs[] = c.getActionSequences();
|
||||
MultiFrameImage frames[][] =
|
||||
new MultiFrameImage[seqs.length][Sprite.NUM_DIRECTIONS];
|
||||
// try {
|
||||
// for (int ii = 0; ii < seqs.length; ii++) {
|
||||
// ActionSequence as = seqs[ii];
|
||||
|
||||
try {
|
||||
for (int ii = 0; ii < seqs.length; ii++) {
|
||||
ActionSequence as = seqs[ii];
|
||||
// // get the tile set containing the component tiles for
|
||||
// // this action sequence
|
||||
// String file = getImageFile(imagedir, as, c);
|
||||
// TileSet tset = null;
|
||||
|
||||
// get the tile set containing the component tiles for
|
||||
// this action sequence
|
||||
String file = getImageFile(imagedir, as, c);
|
||||
TileSet tset = null;
|
||||
// try {
|
||||
// tset = as.tileset.clone(file);
|
||||
// } catch (CloneNotSupportedException e) {
|
||||
// Log.warning("Failed to clone tile set " +
|
||||
// "[tset=" + as.tileset + "].");
|
||||
// return null;
|
||||
// }
|
||||
|
||||
try {
|
||||
tset = as.tileset.clone(file);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
Log.warning("Failed to clone tile set " +
|
||||
"[tset=" + as.tileset + "].");
|
||||
return null;
|
||||
}
|
||||
// // get the number of frames of animation
|
||||
// int frameCount = tset.getTileCount() / Sprite.NUM_DIRECTIONS;
|
||||
|
||||
// get the number of frames of animation
|
||||
int frameCount = tset.getTileCount() / Sprite.NUM_DIRECTIONS;
|
||||
// for (int dir = 0; dir < Sprite.NUM_DIRECTIONS; dir++) {
|
||||
// // retrieve all images for the sequence and direction
|
||||
// Image imgs[] = new Image[frameCount];
|
||||
// for (int jj = 0; jj < frameCount; jj++) {
|
||||
// int idx = (dir * frameCount) + jj;
|
||||
// imgs[jj] = tset.getTileImage(idx);
|
||||
// }
|
||||
|
||||
for (int dir = 0; dir < Sprite.NUM_DIRECTIONS; dir++) {
|
||||
// retrieve all images for the sequence and direction
|
||||
Image imgs[] = new Image[frameCount];
|
||||
for (int jj = 0; jj < frameCount; jj++) {
|
||||
int idx = (dir * frameCount) + jj;
|
||||
imgs[jj] = tset.getTileImage(idx);
|
||||
}
|
||||
// // create the multi frame image
|
||||
// frames[ii][dir] = new MultiFrameImageImpl(imgs);
|
||||
// }
|
||||
// }
|
||||
|
||||
// create the multi frame image
|
||||
frames[ii][dir] = new MultiFrameImageImpl(imgs);
|
||||
}
|
||||
}
|
||||
// } catch (TileException te) {
|
||||
// Log.warning("Exception retrieving character images " +
|
||||
// "[te=" + te + "].");
|
||||
// return null;
|
||||
// }
|
||||
|
||||
} catch (TileException te) {
|
||||
Log.warning("Exception retrieving character images " +
|
||||
"[te=" + te + "].");
|
||||
return null;
|
||||
}
|
||||
// return frames;
|
||||
// }
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file path for the given action sequence and component.
|
||||
*/
|
||||
protected static String getImageFile (
|
||||
String imagedir, ActionSequence as, CharacterComponent c)
|
||||
{
|
||||
return imagedir + as.fileid + "_" + c.getFileId() + IMAGE_SUFFIX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders each of the given <code>src</code> frames into the
|
||||
* corresponding frames of <code>dest</code>.
|
||||
*/
|
||||
protected static void compositeFrames (
|
||||
MultiFrameImage dest, MultiFrameImage src)
|
||||
{
|
||||
int dsize = dest.getFrameCount(), ssize = src.getFrameCount();
|
||||
if (dsize != ssize) {
|
||||
Log.warning(
|
||||
"Can't composite images with differing frame counts " +
|
||||
"[dest=" + dsize + ", src=" + ssize + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int ii = 0; ii < dsize; ii++) {
|
||||
Image dimg = dest.getFrame(ii);
|
||||
Image simg = src.getFrame(ii);
|
||||
dimg.getGraphics().drawImage(simg, 0, 0, null);
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * Returns the file path for the given action sequence and component.
|
||||
// */
|
||||
// protected static String getImageFile (
|
||||
// String imagedir, ActionSequence as, CharacterComponent c)
|
||||
// {
|
||||
// return imagedir + as.fileid + "_" + c.getFileId() + IMAGE_SUFFIX;
|
||||
// }
|
||||
|
||||
/**
|
||||
* An implementation of the {@link MultiFrameImage} interface that
|
||||
@@ -147,31 +127,35 @@ public class TileUtil
|
||||
protected static class BlankFrameImage implements MultiFrameImage
|
||||
{
|
||||
/**
|
||||
* Constructs a blank frame image.
|
||||
* Constructs a blank frame image based on the dimensions of
|
||||
* template multi-frame image.
|
||||
*/
|
||||
public BlankFrameImage (int width, int height, int frameCount)
|
||||
public BlankFrameImage (MultiFrameImage template)
|
||||
{
|
||||
_imgs = new Image[frameCount];
|
||||
for (int ii = 0; ii < frameCount; ii++) {
|
||||
_imgs[ii] = new BufferedImage(
|
||||
width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
int frameCount = template.getFrameCount();
|
||||
_images = new Image[frameCount];
|
||||
for (int i = 0; i < frameCount; i++) {
|
||||
Image img = template.getFrame(i);
|
||||
_images[i] = new BufferedImage(img.getWidth(null),
|
||||
img.getHeight(null),
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public int getFrameCount ()
|
||||
{
|
||||
return _imgs.length;
|
||||
return _images.length;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Image getFrame (int index)
|
||||
{
|
||||
return _imgs[index];
|
||||
return _images[index];
|
||||
}
|
||||
|
||||
/** The frame images. */
|
||||
protected Image _imgs[];
|
||||
protected Image[] _images;
|
||||
}
|
||||
|
||||
/** The image file name suffix appended to component image file names. */
|
||||
|
||||
Reference in New Issue
Block a user