Disected and reassembled things so that a miso scene can be constructed

without a tile manager, which can be provided later, at which point all of
the tiles will be resolved. Also made it possible to replace the model in
a partially constructed scene. How's that for a turn of phrase: partially
constructed scene. Wheee!


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@743 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-12-05 07:29:06 +00:00
parent a8e66a4191
commit f1b92df3d1
3 changed files with 121 additions and 30 deletions
@@ -1,5 +1,5 @@
// //
// $Id: DisplayMisoSceneImpl.java,v 1.47 2001/11/29 23:08:27 mdb Exp $ // $Id: DisplayMisoSceneImpl.java,v 1.48 2001/12/05 07:29:06 mdb Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -36,19 +36,76 @@ public class DisplayMisoSceneImpl
public DisplayMisoSceneImpl (MisoSceneModel model, TileManager tmgr) public DisplayMisoSceneImpl (MisoSceneModel model, TileManager tmgr)
throws NoSuchTileException, NoSuchTileSetException throws NoSuchTileException, NoSuchTileSetException
{ {
int swid = model.width; this(model);
int shei = model.height; setTileManager(tmgr);
}
/**
* Constructs an instance that will be used to display the supplied
* miso scene data. The tiles identified by the scene model will not
* be loaded until a tile manager is provided via {@link
* #setTileManager}.
*
* @param model the scene data that we'll be displaying.
*
* @exception NoSuchTileException thrown if the model references a
* tile which is not available via the supplied tile manager.
*/
public DisplayMisoSceneImpl (MisoSceneModel model)
{
setMisoSceneModel(model);
}
/**
* Instructs this miso scene to use the supplied model instead of its
* current model. This should be followed up by a called to {@link
* #setTileManager} or {@link #populateLayers} if a tile manager has
* already been provided.
*/
protected void setMisoSceneModel (MisoSceneModel model)
{
_model = model;
int swid = _model.width;
int shei = _model.height;
// create the individual tile layer objects // create the individual tile layer objects
_base = new BaseTileLayer(new BaseTile[swid*shei], swid, shei); _base = new BaseTileLayer(new BaseTile[swid*shei], swid, shei);
_fringe = new TileLayer(new Tile[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(new ObjectTile[swid*shei], swid, shei);
}
/**
* Provides this display miso scene with a tile manager from which it
* can load up all of its tiles.
*
* @exception NoSuchTileException thrown if the model references a
* tile which is not available via the supplied tile manager.
*/
public void setTileManager (TileManager tmgr)
throws NoSuchTileException, NoSuchTileSetException
{
_tmgr = tmgr;
populateLayers();
}
/**
* Populates the tile layers with tiles from the tile manager.
*
* @exception NoSuchTileException thrown if the model references a
* tile which is not available via the supplied tile manager.
*/
protected void populateLayers ()
throws NoSuchTileException, NoSuchTileSetException
{
int swid = _base.getWidth();
int shei = _base.getHeight();
// populate the base and fringe layers // populate the base and fringe layers
for (int column = 0; column < shei; column++) { for (int column = 0; column < shei; column++) {
for (int row = 0; row < swid; row++) { for (int row = 0; row < swid; row++) {
// first do the base layer // first do the base layer
int tsid = model.baseTileIds[swid*row+column]; int tsid = _model.baseTileIds[swid*row+column];
if (tsid > 0) { if (tsid > 0) {
int tid = (tsid & 0xFFFF); int tid = (tsid & 0xFFFF);
tsid >>= 16; tsid >>= 16;
@@ -58,23 +115,23 @@ public class DisplayMisoSceneImpl
// map to a base tile as provided by the repository, // map to a base tile as provided by the repository,
// so we just cast it to a base tile and know that all // so we just cast it to a base tile and know that all
// is well // is well
BaseTile mtile = (BaseTile)tmgr.getTile(tsid, tid); BaseTile mtile = (BaseTile)_tmgr.getTile(tsid, tid);
_base.setTile(column, row, mtile); _base.setTile(column, row, mtile);
} }
// then the fringe layer // then the fringe layer
tsid = model.fringeTileIds[swid*row+column]; tsid = _model.fringeTileIds[swid*row+column];
if (tsid > 0) { if (tsid > 0) {
int tid = (tsid & 0xFFFF); int tid = (tsid & 0xFFFF);
tsid >>= 16; tsid >>= 16;
Tile tile = tmgr.getTile(tsid, tid); Tile tile = _tmgr.getTile(tsid, tid);
_fringe.setTile(column, row, tile); _fringe.setTile(column, row, tile);
} }
} }
} }
// sanity check the object layer info // sanity check the object layer info
int ocount = model.objectTileIds.length; int ocount = _model.objectTileIds.length;
if (ocount % 3 != 0) { if (ocount % 3 != 0) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"model.objectTileIds.length % 3 != 0"); "model.objectTileIds.length % 3 != 0");
@@ -82,15 +139,15 @@ public class DisplayMisoSceneImpl
// now populate the object layer // now populate the object layer
for (int i = 0; i < ocount; i+= 3) { for (int i = 0; i < ocount; i+= 3) {
int col = model.objectTileIds[i]; int col = _model.objectTileIds[i];
int row = model.objectTileIds[i+1]; int row = _model.objectTileIds[i+1];
int tsid = model.objectTileIds[i+2]; int tsid = _model.objectTileIds[i+2];
int tid = (tsid & 0xFFFF); int tid = (tsid & 0xFFFF);
tsid >>= 16; tsid >>= 16;
// create the object tile and stick it into the appropriate // create the object tile and stick it into the appropriate
// spot in the object layer // spot in the object layer
ObjectTile otile = (ObjectTile)tmgr.getTile(tsid, tid); ObjectTile otile = (ObjectTile)_tmgr.getTile(tsid, tid);
_object.setTile(col, row, otile); _object.setTile(col, row, otile);
// we have to generate a shadow for this object tile in the // we have to generate a shadow for this object tile in the
@@ -154,6 +211,12 @@ public class DisplayMisoSceneImpl
// ", sy=" + y + ", ex=" + endx + ", ey=" + endy + "]."); // ", sy=" + y + ", ex=" + endx + ", ey=" + endy + "].");
} }
/** The tile manager from which we load tiles. */
protected TileManager _tmgr;
/** The miso scene model from which we obtain our data. */
protected MisoSceneModel _model;
/** The base layer of tiles. */ /** The base layer of tiles. */
protected BaseTileLayer _base; protected BaseTileLayer _base;
@@ -1,5 +1,5 @@
// //
// $Id: EditableMisoScene.java,v 1.8 2001/11/29 00:18:15 mdb Exp $ // $Id: EditableMisoScene.java,v 1.9 2001/12/05 07:29:06 mdb Exp $
package com.threerings.miso.tools.scene; package com.threerings.miso.tools.scene;
@@ -97,4 +97,10 @@ public interface EditableMisoScene
* changes that have been made to this editable miso scene. * changes that have been made to this editable miso scene.
*/ */
public MisoSceneModel getMisoSceneModel (); public MisoSceneModel getMisoSceneModel ();
/**
* Replaces the model in use by this editable miso scene with the
* specified model.
*/
public void setMisoSceneModel (MisoSceneModel model);
} }
@@ -1,5 +1,5 @@
// //
// $Id: EditableMisoSceneImpl.java,v 1.5 2001/11/29 23:08:28 mdb Exp $ // $Id: EditableMisoSceneImpl.java,v 1.6 2001/12/05 07:29:06 mdb Exp $
package com.threerings.miso.tools.scene; package com.threerings.miso.tools.scene;
@@ -36,21 +36,28 @@ public class EditableMisoSceneImpl
throws NoSuchTileException, NoSuchTileSetException throws NoSuchTileException, NoSuchTileSetException
{ {
super(model, tmgr); super(model, tmgr);
unpackObjectLayer();
}
// we'll need to be keeping this /**
_model = model; * Constructs an instance that will be used to display and edit the
* supplied miso scene data. The tiles identified by the scene model
* will not be loaded until a tile manager is provided via {@link
* #setTileManager}.
*
* @param model the scene data that we'll be displaying.
*/
public EditableMisoSceneImpl (MisoSceneModel model)
{
super(model);
unpackObjectLayer();
}
// we need this to track object layer mods // documentation inherited
_objectTileIds = new int[_model.baseTileIds.length]; public void setMisoSceneModel (MisoSceneModel model)
{
// populate our non-spare array super.setMisoSceneModel(model);
int[] otids = model.objectTileIds; unpackObjectLayer();
for (int i = 0; i < otids.length; i += 3) {
int x = otids[i];
int y = otids[i+1];
int fqTileId = otids[i+2];
_objectTileIds[model.width*y + x] = fqTileId;
}
} }
// documentation inherited // documentation inherited
@@ -170,9 +177,24 @@ public class EditableMisoSceneImpl
return _model; return _model;
} }
/** Our scene model, which we always keep in sync with our display /**
* model data. */ * Unpacks the object layer into an array that we can update along
protected MisoSceneModel _model; * with the other layers.
*/
protected void unpackObjectLayer ()
{
// we need this to track object layer mods
_objectTileIds = new int[_model.baseTileIds.length];
// populate our non-spare array
int[] otids = _model.objectTileIds;
for (int i = 0; i < otids.length; i += 3) {
int x = otids[i];
int y = otids[i+1];
int fqTileId = otids[i+2];
_objectTileIds[_model.width*y + x] = fqTileId;
}
}
/** A non-sparse array where we can keep track of the object tile /** A non-sparse array where we can keep track of the object tile
* ids. */ * ids. */