From 53735971434d57528ccde0ac0b8f0948baf3b2b2 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 5 Dec 2002 23:06:30 +0000 Subject: [PATCH] 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 --- .../threerings/miso/client/IsoSceneView.java | 49 ++++++------------- .../com/threerings/miso/client/IsoSprite.java | 21 -------- .../miso/client/MisoCharacterSprite.java | 49 ++----------------- .../miso/client/SceneViewPanel.java | 17 +------ .../com/threerings/miso/client/TilePath.java | 12 ++--- .../threerings/miso/client/util/IsoUtil.java | 21 +------- .../miso/viewer/ViewerSceneViewPanel.java | 3 +- 7 files changed, 29 insertions(+), 143 deletions(-) delete mode 100644 src/java/com/threerings/miso/client/IsoSprite.java diff --git a/src/java/com/threerings/miso/client/IsoSceneView.java b/src/java/com/threerings/miso/client/IsoSceneView.java index d76bc92e1..4dec14657 100644 --- a/src/java/com/threerings/miso/client/IsoSceneView.java +++ b/src/java/com/threerings/miso/client/IsoSceneView.java @@ -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; @@ -381,27 +381,7 @@ public class IsoSceneView implements SceneView if (!bounds.intersects(clip)) { continue; } - - // 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); + appendDirtySprite(_dirtyItems, sprite); // Log.info("Dirtied item: " + sprite); } @@ -419,9 +399,7 @@ public class IsoSceneView implements SceneView foot = IsoUtil.getObjectFootprint(_model, scobj); } - // add the object to the dirty items list _dirtyItems.appendDirtyObject(scobj, foot); - // Log.info("Dirtied item: Object(" + // scobj.x + ", " + scobj.y + ")"); } @@ -434,6 +412,16 @@ public class IsoSceneView implements SceneView _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 * scene for later use while rendering. @@ -475,12 +463,14 @@ public class IsoSceneView implements SceneView } // 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()); // get a reasonable tile path through the scene List points = AStarPathUtil.getPath( _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 return (points == null) ? null : @@ -520,14 +510,7 @@ public class IsoSceneView implements SceneView int hslen = _hitSprites.size(); for (int i = 0; i < hslen; i++) { Sprite sprite = (Sprite)_hitSprites.get(i); - if (sprite instanceof MisoCharacterSprite) { - MisoCharacterSprite msprite = (MisoCharacterSprite)sprite; - _hitList.appendDirtySprite( - msprite, msprite.getTileX(), msprite.getTileY()); - } else { - Log.info("Found non-Miso sprite in view? " + - "[sprite=" + sprite + "]."); - } + appendDirtySprite(_hitList, sprite); } // add the object tiles that contain the point diff --git a/src/java/com/threerings/miso/client/IsoSprite.java b/src/java/com/threerings/miso/client/IsoSprite.java deleted file mode 100644 index f216b1e11..000000000 --- a/src/java/com/threerings/miso/client/IsoSprite.java +++ /dev/null @@ -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 (); -} diff --git a/src/java/com/threerings/miso/client/MisoCharacterSprite.java b/src/java/com/threerings/miso/client/MisoCharacterSprite.java index e2fc3ab05..25fb9075f 100644 --- a/src/java/com/threerings/miso/client/MisoCharacterSprite.java +++ b/src/java/com/threerings/miso/client/MisoCharacterSprite.java @@ -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; import com.threerings.cast.CharacterSprite; - import com.threerings.miso.tile.BaseTile; /** - * 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. + * The miso character sprite extends the basic character sprite to support + * the notion of tile passability. */ public class MisoCharacterSprite extends CharacterSprite - implements Traverser, IsoSprite + implements Traverser { // documentation inherited public boolean canTraverse (BaseTile tile) @@ -25,39 +19,4 @@ public class MisoCharacterSprite extends CharacterSprite // by default, passability is solely the province of the tile 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; } diff --git a/src/java/com/threerings/miso/client/SceneViewPanel.java b/src/java/com/threerings/miso/client/SceneViewPanel.java index e6f66ba87..2314a570d 100644 --- a/src/java/com/threerings/miso/client/SceneViewPanel.java +++ b/src/java/com/threerings/miso/client/SceneViewPanel.java @@ -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; @@ -112,21 +112,6 @@ public class SceneViewPanel extends VirtualMediaPanel 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 public void doLayout () { diff --git a/src/java/com/threerings/miso/client/TilePath.java b/src/java/com/threerings/miso/client/TilePath.java index 21c356526..8f5f864f3 100644 --- a/src/java/com/threerings/miso/client/TilePath.java +++ b/src/java/com/threerings/miso/client/TilePath.java @@ -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; @@ -65,7 +65,6 @@ public class TilePath extends LineSegmentPath // we've arrived int dtx = _dest.getTileX(), dty = _dest.getTileY(); if (pos.x == dtx && pos.y == dty) { - mcs.setTileLocation(dtx, dty); // Log.info("Sprite arrived [dtx=" + dtx + // ", dty=" + dty + "]."); _arrived = true; @@ -103,15 +102,16 @@ public class TilePath extends LineSegmentPath IsoUtil.screenToFull(_model, destx, desty, fpos); // add the starting path node - int stx = sprite.getTileX(), sty = sprite.getTileY(); + Point ipos = new Point(); 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 // to second tile, and penultimate to ultimate tile. // 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(); int size = tiles.size(); 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 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 // determined by studying the fine coordinates dir = IsoUtil.getDirection(_model, sx, sy, spos.x, spos.y); diff --git a/src/java/com/threerings/miso/client/util/IsoUtil.java b/src/java/com/threerings/miso/client/util/IsoUtil.java index 26894abb5..a80ef2d42 100644 --- a/src/java/com/threerings/miso/client/util/IsoUtil.java +++ b/src/java/com/threerings/miso/client/util/IsoUtil.java @@ -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; @@ -27,25 +27,6 @@ import com.threerings.miso.scene.SceneObject; public class IsoUtil 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 * object tile. diff --git a/tests/src/java/com/threerings/miso/viewer/ViewerSceneViewPanel.java b/tests/src/java/com/threerings/miso/viewer/ViewerSceneViewPanel.java index ae457655c..94fd96eb1 100644 --- a/tests/src/java/com/threerings/miso/viewer/ViewerSceneViewPanel.java +++ b/tests/src/java/com/threerings/miso/viewer/ViewerSceneViewPanel.java @@ -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; @@ -95,7 +95,6 @@ public class ViewerSceneViewPanel extends SceneViewPanel // start 'em out standing s.setActionSequence(MisoCharacterSprite.STANDING); s.setLocation(300, 300); - IsoUtil.setSpriteSceneLocation(_viewmodel, s); s.addSpriteObserver(this); spritemgr.addSprite(s); }