Added support for providing colorization assignments when fetching tiles.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2367 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
//
|
//
|
||||||
// $Id: ObjectTileSet.java,v 1.14 2003/02/06 06:23:05 mdb Exp $
|
// $Id: ObjectTileSet.java,v 1.15 2003/04/01 02:16:28 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
import com.threerings.media.image.Mirage;
|
import com.threerings.media.image.Mirage;
|
||||||
|
import com.threerings.media.image.Colorization;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object tileset supports the specification of object information for
|
* The object tileset supports the specification of object information for
|
||||||
@@ -145,6 +146,19 @@ public class ObjectTileSet extends SwissArmyTileSet
|
|||||||
buf.append(", sorients=").append(StringUtil.toString(_sorients));
|
buf.append(", sorients=").append(StringUtil.toString(_sorients));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
protected Colorization[] getColorizations (int tileIndex, Colorizer rizer)
|
||||||
|
{
|
||||||
|
Colorization[] zations = null;
|
||||||
|
if (rizer != null && _zations != null) {
|
||||||
|
zations = new Colorization[_zations.length];
|
||||||
|
for (int ii = 0; ii < _zations.length; ii++) {
|
||||||
|
zations[ii] = rizer.getColorization(_zations[ii]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return zations;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates instances of {@link ObjectTile}, which can span more than a
|
* Creates instances of {@link ObjectTile}, which can span more than a
|
||||||
* single tile's space in a display.
|
* single tile's space in a display.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileManager.java,v 1.30 2003/02/28 02:03:43 mdb Exp $
|
// $Id: TileManager.java,v 1.31 2003/04/01 02:16:28 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -198,7 +198,20 @@ public class TileManager
|
|||||||
throws NoSuchTileSetException, NoSuchTileException
|
throws NoSuchTileSetException, NoSuchTileException
|
||||||
{
|
{
|
||||||
return getTile(TileUtil.getTileSetId(fqTileId),
|
return getTile(TileUtil.getTileSetId(fqTileId),
|
||||||
TileUtil.getTileIndex(fqTileId));
|
TileUtil.getTileIndex(fqTileId), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link Tile} object with the specified fully qualified
|
||||||
|
* tile id. The supplied colorizer will be used to recolor the tile.
|
||||||
|
*
|
||||||
|
* @see TileUtil#getFQTileId
|
||||||
|
*/
|
||||||
|
public Tile getTile (int fqTileId, TileSet.Colorizer rizer)
|
||||||
|
throws NoSuchTileSetException, NoSuchTileException
|
||||||
|
{
|
||||||
|
return getTile(TileUtil.getTileSetId(fqTileId),
|
||||||
|
TileUtil.getTileIndex(fqTileId), rizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -210,28 +223,11 @@ public class TileManager
|
|||||||
*
|
*
|
||||||
* @return the tile object.
|
* @return the tile object.
|
||||||
*/
|
*/
|
||||||
public Tile getTile (int tileSetId, int tileIndex)
|
public Tile getTile (int tileSetId, int tileIndex, TileSet.Colorizer rizer)
|
||||||
throws NoSuchTileSetException, NoSuchTileException
|
throws NoSuchTileSetException, NoSuchTileException
|
||||||
{
|
{
|
||||||
TileSet set = getTileSet(tileSetId);
|
TileSet set = getTileSet(tileSetId);
|
||||||
return set.getTile(tileIndex);
|
return set.getTile(tileIndex, rizer);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link Tile} object from the specified tileset at the
|
|
||||||
* specified index with the specified colorizations applied to it.
|
|
||||||
*
|
|
||||||
* @param tileSetId the tileset id.
|
|
||||||
* @param tileIndex the index of the tile to be retrieved.
|
|
||||||
* @param zations colorizations to be applied to the tile image.
|
|
||||||
*
|
|
||||||
* @return the tile object.
|
|
||||||
*/
|
|
||||||
public Tile getTile (int tileSetId, int tileIndex, Colorization[] zations)
|
|
||||||
throws NoSuchTileSetException, NoSuchTileException
|
|
||||||
{
|
|
||||||
TileSet set = getTileSet(tileSetId);
|
|
||||||
return set.getTile(tileIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The entity through which we decode and cache images. */
|
/** The entity through which we decode and cache images. */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileSet.java,v 1.43 2003/02/04 21:38:46 mdb Exp $
|
// $Id: TileSet.java,v 1.44 2003/04/01 02:16:28 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@ import java.awt.Color;
|
|||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import com.samskivert.util.LRUHashMap;
|
import com.samskivert.util.LRUHashMap;
|
||||||
import com.samskivert.util.RuntimeAdjust;
|
import com.samskivert.util.RuntimeAdjust;
|
||||||
@@ -37,6 +38,16 @@ import com.threerings.media.image.Mirage;
|
|||||||
public abstract class TileSet
|
public abstract class TileSet
|
||||||
implements Cloneable, Serializable
|
implements Cloneable, Serializable
|
||||||
{
|
{
|
||||||
|
/** Used to assign colorizations to tiles that require them. */
|
||||||
|
public static interface Colorizer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the colorization to be used for the specified named
|
||||||
|
* colorization class.
|
||||||
|
*/
|
||||||
|
public Colorization getColorization (String zation);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures this tileset with an image provider that it can use to
|
* Configures this tileset with an image provider that it can use to
|
||||||
* load its tileset image. This will be called automatically when the
|
* load its tileset image. This will be called automatically when the
|
||||||
@@ -45,12 +56,6 @@ public abstract class TileSet
|
|||||||
public void setImageProvider (ImageProvider improv)
|
public void setImageProvider (ImageProvider improv)
|
||||||
{
|
{
|
||||||
_improv = improv;
|
_improv = improv;
|
||||||
|
|
||||||
// HACKOLA: if we're a vessel tileset, colorize ourselves
|
|
||||||
if (_name != null && (this instanceof TrimmedObjectTileSet) &&
|
|
||||||
_name.indexOf("Vessel") != -1) {
|
|
||||||
_zations = ZATIONS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,6 +130,16 @@ public abstract class TileSet
|
|||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equivalent to {@link# getTile(int,Colorizer)} with a null
|
||||||
|
* <code>Colorizer</code> argument.
|
||||||
|
*/
|
||||||
|
public Tile getTile (int tileIndex)
|
||||||
|
throws NoSuchTileException
|
||||||
|
{
|
||||||
|
return getTile(tileIndex, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link Tile} object from this tileset corresponding to
|
* Creates a {@link Tile} object from this tileset corresponding to
|
||||||
* the specified tile id and returns that tile. A null tile will never
|
* the specified tile id and returns that tile. A null tile will never
|
||||||
@@ -134,13 +149,16 @@ public abstract class TileSet
|
|||||||
* @param tileIndex the index of the tile in the tileset. Tile indexes
|
* @param tileIndex the index of the tile in the tileset. Tile indexes
|
||||||
* start with zero as the upper left tile and increase by one as the
|
* start with zero as the upper left tile and increase by one as the
|
||||||
* tiles move left to right and top to bottom over the source image.
|
* tiles move left to right and top to bottom over the source image.
|
||||||
|
* @param rizer an entity that will be used to obtain colorizations
|
||||||
|
* for tilesets that are recolorizable. Passing null if the tileset is
|
||||||
|
* known not to be recolorizable is valid.
|
||||||
*
|
*
|
||||||
* @return the tile object.
|
* @return the tile object.
|
||||||
*
|
*
|
||||||
* @exception NoSuchTileException thrown if the specified tile index
|
* @exception NoSuchTileException thrown if the specified tile index
|
||||||
* is out of range for this tileset.
|
* is out of range for this tileset.
|
||||||
*/
|
*/
|
||||||
public Tile getTile (int tileIndex)
|
public Tile getTile (int tileIndex, Colorizer rizer)
|
||||||
throws NoSuchTileException
|
throws NoSuchTileException
|
||||||
{
|
{
|
||||||
checkTileIndex(tileIndex);
|
checkTileIndex(tileIndex);
|
||||||
@@ -156,12 +174,11 @@ public abstract class TileSet
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch and cache the tile
|
Colorization[] zations = getColorizations(tileIndex, rizer);
|
||||||
Tuple key = new Tuple(this, new Integer(tileIndex));
|
TileKey key = new TileKey(this, tileIndex, zations);
|
||||||
Tile tile = (Tile)_tiles.get(key);
|
Tile tile = (Tile)_tiles.get(key);
|
||||||
if (tile == null) {
|
if (tile == null) {
|
||||||
// create and initialize the tile object
|
tile = createTile(tileIndex, getTileMirage(tileIndex, zations));
|
||||||
tile = createTile(tileIndex, getTileMirage(tileIndex));
|
|
||||||
initTile(tile);
|
initTile(tile);
|
||||||
_tiles.put(key, tile);
|
_tiles.put(key, tile);
|
||||||
}
|
}
|
||||||
@@ -169,6 +186,18 @@ public abstract class TileSet
|
|||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns colorizations for the specified tile image. The default is
|
||||||
|
* to return any colorizations associated with the tileset via a call
|
||||||
|
* to {@link #clone(Colorization[])}, however derived classes may have
|
||||||
|
* dynamic colorization policies that look up colorization assignments
|
||||||
|
* from the supplied colorizer.
|
||||||
|
*/
|
||||||
|
protected Colorization[] getColorizations (int tileIndex, Colorizer rizer)
|
||||||
|
{
|
||||||
|
return _zations;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the entire, raw, uncut, unprepared tileset source image.
|
* Returns the entire, raw, uncut, unprepared tileset source image.
|
||||||
*/
|
*/
|
||||||
@@ -200,6 +229,19 @@ public abstract class TileSet
|
|||||||
*/
|
*/
|
||||||
public Mirage getTileMirage (int tileIndex)
|
public Mirage getTileMirage (int tileIndex)
|
||||||
throws NoSuchTileException
|
throws NoSuchTileException
|
||||||
|
{
|
||||||
|
return getTileMirage(tileIndex, getColorizations(tileIndex, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a prepared version of the image that would be used by the
|
||||||
|
* tile at the specified index. Because tilesets are often used simply
|
||||||
|
* to provide access to a collection of uniform images, this method is
|
||||||
|
* provided to bypass the creation of a {@link Tile} object when all
|
||||||
|
* that is desired is access to the underlying image.
|
||||||
|
*/
|
||||||
|
public Mirage getTileMirage (int tileIndex, Colorization[] zations)
|
||||||
|
throws NoSuchTileException
|
||||||
{
|
{
|
||||||
checkTileIndex(tileIndex);
|
checkTileIndex(tileIndex);
|
||||||
Rectangle bounds = computeTileBounds(tileIndex);
|
Rectangle bounds = computeTileBounds(tileIndex);
|
||||||
@@ -207,7 +249,7 @@ public abstract class TileSet
|
|||||||
Log.warning("Aiya! Tile set missing image provider " +
|
Log.warning("Aiya! Tile set missing image provider " +
|
||||||
"[path=" + _imagePath + "].");
|
"[path=" + _imagePath + "].");
|
||||||
}
|
}
|
||||||
return _improv.getTileImage(_imagePath, bounds, _zations);
|
return _improv.getTileImage(_imagePath, bounds, zations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -282,6 +324,49 @@ public abstract class TileSet
|
|||||||
buf.append(", tileCount=").append(getTileCount());
|
buf.append(", tileCount=").append(getTileCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Used when caching tiles. */
|
||||||
|
protected static class TileKey
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates a new tile key.
|
||||||
|
*/
|
||||||
|
public TileKey (TileSet tileSet, int tileIndex, Colorization[] zations)
|
||||||
|
{
|
||||||
|
_tset = tileSet;
|
||||||
|
_tidx = tileIndex;
|
||||||
|
_zations = zations;
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public boolean equals (Object other)
|
||||||
|
{
|
||||||
|
if (other instanceof TileKey) {
|
||||||
|
TileKey okey = (TileKey)other;
|
||||||
|
return (_tset == okey._tset && _tidx == okey._tidx &&
|
||||||
|
Arrays.equals(_zations, okey._zations));
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public int hashCode ()
|
||||||
|
{
|
||||||
|
int code = _tset.hashCode() ^ _tidx;
|
||||||
|
int zcount = (_zations == null) ? 0 : _zations.length;
|
||||||
|
for (int ii = 0; ii < zcount; ii++) {
|
||||||
|
if (_zations[ii] != null) {
|
||||||
|
code ^= _zations[ii].hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TileSet _tset;
|
||||||
|
protected int _tidx;
|
||||||
|
protected Colorization[] _zations;
|
||||||
|
}
|
||||||
|
|
||||||
/** The path to the file containing the tile images. */
|
/** The path to the file containing the tile images. */
|
||||||
protected String _imagePath;
|
protected String _imagePath;
|
||||||
|
|
||||||
@@ -298,16 +383,6 @@ public abstract class TileSet
|
|||||||
* a class change (modification of fields, inheritance). */
|
* a class change (modification of fields, inheritance). */
|
||||||
private static final long serialVersionUID = 1;
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
/** Temporary HACKOLA. */
|
|
||||||
protected static Colorization[] ZATIONS = new Colorization[] {
|
|
||||||
new Colorization(-1, new Color(0x8A1A76),
|
|
||||||
new float[] { .1f, .3f, 0.6f },
|
|
||||||
new float[] { -.85f, .3f, 0f }),
|
|
||||||
new Colorization(-1, new Color(0x2A864E),
|
|
||||||
new float[] { .1f, .3f, 0.6f },
|
|
||||||
new float[] { .71f, 0f, .07f }),
|
|
||||||
};
|
|
||||||
|
|
||||||
/** A weak cache of our tiles. */
|
/** A weak cache of our tiles. */
|
||||||
protected static LRUHashMap _tiles;
|
protected static LRUHashMap _tiles;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TrimmedObjectTileSet.java,v 1.9 2003/03/26 00:18:55 mdb Exp $
|
// $Id: TrimmedObjectTileSet.java,v 1.10 2003/04/01 02:16:28 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@ import com.samskivert.util.StringUtil;
|
|||||||
import com.threerings.media.Log;
|
import com.threerings.media.Log;
|
||||||
import com.threerings.media.image.Mirage;
|
import com.threerings.media.image.Mirage;
|
||||||
import com.threerings.media.tile.util.TileSetTrimmer;
|
import com.threerings.media.tile.util.TileSetTrimmer;
|
||||||
|
import com.threerings.media.image.Colorization;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object tileset in which the objects have been trimmed to the
|
* An object tileset in which the objects have been trimmed to the
|
||||||
@@ -80,6 +81,19 @@ public class TrimmedObjectTileSet extends TileSet
|
|||||||
return _bounds[tileIndex];
|
return _bounds[tileIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
protected Colorization[] getColorizations (int tileIndex, Colorizer rizer)
|
||||||
|
{
|
||||||
|
Colorization[] zations = null;
|
||||||
|
if (rizer != null && _zations != null) {
|
||||||
|
zations = new Colorization[_zations.length];
|
||||||
|
for (int ii = 0; ii < _zations.length; ii++) {
|
||||||
|
zations[ii] = rizer.getColorization(_zations[ii]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return zations;
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
protected Tile createTile (int tileIndex, Mirage tileImage)
|
protected Tile createTile (int tileIndex, Mirage tileImage)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user