Removed caching of tile coordinates as it was too fragile. It is easy to
forget to update a sprite's tile coordinates when updating its screen coordinates and only TilePath could be used for sprites in the view and generally a huge pain was incurred to avoid what isn't very expensive which is to calculate a sprite's tile coordinates from its screen coordinates when that sprite is involved in a repaint. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2029 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoSceneView.java,v 1.126 2002/11/28 03:42:17 mdb Exp $
|
// $Id: IsoSceneView.java,v 1.127 2002/12/05 23:06:30 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -381,27 +381,7 @@ public class IsoSceneView implements SceneView
|
|||||||
if (!bounds.intersects(clip)) {
|
if (!bounds.intersects(clip)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
appendDirtySprite(_dirtyItems, sprite);
|
||||||
// if this is a miso character sprite, we can use its cached
|
|
||||||
// tile coordinates
|
|
||||||
int tx, ty;
|
|
||||||
if (sprite instanceof IsoSprite) {
|
|
||||||
IsoSprite iso = (IsoSprite)sprite;
|
|
||||||
tx = iso.getTileX();
|
|
||||||
ty = iso.getTileY();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// otherwise we have to compute them from the screen
|
|
||||||
// coordinates of the sprite
|
|
||||||
IsoUtil.screenToTile(
|
|
||||||
_model, sprite.getX(), sprite.getY(), _tcoords);
|
|
||||||
tx = _tcoords.x;
|
|
||||||
ty = _tcoords.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// finally add the sprite and its tile coordinates to the list
|
|
||||||
// of dirty items
|
|
||||||
_dirtyItems.appendDirtySprite(sprite, tx, ty);
|
|
||||||
// Log.info("Dirtied item: " + sprite);
|
// Log.info("Dirtied item: " + sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,9 +399,7 @@ public class IsoSceneView implements SceneView
|
|||||||
foot = IsoUtil.getObjectFootprint(_model, scobj);
|
foot = IsoUtil.getObjectFootprint(_model, scobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the object to the dirty items list
|
|
||||||
_dirtyItems.appendDirtyObject(scobj, foot);
|
_dirtyItems.appendDirtyObject(scobj, foot);
|
||||||
|
|
||||||
// Log.info("Dirtied item: Object(" +
|
// Log.info("Dirtied item: Object(" +
|
||||||
// scobj.x + ", " + scobj.y + ")");
|
// scobj.x + ", " + scobj.y + ")");
|
||||||
}
|
}
|
||||||
@@ -434,6 +412,16 @@ public class IsoSceneView implements SceneView
|
|||||||
_dirtyItems.paintAndClear(gfx);
|
_dirtyItems.paintAndClear(gfx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the tile coordinates of the supplied sprite and appends it
|
||||||
|
* to the supplied dirty item list.
|
||||||
|
*/
|
||||||
|
protected void appendDirtySprite (DirtyItemList list, Sprite sprite)
|
||||||
|
{
|
||||||
|
IsoUtil.screenToTile(_model, sprite.getX(), sprite.getY(), _tcoords);
|
||||||
|
list.appendDirtySprite(sprite, _tcoords.x, _tcoords.y);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates and stores bounding polygons for all object tiles in the
|
* Generates and stores bounding polygons for all object tiles in the
|
||||||
* scene for later use while rendering.
|
* scene for later use while rendering.
|
||||||
@@ -475,12 +463,14 @@ public class IsoSceneView implements SceneView
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the destination tile coordinates
|
// get the destination tile coordinates
|
||||||
|
Point src = IsoUtil.screenToTile(
|
||||||
|
_model, sprite.getX(), sprite.getY(), new Point());
|
||||||
Point dest = IsoUtil.screenToTile(_model, x, y, new Point());
|
Point dest = IsoUtil.screenToTile(_model, x, y, new Point());
|
||||||
|
|
||||||
// get a reasonable tile path through the scene
|
// get a reasonable tile path through the scene
|
||||||
List points = AStarPathUtil.getPath(
|
List points = AStarPathUtil.getPath(
|
||||||
_scene, _model.scenewid, _model.scenehei,
|
_scene, _model.scenewid, _model.scenehei,
|
||||||
sprite, sprite.getTileX(), sprite.getTileY(), dest.x, dest.y);
|
sprite, src.x, src.y, dest.x, dest.y);
|
||||||
|
|
||||||
// construct a path object to guide the sprite on its merry way
|
// construct a path object to guide the sprite on its merry way
|
||||||
return (points == null) ? null :
|
return (points == null) ? null :
|
||||||
@@ -520,14 +510,7 @@ public class IsoSceneView implements SceneView
|
|||||||
int hslen = _hitSprites.size();
|
int hslen = _hitSprites.size();
|
||||||
for (int i = 0; i < hslen; i++) {
|
for (int i = 0; i < hslen; i++) {
|
||||||
Sprite sprite = (Sprite)_hitSprites.get(i);
|
Sprite sprite = (Sprite)_hitSprites.get(i);
|
||||||
if (sprite instanceof MisoCharacterSprite) {
|
appendDirtySprite(_hitList, sprite);
|
||||||
MisoCharacterSprite msprite = (MisoCharacterSprite)sprite;
|
|
||||||
_hitList.appendDirtySprite(
|
|
||||||
msprite, msprite.getTileX(), msprite.getTileY());
|
|
||||||
} else {
|
|
||||||
Log.info("Found non-Miso sprite in view? " +
|
|
||||||
"[sprite=" + sprite + "].");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the object tiles that contain the point
|
// add the object tiles that contain the point
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// $Id: IsoSprite.java,v 1.1 2002/11/28 03:42:17 mdb Exp $
|
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface implementable by sprites that know their tile coordinates
|
|
||||||
* in the isometric view.
|
|
||||||
*/
|
|
||||||
public interface IsoSprite
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Returns the sprite's location on the x-axis in tile coordinates.
|
|
||||||
*/
|
|
||||||
public int getTileX ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sprite's location on the y-axis in tile coordinates.
|
|
||||||
*/
|
|
||||||
public int getTileY ();
|
|
||||||
}
|
|
||||||
@@ -1,23 +1,17 @@
|
|||||||
//
|
//
|
||||||
// $Id: MisoCharacterSprite.java,v 1.6 2002/11/28 03:42:17 mdb Exp $
|
// $Id: MisoCharacterSprite.java,v 1.7 2002/12/05 23:06:30 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
import com.threerings.cast.CharacterSprite;
|
import com.threerings.cast.CharacterSprite;
|
||||||
|
|
||||||
import com.threerings.miso.tile.BaseTile;
|
import com.threerings.miso.tile.BaseTile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The miso character sprite extends the basic character sprite to
|
* The miso character sprite extends the basic character sprite to support
|
||||||
* support the notion of tile passability, and to allow the sprite to
|
* the notion of tile passability.
|
||||||
* 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
|
public class MisoCharacterSprite extends CharacterSprite
|
||||||
implements Traverser, IsoSprite
|
implements Traverser
|
||||||
{
|
{
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public boolean canTraverse (BaseTile tile)
|
public boolean canTraverse (BaseTile tile)
|
||||||
@@ -25,39 +19,4 @@ public class MisoCharacterSprite extends CharacterSprite
|
|||||||
// by default, passability is solely the province of the tile
|
// by default, passability is solely the province of the tile
|
||||||
return tile.isPassable();
|
return tile.isPassable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface
|
|
||||||
public int getTileX ()
|
|
||||||
{
|
|
||||||
return _tilex;
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited from interface
|
|
||||||
public int getTileY ()
|
|
||||||
{
|
|
||||||
return _tiley;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
protected void toString (StringBuffer buf)
|
|
||||||
{
|
|
||||||
super.toString(buf);
|
|
||||||
buf.append(", tilex=").append(_tilex);
|
|
||||||
buf.append(", tiley=").append(_tiley);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The sprite location in tile coordinates. */
|
|
||||||
protected int _tilex, _tiley;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SceneViewPanel.java,v 1.46 2002/11/03 01:15:06 mdb Exp $
|
// $Id: SceneViewPanel.java,v 1.47 2002/12/05 23:06:30 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -112,21 +112,6 @@ public class SceneViewPanel extends VirtualMediaPanel
|
|||||||
return _view;
|
return _view;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the supplied sprite to the scene, setting up its scene
|
|
||||||
* coordinates if it is a {@link MisoCharacterSprite}.
|
|
||||||
*/
|
|
||||||
public void addSprite (Sprite sprite)
|
|
||||||
{
|
|
||||||
if (sprite instanceof MisoCharacterSprite) {
|
|
||||||
// set up the sprite's tile coordinates
|
|
||||||
IsoUtil.setSpriteSceneLocation(
|
|
||||||
_viewmodel, (MisoCharacterSprite)sprite);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.addSprite(sprite);
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void doLayout ()
|
public void doLayout ()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TilePath.java,v 1.10 2002/07/08 21:41:30 mdb Exp $
|
// $Id: TilePath.java,v 1.11 2002/12/05 23:06:30 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -65,7 +65,6 @@ public class TilePath extends LineSegmentPath
|
|||||||
// we've arrived
|
// we've arrived
|
||||||
int dtx = _dest.getTileX(), dty = _dest.getTileY();
|
int dtx = _dest.getTileX(), dty = _dest.getTileY();
|
||||||
if (pos.x == dtx && pos.y == dty) {
|
if (pos.x == dtx && pos.y == dty) {
|
||||||
mcs.setTileLocation(dtx, dty);
|
|
||||||
// Log.info("Sprite arrived [dtx=" + dtx +
|
// Log.info("Sprite arrived [dtx=" + dtx +
|
||||||
// ", dty=" + dty + "].");
|
// ", dty=" + dty + "].");
|
||||||
_arrived = true;
|
_arrived = true;
|
||||||
@@ -103,15 +102,16 @@ public class TilePath extends LineSegmentPath
|
|||||||
IsoUtil.screenToFull(_model, destx, desty, fpos);
|
IsoUtil.screenToFull(_model, destx, desty, fpos);
|
||||||
|
|
||||||
// add the starting path node
|
// add the starting path node
|
||||||
int stx = sprite.getTileX(), sty = sprite.getTileY();
|
Point ipos = new Point();
|
||||||
int sx = sprite.getX(), sy = sprite.getY();
|
int sx = sprite.getX(), sy = sprite.getY();
|
||||||
addNode(stx, sty, sx, sy, NORTH);
|
IsoUtil.screenToTile(_model, sx, sy, ipos);
|
||||||
|
addNode(ipos.x, ipos.y, sx, sy, NORTH);
|
||||||
|
|
||||||
// TODO: make more visually appealing path segments from start
|
// TODO: make more visually appealing path segments from start
|
||||||
// to second tile, and penultimate to ultimate tile.
|
// to second tile, and penultimate to ultimate tile.
|
||||||
|
|
||||||
// add all remaining path nodes excepting the last one
|
// add all remaining path nodes excepting the last one
|
||||||
Point prev = new Point(stx, sty);
|
Point prev = new Point(ipos.x, ipos.y);
|
||||||
Point spos = new Point();
|
Point spos = new Point();
|
||||||
int size = tiles.size();
|
int size = tiles.size();
|
||||||
for (int ii = 1; ii < size - 1; ii++) {
|
for (int ii = 1; ii < size - 1; ii++) {
|
||||||
@@ -142,7 +142,7 @@ public class TilePath extends LineSegmentPath
|
|||||||
|
|
||||||
// get the facing direction for the final node
|
// get the facing direction for the final node
|
||||||
int dir;
|
int dir;
|
||||||
if (prev.x == stx && prev.y == sty) {
|
if (prev.x == ipos.x && prev.y == ipos.y) {
|
||||||
// if destination is within starting tile, direction is
|
// if destination is within starting tile, direction is
|
||||||
// determined by studying the fine coordinates
|
// determined by studying the fine coordinates
|
||||||
dir = IsoUtil.getDirection(_model, sx, sy, spos.x, spos.y);
|
dir = IsoUtil.getDirection(_model, sx, sy, spos.x, spos.y);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoUtil.java,v 1.40 2002/10/16 20:39:46 ray Exp $
|
// $Id: IsoUtil.java,v 1.41 2002/12/05 23:06:30 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene.util;
|
package com.threerings.miso.scene.util;
|
||||||
|
|
||||||
@@ -27,25 +27,6 @@ import com.threerings.miso.scene.SceneObject;
|
|||||||
public class IsoUtil
|
public class IsoUtil
|
||||||
implements DirectionCodes
|
implements DirectionCodes
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* 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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a polygon bounding all footprint tiles of the given
|
* Returns a polygon bounding all footprint tiles of the given
|
||||||
* object tile.
|
* object tile.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ViewerSceneViewPanel.java,v 1.51 2002/06/25 01:21:17 mdb Exp $
|
// $Id: ViewerSceneViewPanel.java,v 1.52 2002/12/05 23:06:30 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.viewer;
|
package com.threerings.miso.viewer;
|
||||||
|
|
||||||
@@ -95,7 +95,6 @@ public class ViewerSceneViewPanel extends SceneViewPanel
|
|||||||
// start 'em out standing
|
// start 'em out standing
|
||||||
s.setActionSequence(MisoCharacterSprite.STANDING);
|
s.setActionSequence(MisoCharacterSprite.STANDING);
|
||||||
s.setLocation(300, 300);
|
s.setLocation(300, 300);
|
||||||
IsoUtil.setSpriteSceneLocation(_viewmodel, s);
|
|
||||||
s.addSpriteObserver(this);
|
s.addSpriteObserver(this);
|
||||||
spritemgr.addSprite(s);
|
spritemgr.addSprite(s);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user