Added support for associating an action with any of the object tiles in

the scene. This will eventually be interpreted by the scene rendering code
to allow objects to be clickable.

Also rewrote scene serialization code using new Java buffer services which
are much more efficient at reading and writing arrays of integers.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@894 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-01-30 18:28:32 +00:00
parent 617d0e8cb0
commit a07282b2d2
7 changed files with 147 additions and 27 deletions
@@ -1,5 +1,5 @@
//
// $Id: EditableMisoScene.java,v 1.9 2001/12/05 07:29:06 mdb Exp $
// $Id: EditableMisoScene.java,v 1.10 2002/01/30 18:28:32 mdb Exp $
package com.threerings.miso.tools.scene;
@@ -77,6 +77,14 @@ public interface EditableMisoScene
*/
public void setObjectTile (int x, int y, ObjectTile tile, int fqTileId);
/**
* Sets the action string for the object tile at the specified
* coordinates. It may be assumed by the implementation that an object
* tile exists in the scene at the specified coordinates, thus callers
* should be sure only to call this method accordingly.
*/
public void setObjectAction (int x, int y, String action);
/**
* Clears out the tile at the specified location in the base layer.
*/
@@ -92,6 +100,14 @@ public interface EditableMisoScene
*/
public void clearObjectTile (int x, int y);
/**
* Clears the action string for the object tile at the specified
* coordinates. It may be assumed by the implementation that an object
* tile exists in the scene at the specified coordinates, thus callers
* should be sure only to call this method accordingly.
*/
public void clearObjectAction (int x, int y);
/**
* Returns a reference to the miso scene model that reflects the
* changes that have been made to this editable miso scene.
@@ -1,5 +1,5 @@
//
// $Id: EditableMisoSceneImpl.java,v 1.6 2001/12/05 07:29:06 mdb Exp $
// $Id: EditableMisoSceneImpl.java,v 1.7 2002/01/30 18:28:32 mdb Exp $
package com.threerings.miso.tools.scene;
@@ -109,6 +109,12 @@ public class EditableMisoSceneImpl
// the default tiles
}
// documentation inherited from interface
public void setObjectAction (int x, int y, String action)
{
_actions.put(objectKey(x, y), action);
}
// documentation inherited
public void clearBaseTile (int x, int y)
{
@@ -137,6 +143,14 @@ public class EditableMisoSceneImpl
}
// clear it out in our non-sparse array
_objectTileIds[_model.width*y + x] = 0;
// clear out any action for this tile as well
_actions.remove(objectKey(x, y));
}
// documentation inherited from interface
public void clearObjectAction (int x, int y)
{
_actions.remove(objectKey(x, y));
}
// documentation inherited
@@ -155,9 +169,10 @@ public class EditableMisoSceneImpl
}
}
// now create and populate the new tileid array
// now create and populate the new tileid and actions arrays
int[] otids = new int[otileCount*3];
int otidx = 0;
String[] actions = new String[otileCount];
int otidx = 0, actidx = 0;
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
int tsid = _objectTileIds[_model.width*r + c];
@@ -167,11 +182,13 @@ public class EditableMisoSceneImpl
otids[otidx++] = c;
otids[otidx++] = r;
otids[otidx++] = tsid;
actions[actidx++] = (String)_actions.get(objectKey(c, r));
}
}
// stuff the new array into the model
// stuff the new arrays into the model
_model.objectTileIds = otids;
_model.objectActions = actions;
// and we're ready to roll
return _model;
@@ -1,5 +1,5 @@
//
// $Id: MisoSceneRuleSet.java,v 1.4 2001/11/29 19:31:12 mdb Exp $
// $Id: MisoSceneRuleSet.java,v 1.5 2002/01/30 18:28:32 mdb Exp $
package com.threerings.miso.tools.scene.xml;
@@ -56,6 +56,8 @@ public class MisoSceneRuleSet extends RuleSetBase
new SetFieldRule(digester, "fringeTileIds"));
digester.addRule(_prefix + "/object",
new SetFieldRule(digester, "objectTileIds"));
digester.addRule(_prefix + "/actions",
new SetFieldRule(digester, "objectActions"));
}
/** The prefix at which me match our scenes. */
@@ -1,5 +1,5 @@
//
// $Id: MisoSceneWriter.java,v 1.3 2001/11/29 06:36:28 mdb Exp $
// $Id: MisoSceneWriter.java,v 1.4 2002/01/30 18:28:32 mdb Exp $
package com.threerings.miso.tools.scene.xml;
@@ -44,5 +44,7 @@ public class MisoSceneWriter
StringUtil.toString(model.fringeTileIds, "", ""));
writer.dataElement("object",
StringUtil.toString(model.objectTileIds, "", ""));
writer.dataElement("actions",
StringUtil.joinEscaped(model.objectActions));
}
}