diff --git a/src/java/com/threerings/miso/client/DisplayMisoScene.java b/src/java/com/threerings/miso/client/DisplayMisoScene.java index 464dca7dd..a7350792d 100644 --- a/src/java/com/threerings/miso/client/DisplayMisoScene.java +++ b/src/java/com/threerings/miso/client/DisplayMisoScene.java @@ -1,13 +1,14 @@ // -// $Id: DisplayMisoScene.java,v 1.6 2002/09/18 02:32:57 mdb Exp $ +// $Id: DisplayMisoScene.java,v 1.7 2002/09/23 21:54:50 mdb Exp $ package com.threerings.miso.scene; -import java.awt.Point; -import java.util.Iterator; +import java.awt.Rectangle; import com.threerings.media.tile.ObjectTile; import com.threerings.media.tile.Tile; + +import com.threerings.miso.scene.util.ObjectSet; import com.threerings.miso.tile.BaseTile; /** @@ -29,29 +30,8 @@ public interface DisplayMisoScene public Tile getFringeTile (int x, int y); /** - * Returns the number of object tiles in the scene. + * Populates the supplied scene object set with all objects whose + * origin falls in the requested region. */ - public int getObjectCount (); - - /** - * Returns the object tile with the specified index. - */ - public ObjectTile getObjectTile (int index); - - /** - * Returns the tile coordinates for the specified object tile. - * - * @param index the index of the object tile for which coordinates are - * desired. - */ - public Point getObjectCoords (int index); - - /** - * Returns the action associated with the specified object tile. Null - * is returned if the object tile does not have an associated action. - * - * @param index the index of the object for which the action is - * desired. - */ - public String getObjectAction (int index); + public void getSceneObjects (Rectangle region, ObjectSet set); } diff --git a/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java b/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java index 0e4159882..543951c37 100644 --- a/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java +++ b/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java @@ -1,12 +1,11 @@ // -// $Id: DisplayMisoSceneImpl.java,v 1.60 2002/09/18 02:32:57 mdb Exp $ +// $Id: DisplayMisoSceneImpl.java,v 1.61 2002/09/23 21:54:50 mdb Exp $ package com.threerings.miso.scene; -import java.awt.Point; +import java.awt.Rectangle; + import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; import java.util.Random; import com.samskivert.util.StringUtil; @@ -19,6 +18,7 @@ import com.threerings.media.tile.TileException; import com.threerings.media.tile.TileLayer; import com.threerings.miso.Log; +import com.threerings.miso.scene.util.ObjectSet; import com.threerings.miso.tile.AutoFringer; import com.threerings.miso.tile.BaseTile; import com.threerings.miso.tile.BaseTileLayer; @@ -157,32 +157,34 @@ public class DisplayMisoSceneImpl * Called to expand each object read from the model into an actual * object tile instance with the appropriate additional data. * - * @return the object info record for the newly created object tile + * @return the scene object record for the newly created object tile * (which will have been put into all the appropriate lists and * tables). */ - protected ObjectInfo expandObject ( + protected SceneObject expandObject ( int col, int row, int tsid, int tid, int fqTid, String action) throws NoSuchTileException, NoSuchTileSetException { // create and initialize an object info record for this object - ObjectInfo oinfo = createObjectInfo(); - oinfo.object = (ObjectTile)_tmgr.getTile(tsid, tid); - oinfo.coords = new Point(col, row); + SceneObject scobj = createSceneObject( + col, row, (ObjectTile)_tmgr.getTile(tsid, tid)); if (!StringUtil.blank(action)) { - oinfo.action = action; + scobj.action = 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(oinfo.object, col, row, true); + setObjectTileFootprint(scobj.tile, col, row, true); + + // assign the object its index + scobj.index = _objects.size(); // add the info record to the list - _objects.add(oinfo); + _objects.add(scobj); // return the object info so that derived classes may access it - return oinfo; + return scobj; } // documentation inherited from interface @@ -198,27 +200,19 @@ public class DisplayMisoSceneImpl } // documentation inherited from interface - public int getObjectCount () + public void getSceneObjects (Rectangle region, ObjectSet set) { - return _objects.size(); - } - - // documentation inherited from interface - public ObjectTile getObjectTile (int index) - { - return ((ObjectInfo)_objects.get(index)).object; - } - - // documentation inherited from interface - public Point getObjectCoords (int index) - { - return ((ObjectInfo)_objects.get(index)).coords; - } - - // documentation inherited from interface - public String getObjectAction (int index) - { - return ((ObjectInfo)_objects.get(index)).action; + // iterate over all of our objects, creating and including scene + // objects for those that intersect the region + int ocount = _objects.size(); + for (int ii = 0; ii < ocount; ii++) { + SceneObject scobj = (SceneObject)_objects.get(ii); + if (region.contains(scobj.x, scobj.y)) { + set.insert(scobj); + } else { + System.err.println("Skipping " + scobj + ", not in " + region + "."); + } + } } /** @@ -233,27 +227,26 @@ public class DisplayMisoSceneImpl } /** - * Creates an object info. This allows derived classes to extend the - * object info record. + * Creates a scene object record. This allows derived classes to + * provide extended records. */ - protected ObjectInfo createObjectInfo () + protected SceneObject createSceneObject (int x, int y, ObjectTile tile) { - return new ObjectInfo(); + return new SceneObject(x, y, tile); } /** - * Locates the object info record for the object tile at the specified - * location. Two of the same kind of object tile cannot exist at the - * same location. + * Locates the scene object record for the object tile at the + * specified location. Two of the same kind of object tile cannot + * exist at the same location. */ - protected ObjectInfo getObjectInfo (ObjectTile tile, int x, int y) + protected SceneObject getSceneObject (ObjectTile tile, int x, int y) { int ocount = _objects.size(); for (int ii = 0; ii < ocount; ii++) { - ObjectInfo info = (ObjectInfo)_objects.get(ii); - if (info.object == tile && - info.coords.x == x && info.coords.y == y) { - return info; + SceneObject scobj = (SceneObject)_objects.get(ii); + if (scobj.tile == tile && scobj.x == x && scobj.y == y) { + return scobj; } } return null; @@ -308,7 +301,7 @@ public class DisplayMisoSceneImpl /** The fringe layer of tiles. */ protected TileLayer _fringe; - /** The object info records. */ + /** The scene object records. */ protected ArrayList _objects = new ArrayList(); /** The autofringer. */ @@ -316,13 +309,4 @@ public class DisplayMisoSceneImpl /** A random number generator for filling random base tiles and fringes. */ protected Random _rando = new Random(); - - /** Used to report information on objects in this scene. */ - protected static class ObjectInfo - { - public ObjectInfo () {} - public ObjectTile object; - public Point coords; - public String action; - } } diff --git a/src/java/com/threerings/miso/client/DisplayObjectInfo.java b/src/java/com/threerings/miso/client/DisplayObjectInfo.java index 5c95fbfbf..1f5589311 100644 --- a/src/java/com/threerings/miso/client/DisplayObjectInfo.java +++ b/src/java/com/threerings/miso/client/DisplayObjectInfo.java @@ -1,5 +1,5 @@ // -// $Id: DisplayObjectInfo.java,v 1.1 2002/09/18 02:32:57 mdb Exp $ +// $Id: DisplayObjectInfo.java,v 1.2 2002/09/23 21:54:50 mdb Exp $ package com.threerings.miso.scene; @@ -44,7 +44,8 @@ public class SceneObject public boolean equals (Object other) { if (other instanceof SceneObject) { - return (index == ((SceneObject)other).index); + SceneObject oso = (SceneObject)other; + return (x == oso.x && y == oso.y && tile == oso.tile); } else { return false; } @@ -53,7 +54,7 @@ public class SceneObject // documentation inherited public int hashCode () { - return x ^ y ^ index ^ tile.hashCode(); + return x ^ y ^ tile.hashCode(); } /** diff --git a/src/java/com/threerings/miso/client/IsoSceneView.java b/src/java/com/threerings/miso/client/IsoSceneView.java index cbf59bd5e..0b0f17b7f 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.119 2002/09/18 02:32:57 mdb Exp $ +// $Id: IsoSceneView.java,v 1.120 2002/09/23 21:54:50 mdb Exp $ package com.threerings.miso.scene; @@ -35,6 +35,7 @@ import com.threerings.miso.Log; import com.threerings.miso.scene.DirtyItemList.DirtyItem; import com.threerings.miso.scene.util.AStarPathUtil; import com.threerings.miso.scene.util.IsoUtil; +import com.threerings.miso.scene.util.ObjectSet; /** * The iso scene view provides an isometric view of a particular scene. It @@ -422,27 +423,17 @@ public class IsoSceneView implements SceneView // clear out any previously existing object data _objects.clear(); - // generate metric records for all objects - int ocount = _scene.getObjectCount(); - for (int ii = 0; ii < ocount; ii++) { - createSceneObject(_scene.getObjectCoords(ii).x, - _scene.getObjectCoords(ii).y, - _scene.getObjectTile(ii), ii, - _scene.getObjectAction(ii)); - } - } + // grab all available objects + Rectangle rect = new Rectangle(Short.MIN_VALUE, Short.MIN_VALUE, + 2*Short.MAX_VALUE, 2*Short.MAX_VALUE); + _scene.getSceneObjects(rect, _objects); - /** - * Creates a new scene object and adds it to the list. - */ - protected void createSceneObject ( - int x, int y, ObjectTile tile, int index, String action) - { - SceneObject scobj = new SceneObject(x, y, tile); - scobj.index = index; - scobj.action = action; - scobj.bounds = IsoUtil.getObjectBounds(_model, scobj); - _objects.add(scobj); + // and fill in those objects' bounds + int ocount = _objects.size(); + for (int ii = 0; ii < ocount; ii++) { + SceneObject scobj = _objects.get(ii); + scobj.bounds = IsoUtil.getObjectBounds(_model, scobj); + } } // documentation inherited @@ -620,8 +611,8 @@ public class IsoSceneView implements SceneView /** The scene to be displayed. */ protected DisplayMisoScene _scene; - /** Metric information for all of the object tiles. */ - protected ArrayList _objects = new ArrayList(); + /** Information for all of the objects visible in the scene. */ + protected ObjectSet _objects = new ObjectSet(); /** The dirty sprites and objects that need to be re-painted. */ protected DirtyItemList _dirtyItems = new DirtyItemList(); diff --git a/src/java/com/threerings/miso/tools/EditableMisoScene.java b/src/java/com/threerings/miso/tools/EditableMisoScene.java index cfdc44502..22ed1038a 100644 --- a/src/java/com/threerings/miso/tools/EditableMisoScene.java +++ b/src/java/com/threerings/miso/tools/EditableMisoScene.java @@ -1,5 +1,5 @@ // -// $Id: EditableMisoScene.java,v 1.17 2002/09/18 02:32:57 mdb Exp $ +// $Id: EditableMisoScene.java,v 1.18 2002/09/23 21:54:50 mdb Exp $ package com.threerings.miso.scene.tools; @@ -9,10 +9,11 @@ import com.threerings.media.tile.ObjectTile; import com.threerings.media.tile.Tile; import com.threerings.media.tile.TileUtil; -import com.threerings.miso.tile.BaseTile; -import com.threerings.miso.tile.BaseTileSet; import com.threerings.miso.scene.DisplayMisoScene; import com.threerings.miso.scene.MisoSceneModel; +import com.threerings.miso.scene.SceneObject; +import com.threerings.miso.tile.BaseTile; +import com.threerings.miso.tile.BaseTileSet; /** * The editable Miso scene interface is used in the offline scene building @@ -59,7 +60,7 @@ public interface EditableMisoScene public void setBaseTiles (Rectangle r, BaseTileSet set, int setId); /** - * Addds an object tile to this scene. + * Adds an object to this scene. * * @param x the object's origin x-coordinate. * @param y the object's origin y-coordinate. @@ -67,14 +68,10 @@ public interface EditableMisoScene * @param fqTileId the fully-qualified tile id (@see * TileUtil#getFQTileId}) of the new default base tile. * - * @return the new object's index in the object list. + * @return the new scene object instance. */ - public int addObjectTile (ObjectTile tile, int x, int y, int fqTileId); - - /** - * Sets the action string for the specified object tile. - */ - public void setObjectAction (int index, String action); + public SceneObject addSceneObject ( + ObjectTile tile, int x, int y, int fqTileId); /** * Clears out the tile at the specified location in the base layer. @@ -82,15 +79,9 @@ public interface EditableMisoScene public void clearBaseTile (int x, int y); /** - * Clears out the specified object tile at the specified coordinates - * from the object list. + * Removes the specified object from the scene. */ - public void removeObjectTile (int index); - - /** - * Clears the action string for the specified object tile. - */ - public void clearObjectAction (int index); + public boolean removeSceneObject (SceneObject scobj); /** * Returns a reference to the miso scene model that reflects the diff --git a/src/java/com/threerings/miso/tools/EditableMisoSceneImpl.java b/src/java/com/threerings/miso/tools/EditableMisoSceneImpl.java index 7005ccda4..725aa70e1 100644 --- a/src/java/com/threerings/miso/tools/EditableMisoSceneImpl.java +++ b/src/java/com/threerings/miso/tools/EditableMisoSceneImpl.java @@ -1,5 +1,5 @@ // -// $Id: EditableMisoSceneImpl.java,v 1.22 2002/09/18 02:32:57 mdb Exp $ +// $Id: EditableMisoSceneImpl.java,v 1.23 2002/09/23 21:54:50 mdb Exp $ package com.threerings.miso.scene.tools; @@ -23,6 +23,7 @@ import com.threerings.miso.tile.MisoTileManager; import com.threerings.miso.scene.DisplayMisoSceneImpl; import com.threerings.miso.scene.MisoSceneModel; +import com.threerings.miso.scene.SceneObject; import com.threerings.miso.scene.util.IsoUtil; /** @@ -110,26 +111,21 @@ public class EditableMisoSceneImpl } // documentation inherited - public int addObjectTile (ObjectTile tile, int x, int y, int fqTileId) + public SceneObject addSceneObject ( + ObjectTile tile, int x, int y, int fqTileId) { - // create an object info record and add it to the list - EditableObjectInfo info = (EditableObjectInfo)createObjectInfo(); - info.object = tile; - info.coords = new Point(x, y); - info.fqTileId = fqTileId; - _objects.add(info); + // create a scene object record and add it to the list + EditableSceneObject scobj = (EditableSceneObject) + createSceneObject(x, y, tile); + scobj.fqTileId = fqTileId; + scobj.index = _objects.size(); + _objects.add(scobj); // toggle the "covered" flag on in all base tiles below this // object tile setObjectTileFootprint(tile, x, y, true); - return _objects.size()-1; - } - - // documentation inherited from interface - public void setObjectAction (int index, String action) - { - ((ObjectInfo)_objects.get(index)).action = action; + return scobj; } // documentation inherited @@ -141,20 +137,16 @@ public class EditableMisoSceneImpl } // documentation inherited - public void removeObjectTile (int index) + public boolean removeSceneObject (SceneObject scobj) { - ObjectInfo info = (ObjectInfo)_objects.remove(index); - - // toggle the "covered" flag off on the base tiles in this object - // tile's footprint - setObjectTileFootprint( - info.object, info.coords.x, info.coords.y, false); - } - - // documentation inherited from interface - public void clearObjectAction (int index) - { - ((ObjectInfo)_objects.get(index)).action = null; + if (_objects.remove(scobj)) { + // toggle the "covered" flag off on the base tiles in this object + // tile's footprint + setObjectTileFootprint(scobj.tile, scobj.x, scobj.y, false); + return true; + } else { + return false; + } } // documentation inherited @@ -170,11 +162,12 @@ public class EditableMisoSceneImpl String[] actions = new String[ocount]; for (int ii = 0; ii < ocount; ii++) { - EditableObjectInfo info = (EditableObjectInfo)_objects.get(ii); - otids[3*ii] = info.coords.x; - otids[3*ii+1] = info.coords.y; - otids[3*ii+2] = info.fqTileId; - actions[ii] = info.action; + EditableSceneObject scobj = (EditableSceneObject) + _objects.get(ii); + otids[3*ii] = scobj.x; + otids[3*ii+1] = scobj.y; + otids[3*ii+2] = scobj.fqTileId; + actions[ii] = scobj.action; } // stuff the new arrays into the model @@ -187,31 +180,36 @@ public class EditableMisoSceneImpl } // documentation inherited - protected ObjectInfo createObjectInfo () + protected SceneObject createSceneObject (int x, int y, ObjectTile tile) { - return new EditableObjectInfo(); + return new EditableSceneObject(x, y, tile); } // documentation inherited - protected ObjectInfo expandObject ( + protected SceneObject expandObject ( int col, int row, int tsid, int tid, int fqTid, String action) throws NoSuchTileException, NoSuchTileSetException { // do the actual object creation - EditableObjectInfo info = (EditableObjectInfo) + EditableSceneObject scobj = (EditableSceneObject) super.expandObject(col, row, tsid, tid, fqTid, action); // we need this to track object layer mods - info.fqTileId = fqTid; + scobj.fqTileId = fqTid; // pass on the objecty goodness - return info; + return scobj; } /** Used to report information on objects in this scene. */ - protected static class EditableObjectInfo extends ObjectInfo + protected static class EditableSceneObject extends SceneObject { public int fqTileId; + + public EditableSceneObject (int x, int y, ObjectTile tile) + { + super(x, y, tile); + } } /** The default tileset with which to fill the base layer. */