diff --git a/src/java/com/threerings/miso/client/Spot.java b/src/java/com/threerings/miso/client/Cluster.java similarity index 63% rename from src/java/com/threerings/miso/client/Spot.java rename to src/java/com/threerings/miso/client/Cluster.java index 874563ef4..075db7b1c 100644 --- a/src/java/com/threerings/miso/client/Spot.java +++ b/src/java/com/threerings/miso/client/Cluster.java @@ -1,32 +1,32 @@ // -// $Id: Spot.java,v 1.1 2001/08/10 00:47:34 shaper Exp $ +// $Id: Cluster.java,v 1.1 2001/08/10 01:31:25 shaper Exp $ package com.threerings.miso.scene; import java.util.ArrayList; /** - * A Spot is a gathering of Location objects + * A Cluster is a gathering of Location objects * that represent a logical grouping for the purposes of display and * interaction in a scene. * *

This class is currently just a wrapper around an * ArrayList, but the theory is that we may soon want * more useful functionality encapsulated herein, and the - * Spot nomenclature is useful in any case. + * Cluster nomenclature is useful in any case. */ -public class Spot +public class Cluster { /** - * Construct a Spot object. + * Construct a Cluster object. */ - public Spot () + public Cluster () { _locations = new ArrayList(); } /** - * Add a location to the spot. + * Add a location to the cluster. * * @param loc the location. */ @@ -36,7 +36,7 @@ public class Spot } /** - * Return whether the spot contains the given location. + * Return whether the cluster contains the given location. * * @param loc the location. */ @@ -46,7 +46,7 @@ public class Spot } /** - * Removes the location from the spot if present, and returns true + * Removes the location from the cluster if present, and returns true * if the location was present, false if not. * * @param loc the location. @@ -57,7 +57,7 @@ public class Spot } /** - * Return the number of locations in the spot. + * Return the number of locations in the cluster. */ public int size () { @@ -65,13 +65,13 @@ public class Spot } /** - * Return the list of locations that the spot is made up of. + * Return the list of locations that the cluster is made up of. */ public ArrayList getLocations () { return _locations; } - /** The list of locations in this spot. */ + /** The list of locations in this cluster. */ protected ArrayList _locations; } diff --git a/src/java/com/threerings/miso/client/ClusterUtil.java b/src/java/com/threerings/miso/client/ClusterUtil.java new file mode 100644 index 000000000..06d73474a --- /dev/null +++ b/src/java/com/threerings/miso/client/ClusterUtil.java @@ -0,0 +1,105 @@ +// +// $Id: ClusterUtil.java,v 1.1 2001/08/10 01:31:25 shaper Exp $ + +package com.threerings.miso.scene; + +import java.util.ArrayList; + +import com.threerings.miso.Log; + +/** + * The ClusterUtil class provides utility routines for + * working with a list of Cluster objects associated with + * a scene. + */ +public class ClusterUtil +{ + /** + * Remove the given location from its cluster, if any. + * + * @param loc the location. + */ + public static void remove (ArrayList clusters, Location loc) + { + int size = clusters.size(); + for (int ii = 0; ii < size; ii++) { + Cluster cluster = (Cluster)clusters.get(ii); + + if (cluster.contains(loc)) { + cluster.remove(loc); + + // remove the cluster itself if it contains no more locations + if (cluster.size() == 0) { + clusters.remove(cluster); + } + + // we know the location can only reside in at most one cluster + break; + } + } + } + + /** + * Re-group the given location to be placed within the given cluster + * index. + * + *

If the cluster index is -1, the location is simply removed + * from any cluster it may reside in. Otherwise, the location is + * removed from any location it may already be in, and placed in + * the cluster corresponding to the requested cluster index. + * + *

