Store object tiles in HashIntMaps instead of in arrays because they may

have coordinates outside of the normal scene coordinates.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1150 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2002-03-26 20:17:51 +00:00
parent 5f42e8d304
commit aca95b8540
5 changed files with 83 additions and 49 deletions
@@ -1,5 +1,5 @@
//
// $Id: DisplayMisoSceneImpl.java,v 1.51 2002/02/17 08:01:15 mdb Exp $
// $Id: DisplayMisoSceneImpl.java,v 1.52 2002/03/26 20:17:51 ray Exp $
package com.threerings.miso.scene;
@@ -74,7 +74,7 @@ public class DisplayMisoSceneImpl
// create the individual tile layer objects
_base = new BaseTileLayer(new BaseTile[swid*shei], swid, shei);
_fringe = new TileLayer(new Tile[swid*shei], swid, shei);
_object = new ObjectTileLayer(new ObjectTile[swid*shei], swid, shei);
_object = new ObjectTileLayer(swid, shei);
// create a mapping for the action strings and populate it
_actions = new HashIntMap();
@@ -227,7 +227,11 @@ public class DisplayMisoSceneImpl
int endy = Math.max(0, (y - otile.getBaseHeight() + 1));
for (int xx = x; xx >= endx; xx--) {
if ((xx < 0) || (xx >= _model.width)) continue;
for (int yy = y; yy >= endy; yy--) {
if ((yy < 0) || (yy >= _model.height)) continue;
BaseTile tile = _base.getTile(xx, yy);
if (tile != null) {
tile.setCovered(covered);
@@ -1,5 +1,5 @@
//
// $Id: IsoSceneView.java,v 1.102 2002/03/16 03:15:05 shaper Exp $
// $Id: IsoSceneView.java,v 1.103 2002/03/26 20:17:51 ray Exp $
package com.threerings.miso.scene;
@@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.List;
import com.samskivert.util.StringUtil;
import com.samskivert.util.HashIntMap;
import com.threerings.media.animation.AnimationManager;
import com.threerings.media.sprite.Path;
@@ -77,7 +78,7 @@ public class IsoSceneView implements SceneView
// create our polygon arrays, these will be populated with the
// tile polygons as they are requested
_polys = new Polygon[model.scenewid][model.scenehei];
_polys = new HashIntMap();
// create the array used to mark dirty tiles
_dirty = new boolean[model.scenewid][model.tilehei];
@@ -502,9 +503,12 @@ public class IsoSceneView implements SceneView
*/
protected Polygon getTilePoly (int x, int y)
{
Polygon poly = _polys[x][y];
int key = IsoUtil.coordsToKey(x, y);
Polygon poly = (Polygon) _polys.get(key);
if (poly == null) {
poly = _polys[x][y] = IsoUtil.getTilePolygon(_model, x, y);
poly = IsoUtil.getTilePolygon(_model, x, y);
_polys.put(key, poly);
}
return poly;
}
@@ -933,7 +937,7 @@ public class IsoSceneView implements SceneView
protected DisplayMisoScene _scene;
/** Polygon outlines for all of our base tiles. */
protected Polygon _polys[][];
protected HashIntMap _polys;
/** Metric information for all of the object tiles. */
protected ArrayList _objects = new ArrayList();
@@ -1,5 +1,5 @@
//
// $Id: IsoUtil.java,v 1.22 2002/03/16 03:15:06 shaper Exp $
// $Id: IsoUtil.java,v 1.23 2002/03/26 20:17:51 ray Exp $
package com.threerings.miso.scene.util;
@@ -446,6 +446,30 @@ public class IsoUtil
return poly;
}
/**
* @return the hash key, give x and y
*/
public static final int coordsToKey (int x, int y)
{
return ((y << 16) & (0xFFFF0000)) | (x & 0xFFFF);
}
/**
* @return the x coordinate from the hash key
*/
public static final int xCoordFromKey (int key)
{
return (key & 0xFFFF);
}
/**
* @return the y coordinate from the hash key
*/
public static final int yCoordFromKey (int key)
{
return ((key >> 16) & 0xFFFF);
}
/** Multiplication factor to embed tile coords in full coords. */
protected static final int FULL_TILE_FACTOR = 100;
}