Removed the last vestiges of the object "layer". Scenes now simply have a
list of objects, they can overlap (I think that objects added to a scene later will be rendered before objects added earlier which ends up feeling natural in the editor); no longer are objects ignored when their footprint lies outside the scene bounds. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1302 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
//
|
||||
// $Id: DisplayMisoScene.java,v 1.4 2002/02/17 08:01:15 mdb Exp $
|
||||
// $Id: DisplayMisoScene.java,v 1.5 2002/04/27 18:41:14 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.threerings.media.tile.ObjectTile;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.miso.tile.BaseTile;
|
||||
@@ -21,20 +24,31 @@ public interface DisplayMisoScene
|
||||
public BaseTile getBaseTile (int x, int y);
|
||||
|
||||
/**
|
||||
* Returns the fring tile at the specified coordinates.
|
||||
* Returns the fringe tile at the specified coordinates.
|
||||
*/
|
||||
public Tile getFringeTile (int x, int y);
|
||||
|
||||
/**
|
||||
* Returns the object tile at the specified coordinates.
|
||||
* Returns an iterator over all object tiles in this scene.
|
||||
*/
|
||||
public ObjectTile getObjectTile (int x, int y);
|
||||
public Iterator getObjectTiles ();
|
||||
|
||||
/**
|
||||
* Returns the action associated with the object tile at the specified
|
||||
* column and row. Null is returned if no object tile exists at that
|
||||
* column and row or if the object tile that does exist does not have
|
||||
* an associated action.
|
||||
* Returns the tile coordinates for the specified object tile.
|
||||
*
|
||||
* @param tile the tile for which coordinates are to be fetched; this
|
||||
* tile must have been obtained from a call to {@link
|
||||
* #getObjectTiles}.
|
||||
*/
|
||||
public String getObjectAction (int column, int row);
|
||||
public Point getObjectCoords (ObjectTile tile);
|
||||
|
||||
/**
|
||||
* Returns the action associated with the specified object tile. Null
|
||||
* is returned if the object tile does not have an associated action.
|
||||
*
|
||||
* @param tile the tile for which the action is to be fetched; this
|
||||
* tile must have been obtained from a call to {@link
|
||||
* #getObjectTiles}.
|
||||
*/
|
||||
public String getObjectAction (ObjectTile tile);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
//
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.54 2002/04/06 01:52:34 mdb Exp $
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.55 2002/04/27 18:41:14 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.media.tile.NoSuchTileException;
|
||||
import com.threerings.media.tile.NoSuchTileSetException;
|
||||
import com.threerings.media.tile.ObjectTile;
|
||||
import com.threerings.media.tile.ObjectTileLayer;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.tile.TileLayer;
|
||||
|
||||
@@ -74,20 +77,6 @@ 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(swid, shei);
|
||||
|
||||
// create a mapping for the action strings and populate it
|
||||
_actions = new HashIntMap();
|
||||
for (int i = 0; i < model.objectActions.length; i++) {
|
||||
String action = model.objectActions[i];
|
||||
// skip null or blank actions
|
||||
if (StringUtil.blank(action)) {
|
||||
continue;
|
||||
}
|
||||
// the key is the composite of the column and row
|
||||
_actions.put(objectKey(model.objectTileIds[3*i],
|
||||
model.objectTileIds[3*i+1]), action);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,51 +141,81 @@ public class DisplayMisoSceneImpl
|
||||
"model.objectTileIds.length % 3 != 0");
|
||||
}
|
||||
|
||||
// now populate the object layer
|
||||
for (int i = 0; i < ocount; i+= 3) {
|
||||
int col = _model.objectTileIds[i];
|
||||
int row = _model.objectTileIds[i+1];
|
||||
int tsid = _model.objectTileIds[i+2];
|
||||
int tid = (tsid & 0xFFFF);
|
||||
tsid >>= 16;
|
||||
// create object tile instances for our objects
|
||||
_objects = new ArrayList();
|
||||
_coords = new HashMap();
|
||||
_actions = new HashMap();
|
||||
|
||||
// create the object tile and stick it into the appropriate
|
||||
// spot in the object layer
|
||||
ObjectTile otile = (ObjectTile)_tmgr.getTile(tsid, tid);
|
||||
_object.setTile(col, row, otile);
|
||||
// generate a "shadow" for this object tile by toggling the
|
||||
// "covered" flag on in all base tiles below it (to prevent
|
||||
// sprites from walking on those tiles)
|
||||
setObjectTileFootprint(otile, col, row, true);
|
||||
for (int ii = 0; ii < ocount; ii+= 3) {
|
||||
int col = _model.objectTileIds[ii];
|
||||
int row = _model.objectTileIds[ii+1];
|
||||
String action = _model.objectActions[ii/3];
|
||||
int fqTid = _model.objectTileIds[ii+2];
|
||||
int tsid = (fqTid >> 16) & 0xFFFF;
|
||||
int tid = (fqTid & 0xFFFF);
|
||||
expandObject(col, row, tsid, tid, fqTid, action);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
/**
|
||||
* Called to expand each object read from the model into an actual
|
||||
* object tile instance with the appropriate additional data.
|
||||
*
|
||||
* @return the newly created object tile (which will have been put
|
||||
* into all the appropriate lists and tables).
|
||||
*/
|
||||
protected ObjectTile expandObject (
|
||||
int col, int row, int tsid, int tid, int fqTid, String action)
|
||||
throws NoSuchTileException, NoSuchTileSetException
|
||||
{
|
||||
// create the object tile and stick it in the list
|
||||
ObjectTile otile = (ObjectTile)_tmgr.getTile(tsid, tid);
|
||||
_objects.add(otile);
|
||||
_coords.put(otile, new Point(col, row));
|
||||
|
||||
// stick the action in the actions table if there is one
|
||||
if (!StringUtil.blank(action)) {
|
||||
_actions.put(otile, action);
|
||||
}
|
||||
|
||||
// generate a "shadow" for this object tile by toggling the
|
||||
// "covered" flag on in all base tiles below it (to prevent
|
||||
// sprites from walking on those tiles)
|
||||
setObjectTileFootprint(otile, col, row, true);
|
||||
|
||||
// return the object tile so that derived classes have easy access
|
||||
// to it
|
||||
return otile;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public BaseTile getBaseTile (int x, int y)
|
||||
{
|
||||
return _base.getTile(x, y);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
// documentation inherited from interface
|
||||
public Tile getFringeTile (int x, int y)
|
||||
{
|
||||
return _fringe.getTile(x, y);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public ObjectTile getObjectTile (int x, int y)
|
||||
// documentation inherited from interface
|
||||
public Iterator getObjectTiles ()
|
||||
{
|
||||
return _object.getTile(x, y);
|
||||
return _objects.iterator();
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public String getObjectAction (int column, int row)
|
||||
public Point getObjectCoords (ObjectTile tile)
|
||||
{
|
||||
if (_actions != null) {
|
||||
return (String)_actions.get(objectKey(column, row));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return (Point)_coords.get(tile);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public String getObjectAction (ObjectTile tile)
|
||||
{
|
||||
return (String)_actions.get(tile);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,15 +266,6 @@ public class DisplayMisoSceneImpl
|
||||
// ", sy=" + y + ", ex=" + endx + ", ey=" + endy + "].");
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the action table key for the object at the specified
|
||||
* column and row.
|
||||
*/
|
||||
protected static int objectKey (int column, int row)
|
||||
{
|
||||
return (column << 15) + row;
|
||||
}
|
||||
|
||||
/** The tile manager from which we load tiles. */
|
||||
protected MisoTileManager _tmgr;
|
||||
|
||||
@@ -268,9 +278,12 @@ public class DisplayMisoSceneImpl
|
||||
/** The fringe layer of tiles. */
|
||||
protected TileLayer _fringe;
|
||||
|
||||
/** The object layer of tiles. */
|
||||
protected ObjectTileLayer _object;
|
||||
/** The object tiles. */
|
||||
protected ArrayList _objects;
|
||||
|
||||
/** A map from object tile coordinates to action string. */
|
||||
protected HashIntMap _actions;
|
||||
/** A map from object tile to coordinate records. */
|
||||
protected HashMap _coords;
|
||||
|
||||
/** A map from object tile to action string. */
|
||||
protected HashMap _actions;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoSceneView.java,v 1.106 2002/04/23 01:18:17 mdb Exp $
|
||||
// $Id: IsoSceneView.java,v 1.107 2002/04/27 18:41:14 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -234,13 +234,13 @@ public class IsoSceneView implements SceneView
|
||||
// if the highlighted object is an object tile, we want to
|
||||
// highlight that
|
||||
if (_hobject instanceof ObjectTile) {
|
||||
ObjectTile otile = (ObjectTile)_hobject;
|
||||
// if we're only highlighting objects with actions, make sure
|
||||
// this one has an action
|
||||
String action = _scene.getObjectAction(_hcoords.x, _hcoords.y);
|
||||
String action = _scene.getObjectAction(otile);
|
||||
if (_hmode != HIGHLIGHT_WITH_ACTION || !StringUtil.blank(action)) {
|
||||
Polygon tpoly = getTilePoly(_hcoords.x, _hcoords.y);
|
||||
hpoly = IsoUtil.getObjectFootprint(
|
||||
_model, tpoly, (ObjectTile)_hobject);
|
||||
hpoly = IsoUtil.getObjectFootprint(_model, tpoly, otile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,13 +402,11 @@ public class IsoSceneView implements SceneView
|
||||
_objects.clear();
|
||||
|
||||
// generate metric records for all objects
|
||||
for (int yy = 0; yy < _model.scenehei; yy++) {
|
||||
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||
ObjectTile tile = _scene.getObjectTile(xx, yy);
|
||||
if (tile != null) {
|
||||
generateObjectMetrics(tile, xx, yy);
|
||||
}
|
||||
}
|
||||
Iterator oiter = _scene.getObjectTiles();
|
||||
while (oiter.hasNext()) {
|
||||
ObjectTile tile = (ObjectTile)oiter.next();
|
||||
Point coords = _scene.getObjectCoords(tile);
|
||||
generateObjectMetrics(tile, coords.x, coords.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,15 +429,15 @@ public class IsoSceneView implements SceneView
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears out the object metrics for the object at the specified tile
|
||||
* coordinates.
|
||||
* Clears out the object metrics for the specified object.
|
||||
*/
|
||||
protected void clearObjectMetrics (int x, int y)
|
||||
protected void clearObjectMetrics (ObjectTile tile)
|
||||
{
|
||||
for (int i = 0; i < _objects.size(); i++) {
|
||||
ObjectMetrics metrics = (ObjectMetrics)_objects.get(i);
|
||||
if (metrics.x == x && metrics.y == y) {
|
||||
_objects.remove(i);
|
||||
int ocount = _objects.size();
|
||||
for (int ii = 0; ii < ocount; ii++) {
|
||||
ObjectMetrics metrics = (ObjectMetrics)_objects.get(ii);
|
||||
if (metrics.tile == tile) {
|
||||
_objects.remove(ii);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -751,7 +749,7 @@ public class IsoSceneView implements SceneView
|
||||
// to repaint if the object has an action
|
||||
if (_hmode != HIGHLIGHT_NEVER) {
|
||||
repaint = (_hmode == HIGHLIGHT_WITH_ACTION) ?
|
||||
(_scene.getObjectAction(_hcoords.x, _hcoords.y) != null) :
|
||||
(_scene.getObjectAction((ObjectTile)_hobject) != null) :
|
||||
true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user