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:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ActionFrames.java,v 1.1 2002/05/04 19:38:13 mdb Exp $
|
||||
// $Id: ActionFrames.java,v 1.2 2002/05/06 18:08:31 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
|
||||
import com.threerings.media.sprite.MultiFrameImage;
|
||||
import com.threerings.media.util.Colorization;
|
||||
import com.threerings.util.DirectionCodes;
|
||||
|
||||
/**
|
||||
@@ -23,10 +24,8 @@ public interface ActionFrames extends MultiFrameImage
|
||||
public void setOrientation (int orient);
|
||||
|
||||
/**
|
||||
* Renders the specified frame at the specified offset applying the
|
||||
* supplied colorizations in the process. Note, the colorizations
|
||||
* should not be applied to the source image, only the rendered copy.
|
||||
* Creates a clone of these action frames which will have the supplied
|
||||
* colorizations applied to the frame images.
|
||||
*/
|
||||
public void paintColoredFrame (
|
||||
Graphics g, int index, int x, int y, Colorization[] zations);
|
||||
public ActionFrames cloneColorized (Colorization[] zations);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
//
|
||||
// $Id: CharacterDescriptor.java,v 1.6 2002/03/10 22:31:06 mdb Exp $
|
||||
// $Id: CharacterDescriptor.java,v 1.7 2002/05/06 18:08:31 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
import java.util.Arrays;
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.threerings.media.util.Colorization;
|
||||
|
||||
/**
|
||||
* The character descriptor object details the components that are
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: CharacterManager.java,v 1.19 2002/05/04 19:38:13 mdb Exp $
|
||||
// $Id: CharacterManager.java,v 1.20 2002/05/06 18:08:31 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
@@ -9,12 +9,13 @@ import java.util.HashMap;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.samskivert.util.Tuple;
|
||||
|
||||
import org.apache.commons.collections.LRUMap;
|
||||
|
||||
import com.threerings.media.util.Colorization;
|
||||
import com.threerings.util.DirectionCodes;
|
||||
|
||||
import com.threerings.cast.Log;
|
||||
import com.threerings.cast.util.TileUtil;
|
||||
|
||||
/**
|
||||
* The character manager provides facilities for constructing sprites that
|
||||
@@ -212,19 +213,20 @@ public class CharacterManager
|
||||
// sort them into the proper rendering order
|
||||
Arrays.sort(components);
|
||||
|
||||
// create an array with the action frames for each component
|
||||
// create colorized versions of all of the source action frames
|
||||
ActionFrames[] sources = new ActionFrames[ccount];
|
||||
zations = new Colorization[ccount][];
|
||||
for (int ii = 0; ii < ccount; ii++) {
|
||||
sources[ii] = components[ii].component.getFrames(action);
|
||||
ActionFrames source = components[ii].component.getFrames(action);
|
||||
if (zations != null) {
|
||||
zations[ii] = components[ii].zations;
|
||||
sources[ii] = source.cloneColorized(components[ii].zations);
|
||||
} else {
|
||||
sources[ii] = source;
|
||||
}
|
||||
}
|
||||
|
||||
// use those to create an entity that will lazily composite things
|
||||
// together as they are needed
|
||||
return new CompositedActionFrames(action, sources, zations);
|
||||
return new CompositedActionFrames(sources);
|
||||
}
|
||||
|
||||
/** Used when compositing component frame images. */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: BundledComponentRepository.java,v 1.10 2002/05/04 19:38:14 mdb Exp $
|
||||
// $Id: BundledComponentRepository.java,v 1.11 2002/05/06 18:08:31 mdb Exp $
|
||||
|
||||
package com.threerings.cast.bundle;
|
||||
|
||||
@@ -27,17 +27,18 @@ import com.threerings.resource.ResourceBundle;
|
||||
import com.threerings.resource.ResourceManager;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
import com.threerings.media.util.Colorization;
|
||||
import com.threerings.media.util.ImageUtil;
|
||||
|
||||
import com.threerings.media.tile.ImageProvider;
|
||||
import com.threerings.media.tile.TileSet;
|
||||
import com.threerings.media.tile.NoSuchTileException;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.tile.TileSet;
|
||||
|
||||
import com.threerings.util.DirectionCodes;
|
||||
|
||||
import com.threerings.cast.ActionFrames;
|
||||
import com.threerings.cast.CharacterComponent;
|
||||
import com.threerings.cast.Colorization;
|
||||
import com.threerings.cast.ComponentClass;
|
||||
import com.threerings.cast.ComponentRepository;
|
||||
import com.threerings.cast.FrameProvider;
|
||||
@@ -311,31 +312,31 @@ public class BundledComponentRepository
|
||||
// documentation inherited from interface
|
||||
public int getWidth (int index)
|
||||
{
|
||||
Image img = getImage(index);
|
||||
return (img == null) ? 0 : img.getWidth(null);
|
||||
Tile tile = getTile(index);
|
||||
return (tile == null) ? 0 : tile.getWidth();
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public int getHeight (int index)
|
||||
{
|
||||
Image img = getImage(index);
|
||||
return (img == null) ? 0 : img.getHeight(null);
|
||||
Tile tile = getTile(index);
|
||||
return (tile == null) ? 0 : tile.getHeight();
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void paintFrame (Graphics g, int index, int x, int y)
|
||||
{
|
||||
Image img = getImage(index);
|
||||
if (img != null) {
|
||||
g.drawImage(img, x, y, null);
|
||||
Tile tile = getTile(index);
|
||||
if (tile != null) {
|
||||
tile.paint(g, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public boolean hitTest (int index, int x, int y)
|
||||
{
|
||||
Image img = getImage(index);
|
||||
return (img != null) ? ImageUtil.hitTest(img, x, y) : false;
|
||||
Tile tile = getTile(index);
|
||||
return (tile != null) ? tile.hitTest(x, y) : false;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
@@ -345,38 +346,22 @@ public class BundledComponentRepository
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void paintColoredFrame (
|
||||
Graphics g, int index, int x, int y, Colorization[] zations)
|
||||
public ActionFrames cloneColorized (Colorization[] zations)
|
||||
{
|
||||
BufferedImage img = (BufferedImage)getImage(index);
|
||||
if (img == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// create a recolored image with which to render
|
||||
if (zations != null) {
|
||||
int zcount = zations.length;
|
||||
Colorization cz;
|
||||
for (int zz = 0; zz < zcount; zz++) {
|
||||
if ((cz = zations[zz]) == null) {
|
||||
continue;
|
||||
}
|
||||
img = ImageUtil.recolorImage(
|
||||
img, cz.rootColor, cz.range, cz.offsets);
|
||||
}
|
||||
}
|
||||
|
||||
g.drawImage(img, x, y, null);
|
||||
TileSet zset = _set.cloneColorized(zations);
|
||||
TileSetFrameImage cframes = new TileSetFrameImage(zset);
|
||||
cframes.setOrientation(_orient);
|
||||
return cframes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the requested tile image.
|
||||
* Fetches the requested tile.
|
||||
*/
|
||||
protected Image getImage (int index)
|
||||
protected Tile getTile (int index)
|
||||
{
|
||||
int tileIndex = _orient * getFrameCount() + index;
|
||||
try {
|
||||
return _set.getTile(tileIndex).getImage();
|
||||
return _set.getTile(tileIndex);
|
||||
} catch (NoSuchTileException nste) {
|
||||
Log.warning("Can't extract action frame [set=" + _set +
|
||||
", orient=" + _orient + ", index=" + index + "].");
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// $Id: TileUtil.java,v 1.14 2002/05/04 19:38:14 mdb Exp $
|
||||
|
||||
package com.threerings.cast.util;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.threerings.media.util.ImageUtil;
|
||||
|
||||
import com.threerings.cast.Log;
|
||||
import com.threerings.cast.ActionFrames;
|
||||
import com.threerings.cast.Colorization;
|
||||
|
||||
/**
|
||||
* Miscellaneous tile-related utility functions.
|
||||
*/
|
||||
public class TileUtil
|
||||
{
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static Image compositeFrames (
|
||||
int orient, int index, ActionFrames[] sources,
|
||||
Colorization[][] zations)
|
||||
{
|
||||
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
|
||||
Colorization[] cz = (zations != null) ? zations[ii] : null;
|
||||
sources[ii].paintColoredFrame(g, index, 0, 0, cz);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user