Abstracted character-sprite-related activity to the cast package in

preparation for character component compositing and other
character-related antics.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@575 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-10-26 01:17:22 +00:00
parent cf51ce8a9c
commit d102a47f13
26 changed files with 923 additions and 307 deletions
+2 -2
View File
@@ -1,11 +1,11 @@
//
// $Id: Log.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
// $Id: Log.java,v 1.3 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso;
/**
* A placeholder class that contains a reference to the log object used by
* the Spine package.
* the miso package.
*/
public class Log
{
@@ -1,5 +1,5 @@
//
// $Id: DirtyItemList.java,v 1.3 2001/10/25 16:35:45 shaper Exp $
// $Id: DirtyItemList.java,v 1.4 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso.scene;
@@ -22,7 +22,7 @@ public class DirtyItemList extends ArrayList
* item list.
*/
public void appendDirtySprite (
Sprite sprite, int x, int y, Rectangle dirtyRect)
MisoCharacterSprite sprite, int x, int y, Rectangle dirtyRect)
{
add(new DirtyItem(sprite, null, x, y, dirtyRect));
}
@@ -164,13 +164,13 @@ public class DirtyItemList extends ArrayList
if (da.ox == db.ox &&
da.oy == db.oy &&
(da.obj instanceof AmbulatorySprite) &&
(db.obj instanceof AmbulatorySprite)) {
(da.obj instanceof MisoCharacterSprite) &&
(db.obj instanceof MisoCharacterSprite)) {
// we're comparing two sprites co-existing on the same
// tile, so study their fine coordinates to determine
// rendering order
AmbulatorySprite as = (AmbulatorySprite)da.obj;
AmbulatorySprite bs = (AmbulatorySprite)db.obj;
MisoCharacterSprite as = (MisoCharacterSprite)da.obj;
MisoCharacterSprite bs = (MisoCharacterSprite)db.obj;
int ahei = as.getFineX() + as.getFineY();
int bhei = bs.getFineX() + bs.getFineY();
@@ -1,5 +1,5 @@
//
// $Id: IsoSceneView.java,v 1.69 2001/10/25 16:36:42 shaper Exp $
// $Id: IsoSceneView.java,v 1.70 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso.scene;
@@ -543,7 +543,8 @@ public class IsoSceneView implements SceneView
int size = _dirtySprites.size();
for (int ii = 0; ii < size; ii++) {
AmbulatorySprite sprite = (AmbulatorySprite)_dirtySprites.get(ii);
MisoCharacterSprite sprite =
(MisoCharacterSprite)_dirtySprites.get(ii);
// get the dirty portion of the sprite
Rectangle drect = sprite.getBounds().intersection(r);
@@ -576,7 +577,7 @@ public class IsoSceneView implements SceneView
}
// documentation inherited
public Path getPath (AmbulatorySprite sprite, int x, int y)
public Path getPath (MisoCharacterSprite sprite, int x, int y)
{
// make sure the destination point is within our bounds
if (!_model.bounds.contains(x, y)) {
@@ -0,0 +1,103 @@
//
// $Id: MisoCharacterSprite.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso.scene;
import com.threerings.cast.CharacterSprite;
import com.threerings.miso.tile.MisoTile;
/**
* The miso character sprite extends the basic character sprite to
* support the notion of tile passability, and to allow the sprite to
* store and make available its tile and fine coordinates within the
* scene. Note that the tile and fine coordinates must initially be
* set properly by whomever creates the sprite. Thereafter, the
* sprite will only be moved about via the {@link TilePath}, which
* will itself keep the sprite coordinates properly up to date.
*/
public class MisoCharacterSprite
extends CharacterSprite
implements Traverser
{
// documentation inherited
public boolean canTraverse (MisoTile tile)
{
// by default, passability is solely the province of the tile
return tile.passable;
}
/**
* Returns the sprite's location on the x-axis in tile coordinates.
*/
public int getTileX ()
{
return _tilex;
}
/**
* Returns the sprite's location on the y-axis in tile coordinates.
*/
public int getTileY ()
{
return _tiley;
}
/**
* Returns the sprite's location on the x-axis within its current
* tile in fine coordinates.
*/
public int getFineX ()
{
return _finex;
}
/**
* Returns the sprite's location on the y-axis within its current
* tile in fine coordinates.
*/
public int getFineY ()
{
return _finey;
}
/**
* Sets the sprite's location in tile coordinates; the sprite is
* not actually moved in any way. This method is only intended
* for use in updating the sprite's stored position which is made
* accessible to others that may care to review it.
*/
public void setTileLocation (int x, int y)
{
_tilex = x;
_tiley = y;
}
/**
* Sets the sprite's location in fine coordinates; the sprite is
* not actually moved in any way. This method is only intended
* for use in updating the sprite's stored position which is made
* accessible to others that may care to review it.
*/
public void setFineLocation (int x, int y)
{
_finex = x;
_finey = y;
}
// documentation inherited
protected void toString (StringBuffer buf)
{
super.toString(buf);
buf.append(", tilex=").append(_tilex);
buf.append(", tiley=").append(_tiley);
buf.append(", finex=").append(_finex);
buf.append(", finey=").append(_finey);
}
/** The sprite location in tile coordinates. */
protected int _tilex, _tiley;
/** The sprite location in fine coordinates. */
protected int _finex, _finey;
}
@@ -1,5 +1,5 @@
//
// $Id: SceneView.java,v 1.17 2001/10/22 18:21:41 shaper Exp $
// $Id: SceneView.java,v 1.18 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso.scene;
@@ -49,5 +49,5 @@ public interface SceneView
*
* @return the sprite's path, or null if no valid path exists.
*/
public Path getPath (AmbulatorySprite sprite, int x, int y);
public Path getPath (MisoCharacterSprite sprite, int x, int y);
}
@@ -1,5 +1,5 @@
//
// $Id: TilePath.java,v 1.1 2001/10/24 00:55:08 shaper Exp $
// $Id: TilePath.java,v 1.2 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso.scene;
@@ -31,7 +31,7 @@ public class TilePath extends LineSegmentPath
* coordinates.
*/
public TilePath (
IsoSceneViewModel model, AmbulatorySprite sprite, List tiles,
IsoSceneViewModel model, MisoCharacterSprite sprite, List tiles,
int destx, int desty)
{
_model = model;
@@ -46,7 +46,7 @@ public class TilePath extends LineSegmentPath
boolean moved = super.updatePosition(sprite, timestamp);
if (moved) {
AmbulatorySprite as = (AmbulatorySprite)sprite;
MisoCharacterSprite mcs = (MisoCharacterSprite)sprite;
int sx = sprite.getX(), sy = sprite.getY();
Point pos = new Point();
@@ -60,7 +60,7 @@ public class TilePath extends LineSegmentPath
// we've arrived
int dtx = _dest.getTileX(), dty = _dest.getTileY();
if (pos.x == dtx && pos.y == dty) {
as.setTileLocation(dtx, dty);
mcs.setTileLocation(dtx, dty);
// Log.info("Sprite arrived [dtx=" + dtx +
// ", dty=" + dty + "].");
_arrived = true;
@@ -68,14 +68,14 @@ public class TilePath extends LineSegmentPath
}
// get the sprite's latest fine coordinates
IsoUtil.tileToScreen(_model, as.getTileX(), as.getTileY(), pos);
IsoUtil.tileToScreen(_model, mcs.getTileX(), mcs.getTileY(), pos);
Point fpos = new Point();
IsoUtil.pixelToFine(_model, sx - pos.x, sy - pos.y, fpos);
// inform the sprite
as.setFineLocation(fpos.x, fpos.y);
mcs.setFineLocation(fpos.x, fpos.y);
// Log.info("Sprite moved [s=" + as + "].");
// Log.info("Sprite moved [s=" + mcs + "].");
}
return moved;
@@ -99,7 +99,7 @@ public class TilePath extends LineSegmentPath
* following the given list of tile coordinates.
*/
protected void createPath (
AmbulatorySprite sprite, List tiles, int destx, int desty)
MisoCharacterSprite sprite, List tiles, int destx, int desty)
{
// constrain destination pixels to fine coordinates
Point fpos = new Point();
@@ -1,5 +1,5 @@
//
// $Id: IsoUtil.java,v 1.13 2001/10/24 00:55:08 shaper Exp $
// $Id: IsoUtil.java,v 1.14 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso.scene.util;
@@ -18,6 +18,27 @@ import com.threerings.miso.scene.*;
*/
public class IsoUtil
{
/**
* Sets the given character sprite's tile and fine coordinate
* locations within the scene based on the sprite's current screen
* pixel coordinates. This method should be called whenever a
* {@link MisoCharacterSprite} is first created, but after its
* location has been set via {@link Sprite#setLocation}.
*/
public static void setSpriteSceneLocation (
IsoSceneViewModel model, MisoCharacterSprite sprite)
{
// get the sprite's position in full coordinates
Point fpos = new Point();
screenToFull(model, sprite.getX(), sprite.getY(), fpos);
// set the sprite's tile and fine coordinates
sprite.setTileLocation(
IsoUtil.fullToTile(fpos.x), IsoUtil.fullToTile(fpos.y));
sprite.setFineLocation(
IsoUtil.fullToFine(fpos.x), IsoUtil.fullToFine(fpos.y));
}
/**
* Returns a polygon bounding all footprint tiles of the given
* object tile.
@@ -1,69 +0,0 @@
//
// $Id: TileUtil.java,v 1.8 2001/10/25 18:06:17 shaper Exp $
package com.threerings.miso.tile;
import java.awt.Image;
import com.threerings.media.sprite.*;
import com.threerings.media.tile.*;
import com.threerings.miso.Log;
import com.threerings.miso.scene.AmbulatorySprite.CharacterImages;
/**
* Tile-related utility functions.
*/
public class TileUtil
{
/**
* Returns a {@link CharacterImages} object containing the frames
* of animation used to render the sprite while standing or
* walking in each of the directions it may face. The tileset id
* referenced must contain <code>Sprite.NUM_DIRECTIONS</code> rows
* of tiles, with each row containing first the single standing
* tile, followed by <code>frameCount</code> tiles describing the
* walking animation.
*
* @param tilemgr the tile manager to retrieve tiles from.
* @param tsid the tileset id containing the sprite tiles.
* @param frameCount the number of walking frames of animation.
*
* @return the ambulatory images object.
*/
public static CharacterImages getCharacterImages (
TileManager tilemgr, int tsid, int frameCount)
{
CharacterImages images = new CharacterImages();
images.standing = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
images.walking = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
try {
for (int ii = 0; ii < Sprite.NUM_DIRECTIONS; ii++) {
Image walkimgs[] = new Image[frameCount];
int rowcount = frameCount + 1;
for (int jj = 0; jj < rowcount; jj++) {
int idx = (ii * rowcount) + jj;
Image img = tilemgr.getTile(tsid, idx).img;
if (jj == 0) {
images.standing[ii] = new SingleFrameImageImpl(img);
} else {
walkimgs[jj - 1] = img;
}
}
images.walking[ii] = new MultiFrameImageImpl(walkimgs);
}
} catch (TileException te) {
Log.warning("Exception retrieving character images " +
"[te=" + te + "].");
return null;
}
return images;
}
}
@@ -1,5 +1,5 @@
//
// $Id: MisoUtil.java,v 1.9 2001/08/29 18:41:46 shaper Exp $
// $Id: MisoUtil.java,v 1.10 2001/10/26 01:17:22 shaper Exp $
package com.threerings.miso.util;
@@ -9,18 +9,24 @@ import java.net.URL;
import java.net.MalformedURLException;
import com.samskivert.util.*;
import com.threerings.cast.CharacterManager;
import com.threerings.resource.ResourceManager;
import com.threerings.media.ImageManager;
import com.threerings.media.tile.*;
import com.threerings.miso.Log;
import com.threerings.miso.scene.*;
import com.threerings.miso.scene.xml.XMLFileComponentRepository;
import com.threerings.miso.scene.xml.XMLFileSceneRepository;
import com.threerings.miso.tile.*;
/**
* MisoUtil provides miscellaneous routines for applications or other
* layers that intend to make use of Miso services.
* The miso util class provides miscellaneous routines for
* applications or other layers that intend to make use of Miso
* services.
*/
public class MisoUtil
{
@@ -28,7 +34,7 @@ public class MisoUtil
public static final String CONFIG_KEY = "miso";
/**
* Populate the config object with miso configuration values.
* Populates the config object with miso configuration values.
*
* @param config the <code>Config</code> object to populate.
*/
@@ -38,8 +44,27 @@ public class MisoUtil
}
/**
* Create an <code>XMLFileSceneRepository</code> object, reading the
* name of the class to instantiate from the config object.
* Creates a <code>CharacterManager</code> object.
*
* @param config the <code>Config</code> object.
* @param tilemgr the tile manager.
*
* @return the new character manager object or null if an error
* occurred.
*/
public static CharacterManager createCharacterManager (
Config config, TileManager tilemgr)
{
XMLFileComponentRepository crepo =
new XMLFileComponentRepository(config, tilemgr);
CharacterManager charmgr = new CharacterManager(tilemgr, crepo);
charmgr.setCharacterClass(MisoCharacterSprite.class);
return charmgr;
}
/**
* Creates an <code>XMLFileSceneRepository</code> object, reading
* the name of the class to instantiate from the config object.
*
* @param config the <code>Config</code> object.
*
@@ -63,7 +88,7 @@ public class MisoUtil
}
/**
* Create a <code>TileManager</code> object.
* Creates a <code>TileManager</code> object.
*
* @param config the <code>Config</code> object.
* @param frame the root frame to which images will be rendered.
@@ -80,7 +105,7 @@ public class MisoUtil
}
/**
* Create a <code>ResourceManager</code> object.
* Creates a <code>ResourceManager</code> object.
*
* @return the new resource manager object or null if an error occurred.
*/
@@ -90,7 +115,7 @@ public class MisoUtil
}
/**
* Create a <code>TileSetManager</code> object, reading the class
* Creates a <code>TileSetManager</code> object, reading the class
* name to instantiate from the config object.
*
* @param config the <code>Config</code> object.