The big fat bernie revamp! Er, big fat miso revamp rather:
- Combined SceneViewPanel and IsoSceneView into one happy panel. - Ditched the DisplayMisoScene notion; the new MisoScenePanel now manages resolved scene information (like base, object and fringe tiles) itself so that it can... - ...support scrolling scenes by keeping blocks of resolved base, fringe and object information loaded only for what is potentially visible rather than for the whole scene. Other things were surely cleaned up or broken in the process to keep a keen eye out. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2413 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
//
|
||||
// $Id: MisoScene.java,v 1.3 2003/02/24 18:40:41 mdb Exp $
|
||||
|
||||
package com.threerings.miso.data;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import com.threerings.miso.client.util.ObjectSet;
|
||||
|
||||
/**
|
||||
* Provides information on the composition of tiles in a Miso scene.
|
||||
*/
|
||||
public interface MisoScene
|
||||
{
|
||||
/**
|
||||
* Returns the fully qualified tile id of the base tile at the
|
||||
* specified coordinates. <code>-1</code> will be returned if there is
|
||||
* no tile at the specified coordinate.
|
||||
*/
|
||||
public int getBaseTileId (int x, int y);
|
||||
|
||||
/**
|
||||
* Populates the supplied object set with info on all objects whose
|
||||
* origin falls in the requested region.
|
||||
*/
|
||||
public void getObjects (Rectangle region, ObjectSet set);
|
||||
|
||||
/**
|
||||
* Updates the tile at the specified location in the base layer.
|
||||
*
|
||||
* @param fqTileId the fully-qualified tile id (@see
|
||||
* TileUtil#getFQTileId}) of the tile to set.
|
||||
* @param x the x-coordinate of the tile to set.
|
||||
* @param y the y-coordinate of the tile to set.
|
||||
*
|
||||
* Note that if there are fringe tiles associated with this scene,
|
||||
* calling this method may result in the surrounding fringe tiles being
|
||||
* cleared and subsequently recalculated. This should not be called
|
||||
* on a displaying scene unless you know what you are doing.
|
||||
*/
|
||||
public void setBaseTile (int fqTileId, int x, int y);
|
||||
|
||||
/**
|
||||
* Fill a rectangular area with random tiles from the specified base
|
||||
* tileset.
|
||||
*
|
||||
* @param r the region to be filled.
|
||||
* @param setId the id of the tileset to use when filling.
|
||||
* @param setSize the number of tiles in the tileset.
|
||||
*/
|
||||
public void setBaseTiles (Rectangle r, int setId, int setSize);
|
||||
|
||||
/**
|
||||
* Adds an object to this scene.
|
||||
*
|
||||
* @param fqTileId the fully-qualified tile id (@see
|
||||
* TileUtil#getFQTileId}) of the object tile.
|
||||
* @param x the object's origin x-coordinate.
|
||||
* @param y the object's origin y-coordinate.
|
||||
*
|
||||
* @return the new object info record.
|
||||
*/
|
||||
public ObjectInfo addObject (int fqTileId, int x, int y);
|
||||
|
||||
/**
|
||||
* Removes the specified object from the scene.
|
||||
*/
|
||||
public boolean removeObject (ObjectInfo info);
|
||||
|
||||
/**
|
||||
* Returns the scene model used by this scene. This is an expensive
|
||||
* operation as it must recreate the scene model from the (possibly
|
||||
* changed) runtime data. Thus it should not be called in a normal
|
||||
* client display and is provided mainly for scene editors and such.
|
||||
*/
|
||||
public MisoSceneModel getSceneModel ();
|
||||
}
|
||||
@@ -1,48 +1,31 @@
|
||||
//
|
||||
// $Id: MisoSceneModel.java,v 1.13 2003/04/12 02:14:10 mdb Exp $
|
||||
// $Id: MisoSceneModel.java,v 1.14 2003/04/17 19:21:16 mdb Exp $
|
||||
|
||||
package com.threerings.miso.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.ArrayUtil;
|
||||
import com.samskivert.util.IntListUtil;
|
||||
import com.samskivert.util.ListUtil;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.Random;
|
||||
|
||||
import com.threerings.io.SimpleStreamableObject;
|
||||
|
||||
import com.threerings.media.tile.TileUtil;
|
||||
import com.threerings.media.util.MathUtil;
|
||||
|
||||
import com.threerings.miso.util.ObjectSet;
|
||||
|
||||
/**
|
||||
* Contains basic information for a miso scene model that is shared among
|
||||
* every specialized model implementation.
|
||||
* the specialized model implementations.
|
||||
*/
|
||||
public class MisoSceneModel extends SimpleStreamableObject
|
||||
public abstract class MisoSceneModel extends SimpleStreamableObject
|
||||
implements Cloneable
|
||||
{
|
||||
/** The width of this scene or section of the scene (depending on the
|
||||
* model implementation), in tile units. */
|
||||
/** The width of this scene in tiles. */
|
||||
public short width;
|
||||
|
||||
/** The height of this scene or section of the scene (depending on the
|
||||
* model implementation), in tile units. */
|
||||
/** The height of this scene in tiles. */
|
||||
public short height;
|
||||
|
||||
/** The combined tile ids (tile set id and tile id) of the
|
||||
* "uninteresting" tiles in the object layer. */
|
||||
public int[] objectTileIds;
|
||||
|
||||
/** The x coordinate of the "uninteresting" tiles in the object
|
||||
* layer. */
|
||||
public short[] objectXs;
|
||||
|
||||
/** The y coordinate of the "uninteresting" tiles in the object
|
||||
* layer. */
|
||||
public short[] objectYs;
|
||||
|
||||
/** Information records for the "interesting" objects in the object
|
||||
* layer. */
|
||||
public ObjectInfo[] objectInfo;
|
||||
|
||||
/**
|
||||
* Creates a completely uninitialized model suitable for little more
|
||||
* than unserialization.
|
||||
@@ -60,47 +43,74 @@ public class MisoSceneModel extends SimpleStreamableObject
|
||||
Short.MIN_VALUE, width, Short.MAX_VALUE);
|
||||
this.height = (short)MathUtil.bound(
|
||||
Short.MIN_VALUE, height, Short.MAX_VALUE);
|
||||
|
||||
// start with zero-length object arrays
|
||||
objectTileIds = new int[0];
|
||||
objectXs = new short[0];
|
||||
objectYs = new short[0];
|
||||
objectInfo = new ObjectInfo[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an object to this model.
|
||||
* Returns the fully qualified tile id of the base tile at the
|
||||
* specified coordinates. <code>-1</code> will be returned if there is
|
||||
* no tile at the specified coordinate.
|
||||
*/
|
||||
public void addObject (ObjectInfo info)
|
||||
public abstract int getBaseTileId (int x, int y);
|
||||
|
||||
/**
|
||||
* Updates the tile at the specified location in the base layer.
|
||||
*
|
||||
* <p> Note that if there are fringe tiles associated with this scene,
|
||||
* calling this method may result in the surrounding fringe tiles
|
||||
* being cleared and subsequently recalculated. This should not be
|
||||
* called on a displaying scene unless you know what you are doing.
|
||||
*
|
||||
* @param fqTileId the fully-qualified tile id (@see
|
||||
* TileUtil#getFQTileId}) of the tile to set.
|
||||
* @param x the x-coordinate of the tile to set.
|
||||
* @param y the y-coordinate of the tile to set.
|
||||
*
|
||||
* @return false if the specified tile coordinates are outside of the
|
||||
* scene and the tile was not saved, true otherwise.
|
||||
*/
|
||||
public abstract boolean setBaseTile (int fqTileId, int x, int y);
|
||||
|
||||
/**
|
||||
* Fill a rectangular area with random tiles from the specified base
|
||||
* tileset.
|
||||
*
|
||||
* @param r the region to be filled.
|
||||
* @param setId the id of the tileset to use when filling.
|
||||
* @param setSize the number of tiles in the tileset.
|
||||
*/
|
||||
public void setBaseTiles (Rectangle r, int setId, int setSize)
|
||||
{
|
||||
if (info.isInteresting()) {
|
||||
objectInfo = (ObjectInfo[])ArrayUtil.append(objectInfo, info);
|
||||
} else {
|
||||
objectTileIds = ArrayUtil.append(objectTileIds, info.tileId);
|
||||
objectXs = ArrayUtil.append(objectXs, (short)info.x);
|
||||
objectYs = ArrayUtil.append(objectYs, (short)info.y);
|
||||
for (int x = r.x; x < r.x + r.width; x++) {
|
||||
for (int y = r.y; y < r.y + r.height; y++) {
|
||||
int index = _rando.nextInt(setSize);
|
||||
setBaseTile(TileUtil.getFQTileId(setId, index), x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an object from this model.
|
||||
* Populates the supplied object set with info on all objects whose
|
||||
* origin falls in the requested region.
|
||||
*/
|
||||
public void removeObject (ObjectInfo info)
|
||||
{
|
||||
// look for it in the interesting info array
|
||||
int oidx = ListUtil.indexOfEqual(objectInfo, info);
|
||||
if (oidx != -1) {
|
||||
objectInfo = (ObjectInfo[])ArrayUtil.splice(objectInfo, oidx, 1);
|
||||
}
|
||||
public abstract void getObjects (Rectangle region, ObjectSet set);
|
||||
|
||||
// look for it in the uninteresting arrays
|
||||
oidx = IntListUtil.indexOf(objectTileIds, info.tileId);
|
||||
if (oidx != -1) {
|
||||
objectTileIds = ArrayUtil.splice(objectTileIds, oidx, 1);
|
||||
objectXs = ArrayUtil.splice(objectXs, oidx, 1);
|
||||
objectYs = ArrayUtil.splice(objectYs, oidx, 1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds an object to this scene.
|
||||
*/
|
||||
public abstract void addObject (ObjectInfo info);
|
||||
|
||||
/**
|
||||
* Updates an object in this scene.
|
||||
*/
|
||||
public abstract void updateObject (ObjectInfo info);
|
||||
|
||||
/**
|
||||
* Removes the specified object from the scene.
|
||||
*
|
||||
* @return true if it was removed, false if the object was not in the
|
||||
* scene.
|
||||
*/
|
||||
public abstract boolean removeObject (ObjectInfo info);
|
||||
|
||||
/**
|
||||
* Creates a copy of this scene model.
|
||||
@@ -108,39 +118,12 @@ public class MisoSceneModel extends SimpleStreamableObject
|
||||
public Object clone ()
|
||||
{
|
||||
try {
|
||||
MisoSceneModel model = (MisoSceneModel)super.clone();
|
||||
model.objectTileIds = (int[])objectTileIds.clone();
|
||||
model.objectXs = (short[])objectXs.clone();
|
||||
model.objectYs = (short[])objectYs.clone();
|
||||
model.objectInfo = (ObjectInfo[])objectInfo.clone();
|
||||
return model;
|
||||
return (MisoSceneModel)super.clone();
|
||||
} catch (CloneNotSupportedException cnse) {
|
||||
throw new RuntimeException("MisoSceneModel.clone: " + cnse);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the interesting and uninteresting parts of a miso scene
|
||||
* model given lists of {@link ObjectInfo} records for each.
|
||||
*/
|
||||
public static void populateObjects (MisoSceneModel model,
|
||||
ArrayList ilist, ArrayList ulist)
|
||||
{
|
||||
// set up the uninteresting arrays
|
||||
int ucount = ulist.size();
|
||||
model.objectTileIds = new int[ucount];
|
||||
model.objectXs = new short[ucount];
|
||||
model.objectYs = new short[ucount];
|
||||
for (int ii = 0; ii < ucount; ii++) {
|
||||
ObjectInfo info = (ObjectInfo)ulist.get(ii);
|
||||
model.objectTileIds[ii] = info.tileId;
|
||||
model.objectXs[ii] = (short)info.x;
|
||||
model.objectYs[ii] = (short)info.y;
|
||||
}
|
||||
|
||||
// set up the interesting array
|
||||
int icount = ilist.size();
|
||||
model.objectInfo = new ObjectInfo[icount];
|
||||
ilist.toArray(model.objectInfo);
|
||||
}
|
||||
/** A random number generator for filling random base tiles. */
|
||||
protected transient Random _rando = new Random();
|
||||
}
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
//
|
||||
// $Id: SimpleMisoSceneImpl.java,v 1.2 2003/02/24 18:40:41 mdb Exp $
|
||||
|
||||
package com.threerings.miso.data;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import com.threerings.media.tile.TileUtil;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.client.util.ObjectSet;
|
||||
|
||||
/**
|
||||
* A simple implementation of the {@link MisoScene} interface that assumes
|
||||
* a scene will be relatively small and all tile and object data can be
|
||||
* held in memory all at once.
|
||||
*/
|
||||
public class SimpleMisoSceneImpl
|
||||
implements MisoScene
|
||||
{
|
||||
/**
|
||||
* Creates an initializes an instance using the supplied source model.
|
||||
*/
|
||||
public SimpleMisoSceneImpl (SimpleMisoSceneModel model)
|
||||
{
|
||||
_model = model;
|
||||
|
||||
// create display object infos for our uninteresting objects
|
||||
int ocount = (_model.objectTileIds == null) ? 0 :
|
||||
_model.objectTileIds.length;
|
||||
for (int ii = 0; ii < ocount; ii++) {
|
||||
_objects.add(createObjectInfo(_model.objectTileIds[ii],
|
||||
_model.objectXs[ii],
|
||||
_model.objectYs[ii]));
|
||||
}
|
||||
|
||||
// create display object infos for our interesting objects
|
||||
for (int ii = 0, ll = _model.objectInfo.length; ii < ll; ii++) {
|
||||
// replace the object info in our model with the possibly
|
||||
// expanded derived class
|
||||
_model.objectInfo[ii] = createObjectInfo(_model.objectInfo[ii]);
|
||||
_objects.add(_model.objectInfo[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public int getBaseTileId (int x, int y)
|
||||
{
|
||||
return _model.getBaseTile(x, y);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void getObjects (Rectangle region, ObjectSet set)
|
||||
{
|
||||
for (int ii = 0, ll = _objects.size(); ii < ll; ii++) {
|
||||
ObjectInfo info = (ObjectInfo)_objects.get(ii);
|
||||
if (region.contains(info.x, info.y)) {
|
||||
set.insert(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void setBaseTile (int fqTileId, int x, int y)
|
||||
{
|
||||
_model.setBaseTile(x, y, fqTileId);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void setBaseTiles (Rectangle r, int setId, int setSize)
|
||||
{
|
||||
for (int x = r.x; x < r.x + r.width; x++) {
|
||||
for (int y = r.y; y < r.y + r.height; y++) {
|
||||
int index = _rando.nextInt(setSize);
|
||||
setBaseTile(TileUtil.getFQTileId(setId, index), x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public ObjectInfo addObject (int fqTileId, int x, int y)
|
||||
{
|
||||
ObjectInfo info = createObjectInfo(fqTileId, x, y);
|
||||
_objects.add(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public boolean removeObject (ObjectInfo info)
|
||||
{
|
||||
return _objects.remove(info);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public MisoSceneModel getSceneModel ()
|
||||
{
|
||||
// flush our objects list back to the arrays so that we pick up
|
||||
// any changes made since we created the list from the model
|
||||
int plain = 0, ocount = _objects.size();
|
||||
for (int ii = 0; ii < ocount; ii++) {
|
||||
ObjectInfo info = (ObjectInfo)_objects.get(ii);
|
||||
if (!info.isInteresting()) {
|
||||
plain++;
|
||||
}
|
||||
}
|
||||
|
||||
// create new arrays of the appropriate size
|
||||
_model.objectInfo = new ObjectInfo[ocount-plain];
|
||||
_model.objectTileIds = new int[plain];
|
||||
_model.objectXs = new short[plain];
|
||||
_model.objectYs = new short[plain];
|
||||
|
||||
// populate those arrays appropriately
|
||||
for (int cc = 0, pp = 0, ii = 0; cc < ocount; cc++) {
|
||||
ObjectInfo info = (ObjectInfo)_objects.get(cc);
|
||||
if (info.isInteresting()) {
|
||||
_model.objectInfo[ii++] = info;
|
||||
} else {
|
||||
_model.objectTileIds[pp] = info.tileId;
|
||||
_model.objectXs[pp] = (short)info.x;
|
||||
_model.objectYs[pp++] = (short)info.y;
|
||||
}
|
||||
}
|
||||
|
||||
return _model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this Miso scene object.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer("[");
|
||||
toString(buf);
|
||||
return buf.append("]").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* An extensible {@link #toString()} helper.
|
||||
*/
|
||||
protected void toString (StringBuffer buf)
|
||||
{
|
||||
buf.append("width=").append(_model.width);
|
||||
buf.append(", height=").append(_model.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link ObjectInfo} record from the supplied tile
|
||||
* information.
|
||||
*/
|
||||
protected ObjectInfo createObjectInfo (int tileId, int x, int y)
|
||||
{
|
||||
return new ObjectInfo(tileId, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link ObjectInfo} record from the supplied source
|
||||
* record.
|
||||
*/
|
||||
protected ObjectInfo createObjectInfo (ObjectInfo source)
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
/** The miso scene model from which we obtain our data. */
|
||||
protected SimpleMisoSceneModel _model;
|
||||
|
||||
/** The scene object records. */
|
||||
protected ArrayList _objects = new ArrayList();
|
||||
|
||||
/** A random number generator for filling random base tiles. */
|
||||
protected Random _rando = new Random();
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
//
|
||||
// $Id: SimpleMisoSceneModel.java,v 1.2 2003/04/12 02:14:10 mdb Exp $
|
||||
// $Id: SimpleMisoSceneModel.java,v 1.3 2003/04/17 19:21:16 mdb Exp $
|
||||
|
||||
package com.threerings.miso.data;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.ArrayUtil;
|
||||
import com.samskivert.util.IntListUtil;
|
||||
import com.samskivert.util.ListUtil;
|
||||
|
||||
import com.threerings.miso.util.ObjectSet;
|
||||
|
||||
/**
|
||||
* Contains miso scene data for a scene that is assumed to be reasonably
|
||||
* simple and small, such that all base tile data for the entire scene can
|
||||
@@ -33,6 +36,22 @@ public class SimpleMisoSceneModel extends MisoSceneModel
|
||||
* methods. */
|
||||
public int[] baseTileIds;
|
||||
|
||||
/** The combined tile ids (tile set id and tile id) of the
|
||||
* "uninteresting" tiles in the object layer. */
|
||||
public int[] objectTileIds;
|
||||
|
||||
/** The x coordinate of the "uninteresting" tiles in the object
|
||||
* layer. */
|
||||
public short[] objectXs;
|
||||
|
||||
/** The y coordinate of the "uninteresting" tiles in the object
|
||||
* layer. */
|
||||
public short[] objectYs;
|
||||
|
||||
/** Information records for the "interesting" objects in the object
|
||||
* layer. */
|
||||
public ObjectInfo[] objectInfo;
|
||||
|
||||
/**
|
||||
* Creates a completely uninitialized model suitable for little more
|
||||
* than unserialization.
|
||||
@@ -50,24 +69,22 @@ public class SimpleMisoSceneModel extends MisoSceneModel
|
||||
this.vwidth = vwidth;
|
||||
this.vheight = vheight;
|
||||
allocateBaseTileArray();
|
||||
|
||||
// start with zero-length object arrays
|
||||
objectTileIds = new int[0];
|
||||
objectXs = new short[0];
|
||||
objectYs = new short[0];
|
||||
objectInfo = new ObjectInfo[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully-qualified tile id of the base tile at the specified
|
||||
* row and column.
|
||||
*/
|
||||
public int getBaseTile (int col, int row)
|
||||
// documentation inherited
|
||||
public int getBaseTileId (int col, int row)
|
||||
{
|
||||
int index = getIndex(col, row);
|
||||
return (index == -1) ? 0 : baseTileIds[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fully-qualified tile id of a base tile.
|
||||
*
|
||||
* @return false if the specified tile coordinates are outside
|
||||
* of the viewport and the tile was not saved.
|
||||
*/
|
||||
// documentation inherited
|
||||
public boolean setBaseTile (int col, int row, int fqBaseTileId)
|
||||
{
|
||||
int index = getIndex(col, row);
|
||||
@@ -78,6 +95,80 @@ public class SimpleMisoSceneModel extends MisoSceneModel
|
||||
return true;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void getObjects (Rectangle region, ObjectSet set)
|
||||
{
|
||||
// first look for intersecting interesting objects
|
||||
for (int ii = 0; ii < objectInfo.length; ii++) {
|
||||
ObjectInfo info = objectInfo[ii];
|
||||
if (region.contains(info.x, info.y)) {
|
||||
set.insert(info);
|
||||
}
|
||||
}
|
||||
|
||||
// now look for intersecting non-interesting objects
|
||||
for (int ii = 0; ii < objectTileIds.length; ii++) {
|
||||
int x = objectXs[ii], y = objectYs[ii];
|
||||
if (region.contains(x, y)) {
|
||||
set.insert(new ObjectInfo(objectTileIds[ii], x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void addObject (ObjectInfo info)
|
||||
{
|
||||
if (info.isInteresting()) {
|
||||
objectInfo = (ObjectInfo[])ArrayUtil.append(objectInfo, info);
|
||||
} else {
|
||||
objectTileIds = ArrayUtil.append(objectTileIds, info.tileId);
|
||||
objectXs = ArrayUtil.append(objectXs, (short)info.x);
|
||||
objectYs = ArrayUtil.append(objectYs, (short)info.y);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void updateObject (ObjectInfo info)
|
||||
{
|
||||
// not efficient, but this is only done in editing situations
|
||||
removeObject(info);
|
||||
addObject(info);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public boolean removeObject (ObjectInfo info)
|
||||
{
|
||||
// look for it in the interesting info array
|
||||
int oidx = ListUtil.indexOfEqual(objectInfo, info);
|
||||
if (oidx != -1) {
|
||||
objectInfo = (ObjectInfo[])ArrayUtil.splice(objectInfo, oidx, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
// look for it in the uninteresting arrays
|
||||
oidx = IntListUtil.indexOf(objectTileIds, info.tileId);
|
||||
if (oidx != -1) {
|
||||
objectTileIds = ArrayUtil.splice(objectTileIds, oidx, 1);
|
||||
objectXs = ArrayUtil.splice(objectXs, oidx, 1);
|
||||
objectYs = ArrayUtil.splice(objectYs, oidx, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Object clone ()
|
||||
{
|
||||
SimpleMisoSceneModel model = (SimpleMisoSceneModel)super.clone();
|
||||
model.baseTileIds = (int[])baseTileIds.clone();
|
||||
model.objectTileIds = (int[])objectTileIds.clone();
|
||||
model.objectXs = (short[])objectXs.clone();
|
||||
model.objectYs = (short[])objectYs.clone();
|
||||
model.objectInfo = (ObjectInfo[])objectInfo.clone();
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index into the baseTileIds[] for the specified
|
||||
* x and y coordinates, or return -1 if the specified coordinates
|
||||
@@ -135,11 +226,28 @@ public class SimpleMisoSceneModel extends MisoSceneModel
|
||||
baseTileIds = new int[vwidth + vheight + ((vwidth * vheight) << 1)];
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Object clone ()
|
||||
/**
|
||||
* Populates the interesting and uninteresting parts of a miso scene
|
||||
* model given lists of {@link ObjectInfo} records for each.
|
||||
*/
|
||||
public static void populateObjects (SimpleMisoSceneModel model,
|
||||
ArrayList ilist, ArrayList ulist)
|
||||
{
|
||||
SimpleMisoSceneModel model = (SimpleMisoSceneModel)super.clone();
|
||||
model.baseTileIds = (int[])baseTileIds.clone();
|
||||
return model;
|
||||
// set up the uninteresting arrays
|
||||
int ucount = ulist.size();
|
||||
model.objectTileIds = new int[ucount];
|
||||
model.objectXs = new short[ucount];
|
||||
model.objectYs = new short[ucount];
|
||||
for (int ii = 0; ii < ucount; ii++) {
|
||||
ObjectInfo info = (ObjectInfo)ulist.get(ii);
|
||||
model.objectTileIds[ii] = info.tileId;
|
||||
model.objectXs[ii] = (short)info.x;
|
||||
model.objectYs[ii] = (short)info.y;
|
||||
}
|
||||
|
||||
// set up the interesting array
|
||||
int icount = ilist.size();
|
||||
model.objectInfo = new ObjectInfo[icount];
|
||||
ilist.toArray(model.objectInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// $Id: VirtualMisoSceneModel.java,v 1.1 2003/04/17 19:21:16 mdb Exp $
|
||||
|
||||
package com.threerings.miso.data;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
* A convenient base class for "virtual" scenes which do not allow editing
|
||||
* and compute the base and object tiles rather than obtain them from some
|
||||
* data structure.
|
||||
*/
|
||||
public abstract class VirtualMisoSceneModel extends MisoSceneModel
|
||||
{
|
||||
public VirtualMisoSceneModel ()
|
||||
{
|
||||
}
|
||||
|
||||
public VirtualMisoSceneModel (int width, int height)
|
||||
{
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public boolean setBaseTile (int fqTileId, int x, int y)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void setBaseTiles (Rectangle r, int setId, int setSize)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void addObject (ObjectInfo info)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void updateObject (ObjectInfo info)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public boolean removeObject (ObjectInfo info)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user