More polishing work on scene rendering.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@543 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-10-24 00:55:08 +00:00
parent 7263ecba95
commit c839b61548
12 changed files with 745 additions and 351 deletions
@@ -1,5 +1,5 @@
//
// $Id: CharacterManager.java,v 1.2 2001/10/22 18:21:41 shaper Exp $
// $Id: CharacterManager.java,v 1.3 2001/10/24 00:55:08 shaper Exp $
package com.threerings.miso.scene;
@@ -26,9 +26,11 @@ public class CharacterManager
/**
* Construct the character manager.
*/
public CharacterManager (Config config, TileManager tilemgr)
public CharacterManager (
Config config, TileManager tilemgr, IsoSceneViewModel model)
{
_tilemgr = tilemgr;
_model = model;
// load character data descriptions
String file = config.getValue(CHARFILE_KEY, DEFAULT_CHARFILE);
@@ -58,8 +60,8 @@ public class CharacterManager
MultiFrameImage[] anims = TileUtil.getAmbulatorySpriteFrames(
_tilemgr, tsid, info.frameCount);
AmbulatorySprite sprite = new AmbulatorySprite(0, 0, anims);
sprite.setFrameRate(info.frameRate);
AmbulatorySprite sprite = new AmbulatorySprite(_model, 0, 0, anims);
sprite.setFrameRate(info.fps);
sprite.setOrigin(info.origin.x, info.origin.y);
return sprite;
@@ -79,6 +81,9 @@ public class CharacterManager
/** The tile manager. */
protected TileManager _tilemgr;
/** The iso scene view model. */
protected IsoSceneViewModel _model;
/**
* A class that contains character description information for a
* single character for use when constructing the character's
@@ -88,13 +93,13 @@ public class CharacterManager
{
public int tsid;
public int frameCount;
public int frameRate;
public int fps;
public Point origin = new Point();
public String toString ()
{
return "[tsid=" + tsid + ", frameCount=" + frameCount +
", frameRate=" + frameRate + ", origin=" + origin + "]";
", fps=" + fps + ", origin=" + origin + "]";
}
}
}
@@ -1,12 +1,15 @@
//
// $Id: CharacterSprite.java,v 1.13 2001/10/22 18:21:41 shaper Exp $
// $Id: CharacterSprite.java,v 1.14 2001/10/24 00:55:08 shaper Exp $
package com.threerings.miso.scene;
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;
/**
* An ambulatory sprite is a sprite that animates itself while walking
@@ -25,11 +28,13 @@ public class AmbulatorySprite extends Sprite implements Traverser
* @param anims the set of multi-frame images to use when animating
* the sprite in each of the compass directions.
*/
public AmbulatorySprite (int x, int y, MultiFrameImage[] anims)
public AmbulatorySprite (
IsoSceneViewModel model, int x, int y, MultiFrameImage[] anims)
{
super(x, y);
// keep track of these
_model = model;
_anims = anims;
// give ourselves an initial orientation
@@ -115,9 +120,111 @@ public class AmbulatorySprite extends Sprite implements Traverser
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);
}
/** The animation frames for the sprite facing each direction. */
protected MultiFrameImage[] _anims;
/** The iso scene view model. */
protected IsoSceneViewModel _model;
/** 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;
}