Modified scene interface so that tiles are requested directly so that we
can implement "virtual" scenes which return tiles infinitely in all directions in anticipation of supporting scrolling. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1007 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
//
|
//
|
||||||
// $Id: DisplayMisoScene.java,v 1.3 2002/01/30 18:28:32 mdb Exp $
|
// $Id: DisplayMisoScene.java,v 1.4 2002/02/17 08:01:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
import com.threerings.media.tile.ObjectTileLayer;
|
import com.threerings.media.tile.ObjectTile;
|
||||||
import com.threerings.media.tile.TileLayer;
|
import com.threerings.media.tile.Tile;
|
||||||
import com.threerings.miso.tile.BaseTileLayer;
|
import com.threerings.miso.tile.BaseTile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes available the information from the {@link MisoSceneModel} in a
|
* Makes available the information from the {@link MisoSceneModel} in a
|
||||||
@@ -16,22 +16,19 @@ import com.threerings.miso.tile.BaseTileLayer;
|
|||||||
public interface DisplayMisoScene
|
public interface DisplayMisoScene
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns the tiles that comprise the base layer of this scene. This
|
* Returns the base tile at the specified coordinates.
|
||||||
* layer is read-only and not to be modified.
|
|
||||||
*/
|
*/
|
||||||
public BaseTileLayer getBaseLayer ();
|
public BaseTile getBaseTile (int x, int y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the tiles that comprise the fringe layer of this scene.
|
* Returns the fring tile at the specified coordinates.
|
||||||
* This layer is read-only and not to be modified.
|
|
||||||
*/
|
*/
|
||||||
public TileLayer getFringeLayer ();
|
public Tile getFringeTile (int x, int y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the tiles that comprise the object layer of this scene.
|
* Returns the object tile at the specified coordinates.
|
||||||
* This layer is read-only and not to be modified.
|
|
||||||
*/
|
*/
|
||||||
public ObjectTileLayer getObjectLayer ();
|
public ObjectTile getObjectTile (int x, int y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the action associated with the object tile at the specified
|
* Returns the action associated with the object tile at the specified
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DisplayMisoSceneImpl.java,v 1.50 2002/02/06 17:13:06 mdb Exp $
|
// $Id: DisplayMisoSceneImpl.java,v 1.51 2002/02/17 08:01:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -172,21 +172,21 @@ public class DisplayMisoSceneImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public BaseTileLayer getBaseLayer ()
|
public BaseTile getBaseTile (int x, int y)
|
||||||
{
|
{
|
||||||
return _base;
|
return _base.getTile(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public TileLayer getFringeLayer ()
|
public Tile getFringeTile (int x, int y)
|
||||||
{
|
{
|
||||||
return _fringe;
|
return _fringe.getTile(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public ObjectTileLayer getObjectLayer ()
|
public ObjectTile getObjectTile (int x, int y)
|
||||||
{
|
{
|
||||||
return _object;
|
return _object.getTile(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface
|
// documentation inherited from interface
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoSceneView.java,v 1.94 2002/02/17 07:30:45 mdb Exp $
|
// $Id: IsoSceneView.java,v 1.95 2002/02/17 08:01:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -27,15 +27,12 @@ import com.threerings.media.sprite.Path;
|
|||||||
import com.threerings.media.sprite.SpriteManager;
|
import com.threerings.media.sprite.SpriteManager;
|
||||||
|
|
||||||
import com.threerings.media.tile.ObjectTile;
|
import com.threerings.media.tile.ObjectTile;
|
||||||
import com.threerings.media.tile.ObjectTileLayer;
|
|
||||||
import com.threerings.media.tile.Tile;
|
import com.threerings.media.tile.Tile;
|
||||||
import com.threerings.media.tile.TileLayer;
|
|
||||||
|
|
||||||
import com.threerings.miso.Log;
|
import com.threerings.miso.Log;
|
||||||
import com.threerings.miso.scene.DirtyItemList.DirtyItem;
|
import com.threerings.miso.scene.DirtyItemList.DirtyItem;
|
||||||
import com.threerings.miso.scene.util.AStarPathUtil;
|
import com.threerings.miso.scene.util.AStarPathUtil;
|
||||||
import com.threerings.miso.scene.util.IsoUtil;
|
import com.threerings.miso.scene.util.IsoUtil;
|
||||||
import com.threerings.miso.tile.BaseTileLayer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The iso scene view provides an isometric view of a particular
|
* The iso scene view provides an isometric view of a particular
|
||||||
@@ -301,22 +298,19 @@ public class IsoSceneView implements SceneView
|
|||||||
*/
|
*/
|
||||||
protected void renderTiles (Graphics2D gfx)
|
protected void renderTiles (Graphics2D gfx)
|
||||||
{
|
{
|
||||||
BaseTileLayer base = _scene.getBaseLayer();
|
|
||||||
TileLayer fringe = _scene.getFringeLayer();
|
|
||||||
|
|
||||||
// render the base and fringe layers
|
// render the base and fringe layers
|
||||||
for (int yy = 0; yy < base.getHeight(); yy++) {
|
for (int yy = 0; yy < _model.scenehei; yy++) {
|
||||||
for (int xx = 0; xx < base.getWidth(); xx++) {
|
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||||
if (!_dirty[xx][yy]) {
|
if (!_dirty[xx][yy]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw the base and fringe tile images
|
// draw the base and fringe tile images
|
||||||
Tile tile;
|
Tile tile;
|
||||||
if ((tile = base.getTile(xx, yy)) != null) {
|
if ((tile = _scene.getBaseTile(xx, yy)) != null) {
|
||||||
tile.paint(gfx, getTilePoly(xx, yy));
|
tile.paint(gfx, getTilePoly(xx, yy));
|
||||||
}
|
}
|
||||||
if ((tile = fringe.getTile(xx, yy)) != null) {
|
if ((tile = _scene.getFringeTile(xx, yy)) != null) {
|
||||||
tile.paint(gfx, getTilePoly(xx, yy));
|
tile.paint(gfx, getTilePoly(xx, yy));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,24 +361,45 @@ public class IsoSceneView implements SceneView
|
|||||||
_objects.clear();
|
_objects.clear();
|
||||||
|
|
||||||
// generate metric records for all objects
|
// generate metric records for all objects
|
||||||
ObjectTileLayer tiles = _scene.getObjectLayer();
|
for (int yy = 0; yy < _model.scenehei; yy++) {
|
||||||
for (int yy = 0; yy < tiles.getHeight(); yy++) {
|
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||||
for (int xx = 0; xx < tiles.getWidth(); xx++) {
|
ObjectTile tile = _scene.getObjectTile(xx, yy);
|
||||||
ObjectTile tile = tiles.getTile(xx, yy);
|
if (tile != null) {
|
||||||
if (tile == null) {
|
generateObjectMetrics(tile, xx, yy);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create a metrics record for this object
|
/**
|
||||||
ObjectMetrics metrics = new ObjectMetrics();
|
* Generates object tile metrics for the supplied object tile and adds
|
||||||
metrics.tile = tile;
|
* them to the list.
|
||||||
metrics.x = xx;
|
*/
|
||||||
metrics.y = yy;
|
protected void generateObjectMetrics (ObjectTile tile, int x, int y)
|
||||||
metrics.bounds = IsoUtil.getObjectBounds(
|
{
|
||||||
_model, getTilePoly(xx, yy), tile);
|
// create a metrics record for this object
|
||||||
|
ObjectMetrics metrics = new ObjectMetrics();
|
||||||
|
metrics.tile = tile;
|
||||||
|
metrics.x = x;
|
||||||
|
metrics.y = y;
|
||||||
|
metrics.bounds = IsoUtil.getObjectBounds(
|
||||||
|
_model, getTilePoly(x, y), tile);
|
||||||
|
|
||||||
// and add it to the list
|
// and add it to the list
|
||||||
_objects.add(metrics);
|
_objects.add(metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears out the object metrics for the object at the specified tile
|
||||||
|
* coordinates.
|
||||||
|
*/
|
||||||
|
protected void clearObjectMetrics (int x, int y)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _objects.size(); i++) {
|
||||||
|
ObjectMetrics metrics = (ObjectMetrics)_objects.get(i);
|
||||||
|
if (metrics.x == x && metrics.y == y) {
|
||||||
|
_objects.remove(i);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -661,7 +676,7 @@ public class IsoSceneView implements SceneView
|
|||||||
|
|
||||||
// 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.getBaseLayer(), _model.scenewid, _model.scenehei,
|
_scene, _model.scenewid, _model.scenehei,
|
||||||
sprite, sprite.getTileX(), sprite.getTileY(), dest.x, dest.y);
|
sprite, sprite.getTileX(), sprite.getTileY(), 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
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: AStarPathUtil.java,v 1.12 2002/02/07 20:02:53 mdb Exp $
|
// $Id: AStarPathUtil.java,v 1.13 2002/02/17 08:01:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene.util;
|
package com.threerings.miso.scene.util;
|
||||||
|
|
||||||
@@ -9,9 +9,9 @@ import java.util.*;
|
|||||||
import com.threerings.media.util.MathUtil;
|
import com.threerings.media.util.MathUtil;
|
||||||
|
|
||||||
import com.threerings.miso.Log;
|
import com.threerings.miso.Log;
|
||||||
|
import com.threerings.miso.scene.DisplayMisoScene;
|
||||||
import com.threerings.miso.scene.Traverser;
|
import com.threerings.miso.scene.Traverser;
|
||||||
import com.threerings.miso.tile.BaseTile;
|
import com.threerings.miso.tile.BaseTile;
|
||||||
import com.threerings.miso.tile.BaseTileLayer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>AStarPathUtil</code> class provides a facility for
|
* The <code>AStarPathUtil</code> class provides a facility for
|
||||||
@@ -26,15 +26,14 @@ public class AStarPathUtil
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Return a list of <code>Point</code> objects representing a path
|
* Return a list of <code>Point</code> objects representing a path
|
||||||
* from coordinates <code>(ax, by)</code> to
|
* from coordinates <code>(ax, by)</code> to <code>(bx, by)</code>,
|
||||||
* <code>(bx, by)</code>, inclusive, determined by performing an
|
* inclusive, determined by performing an A* search in the given
|
||||||
* A* search in the given array of tiles. Assumes the starting
|
* scene's base tile layer. Assumes the starting and destination nodes
|
||||||
* and destination nodes are traversable by the specified
|
* are traversable by the specified traverser.
|
||||||
* traverser.
|
|
||||||
*
|
*
|
||||||
* @param tiles the tile array.
|
* @param scene the scene in which a path is to be computed.
|
||||||
* @param tilewid the tile array width.
|
* @param tilewid the scene width in tiles.
|
||||||
* @param tilehei the tile array height.
|
* @param tilehei the scene height in tiles.
|
||||||
* @param trav the traverser to follow the path.
|
* @param trav the traverser to follow the path.
|
||||||
* @param ax the starting x-position in tile coordinates.
|
* @param ax the starting x-position in tile coordinates.
|
||||||
* @param ay the starting y-position in tile coordinates.
|
* @param ay the starting y-position in tile coordinates.
|
||||||
@@ -44,10 +43,10 @@ public class AStarPathUtil
|
|||||||
* @return the list of points in the path.
|
* @return the list of points in the path.
|
||||||
*/
|
*/
|
||||||
public static List getPath (
|
public static List getPath (
|
||||||
BaseTileLayer tiles, int tilewid, int tilehei, Traverser trav,
|
DisplayMisoScene scene, int tilewid, int tilehei, Traverser trav,
|
||||||
int ax, int ay, int bx, int by)
|
int ax, int ay, int bx, int by)
|
||||||
{
|
{
|
||||||
AStarInfo info = new AStarInfo(tiles, tilewid, tilehei, trav, bx, by);
|
AStarInfo info = new AStarInfo(scene, tilewid, tilehei, trav, bx, by);
|
||||||
|
|
||||||
// set up the starting node
|
// set up the starting node
|
||||||
AStarNode s = getNode(info, ax, ay);
|
AStarNode s = getNode(info, ax, ay);
|
||||||
@@ -199,7 +198,7 @@ public class AStarPathUtil
|
|||||||
protected static boolean isTraversable (AStarInfo info, int x, int y)
|
protected static boolean isTraversable (AStarInfo info, int x, int y)
|
||||||
{
|
{
|
||||||
return (isCoordinateValid(info, x, y) &&
|
return (isCoordinateValid(info, x, y) &&
|
||||||
info.trav.canTraverse(info.tiles.getTile(x, y)));
|
info.trav.canTraverse(info.scene.getBaseTile(x, y)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -253,8 +252,8 @@ public class AStarPathUtil
|
|||||||
*/
|
*/
|
||||||
class AStarInfo
|
class AStarInfo
|
||||||
{
|
{
|
||||||
/** The tile layer being traversed. */
|
/** The scene whose base tile layer is being traversed. */
|
||||||
public BaseTileLayer tiles;
|
public DisplayMisoScene scene;
|
||||||
|
|
||||||
/** The tile array dimensions. */
|
/** The tile array dimensions. */
|
||||||
public int tilewid, tilehei;
|
public int tilewid, tilehei;
|
||||||
@@ -275,11 +274,11 @@ class AStarInfo
|
|||||||
public int destx, desty;
|
public int destx, desty;
|
||||||
|
|
||||||
public AStarInfo (
|
public AStarInfo (
|
||||||
BaseTileLayer tiles, int tilewid, int tilehei, Traverser trav,
|
DisplayMisoScene scene, int tilewid, int tilehei, Traverser trav,
|
||||||
int destx, int desty)
|
int destx, int desty)
|
||||||
{
|
{
|
||||||
// save off references
|
// save off references
|
||||||
this.tiles = tiles;
|
this.scene = scene;
|
||||||
this.tilewid = tilewid;
|
this.tilewid = tilewid;
|
||||||
this.tilehei = tilehei;
|
this.tilehei = tilehei;
|
||||||
this.trav = trav;
|
this.trav = trav;
|
||||||
|
|||||||
Reference in New Issue
Block a user