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
+3 -3
View File
@@ -1,5 +1,5 @@
#
# $Id: miso.properties,v 1.13 2001/10/15 23:53:43 shaper Exp $
# $Id: miso.properties,v 1.14 2001/10/26 01:17:21 shaper Exp $
#
# Initial test config values for miso development.
#
@@ -16,8 +16,8 @@ sceneroot = rsrc/scenes
# the tileset descriptions
tilesets = rsrc/config/miso/tilesets.xml
# the character descriptions
characters = rsrc/config/miso/characters.xml
# the component descriptions
components = rsrc/config/miso/components.xml
# the list of building types
buildings = Inn, Hall, Bank, Agent, Palace
@@ -0,0 +1,83 @@
//
// $Id: CharacterComponent.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.cast;
import com.threerings.media.sprite.MultiFrameImage;
/**
* The character component represents a single component that can be
* composited with other character components to comprise an image
* representing a single monolithic character displayable in any of
* the eight cardinal compass directions as detailed in the {@link
* com.threerings.media.sprite.Sprite} class's direction constants.
*/
public class CharacterComponent
{
/**
* Constructs a character component.
*/
public CharacterComponent (ComponentType type, int cid,
ComponentFrames frames)
{
_type = type;
_cid = cid;
_frames = frames;
}
/**
* Returns the unique component identifier.
*/
public int getId ()
{
return _cid;
}
/**
* Returns the display frames used to display this component.
*/
public ComponentFrames getFrames ()
{
return _frames;
}
/**
* Returns the {@link ComponentType} object describing the base
* component type information associated with this component.
*/
public ComponentType getType ()
{
return _type;
}
/**
* Returns a string representation of this character component.
*/
public String toString ()
{
return "[cid=" + _cid + ", type=" + _type + "]";
}
/**
* A class to hold the standing and walking frames of animation
* that comprise a {@link CharacterComponent} object's various
* display images.
*/
public static class ComponentFrames
{
/** The standing animations in each orientation. */
public MultiFrameImage stand[];
/** The walking animations in each orientation. */
public MultiFrameImage walk[];
}
/** The unique character component identifier. */
protected int _cid;
/** The animation frames. */
protected ComponentFrames _frames;
/** The character component type. */
protected ComponentType _type;
}
@@ -0,0 +1,44 @@
//
// $Id: CharacterDescriptor.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.cast;
import com.samskivert.util.StringUtil;
/**
* The character descriptor object contains all necessary information
* on the character components that are composited together to create
* a character image.
*/
public class CharacterDescriptor
{
/**
* Constructs the character descriptor.
*/
public CharacterDescriptor (int components[])
{
_components = components;
}
/**
* Returns a list of the component identifiers comprising the
* character described by this descriptor.
*/
public int[] getComponents ()
{
return _components;
}
/**
* Returns a string representation of this character descriptor.
*/
public String toString ()
{
StringBuffer buf = new StringBuffer();
buf.append("[").append(StringUtil.toString(_components));
return buf.append("]").toString();
}
/** The array of component identifiers. */
protected int _components[];
}
@@ -1,22 +1,15 @@
//
// $Id: CharacterManager.java,v 1.4 2001/10/25 18:06:17 shaper Exp $
// $Id: CharacterManager.java,v 1.5 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso.scene;
package com.threerings.cast;
import java.awt.Point;
import java.io.IOException;
import com.samskivert.util.Config;
import com.samskivert.util.HashIntMap;
import com.threerings.media.sprite.MultiFrameImage;
import com.threerings.media.tile.TileManager;
import com.threerings.miso.Log;
import com.threerings.miso.scene.AmbulatorySprite.CharacterImages;
import com.threerings.miso.scene.xml.XMLCharacterParser;
import com.threerings.miso.tile.TileUtil;
import com.threerings.miso.util.MisoUtil;
import com.threerings.cast.Log;
import com.threerings.cast.TileUtil;
/**
* The character manager provides facilities for constructing sprites
@@ -25,82 +18,93 @@ import com.threerings.miso.util.MisoUtil;
public class CharacterManager
{
/**
* Construct the character manager.
* Constructs the character manager.
*/
public CharacterManager (
Config config, TileManager tilemgr, IsoSceneViewModel model)
public CharacterManager (TileManager tilemgr, ComponentRepository repo)
{
// save off our objects
_tilemgr = tilemgr;
_model = model;
// load character data descriptions
String file = config.getValue(CHARFILE_KEY, DEFAULT_CHARFILE);
try {
new XMLCharacterParser().loadCharacters(file, _characters);
} catch (IOException ioe) {
Log.warning("Exception loading character descriptions " +
"[ioe=" + ioe + "].");
}
_repo = repo;
}
/**
* Returns a sprite representing the character described by the
* given tile set id.
* Returns a {@link CharacterSprite} representing the character
* described by the given {@link CharacterDescriptor}, or
* <code>null</code> if an error occurs.
*
* @param the character tile set id.
* @param desc the character descriptor.
*/
public AmbulatorySprite getCharacter (int tsid)
public CharacterSprite getCharacter (CharacterDescriptor desc)
{
CharacterInfo info = (CharacterInfo)_characters.get(tsid);
if (info == null) {
// no such character
Log.warning("Unknown character requested [tsid=" + tsid + "].");
// get the list of component ids
int components[] = desc.getComponents();
// TODO: here is where we'd iterate through all components
// building up the full composite image of the sprite in each
// orientation, standing and walking. we punt for now, but
// we'll revisit this soon enough.
if (components.length == 0 || components.length > 1) {
Log.warning("Invalid number of components " +
" [size=" + components.length + "].");
return null;
}
CharacterImages imgs = TileUtil.getCharacterImages(
_tilemgr, tsid, info.frameCount);
CharacterComponent comp;
try {
// as noted above, no compositing for now. note that when
// we do composite, we probably will want to make sure all
// components share a compatible component type.
comp = _repo.getComponent(components[0]);
} catch (Exception e) {
Log.warning("Exception retrieving character component " +
"[e=" + e + "].");
return null;
}
AmbulatorySprite sprite = new AmbulatorySprite(_model, 0, 0, imgs);
sprite.setFrameRate(info.fps);
sprite.setOrigin(info.origin.x, info.origin.y);
// instantiate the character sprite
CharacterSprite sprite;
try {
sprite = (CharacterSprite)_charClass.newInstance();
} catch (Exception e) {
Log.warning("Failed to instantiate character sprite " +
"[e=" + e + "].");
Log.logStackTrace(e);
return null;
}
// populate the character sprite with its attributes
ComponentType ctype = comp.getType();
sprite.setFrames(comp.getFrames());
sprite.setFrameRate(ctype.fps);
sprite.setOrigin(ctype.origin.x, ctype.origin.y);
return sprite;
}
/** The config key for the character description file. */
protected static final String CHARFILE_KEY =
MisoUtil.CONFIG_KEY + ".characters";
/**
* Instructs the character manager to construct instances of this
* derived class of <code>CharacterSprite</code>.
*/
public void setCharacterClass (Class charClass)
{
// sanity check
if (!CharacterSprite.class.isAssignableFrom(charClass)) {
Log.warning("Requested to use character class that does not " +
"derive from CharacterSprite " +
"[class=" + charClass.getName() + "].");
return;
}
/** The default character description file. */
protected static final String DEFAULT_CHARFILE =
"rsrc/config/miso/characters.xml";
/** The hashtable of character info objects. */
protected HashIntMap _characters = new HashIntMap();
// make a note of it
_charClass = charClass;
}
/** The tile manager. */
protected TileManager _tilemgr;
/** The iso scene view model. */
protected IsoSceneViewModel _model;
/** The component repository. */
protected ComponentRepository _repo;
/**
* A class that contains character description information for a
* single character for use when constructing the character's
* sprite.
*/
public static class CharacterInfo
{
public int tsid;
public int frameCount;
public int fps;
public Point origin = new Point();
public String toString ()
{
return "[tsid=" + tsid + ", frameCount=" + frameCount +
", fps=" + fps + ", origin=" + origin + "]";
}
}
/** The character class to be created. */
protected Class _charClass = CharacterSprite.class;
}
+24 -152
View File
@@ -1,44 +1,38 @@
//
// $Id: CharacterSprite.java,v 1.15 2001/10/25 18:06:17 shaper Exp $
// $Id: CharacterSprite.java,v 1.16 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso.scene;
package com.threerings.cast;
import java.awt.Point;
import com.threerings.media.sprite.*;
import com.threerings.miso.Log;
import com.threerings.miso.tile.MisoTile;
import com.threerings.miso.scene.util.IsoUtil;
import com.threerings.cast.Log;
import com.threerings.cast.CharacterComponent.ComponentFrames;
/**
* An ambulatory sprite is a sprite that animates itself while walking
* A character sprite is a sprite that animates itself while walking
* about in a scene.
*/
public class AmbulatorySprite extends Sprite implements Traverser
public class CharacterSprite extends Sprite
{
/**
* Construct an <code>AmbulatorySprite</code>, with a multi-frame
* image associated with each of the eight compass directions. The
* array should be in the order defined by the <code>Sprite</code>
* direction constants (SW, W, NW, N, NE, E, SE, S).
*
* @param x the sprite x-position in pixels.
* @param y the sprite y-position in pixels.
* @param images the images used to display the sprite when
* standing or walking about.
* Constructs a character sprite.
*/
public AmbulatorySprite (
IsoSceneViewModel model, int x, int y, CharacterImages images)
public CharacterSprite ()
{
super(x, y);
// assign an arbitrary starting orientation
_orient = DIR_NORTH;
}
// keep track of these
_model = model;
_images = images;
// give ourselves an initial orientation
setOrientation(DIR_NORTH);
/**
* Sets the walking and standing frames of animation used to
* display this character.
*/
public void setFrames (ComponentFrames frames)
{
_anims = frames;
setFrames(_anims.walk[_orient]);
}
// documentation inherited
@@ -48,9 +42,9 @@ public class AmbulatorySprite extends Sprite implements Traverser
// update the sprite frames to reflect the direction
if (_path == null) {
setFrames(_images.standing[_orient]);
setFrames(_anims.stand[_orient]);
} else {
setFrames(_images.walking[_orient]);
setFrames(_anims.walk[_orient]);
}
}
@@ -110,137 +104,15 @@ public class AmbulatorySprite extends Sprite implements Traverser
protected void halt ()
{
// come to a halt looking settled and at peace
setFrames(_images.standing[_orient]);
setFrames(_anims.stand[_orient]);
// disable walking animation
setAnimationMode(NO_ANIMATION);
}
// 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;
}
// documentation inherited
public void setLocation (int x, int y)
{
super.setLocation(x, y);
if (_path == null) {
// we only calculate the sprite's tile and fine
// coordinates if we have no path, since paths that move
// us about are responsible for keeping our scene
// coordinates up to date since only they can know where
// we really are while in transition from one place to
// another.
// get the sprite's position in full coordinates
Point fpos = new Point();
IsoUtil.screenToFull(_model, _x, _y, fpos);
// save off the sprite's tile and fine coordinates
_tilex = IsoUtil.fullToTile(fpos.x);
_tiley = IsoUtil.fullToTile(fpos.y);
_finex = IsoUtil.fullToFine(fpos.x);
_finey = IsoUtil.fullToFine(fpos.y);
}
}
/**
* 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);
}
/**
* A class to hold the images that are used to display the sprite
* while walking about.
*/
public static class CharacterImages
{
/** The images of the sprite standing at rest in each orientation. */
public MultiFrameImage standing[];
/** The images of the sprite walking in each orientation. */
public MultiFrameImage walking[];
}
/** The animation frames for the sprite facing each direction. */
protected CharacterImages _images;
/** The iso scene view model. */
protected IsoSceneViewModel _model;
/** The standing and walking animations for the sprite. */
protected ComponentFrames _anims;
/** The origin of the sprite. */
protected int _xorigin, _yorigin;
/** The sprite location in tile coordinates. */
protected int _tilex, _tiley;
/** The sprite location in fine coordinates. */
protected int _finex, _finey;
}
@@ -0,0 +1,36 @@
//
// $Id: ComponentRepository.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.cast;
import java.util.Iterator;
/**
* The component repository interface is intended to be implemented by
* classes that provide access to {@link CharacterComponent} objects
* keyed on their unique component identifier.
*/
public interface ComponentRepository
{
/**
* Returns the {@link CharacterComponent} object for the given
* unique component identifier.
*/
public CharacterComponent getComponent (int cid)
throws NoSuchComponentException, NoSuchComponentTypeException;
/**
* Returns an iterator over the <code>Integer</code> objects
* representing all available character component identifiers for
* the given character component type identifier.
*/
public Iterator enumerateComponents (int ctid)
throws NoSuchComponentTypeException;
/**
* Returns an iterator over the <code>Integer</code> objects
* representing all available character component type
* identifiers.
*/
public Iterator enumerateComponentTypes ();
}
@@ -0,0 +1,35 @@
//
// $Id: ComponentType.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.cast;
import java.awt.Point;
/**
* The component type class contains the base information necessary
* for a variety of {@link CharacterComponent} objects to be usefully
* composited into animation sequences representing a character.
*/
public class ComponentType
{
/** The unique component type identifier. */
public int ctid;
/** The number of animation frames. */
public int frameCount;
/** The number of frames per second to show when animating. */
public int fps;
/** The origin of the component type's base. */
public Point origin = new Point();
/**
* Returns a string representation of this component type.
*/
public String toString ()
{
return "[ctid=" + ctid + ", frameCount=" + frameCount +
", fps=" + fps + ", origin=" + origin + "]";
}
}
+38
View File
@@ -0,0 +1,38 @@
//
// $Id: Log.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.cast;
/**
* A placeholder class that contains a reference to the log object used by
* the cast package.
*/
public class Log
{
public static com.samskivert.util.Log log =
new com.samskivert.util.Log("cast");
/** Convenience function. */
public static void debug (String message)
{
log.debug(message);
}
/** Convenience function. */
public static void info (String message)
{
log.info(message);
}
/** Convenience function. */
public static void warning (String message)
{
log.warning(message);
}
/** Convenience function. */
public static void logStackTrace (Throwable t)
{
log.logStackTrace(com.samskivert.util.Log.WARNING, t);
}
}
@@ -0,0 +1,24 @@
//
// $Id: NoSuchComponentException.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.cast;
/**
* Thrown when an attempt is made to retrieve a non-existent character
* component from the component repository.
*/
public class NoSuchComponentException extends Exception
{
public NoSuchComponentException (int cid)
{
super("No such component [cid=" + cid + "]");
_cid = cid;
}
public int getId ()
{
return _cid;
}
protected int _cid;
}
@@ -0,0 +1,24 @@
//
// $Id: NoSuchComponentTypeException.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.cast;
/**
* Thrown when an attempt is made to reference a non-existent
* component type in the component repository.
*/
public class NoSuchComponentTypeException extends Exception
{
public NoSuchComponentTypeException (int ctid)
{
super("No such component type [ctid=" + ctid + "]");
_ctid = ctid;
}
public int getTypeId ()
{
return _ctid;
}
protected int _ctid;
}
@@ -1,23 +1,23 @@
//
// $Id: TileUtil.java,v 1.8 2001/10/25 18:06:17 shaper Exp $
// $Id: TileUtil.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.miso.tile;
package com.threerings.cast;
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;
import com.threerings.cast.Log;
import com.threerings.cast.CharacterComponent.ComponentFrames;
/**
* Tile-related utility functions.
* Miscellaneous tile-related utility functions.
*/
public class TileUtil
{
/**
* Returns a {@link CharacterImages} object containing the frames
* Returns a {@link ComponentFrames} 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
@@ -28,42 +28,39 @@ public class TileUtil
* @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 (
public static ComponentFrames getComponentFrames (
TileManager tilemgr, int tsid, int frameCount)
{
CharacterImages images = new CharacterImages();
images.standing = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
images.walking = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
ComponentFrames frames = new ComponentFrames();
frames.walk = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
frames.stand = 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);
frames.stand[ii] = new SingleFrameImageImpl(img);
} else {
walkimgs[jj - 1] = img;
}
}
images.walking[ii] = new MultiFrameImageImpl(walkimgs);
frames.walk[ii] = new MultiFrameImageImpl(walkimgs);
}
} catch (TileException te) {
Log.warning("Exception retrieving character images " +
"[te=" + te + "].");
return null;
return null;
}
return images;
return frames;
}
}
@@ -0,0 +1,80 @@
//
// $Id: XMLComponentParser.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
package com.threerings.cast;
import java.awt.Point;
import java.io.IOException;
import org.xml.sax.*;
import com.samskivert.util.HashIntMap;
import com.samskivert.util.StringUtil;
import com.samskivert.xml.SimpleParser;
public class XMLComponentParser extends SimpleParser
{
// documentation inherited
public void startElement (String uri, String localName,
String qName, Attributes attributes)
{
if (qName.equals("type")) {
// construct the component type object
ComponentType ct = new ComponentType();
// retrieve character attributes
ct.ctid = parseInt(attributes.getValue("ctid"));
ct.frameCount = parseInt(attributes.getValue("frames"));
ct.fps = parseInt(attributes.getValue("fps"));
parsePoint(attributes.getValue("origin"), ct.origin);
Log.info("Parsed component type [ct=" + ct + "].");
// save the component type
_types.put(ct.ctid, ct);
} else if (qName.equals("component")) {
// save off the component info
int cid = parseInt(attributes.getValue("cid"));
int ctid = parseInt(attributes.getValue("ctid"));
_components.put(cid, new Integer(ctid));
}
}
/**
* Loads the component descriptions in the given file into {@link
* ComponentType} and {@link CharacterComponent} objects in the
* given hashtables, respectively, keyed on the type and component
* unique id, also respectively.
*/
public void loadComponents (
String file, HashIntMap types, HashIntMap components)
throws IOException
{
// save off hashtables for reference while parsing
_types = types;
_components = components;
parseFile(file);
}
/**
* Converts a string containing values as (x, y) into the
* corresponding integer values and populates the given point
* object.
*
* @param str the point values in string format.
* @param point the point object to populate.
*/
protected void parsePoint (String str, Point point)
{
int vals[] = StringUtil.parseIntArray(str);
point.setLocation(vals[0], vals[1]);
}
/** The hashtable of component types gathered while parsing. */
protected HashIntMap _types;
/** The hashtable of character components gathered while parsing. */
protected HashIntMap _components;
}
@@ -0,0 +1,159 @@
//
// $Id: XMLComponentRepository.java,v 1.1 2001/10/26 01:17:22 shaper Exp $
package com.threerings.miso.scene.xml;
import java.io.IOException;
import java.util.Iterator;
import com.samskivert.util.Config;
import com.samskivert.util.HashIntMap;
import com.threerings.cast.*;
import com.threerings.cast.CharacterComponent.ComponentFrames;
import com.threerings.media.tile.TileManager;
import com.threerings.miso.Log;
import com.threerings.miso.util.MisoUtil;
/**
* The xml file component repository provides access to character
* components obtained from component descriptions stored in an XML
* file.
*/
public class XMLFileComponentRepository implements ComponentRepository
{
/**
* Constructs an xml file component repository.
*/
public XMLFileComponentRepository (Config config, TileManager tilemgr)
{
// save off our objects
_tilemgr = tilemgr;
// load component types and components
String file = config.getValue(COMPFILE_KEY, DEFAULT_COMPFILE);
try {
new XMLComponentParser().loadComponents(
file, _types, _components);
} catch (IOException ioe) {
Log.warning("Exception loading component descriptions " +
"[ioe=" + ioe + "].");
}
}
// documentation inherited
public CharacterComponent getComponent (int cid)
throws NoSuchComponentException, NoSuchComponentTypeException
{
// get the component type id
Integer ctid = (Integer)_components.get(cid);
if (ctid == null) {
throw new NoSuchComponentException(cid);
}
// get the component type
ComponentType type = (ComponentType)_types.get(ctid.intValue());
if (type == null) {
throw new NoSuchComponentTypeException(ctid.intValue());
}
// get the character animation images
ComponentFrames frames = TileUtil.getComponentFrames(
_tilemgr, cid, type.frameCount);
// create the component
return new CharacterComponent(type, cid, frames);
}
// documentation inherited
public Iterator enumerateComponents (int ctid)
throws NoSuchComponentTypeException
{
return new ComponentTypeIterator(ctid);
}
// documentation inherited
public Iterator enumerateComponentTypes ()
{
return _types.keys();
}
/**
* Iterates over all components of a specified component type in
* the component hashtable.
*/
protected class ComponentTypeIterator implements Iterator
{
public ComponentTypeIterator (int ctid)
throws NoSuchComponentTypeException
{
_ctid = ctid;
_iter = _components.keys();
advance();
// make sure we have at least one component of the
// specified type
if (_next == null) {
throw new NoSuchComponentTypeException(ctid);
}
}
public boolean hasNext ()
{
return (_next != null);
}
public Object next ()
{
Object next = _next;
advance();
return next;
}
public void remove ()
{
throw new UnsupportedOperationException();
}
protected void advance ()
{
while (_iter.hasNext()) {
CharacterComponent c = (CharacterComponent)_iter.next();
if (c.getType().ctid == _ctid) {
_next = c;
return;
}
}
_next = null;
}
/** The component type id we're enumerating over. */
protected int _ctid;
/** The next character component of the component type id
* associated with this iterator, or null if no more exist. */
protected Object _next;
/** Iterator over the components in the repository. */
protected Iterator _iter;
}
/** The config key for the character description file. */
protected static final String COMPFILE_KEY =
MisoUtil.CONFIG_KEY + ".components";
/** The default character description file. */
protected static final String DEFAULT_COMPFILE =
"rsrc/config/miso/components.xml";
/** The hashtable of component types. */
protected HashIntMap _types = new HashIntMap();
/** The hashtable of character components. */
protected HashIntMap _components = new HashIntMap();
/** The tile manager. */
protected TileManager _tilemgr;
}
@@ -1,5 +1,5 @@
//
// $Id: Sprite.java,v 1.29 2001/10/25 03:01:13 shaper Exp $
// $Id: Sprite.java,v 1.30 2001/10/26 01:17:21 shaper Exp $
package com.threerings.media.sprite;
@@ -49,7 +49,32 @@ public class Sprite
public static final int TIME_BASED = 2;
/**
* Construct a sprite object.
* Constructs a sprite without any associated frames and with a
* default initial location of <code>(0, 0)</code>. The sprite
* should be populated with a set of frames used to display it via
* a subsequent call to {@link #setFrames}, and its location
* can be updated with {@link #setLocation}.
*/
public Sprite ()
{
init(0, 0, null);
}
/**
* Constructs a sprite without any associated frames. The sprite
* should be populated with a set of frames used to display it via
* a subsequent call to {@link #setFrames}.
*
* @param x the sprite x-position in pixels.
* @param y the sprite y-position in pixels.
*/
public Sprite (int x, int y)
{
init(x, y, null);
}
/**
* Constructs a sprite.
*
* @param x the sprite x-position in pixels.
* @param y the sprite y-position in pixels.
@@ -60,19 +85,6 @@ public class Sprite
init(x, y, frames);
}
/**
* Construct a sprite object without any associated frames. The sprite
* should be populated with a set of frames used to display it via a
* subsequent call to {@link #setFrames}.
*
* @param x the sprite x-position in pixels.
* @param y the sprite y-position in pixels.
*/
public Sprite (int x, int y)
{
init(x, y, null);
}
/**
* Returns the sprite's x position in screen coordinates.
*/
+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,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.
-12
View File
@@ -1,12 +0,0 @@
<?xml version="1.0" standalone="yes"?>
<!-- $Id: characters.xml,v 1.5 2001/10/25 18:07:13 shaper Exp $ -->
<!-- Initial test character description data. -->
<characters>
<character tsid="1011" frames="5" fps="5" origin="47, 80"/>
<character tsid="1012" frames="6" fps="5" origin="47, 80"/>
</characters>
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" standalone="yes"?>
<!-- $Id: components.xml,v 1.1 2001/10/26 01:17:21 shaper Exp $ -->
<!-- Initial test character component description data. -->
<charactercomponents>
<componenttypes>
<type ctid="1" frames="5" fps="5" origin="47, 80"/>
<type ctid="2" frames="6" fps="5" origin="47, 80"/>
</componenttypes>
<components>
<component cid="1011" ctid="1"/>
<component cid="1012" ctid="2"/>
</components>
</charactercomponents>
+43
View File
@@ -0,0 +1,43 @@
<?xml version="1.0" standalone="yes"?>
<scene>
<name>Untitled Scene</name>
<version>1</version>
<locations></locations>
<clusters></clusters>
<portals></portals>
<tiles>
<layer lnum="0">
<row rownum="0">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="1">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,3,1010,2,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="2">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,3,1010,3,1010,2,1010,2,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="3">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,3,1010,3,1010,3,1010,3,1010,2,1010,2,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="4">1004,10,1004,10,1004,10,1004,10,1004,10,1010,2,1010,2,1010,2,1010,3,1010,2,1010,2,1010,2,1010,2,1010,3,1010,3,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="5">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,3,1010,2,1010,2,1010,2,1010,2,1010,2,1010,3,1010,3,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="6">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,3,1010,2,1010,2,1010,2,1010,2,1010,2,1010,3,1010,3,1010,3,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="7">1004,10,1004,10,1010,3,1010,3,1004,10,1004,10,1004,10,1004,10,1010,3,1010,2,1010,2,1010,2,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="8">1004,10,1010,2,1010,3,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,3,1010,2,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1010,3,1004,10,1004,10,1004,10</row>
<row rownum="9">1010,2,1010,2,1010,3,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,3,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1010,3,1010,3,1004,10,1004,10</row>
<row rownum="10">1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,3,1010,3,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1004,10</row>
<row rownum="11">1004,10,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2</row>
<row rownum="12">1004,10,1004,10,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,3,1010,3,1010,3,1010,2,1010,2</row>
<row rownum="13">1004,10,1004,10,1004,10,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1010,2,1010,2,1004,10,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1010,2,1004,10</row>
<row rownum="14">1004,10,1004,10,1004,10,1004,10,1010,2,1004,10,1004,10,1004,10,1004,10,1010,2,1010,2,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1010,2,1010,2,1010,2,1004,10,1004,10</row>
<row rownum="15">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,2,1010,2,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1010,3,1010,3,1004,10,1004,10,1004,10</row>
<row rownum="16">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,3,1010,3,1010,3,1010,2,1010,2,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1010,3,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="17">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,3,1010,3,1010,2,1010,3,1010,3,1010,2,1010,3,1010,3,1010,3,1010,3,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="18">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,3,1010,2,1010,2,1010,3,1010,2,1010,3,1010,3,1010,3,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="19">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,2,1010,2,1010,2,1010,2,1010,3,1010,3,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="20">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,2,1010,2,1010,2,1010,3,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
<row rownum="21">1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1010,2,1010,2,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10,1004,10</row>
</layer>
<layer lnum="1"></layer>
<layer lnum="2">
<row rownum="7" colstart="7">1009,0</row>
<row rownum="9" colstart="17">1009,0</row>
<row rownum="15" colstart="8">1009,0</row>
<row rownum="16" colstart="16">1009,0</row>
</layer>
</tiles>
</scene>
@@ -1,5 +1,5 @@
//
// $Id: ViewerSceneViewPanel.java,v 1.22 2001/10/25 22:08:29 mdb Exp $
// $Id: ViewerSceneViewPanel.java,v 1.23 2001/10/26 01:17:22 shaper Exp $
package com.threerings.miso.viewer;
@@ -10,7 +10,10 @@ import javax.swing.JPanel;
import com.samskivert.util.Config;
import com.threerings.cast.*;
import com.threerings.media.sprite.*;
import com.threerings.media.tile.TileManager;
import com.threerings.media.util.RandomUtil;
import com.threerings.media.util.PerformanceMonitor;
import com.threerings.media.util.PerformanceObserver;
@@ -18,6 +21,7 @@ import com.threerings.media.util.PerformanceObserver;
import com.threerings.miso.Log;
import com.threerings.miso.scene.*;
import com.threerings.miso.scene.xml.XMLFileSceneRepository;
import com.threerings.miso.scene.util.IsoUtil;
import com.threerings.miso.util.*;
import com.threerings.miso.viewer.util.ViewerContext;
@@ -40,8 +44,8 @@ public class ViewerSceneViewPanel extends SceneViewPanel
prepareStartingScene();
// construct the character manager from which we obtain sprites
CharacterManager charmgr = new CharacterManager(
ctx.getConfig(), ctx.getTileManager(), _scenemodel);
CharacterManager charmgr = MisoUtil.createCharacterManager(
ctx.getConfig(), ctx.getTileManager());
// create the manipulable sprite
_sprite = createSprite(spritemgr, charmgr, TSID_CHAR_USER);
@@ -62,12 +66,16 @@ public class ViewerSceneViewPanel extends SceneViewPanel
/**
* Creates a new sprite.
*/
protected AmbulatorySprite createSprite (
protected MisoCharacterSprite createSprite (
SpriteManager spritemgr, CharacterManager charmgr, int tsid)
{
AmbulatorySprite s = charmgr.getCharacter(tsid);
int dummy[] = { tsid };
CharacterDescriptor desc = new CharacterDescriptor(dummy);
MisoCharacterSprite s =
(MisoCharacterSprite)charmgr.getCharacter(desc);
if (s != null) {
s.setLocation(300, 300);
IsoUtil.setSpriteSceneLocation(_scenemodel, s);
s.addSpriteObserver(this);
spritemgr.addSprite(s);
}
@@ -81,7 +89,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
protected void createDecoys (
SpriteManager spritemgr, CharacterManager charmgr)
{
_decoys = new AmbulatorySprite[NUM_DECOYS];
_decoys = new MisoCharacterSprite[NUM_DECOYS];
for (int ii = 0; ii < NUM_DECOYS; ii++) {
_decoys[ii] = createSprite(spritemgr, charmgr, TSID_CHAR);
if (_decoys[ii] != null) {
@@ -133,7 +141,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
* screen coordinates. Returns whether a path was successfully
* assigned.
*/
protected boolean createPath (AmbulatorySprite s, int x, int y)
protected boolean createPath (MisoCharacterSprite s, int x, int y)
{
// get the path from here to there
Path path = _view.getPath(s, x, y);
@@ -151,7 +159,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
/**
* Assigns a new random path to the given sprite.
*/
protected void createRandomPath (AmbulatorySprite s)
protected void createRandomPath (MisoCharacterSprite s)
{
Dimension d = _scenemodel.bounds.getSize();
@@ -166,7 +174,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
public void handleEvent (SpriteEvent event)
{
if (event instanceof PathCompletedEvent) {
AmbulatorySprite s = (AmbulatorySprite)event.getSprite();
MisoCharacterSprite s = (MisoCharacterSprite)event.getSprite();
if (s != _sprite) {
// move the sprite to a new random location
@@ -188,10 +196,10 @@ public class ViewerSceneViewPanel extends SceneViewPanel
protected AnimationManager _animmgr;
/** The sprite we're manipulating within the view. */
protected AmbulatorySprite _sprite;
protected MisoCharacterSprite _sprite;
/** The test sprites that meander about aimlessly. */
protected AmbulatorySprite _decoys[];
protected MisoCharacterSprite _decoys[];
/** The context object. */
protected ViewerContext _ctx;