Switch to new unified direction constants.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@818 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: CharacterManager.java,v 1.10 2001/11/27 08:09:34 mdb Exp $
|
||||
// $Id: CharacterManager.java,v 1.11 2001/12/17 03:33:40 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
@@ -130,7 +130,7 @@ public class CharacterManager
|
||||
CharacterDescriptor descrip, String action)
|
||||
throws NoSuchComponentException
|
||||
{
|
||||
MultiFrameImage[] frames = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
|
||||
MultiFrameImage[] frames = new MultiFrameImage[Sprite.DIRECTION_COUNT];
|
||||
|
||||
// obtain the necessary components
|
||||
int[] cids = descrip.getComponentIds();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: CharacterSprite.java,v 1.19 2001/11/29 20:33:44 mdb Exp $
|
||||
// $Id: CharacterSprite.java,v 1.20 2001/12/17 03:33:40 mdb Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CharacterSprite
|
||||
_charmgr = charmgr;
|
||||
|
||||
// assign an arbitrary starting orientation
|
||||
_orient = DIR_NORTH;
|
||||
_orient = NORTH;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SpritePanel.java,v 1.7 2001/12/13 06:35:52 mdb Exp $
|
||||
// $Id: SpritePanel.java,v 1.8 2001/12/17 03:33:40 mdb Exp $
|
||||
|
||||
package com.threerings.cast.builder;
|
||||
|
||||
@@ -95,7 +95,7 @@ public class SpritePanel
|
||||
protected void setSprite (CharacterSprite sprite)
|
||||
{
|
||||
sprite.setActionSequence(StandardActions.STANDING);
|
||||
sprite.setOrientation(Sprite.DIR_WEST);
|
||||
sprite.setOrientation(Sprite.WEST);
|
||||
_sprite = sprite;
|
||||
centerSprite();
|
||||
repaint();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: BundledComponentRepository.java,v 1.4 2001/12/07 01:33:29 mdb Exp $
|
||||
// $Id: BundledComponentRepository.java,v 1.5 2001/12/17 03:33:41 mdb Exp $
|
||||
|
||||
package com.threerings.cast.bundle;
|
||||
|
||||
@@ -233,7 +233,7 @@ public class BundledComponentRepository
|
||||
|
||||
// and create the necessary multiframe image instances
|
||||
MultiFrameImage[] frames =
|
||||
new MultiFrameImage[Sprite.NUM_DIRECTIONS];
|
||||
new MultiFrameImage[Sprite.DIRECTION_COUNT];
|
||||
for (int i = 0; i < frames.length; i++) {
|
||||
frames[i] = new TileSetFrameImage(fset, i);
|
||||
}
|
||||
@@ -271,7 +271,7 @@ public class BundledComponentRepository
|
||||
// documentation inherited
|
||||
public int getFrameCount ()
|
||||
{
|
||||
return _set.getTileCount() / Sprite.NUM_DIRECTIONS;
|
||||
return _set.getTileCount() / Sprite.DIRECTION_COUNT;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TileUtil.java,v 1.5 2001/11/27 08:39:43 mdb Exp $
|
||||
// $Id: TileUtil.java,v 1.6 2001/12/17 03:33:41 mdb Exp $
|
||||
|
||||
package com.threerings.cast.util;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class TileUtil
|
||||
public static void compositeFrames (
|
||||
MultiFrameImage[] dest, MultiFrameImage[] src)
|
||||
{
|
||||
for (int orient = 0; orient < Sprite.NUM_DIRECTIONS; orient++) {
|
||||
for (int orient = 0; orient < Sprite.DIRECTION_COUNT; orient++) {
|
||||
MultiFrameImage sframes = src[orient];
|
||||
MultiFrameImage dframes = dest[orient];
|
||||
|
||||
@@ -56,69 +56,6 @@ public class TileUtil
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 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];
|
||||
|
||||
// // 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;
|
||||
// }
|
||||
|
||||
// // 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);
|
||||
// }
|
||||
|
||||
// // create the multi frame image
|
||||
// frames[ii][dir] = new MultiFrameImageImpl(imgs);
|
||||
// }
|
||||
// }
|
||||
|
||||
// } catch (TileException te) {
|
||||
// Log.warning("Exception retrieving character images " +
|
||||
// "[te=" + te + "].");
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// 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;
|
||||
// }
|
||||
|
||||
/**
|
||||
* An implementation of the {@link MultiFrameImage} interface that
|
||||
* initializes itself to contain a specified number of blank
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Sprite.java,v 1.31 2001/11/02 01:09:08 shaper Exp $
|
||||
// $Id: Sprite.java,v 1.32 2001/12/17 03:32:52 mdb Exp $
|
||||
|
||||
package com.threerings.media.sprite;
|
||||
|
||||
@@ -8,34 +8,15 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.threerings.media.Log;
|
||||
import com.threerings.util.DirectionCodes;
|
||||
|
||||
/**
|
||||
* The sprite class represents a single moveable object in an animated
|
||||
* view. A sprite has a position within the view, and a set of images
|
||||
* used to render it (perhaps multiple frames for animation).
|
||||
*/
|
||||
public class Sprite
|
||||
public class Sprite implements DirectionCodes
|
||||
{
|
||||
/** The number of distinct directions. */
|
||||
public static final int NUM_DIRECTIONS = 8;
|
||||
|
||||
/** Direction constants. */
|
||||
public static final int DIR_NONE = -1;
|
||||
public static final int DIR_SOUTHWEST = 0;
|
||||
public static final int DIR_WEST = 1;
|
||||
public static final int DIR_NORTHWEST = 2;
|
||||
public static final int DIR_NORTH = 3;
|
||||
public static final int DIR_NORTHEAST = 4;
|
||||
public static final int DIR_EAST = 5;
|
||||
public static final int DIR_SOUTHEAST = 6;
|
||||
public static final int DIR_SOUTH = 7;
|
||||
|
||||
/** String translations for the direction constants. */
|
||||
public static String[] XLATE_DIRS = {
|
||||
"Southwest", "West", "Northwest", "North", "Northeast",
|
||||
"East", "Southeast", "South"
|
||||
};
|
||||
|
||||
/** Default frame rate. */
|
||||
public static final int DEFAULT_FRAME_RATE = 15;
|
||||
|
||||
@@ -160,10 +141,10 @@ public class Sprite
|
||||
|
||||
/**
|
||||
* Sprites have an orientation in one of the eight cardinal
|
||||
* directions: <code>DIR_NORTH</code>, <code>DIR_NORTHEAST</code>,
|
||||
* etc. Sprite derived classes can choose to override this member
|
||||
* function and select a different set of images based on their
|
||||
* orientation, or they can ignore the orientation information.
|
||||
* directions: <code>NORTH</code>, <code>NORTHEAST</code>, etc. Sprite
|
||||
* derived classes can choose to override this member function and
|
||||
* select a different set of images based on their orientation, or
|
||||
* they can ignore the orientation information.
|
||||
*/
|
||||
public void setOrientation (int orient)
|
||||
{
|
||||
@@ -172,8 +153,7 @@ public class Sprite
|
||||
|
||||
/**
|
||||
* Returns the sprite's orientation as one of the eight cardinal
|
||||
* directions: <code>DIR_NORTH</code>, <code>DIR_NORTHEAST</code>,
|
||||
* etc.
|
||||
* directions: <code>NORTH</code>, <code>NORTHEAST</code>, etc.
|
||||
*/
|
||||
public int getOrientation ()
|
||||
{
|
||||
@@ -530,7 +510,7 @@ public class Sprite
|
||||
protected int _frameIdx;
|
||||
|
||||
/** The orientation of this sprite. */
|
||||
protected int _orient = DIR_NONE;
|
||||
protected int _orient = NONE;
|
||||
|
||||
/** The location of the sprite in pixel coordinates. */
|
||||
protected int _x, _y;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: LineSegmentPath.java,v 1.13 2001/12/16 08:05:46 mdb Exp $
|
||||
// $Id: LineSegmentPath.java,v 1.14 2001/12/17 03:32:52 mdb Exp $
|
||||
|
||||
package com.threerings.media.sprite;
|
||||
|
||||
@@ -208,7 +208,7 @@ public class LineSegmentPath implements Path
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Point p = (Point)points.get(ii);
|
||||
|
||||
int dir = (ii == 0) ? Sprite.DIR_NORTH : getDirection(last, p);
|
||||
int dir = (ii == 0) ? Sprite.NORTH : getDirection(last, p);
|
||||
addNode(p.x, p.y, dir);
|
||||
last = p;
|
||||
}
|
||||
@@ -243,24 +243,24 @@ public class LineSegmentPath implements Path
|
||||
protected int getDirection (Point a, Point b)
|
||||
{
|
||||
if (a.x == b.x && a.y > b.y) {
|
||||
return Sprite.DIR_NORTH;
|
||||
return Sprite.NORTH;
|
||||
} else if (a.x < b.x && a.y > b.y) {
|
||||
return Sprite.DIR_NORTHEAST;
|
||||
return Sprite.NORTHEAST;
|
||||
} else if (a.x > b.x && a.y == b.y) {
|
||||
return Sprite.DIR_EAST;
|
||||
return Sprite.EAST;
|
||||
} else if (a.x > b.x && a.y < b.y) {
|
||||
return Sprite.DIR_SOUTHEAST;
|
||||
return Sprite.SOUTHEAST;
|
||||
} else if (a.x == b.x && a.y < b.y) {
|
||||
return Sprite.DIR_SOUTH;
|
||||
return Sprite.SOUTH;
|
||||
} else if (a.x > b.x && a.y < b.y) {
|
||||
return Sprite.DIR_SOUTHWEST;
|
||||
return Sprite.SOUTHWEST;
|
||||
} else if (a.x > b.x && a.y == b.y) {
|
||||
return Sprite.DIR_WEST;
|
||||
return Sprite.WEST;
|
||||
} else if (a.x > b.x && a.y > b.y) {
|
||||
return Sprite.DIR_NORTHWEST;
|
||||
return Sprite.NORTHWEST;
|
||||
}
|
||||
|
||||
return Sprite.DIR_NONE;
|
||||
return Sprite.NONE;
|
||||
}
|
||||
|
||||
/** The nodes that make up the path. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TilePath.java,v 1.2 2001/10/26 01:17:21 shaper Exp $
|
||||
// $Id: TilePath.java,v 1.3 2001/12/17 03:33:18 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -108,7 +108,7 @@ public class TilePath extends LineSegmentPath
|
||||
// add the starting path node
|
||||
int stx = sprite.getTileX(), sty = sprite.getTileY();
|
||||
int sx = sprite.getX(), sy = sprite.getY();
|
||||
addNode(stx, sty, sx, sy, Sprite.DIR_NORTH);
|
||||
addNode(stx, sty, sx, sy, Sprite.NORTH);
|
||||
|
||||
// TODO: make more visually appealing path segments from start
|
||||
// to second tile, and penultimate to ultimate tile.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoUtil.java,v 1.15 2001/11/18 04:09:22 mdb Exp $
|
||||
// $Id: IsoUtil.java,v 1.16 2001/12/17 03:33:18 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
@@ -169,7 +169,7 @@ public class IsoUtil
|
||||
|
||||
// compare tile coordinates to determine direction
|
||||
int dir = getIsoDirection(tax, tay, tbx, tby);
|
||||
if (dir != Sprite.DIR_NONE) return dir;
|
||||
if (dir != Sprite.NONE) return dir;
|
||||
|
||||
// destination point is in the same tile as the
|
||||
// origination point, so consider fine coordinates
|
||||
@@ -185,15 +185,15 @@ public class IsoUtil
|
||||
dir = getIsoDirection(fax, fay, fbx, fby);
|
||||
|
||||
// arbitrarily return southwest if fine coords were also equivalent
|
||||
return (dir == -1) ? Sprite.DIR_SOUTHWEST : dir;
|
||||
return (dir == -1) ? Sprite.SOUTHWEST : dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two points in an isometric coordinate system, return the
|
||||
* compass direction that point B lies in from point A. This
|
||||
* method is used to determine direction for both tile coordinates
|
||||
* and fine coordinates within a tile, since the coordinate
|
||||
* systems are the same.
|
||||
* compass direction that point B lies in from point A. This method
|
||||
* is used to determine direction for both tile coordinates and fine
|
||||
* coordinates within a tile, since the coordinate systems are the
|
||||
* same.
|
||||
*
|
||||
* @param ax the x-position of point A.
|
||||
* @param ay the y-position of point A.
|
||||
@@ -201,22 +201,28 @@ public class IsoUtil
|
||||
* @param by the y-position of point B.
|
||||
*
|
||||
* @return the direction specified as one of the <code>Sprite</code>
|
||||
* class's direction constants, or <code>Sprite.DIR_NONE</code>
|
||||
* class's direction constants, or <code>Sprite.NONE</code>
|
||||
* if point B is equivalent to point A.
|
||||
*/
|
||||
public static int getIsoDirection (int ax, int ay, int bx, int by)
|
||||
{
|
||||
if (bx > ax) {
|
||||
if (by == ay) return Sprite.DIR_SOUTH;
|
||||
return (by < ay) ? Sprite.DIR_SOUTHEAST : Sprite.DIR_SOUTHWEST;
|
||||
if (by == ay) {
|
||||
return Sprite.SOUTH;
|
||||
}
|
||||
return (by < ay) ? Sprite.SOUTHEAST : Sprite.SOUTHWEST;
|
||||
|
||||
} else if (bx == ax) {
|
||||
if (by == ay) return Sprite.DIR_NONE;
|
||||
return (by < ay) ? Sprite.DIR_EAST : Sprite.DIR_WEST;
|
||||
if (by == ay) {
|
||||
return Sprite.NONE;
|
||||
}
|
||||
return (by < ay) ? Sprite.EAST : Sprite.WEST;
|
||||
|
||||
} else { // bx < ax
|
||||
if (by == ay) return Sprite.DIR_NORTH;
|
||||
return (by < ay) ? Sprite.DIR_NORTHEAST : Sprite.DIR_NORTHWEST;
|
||||
if (by == ay) {
|
||||
return Sprite.NORTH;
|
||||
}
|
||||
return (by < ay) ? Sprite.NORTHEAST : Sprite.NORTHWEST;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
//
|
||||
// $Id: DirectionalEdge.java,v 1.3 2001/08/24 22:13:10 shaper Exp $
|
||||
// $Id: DirectionalEdge.java,v 1.4 2001/12/17 03:34:04 mdb Exp $
|
||||
|
||||
package com.threerings.nodemap.direction;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import com.threerings.nodemap.*;
|
||||
import com.threerings.util.DirectionCodes;
|
||||
|
||||
import com.threerings.nodemap.Edge;
|
||||
import com.threerings.nodemap.Node;
|
||||
|
||||
/**
|
||||
* A directional edge extends the {@link Edge} object to allow
|
||||
* associating a direction with the edge and rendering the edge to the
|
||||
* screen. The edge direction must be one of the directional
|
||||
* constants detailed in the {@link Directions} object.
|
||||
* A directional edge extends the {@link Edge} object to allow associating
|
||||
* a direction with the edge and rendering the edge to the screen. The
|
||||
* edge direction must be one of the directional constants detailed in the
|
||||
* {@link DirectionCodes} class.
|
||||
*/
|
||||
public class DirectionalEdge extends Edge
|
||||
{
|
||||
/** The edge direction as a {@link Directions} constant. */
|
||||
/** The edge direction as a {@link DirectionCodes} constant. */
|
||||
public int dir;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
//
|
||||
// $Id: DirectionalLayoutManager.java,v 1.3 2001/09/28 00:46:54 shaper Exp $
|
||||
// $Id: DirectionalLayoutManager.java,v 1.4 2001/12/17 03:34:04 mdb Exp $
|
||||
|
||||
package com.threerings.nodemap.direction;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.threerings.nodemap.*;
|
||||
import com.threerings.util.DirectionCodes;
|
||||
|
||||
import com.threerings.nodemap.Node;
|
||||
import com.threerings.nodemap.LayoutManager;
|
||||
|
||||
/**
|
||||
* The directional layout manager lays nodes out according to the
|
||||
* eight cardinal directions as specified in the {@link Directions}
|
||||
* class. The nodes must be fully connected in both directions with
|
||||
* {@link DirectionalEdge} edges.
|
||||
* The directional layout manager lays nodes out according to the eight
|
||||
* cardinal directions as specified in the {@link DirectionCodes} class.
|
||||
* The nodes must be fully connected in both directions with {@link
|
||||
* DirectionalEdge} edges.
|
||||
*/
|
||||
public class DirectionalLayoutManager implements LayoutManager
|
||||
public class DirectionalLayoutManager
|
||||
implements LayoutManager, DirectionCodes
|
||||
{
|
||||
/**
|
||||
* Construct a directional layout manager that lays out nodes
|
||||
@@ -57,39 +63,39 @@ public class DirectionalLayoutManager implements LayoutManager
|
||||
|
||||
// shift the node in the appropriate direction
|
||||
switch (e.dir) {
|
||||
case Directions.NORTH:
|
||||
case NORTH:
|
||||
tx -= (_edgelen + wid);
|
||||
ty -= (_edgelen + hei);
|
||||
break;
|
||||
|
||||
case Directions.NORTHEAST:
|
||||
case NORTHEAST:
|
||||
ty -= (_edgelen + hei);
|
||||
break;
|
||||
|
||||
case Directions.EAST:
|
||||
case EAST:
|
||||
tx += (_edgelen + wid);
|
||||
ty -= (_edgelen + hei);
|
||||
break;
|
||||
|
||||
case Directions.SOUTHEAST:
|
||||
case SOUTHEAST:
|
||||
tx += (_edgelen + wid);
|
||||
break;
|
||||
|
||||
case Directions.SOUTH:
|
||||
case SOUTH:
|
||||
tx += (_edgelen + wid);
|
||||
ty += (_edgelen + hei);
|
||||
break;
|
||||
|
||||
case Directions.SOUTHWEST:
|
||||
case SOUTHWEST:
|
||||
ty += (_edgelen + hei);
|
||||
break;
|
||||
|
||||
case Directions.WEST:
|
||||
case WEST:
|
||||
tx -= (_edgelen + wid);
|
||||
ty += (_edgelen + hei);
|
||||
break;
|
||||
|
||||
case Directions.NORTHWEST:
|
||||
case NORTHWEST:
|
||||
tx -= (_edgelen + wid);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
//
|
||||
// $Id: Directions.java,v 1.1 2001/08/20 22:56:55 shaper Exp $
|
||||
|
||||
package com.threerings.nodemap.direction;
|
||||
|
||||
/**
|
||||
* This class provides a holding place for constants referenced by the
|
||||
* classes that support and make use of directional node maps.
|
||||
*/
|
||||
public class Directions
|
||||
{
|
||||
/** Constants for the eight cardinal compass-point directions. */
|
||||
public static final int NORTH = 0;
|
||||
public static final int NORTHEAST = 1;
|
||||
public static final int EAST = 2;
|
||||
public static final int SOUTHEAST = 3;
|
||||
public static final int SOUTH = 4;
|
||||
public static final int SOUTHWEST = 5;
|
||||
public static final int WEST = 6;
|
||||
public static final int NORTHWEST = 7;
|
||||
|
||||
/** The number of directions. */
|
||||
public static final int NUM_DIRECTIONS = 8;
|
||||
}
|
||||
Reference in New Issue
Block a user