The cluster index may be equal to the current number of clusters + * in the group, in which case a new cluster object will be created + * that initially contains only the given location. + * + * @param clusters the list of clusters. + * @param loc the location. + * @param clusteridx the cluster index, or -1 to remove the location + * from any cluster. + */ + public static void regroup (ArrayList clusters, Location loc, + int clusteridx) + { + // just remove the location if clusteridx is -1 + if (clusteridx == -1) { + remove(clusters, loc); + return; + } + + // make sure we're okay with the requested cluster index + int size = clusters.size(); + if (clusteridx > size) { + Log.warning("Attempt to regroup location to a non-contiguous " + + "cluster index [loc=" + loc + ", clusteridx=" + + clusteridx + "]."); + return; + } + + // get the cluster object the location's to be placed in + Cluster cluster = null; + if (clusteridx == size) { + // the location's being added to a new cluster, so create it + clusters.add(cluster = new Cluster()); + + } else { + // retrieve the cluster we're planning to place the location in + cluster = (Cluster)clusters.get(clusteridx); + + // this should never happen, but sanity-check anyway + if (cluster == null) { + Log.warning("Failed to retrieve cluster [clusteridx=" + + clusteridx + "]."); + return; + } + + // bail if the cluster already contains the location + if (cluster.contains(loc)) return; + } + + // remove the location from any other cluster it may already be in + remove(clusters, loc); + + // add the location to the cluster + cluster.add(loc); + } +} diff --git a/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java b/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java index e74c842c2..143f4765f 100644 --- a/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java +++ b/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java @@ -1,5 +1,5 @@ // -// $Id: DisplayMisoSceneImpl.java,v 1.20 2001/08/10 00:47:34 shaper Exp $ +// $Id: DisplayMisoSceneImpl.java,v 1.21 2001/08/10 01:31:25 shaper Exp $ package com.threerings.miso.scene; @@ -66,7 +66,7 @@ public class Scene _sid = SID_INVALID; _name = DEF_SCENE_NAME; _locations = new ArrayList(); - _spots = new SpotGroup(); + _clusters = new ArrayList(); _exits = new ArrayList(); tiles = new Tile[TILE_WIDTH][TILE_HEIGHT][NUM_LAYERS]; @@ -92,22 +92,22 @@ public class Scene * @param tiles the tiles comprising the scene. */ public Scene (TileManager tilemgr, String name, - ArrayList locations, ArrayList spots, ArrayList exits, + ArrayList locations, ArrayList clusters, ArrayList exits, Tile tiles[][][]) { _tilemgr = tilemgr; _sid = SID_INVALID; _name = name; _locations = locations; - _spots = new SpotGroup(spots); + _clusters = clusters; _exits = exits; this.tiles = tiles; } - public void updateLocation (int x, int y, int orient, int spotidx) + public void updateLocation (int x, int y, int orient, int clusteridx) { Log.info("updateLocation [x=" + x + ", y=" + y + - ", orient=" + orient + ", spotidx=" + spotidx + "]."); + ", orient=" + orient + ", clusteridx=" + clusteridx + "]."); // look the location up in our existing location list int size = _locations.size(); @@ -121,8 +121,8 @@ public class Scene tloc.y = y; tloc.orient = orient; - // and update the spot contents - _spots.respot(tloc, spotidx); + // and update the cluster contents + ClusterUtil.regroup(_clusters, tloc, clusteridx); return; } @@ -130,7 +130,7 @@ public class Scene // else we didn't find a location object, so create one _locations.add(loc = new Location(x, y, orient)); - _spots.respot(loc, spotidx); + ClusterUtil.regroup(_clusters, loc, clusteridx); } /** @@ -158,11 +158,11 @@ public class Scene } /** - * Return the spot group. + * Return the cluster list. */ - public SpotGroup getSpotGroup () + public ArrayList getClusters () { - return _spots; + return _clusters; } /** @@ -173,9 +173,9 @@ public class Scene return _exits; } - public int getNumSpots () + public int getNumClusters () { - return _spots.size(); + return _clusters.size(); } /** @@ -214,8 +214,8 @@ public class Scene buf.append("[name=").append(_name); buf.append(", sid=").append(_sid); buf.append(", locations=").append(StringUtil.toString(_locations)); + buf.append(", clusters=").append(StringUtil.toString(_clusters)); buf.append(", exits=").append(StringUtil.toString(_exits)); - buf.append(", spots=").append(StringUtil.toString(_spots)); return buf.append("]").toString(); } @@ -231,12 +231,12 @@ public class Scene /** The locations within the scene. */ protected ArrayList _locations; + /** The clusters within the scene. */ + protected ArrayList _clusters; + /** The exits to different scenes. */ protected ArrayList _exits; - /** The spots within the scene. */ - protected SpotGroup _spots; - /** The default tile for the base layer in the scene. */ protected Tile _deftile; diff --git a/src/java/com/threerings/miso/client/IsoSceneView.java b/src/java/com/threerings/miso/client/IsoSceneView.java index 9c13254c9..16e58d5ce 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.36 2001/08/10 00:47:34 shaper Exp $ +// $Id: IsoSceneView.java,v 1.37 2001/08/10 01:31:25 shaper Exp $ package com.threerings.miso.scene; @@ -501,14 +501,14 @@ public class IsoSceneView implements EditableSceneView return path; } - public void updateLocation (int x, int y, int orient, int spotidx) + public void updateLocation (int x, int y, int orient, int clusteridx) { - _scene.updateLocation(x, y, orient, spotidx); + _scene.updateLocation(x, y, orient, clusteridx); } - public int getNumSpots () + public int getNumClusters () { - return (_scene == null) ? 0 : _scene.getNumSpots(); + return (_scene == null) ? 0 : _scene.getNumClusters(); } /** The color to draw the highlighted tile. */ diff --git a/src/java/com/threerings/miso/client/SpotGroup.java b/src/java/com/threerings/miso/client/SpotGroup.java deleted file mode 100644 index 8b8881d4a..000000000 --- a/src/java/com/threerings/miso/client/SpotGroup.java +++ /dev/null @@ -1,141 +0,0 @@ -// -// $Id: SpotGroup.java,v 1.1 2001/08/10 00:47:34 shaper Exp $ - -package com.threerings.miso.scene; - -import java.util.ArrayList; - -import com.threerings.miso.Log; - -/** - * The SpotGroup class manages all of the - * Spot objects associated with a scene. The scene should - * only interact with spots via the SpotGroup class. - */ -public class SpotGroup -{ - /** - * Construct a SpotGroup object. - */ - public SpotGroup () - { - _spots = new ArrayList(); - } - - /** - * Construct a SpotGroup object, initializing it to - * contain the given list of Spot objects. - * - * @param list the list of spots. - */ - public SpotGroup (ArrayList spots) - { - _spots = spots; - } - - /** - * Return the list of Spot objects contained in the group. - */ - public ArrayList getSpots () - { - return _spots; - } - - /** - * Remove the given location from its spot, if any. - * - * @param loc the location. - */ - public void remove (Location loc) - { - int size = _spots.size(); - for (int ii = 0; ii < size; ii++) { - Spot spot = (Spot)_spots.get(ii); - - if (spot.contains(loc)) { - spot.remove(loc); - - // remove the spot itself if it contains no more locations - if (spot.size() == 0) { - _spots.remove(spot); - } - - // we know the location can only reside in at most one spot - break; - } - } - } - - /** - * Re-spot the given location to be placed within the given spot - * index. - * - *

If the spot index is -1, the location is simply removed - * from any spot it may reside in. Otherwise, the location is - * removed from any location it may already be in, and placed in - * the spot corresponding to the requested spot index. - * - *

The spot index may be equal to the current number of spots - * in the group, in which case a new spot object will be created - * that initially contains only the given location. - * - * @param loc the location. - * @param spotidx the spot index, or -1 to remove the location - * from any containing spot. - */ - public void respot (Location loc, int spotidx) - { - // just remove the location if spotidx is -1 - if (spotidx == -1) { - remove(loc); - return; - } - - // make sure we're okay with the requested spot index - int size = _spots.size(); - if (spotidx > size) { - Log.warning("Attempt to respot location to a non-contiguous " + - "spot index [loc=" + loc + ", spotidx=" + - spotidx + "]."); - return; - } - - // get the spot object the location's to be placed in - Spot spot = null; - if (spotidx == size) { - // the location's being added to a new spot, so create it - _spots.add(spot = new Spot()); - - } else { - // retrieve the spot we're planning to place the location in - spot = (Spot)_spots.get(spotidx); - - // this should never happen, but sanity-check anyway - if (spot == null) { - Log.warning("Failed to retrieve spot [spotidx=" + - spotidx + "]."); - return; - } - - // bail if the spot already contains the location - if (spot.contains(loc)) return; - } - - // remove the location from any other spot it may already be in - remove(loc); - - // add the location to the spot - spot.add(loc); - } - - /** - * Return the number of spots in the group. - */ - public int size () - { - return _spots.size(); - } - - /** The list of spots in the spot group. */ - protected ArrayList _spots; -} diff --git a/src/java/com/threerings/miso/tools/xml/XMLSceneParser.java b/src/java/com/threerings/miso/tools/xml/XMLSceneParser.java index e6a42c58f..0c2043a7d 100644 --- a/src/java/com/threerings/miso/tools/xml/XMLSceneParser.java +++ b/src/java/com/threerings/miso/tools/xml/XMLSceneParser.java @@ -1,5 +1,5 @@ // -// $Id: XMLSceneParser.java,v 1.7 2001/08/10 00:47:34 shaper Exp $ +// $Id: XMLSceneParser.java,v 1.8 2001/08/10 01:31:25 shaper Exp $ package com.threerings.miso.scene.xml; @@ -70,9 +70,9 @@ public class XMLSceneParser extends DefaultHandler int vals[] = StringUtil.parseIntArray(_chars.toString()); _scLocations = toLocationsList(vals); - } else if (qName.equals("spot")) { + } else if (qName.equals("cluster")) { int vals[] = StringUtil.parseIntArray(_chars.toString()); - _scSpots.add(toSpot(_scLocations, vals)); + _scClusters.add(toCluster(_scLocations, vals)); } else if (qName.equals("exits")) { String vals[] = StringUtil.parseStringArray(_chars.toString()); @@ -88,7 +88,8 @@ public class XMLSceneParser extends DefaultHandler } else if (qName.equals("scene")) { // construct the scene object on tag close _scene = new Scene( - _tilemgr, _scName, _scLocations, _scSpots, _scExits, _scTiles); + _tilemgr, _scName, _scLocations, _scClusters, + _scExits, _scTiles); Log.info("Constructed parsed scene [scene=" + _scene + "]."); } @@ -168,22 +169,22 @@ public class XMLSceneParser extends DefaultHandler } /** - * Given an array of integer values, return a Spot + * Given an array of integer values, return a Cluster * object containing the location objects identified by location * index number in the integer array. * * @param locs the locations list. * @param vals the integer values. * - * @return the spot object. + * @return the cluster object. */ - protected Spot toSpot (ArrayList locs, int[] vals) + protected Cluster toCluster (ArrayList locs, int[] vals) { - Spot spot = new Spot(); + Cluster cluster = new Cluster(); for (int ii = 0; ii < vals.length; ii++) { - spot.add((Location)locs.get(vals[ii])); + cluster.add((Location)locs.get(vals[ii])); } - return spot; + return cluster; } /** @@ -268,7 +269,7 @@ public class XMLSceneParser extends DefaultHandler _scTiles = new Tile[width][height][Scene.NUM_LAYERS]; _scLocations = null; _scExits = null; - _scSpots = new ArrayList(); + _scClusters = new ArrayList(); } /** @@ -320,7 +321,7 @@ public class XMLSceneParser extends DefaultHandler // temporary storage of scene object values and data protected StringBuffer _chars; protected String _scName; - protected ArrayList _scLocations, _scExits, _scSpots; + protected ArrayList _scLocations, _scExits, _scClusters; protected Tile[][][] _scTiles; protected int _scLnum, _scRownum, _scColstart; } diff --git a/src/java/com/threerings/miso/tools/xml/XMLSceneWriter.java b/src/java/com/threerings/miso/tools/xml/XMLSceneWriter.java index e644d3bad..26fb1c0be 100644 --- a/src/java/com/threerings/miso/tools/xml/XMLSceneWriter.java +++ b/src/java/com/threerings/miso/tools/xml/XMLSceneWriter.java @@ -1,5 +1,5 @@ // -// $Id: XMLSceneWriter.java,v 1.5 2001/08/10 00:47:34 shaper Exp $ +// $Id: XMLSceneWriter.java,v 1.6 2001/08/10 01:31:25 shaper Exp $ package com.threerings.miso.scene.xml; @@ -53,9 +53,9 @@ public class XMLSceneWriter extends DataWriter dataElement("version", "" + Scene.VERSION); dataElement("locations", getLocationData(scene)); - startElement("spots"); - writeSpots(scene); - endElement("spots"); + startElement("clusters"); + writeClusters(scene); + endElement("clusters"); dataElement("exits", getExitData(scene)); @@ -76,32 +76,32 @@ public class XMLSceneWriter extends DataWriter } /** - * Output XML detailing the spot objects. Spots are described by - * a list of location object indexes that are contained within the - * spot. + * Output XML detailing the cluster objects. Clusters are + * described by a list of location object indexes that are + * contained within the cluster. * * @param scene the scene object. */ - protected void writeSpots (Scene scene) throws SAXException + protected void writeClusters (Scene scene) throws SAXException { - ArrayList spots = scene.getSpotGroup().getSpots(); + ArrayList clusters = scene.getClusters(); ArrayList locs = scene.getLocations(); - int size = spots.size(); + int size = clusters.size(); for (int ii = 0; ii < size; ii++) { StringBuffer buf = new StringBuffer(); - Spot spot = (Spot)spots.get(ii); - ArrayList spotlocs = spot.getLocations(); + Cluster cluster = (Cluster)clusters.get(ii); + ArrayList clusterlocs = cluster.getLocations(); - int spotsize = spotlocs.size(); - for (int jj = 0; jj < spotsize; jj++) { - buf.append(locs.indexOf(spotlocs.get(jj))).append(","); - if (jj < spotsize - 1) buf.append(","); + int clustersize = clusterlocs.size(); + for (int jj = 0; jj < clustersize; jj++) { + buf.append(locs.indexOf(clusterlocs.get(jj))).append(","); + if (jj < clustersize - 1) buf.append(","); } - dataElement("spot", buf.toString()); + dataElement("cluster", buf.toString()); } } @@ -159,8 +159,8 @@ public class XMLSceneWriter extends DataWriter /** * Return a string representation of the locations in the scene. - * Each location is specified by a comma-delimited quartet of - * (spot id, x, y, orientation) values. + * Each location is specified by a comma-delimited triplet of + * (x, y, orientation) values. * * @return the locations in String format. */