Pass along the priorities and other business when trimming an object tile

set; also changed some things to be bytes since they are bytes.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2231 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-02-04 02:59:47 +00:00
parent d00619fe4d
commit f2f8611028
4 changed files with 178 additions and 7 deletions
@@ -1,5 +1,5 @@
//
// $Id: ObjectTileSet.java,v 1.12 2003/01/29 21:53:51 mdb Exp $
// $Id: ObjectTileSet.java,v 1.13 2003/02/04 02:59:47 mdb Exp $
package com.threerings.media.tile;
@@ -55,7 +55,7 @@ public class ObjectTileSet extends SwissArmyTileSet
/**
* Sets the default render priorities for our object tiles.
*/
public void setPriorities (int[] priorities)
public void setPriorities (byte[] priorities)
{
_priorities = priorities;
}
@@ -69,6 +69,58 @@ public class ObjectTileSet extends SwissArmyTileSet
_zations = zations;
}
/**
* Sets the x offset to the "spots" associated with our object tiles.
*/
public void setXSpots (short[] xspots)
{
_xspots = xspots;
}
/**
* Sets the y offset to the "spots" associated with our object tiles.
*/
public void setYSpots (short[] yspots)
{
_yspots = yspots;
}
/**
* Sets the orientation of the "spots" associated with our object
* tiles.
*/
public void setSpotOrients (byte[] sorients)
{
_sorients = sorients;
}
/**
* Returns the x coordinate of the spot associated with the specified
* tile index.
*/
public int getXSpot (int tileIdx)
{
return (_xspots == null) ? 0 : _xspots[tileIdx];
}
/**
* Returns the y coordinate of the spot associated with the specified
* tile index.
*/
public int getYSpot (int tileIdx)
{
return (_yspots == null) ? 0 : _yspots[tileIdx];
}
/**
* Returns the orientation of the spot associated with the specified
* tile index.
*/
public int getSpotOrient (int tileIdx)
{
return (_sorients == null) ? 0 : _sorients[tileIdx];
}
/**
* Returns the colorization classes that should be used to recolor
* objects in this tileset.
@@ -88,6 +140,9 @@ public class ObjectTileSet extends SwissArmyTileSet
buf.append(", yorigins=").append(StringUtil.toString(_yorigins));
buf.append(", prios=").append(StringUtil.toString(_priorities));
buf.append(", zations=").append(StringUtil.toString(_zations));
buf.append(", xspots=").append(StringUtil.toString(_xspots));
buf.append(", yspots=").append(StringUtil.toString(_yspots));
buf.append(", sorients=").append(StringUtil.toString(_sorients));
}
/**
@@ -122,11 +177,20 @@ public class ObjectTileSet extends SwissArmyTileSet
protected int[] _yorigins;
/** The default render priorities of our objects. */
protected int[] _priorities;
protected byte[] _priorities;
/** Colorization classes that apply to our objects. */
protected String[] _zations;
/** The x offset to the "spots" associated with our tiles. */
protected short[] _xspots;
/** The y offset to the "spots" associated with our tiles. */
protected short[] _yspots;
/** The orientation of the "spots" associated with our tiles. */
protected byte[] _sorients;
/** Increase this value when object's serialized state is impacted by
* a class change (modification of fields, inheritance). */
private static final long serialVersionUID = 1;
@@ -1,5 +1,5 @@
//
// $Id: TileManager.java,v 1.27 2003/01/13 22:49:46 mdb Exp $
// $Id: TileManager.java,v 1.28 2003/02/04 02:59:47 mdb Exp $
package com.threerings.media.tile;
@@ -199,6 +199,23 @@ public class TileManager
return set.getTile(tileIndex);
}
/**
* 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. */
protected ImageManager _imgr;
@@ -1,5 +1,5 @@
//
// $Id: TrimmedObjectTileSet.java,v 1.4 2003/01/15 09:28:43 mdb Exp $
// $Id: TrimmedObjectTileSet.java,v 1.5 2003/02/04 02:59:47 mdb Exp $
package com.threerings.media.tile;
@@ -7,6 +7,7 @@ import java.awt.Rectangle;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import com.samskivert.util.StringUtil;
@@ -41,6 +42,9 @@ public class TrimmedObjectTileSet extends TileSet
ObjectTile tile = new ObjectTile(tileImage);
tile.setBase(_ometrics[tileIndex].width, _ometrics[tileIndex].height);
tile.setOrigin(_ometrics[tileIndex].x, _ometrics[tileIndex].y);
if (_bits != null) {
tile.setPriority(_bits[tileIndex].priority);
}
return tile;
}
@@ -50,6 +54,8 @@ public class TrimmedObjectTileSet extends TileSet
super.toString(buf);
buf.append(", ometrics=").append(StringUtil.toString(_ometrics));
buf.append(", bounds=").append(StringUtil.toString(_bounds));
buf.append(", bits=").append(StringUtil.toString(_bits));
buf.append(", zations=").append(StringUtil.toString(_zations));
}
/**
@@ -75,6 +81,15 @@ public class TrimmedObjectTileSet extends TileSet
tset._bounds = new Rectangle[tcount];
tset._ometrics = new Rectangle[tcount];
// create our bits if needed
if (source._priorities != null ||
source._xspots != null) {
tset._bits = new Bits[tcount];
}
// copy our colorizations
tset._zations = source.getColorizations();
// fill in the original object metrics
for (int ii = 0; ii < tcount; ii++) {
tset._ometrics[ii] = new Rectangle();
@@ -86,6 +101,19 @@ public class TrimmedObjectTileSet extends TileSet
}
tset._ometrics[ii].width = source._owidths[ii];
tset._ometrics[ii].height = source._oheights[ii];
// fill in our bits
if (tset._bits != null) {
tset._bits[ii] = new Bits();
}
if (source._priorities != null) {
tset._bits[ii].priority = source._priorities[ii];
}
if (source._xspots != null) {
tset._bits[ii].xspot = source._xspots[ii];
tset._bits[ii].yspot = source._yspots[ii];
tset._bits[ii].sorient = source._sorients[ii];
}
}
// create the trimmed tileset image
@@ -109,6 +137,32 @@ public class TrimmedObjectTileSet extends TileSet
return tset;
}
/** Extra bits related to object tiles. */
protected static class Bits implements Serializable
{
/** The default render priority for this object. */
public byte priority;
/** The x coordinate of the "spot" associated with this object. */
public short xspot;
/** The y coordinate of the "spot" associated with this object. */
public short yspot;
/** The orientation of the "spot" associated with this object. */
public short sorient;
/** Generates a string representation of this instance. */
public String toString ()
{
return StringUtil.fieldsToString(this);
}
/** Increase this value when object's serialized state is impacted
* by a class change (modification of fields, inheritance). */
private static final long serialVersionUID = 1;
}
/** Contains the width and height of each object tile and the offset
* into the tileset image of their image data. */
protected Rectangle[] _bounds;
@@ -117,6 +171,12 @@ public class TrimmedObjectTileSet extends TileSet
* footprint width and height (in tile units). */
protected Rectangle[] _ometrics;
/** Extra bits relating to our objects. */
protected Bits[] _bits;
/** Colorization classes that apply to our objects. */
protected String[] _zations;
/** Increase this value when object's serialized state is impacted by
* a class change (modification of fields, inheritance). */
private static final long serialVersionUID = 1;
@@ -1,5 +1,5 @@
//
// $Id: ObjectTileSetRuleSet.java,v 1.6 2003/01/29 21:53:51 mdb Exp $
// $Id: ObjectTileSetRuleSet.java,v 1.7 2003/02/04 02:59:47 mdb Exp $
package com.threerings.media.tile.tools.xml;
@@ -93,7 +93,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
new CallMethodSpecialRule(digester) {
public void parseAndSet (String bodyText, Object target)
{
int[] prios = StringUtil.parseIntArray(bodyText);
byte[] prios = StringUtil.parseByteArray(bodyText);
((ObjectTileSet)target).setPriorities(prios);
}
});
@@ -107,6 +107,36 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
((ObjectTileSet)target).setColorizations(zations);
}
});
digester.addRule(
_prefix + TILESET_PATH + "/xspots",
new CallMethodSpecialRule(digester) {
public void parseAndSet (String bodyText, Object target)
{
short[] xspots = StringUtil.parseShortArray(bodyText);
((ObjectTileSet)target).setXSpots(xspots);
}
});
digester.addRule(
_prefix + TILESET_PATH + "/yspots",
new CallMethodSpecialRule(digester) {
public void parseAndSet (String bodyText, Object target)
{
short[] yspots = StringUtil.parseShortArray(bodyText);
((ObjectTileSet)target).setYSpots(yspots);
}
});
digester.addRule(
_prefix + TILESET_PATH + "/sorients",
new CallMethodSpecialRule(digester) {
public void parseAndSet (String bodyText, Object target)
{
byte[] sorients = StringUtil.parseByteArray(bodyText);
((ObjectTileSet)target).setSpotOrients(sorients);
}
});
}
// documentation inherited