When two sprites occupy the same tile, their screen y coordinate is used
instead of their fine coordinates. It achieves the same effect and alleviates the need to track fine coordinates in the MisoCharacterSprite. Additionally, IsoSceneView and friends were modified to allow any sprites to wander their crooked realms, MisoCharacterSprite instances are simply more efficient because they maintain cached copies of their tile coordinates whereas other sprites must have their tile location computed from their screen location whenever they are to be repainted. At some point in the future, the tile coordinate tracking facilities of MisoCharacterSprite should be accessed through an interface so that other spritely entities can cache their tile coordinates if they so desire. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1560 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DirtyItemList.java,v 1.11 2002/06/18 22:38:12 mdb Exp $
|
||||
// $Id: DirtyItemList.java,v 1.12 2002/07/08 21:41:30 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DirtyItemList
|
||||
* @param tx the sprite's x tile position.
|
||||
* @param ty the sprite's y tile position.
|
||||
*/
|
||||
public void appendDirtySprite (MisoCharacterSprite sprite, int tx, int ty)
|
||||
public void appendDirtySprite (Sprite sprite, int tx, int ty)
|
||||
{
|
||||
DirtyItem item = getDirtyItem();
|
||||
item.init(sprite, null, null, tx, ty);
|
||||
@@ -462,8 +462,8 @@ public class DirtyItemList
|
||||
int startidx = aidx + 1, endidx = startidx + size;
|
||||
for (int pidx = startidx; pidx < endidx; pidx++) {
|
||||
DirtyItem dp = (DirtyItem)sitems.get(pidx);
|
||||
if (dp.obj instanceof MisoCharacterSprite) {
|
||||
// character sprites can't partition things
|
||||
if (dp.obj instanceof Sprite) {
|
||||
// sprites can't partition things
|
||||
continue;
|
||||
} else if ((dp.obj == da.obj) ||
|
||||
(dp.obj == db.obj)) {
|
||||
@@ -510,18 +510,13 @@ public class DirtyItemList
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((da.obj instanceof MisoCharacterSprite) &&
|
||||
(db.obj instanceof MisoCharacterSprite)) {
|
||||
if ((da.obj instanceof Sprite) && (db.obj instanceof Sprite)) {
|
||||
// we're comparing two sprites co-existing on the same
|
||||
// tile, so study their fine coordinates
|
||||
MisoCharacterSprite as = (MisoCharacterSprite)da.obj;
|
||||
MisoCharacterSprite bs = (MisoCharacterSprite)db.obj;
|
||||
|
||||
int ahei = as.getFineX() + as.getFineY();
|
||||
int bhei = bs.getFineX() + bs.getFineY();
|
||||
int diff = ahei - bhei;
|
||||
// if they're at the same vertical row of intra-tile
|
||||
// tiles, just use hashCode() for consistency
|
||||
// tile, so simply sort them by y-position
|
||||
Sprite as = (Sprite)da.obj, bs = (Sprite)db.obj;
|
||||
int diff = as.getY() - bs.getY();
|
||||
// if they're at the same height, just use hashCode()
|
||||
// to establish a consistent arbitrary ordering
|
||||
return (diff != 0) ? diff :
|
||||
(as.hashCode() - bs.hashCode());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoSceneView.java,v 1.116 2002/06/29 01:32:28 ray Exp $
|
||||
// $Id: IsoSceneView.java,v 1.117 2002/07/08 21:41:30 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.media.RegionManager;
|
||||
|
||||
import com.threerings.media.sprite.Sprite;
|
||||
import com.threerings.media.sprite.SpriteManager;
|
||||
import com.threerings.media.util.Path;
|
||||
|
||||
@@ -363,15 +364,32 @@ public class IsoSceneView implements SceneView
|
||||
_spritemgr.getIntersectingSprites(_dirtySprites, clip);
|
||||
int size = _dirtySprites.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
MisoCharacterSprite sprite = (MisoCharacterSprite)
|
||||
_dirtySprites.get(ii);
|
||||
Sprite sprite = (Sprite)_dirtySprites.get(ii);
|
||||
Rectangle bounds = sprite.getBounds();
|
||||
if (!bounds.intersects(clip)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
_dirtyItems.appendDirtySprite(
|
||||
sprite, sprite.getTileX(), sprite.getTileY());
|
||||
// if this is a miso character sprite, we can use its cached
|
||||
// tile coordinates
|
||||
int tx, ty;
|
||||
if (sprite instanceof MisoCharacterSprite) {
|
||||
MisoCharacterSprite mcs = (MisoCharacterSprite)sprite;
|
||||
tx = mcs.getTileX();
|
||||
ty = mcs.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);
|
||||
}
|
||||
|
||||
@@ -683,6 +701,9 @@ public class IsoSceneView implements SceneView
|
||||
/** Used when rendering tiles. */
|
||||
protected Rectangle _tbounds;
|
||||
|
||||
/** Used when dirtying sprites. */
|
||||
protected Point _tcoords = new Point();
|
||||
|
||||
/** Used to collect the list of sprites "hit" by a particular mouse
|
||||
* location. */
|
||||
protected List _hitSprites = new ArrayList();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: MisoCharacterSprite.java,v 1.4 2002/06/20 07:47:14 shaper Exp $
|
||||
// $Id: MisoCharacterSprite.java,v 1.5 2002/07/08 21:41:30 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -42,24 +42,6 @@ public class MisoCharacterSprite extends CharacterSprite
|
||||
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
|
||||
@@ -72,31 +54,14 @@ public class MisoCharacterSprite extends CharacterSprite
|
||||
_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: TilePath.java,v 1.9 2002/06/22 00:59:02 ray Exp $
|
||||
// $Id: TilePath.java,v 1.10 2002/07/08 21:41:30 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -72,14 +72,6 @@ public class TilePath extends LineSegmentPath
|
||||
}
|
||||
}
|
||||
|
||||
// get the sprite's latest fine coordinates
|
||||
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
|
||||
mcs.setFineLocation(fpos.x, fpos.y);
|
||||
|
||||
// Log.info("Sprite moved [s=" + mcs + "].");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoUtil.java,v 1.37 2002/07/02 23:15:53 shaper Exp $
|
||||
// $Id: IsoUtil.java,v 1.38 2002/07/08 21:41:30 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
@@ -44,8 +44,6 @@ public class IsoUtil
|
||||
// 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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user