Objects now have explicit render priorities rather than relying on the

order in which they were added to the scene (that information is no longer
available as objects are reordered arbitrarily once loaded).

Also removed old-school scene conversion.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1743 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-09-23 23:07:11 +00:00
parent 92c8748c7c
commit 68af441fbf
7 changed files with 41 additions and 67 deletions
@@ -1,5 +1,5 @@
// //
// $Id: DirtyItemList.java,v 1.13 2002/09/18 02:32:57 mdb Exp $ // $Id: DirtyItemList.java,v 1.14 2002/09/23 23:07:11 mdb Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -525,16 +525,16 @@ public class DirtyItemList
} }
// if the two objects are scene objects and they overlap, we // if the two objects are scene objects and they overlap, we
// compare them solely based on the order in which they were // compare them solely based on their human assigned render
// added to the scene; this allows the scene creator to avoid // priority scene; this allows us to avoid all sorts of sticky
// all sorts of sticky business wherein the render order // business wherein the render order between two overlapping
// between two overlapping objects cannot be determined // objects cannot be determined without a z-buffer
if ((da.obj instanceof SceneObject) && if ((da.obj instanceof SceneObject) &&
(db.obj instanceof SceneObject)) { (db.obj instanceof SceneObject)) {
SceneObject soa = (SceneObject)da.obj; SceneObject soa = (SceneObject)da.obj;
SceneObject sob = (SceneObject)db.obj; SceneObject sob = (SceneObject)db.obj;
if (IsoUtil.objectFootprintsOverlap(soa, sob)) { if (IsoUtil.objectFootprintsOverlap(soa, sob)) {
return (soa.index - sob.index); return (soa.priority - sob.priority);
} }
} }
@@ -1,5 +1,5 @@
// //
// $Id: DisplayMisoSceneImpl.java,v 1.61 2002/09/23 21:54:50 mdb Exp $ // $Id: DisplayMisoSceneImpl.java,v 1.62 2002/09/23 23:07:11 mdb Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -138,17 +138,14 @@ public class DisplayMisoSceneImpl
for (int ii = 0; ii < ocount; ii+= 3) { for (int ii = 0; ii < ocount; ii+= 3) {
int col = _model.objectTileIds[ii]; int col = _model.objectTileIds[ii];
int row = _model.objectTileIds[ii+1]; int row = _model.objectTileIds[ii+1];
String action = _model.objectActions[ii/3];
int fqTid = _model.objectTileIds[ii+2]; int fqTid = _model.objectTileIds[ii+2];
int tsid = (fqTid >> 16) & 0xFFFF; int tsid = (fqTid >> 16) & 0xFFFF, tid = (fqTid & 0xFFFF);
int tid = (fqTid & 0xFFFF);
try { try {
expandObject(col, row, tsid, tid, fqTid, action); expandObject(col, row, tsid, tid, fqTid, ii/3);
} catch (TileException te) { } catch (TileException te) {
Log.warning("Scene contains non-existent object tile " + Log.warning("Scene contains non-existent object tile " +
"[tsid=" + tsid + ", tid=" + tid + "[tsid=" + tsid + ", tid=" + tid +
", col=" + col + ", row=" + row + ", col=" + col + ", row=" + row + "].");
", action=" + action + "].");
} }
} }
} }
@@ -162,14 +159,20 @@ public class DisplayMisoSceneImpl
* tables). * tables).
*/ */
protected SceneObject expandObject ( protected SceneObject expandObject (
int col, int row, int tsid, int tid, int fqTid, String action) int col, int row, int tsid, int tid, int fqTid, int objidx)
throws NoSuchTileException, NoSuchTileSetException throws NoSuchTileException, NoSuchTileSetException
{ {
// create and initialize an object info record for this object // create and initialize an object info record for this object
SceneObject scobj = createSceneObject( SceneObject scobj = createSceneObject(
col, row, (ObjectTile)_tmgr.getTile(tsid, tid)); col, row, (ObjectTile)_tmgr.getTile(tsid, tid));
if (!StringUtil.blank(action)) {
scobj.action = action; // assign the object's remaining attributes
if (!StringUtil.blank(_model.objectActions[objidx])) {
scobj.action = _model.objectActions[objidx];
}
// if we have object priorities, use 'em
if (_model.objectPrios != null) {
scobj.priority = _model.objectPrios[objidx];
} }
// generate a "shadow" for this object tile by toggling the // generate a "shadow" for this object tile by toggling the
@@ -177,9 +180,6 @@ public class DisplayMisoSceneImpl
// sprites from walking on those tiles) // sprites from walking on those tiles)
setObjectTileFootprint(scobj.tile, 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 // add the info record to the list
_objects.add(scobj); _objects.add(scobj);
@@ -209,8 +209,6 @@ public class DisplayMisoSceneImpl
SceneObject scobj = (SceneObject)_objects.get(ii); SceneObject scobj = (SceneObject)_objects.get(ii);
if (region.contains(scobj.x, scobj.y)) { if (region.contains(scobj.x, scobj.y)) {
set.insert(scobj); set.insert(scobj);
} else {
System.err.println("Skipping " + scobj + ", not in " + region + ".");
} }
} }
} }
@@ -1,5 +1,5 @@
// //
// $Id: DisplayObjectInfo.java,v 1.2 2002/09/23 21:54:50 mdb Exp $ // $Id: DisplayObjectInfo.java,v 1.3 2002/09/23 23:07:11 mdb Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -20,8 +20,8 @@ public class SceneObject
/** The x and y tile coordinates of the object. */ /** The x and y tile coordinates of the object. */
public int x = -1, y = -1; public int x = -1, y = -1;
/** The object's index in the scene object list. */ /** The object's render priority. */
public int index = -1; public byte priority = 0;
/** The action associated with this object or null if it has no /** The action associated with this object or null if it has no
* action. */ * action. */
@@ -1,5 +1,5 @@
// //
// $Id: MisoSceneModel.java,v 1.9 2002/07/23 05:54:52 mdb Exp $ // $Id: MisoSceneModel.java,v 1.10 2002/09/23 23:07:11 mdb Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -44,6 +44,10 @@ public class MisoSceneModel extends SimpleStreamableObject
* empty string during serialization. */ * empty string during serialization. */
public String[] objectActions; public String[] objectActions;
/** Render priorities for each object tile in the scene, which are
* used to resolve overlapped object render order conflicts. */
public byte[] objectPrios;
/** /**
* Get the fully-qualified tile id of the base tile at the specified * Get the fully-qualified tile id of the base tile at the specified
* row and column. * row and column.
@@ -119,34 +123,6 @@ public class MisoSceneModel extends SimpleStreamableObject
} }
} }
/**
* Convert an old school model to the new-style, baby.
* TODO: Remove this method someday after we've converted all
* our old scenes.
*/
public void convertOldSchool (int vwidth, int vheight)
{
// sanity check
if (baseTileIds.length != (width * height)) {
Log.warning("This isn't an old-school scene model!");
return;
}
this.vwidth = vwidth;
this.vheight = vheight;
// make a copy of the oldschool base tile ids
int[] oldschool = baseTileIds;
allocateBaseTileArray();
int idx = 0;
for (int yy=0; yy < height; yy++) {
for (int xx=0; xx < width; xx++) {
setBaseTile(xx, yy, oldschool[idx++]);
}
}
}
/** /**
* Allocate the base tile array. * Allocate the base tile array.
*/ */
@@ -165,6 +141,7 @@ public class MisoSceneModel extends SimpleStreamableObject
model.baseTileIds = (int[])baseTileIds.clone(); model.baseTileIds = (int[])baseTileIds.clone();
model.objectTileIds = (int[])objectTileIds.clone(); model.objectTileIds = (int[])objectTileIds.clone();
model.objectActions = (String[])objectActions.clone(); model.objectActions = (String[])objectActions.clone();
model.objectPrios = (byte[])objectPrios.clone();
return model; return model;
} }
@@ -204,5 +181,6 @@ public class MisoSceneModel extends SimpleStreamableObject
model.allocateBaseTileArray(); model.allocateBaseTileArray();
model.objectTileIds = new int[0]; model.objectTileIds = new int[0];
model.objectActions = new String[0]; model.objectActions = new String[0];
model.objectPrios = new byte[0];
} }
} }
@@ -1,5 +1,5 @@
// //
// $Id: EditableMisoSceneImpl.java,v 1.23 2002/09/23 21:54:50 mdb Exp $ // $Id: EditableMisoSceneImpl.java,v 1.24 2002/09/23 23:07:11 mdb Exp $
package com.threerings.miso.scene.tools; package com.threerings.miso.scene.tools;
@@ -118,7 +118,6 @@ public class EditableMisoSceneImpl
EditableSceneObject scobj = (EditableSceneObject) EditableSceneObject scobj = (EditableSceneObject)
createSceneObject(x, y, tile); createSceneObject(x, y, tile);
scobj.fqTileId = fqTileId; scobj.fqTileId = fqTileId;
scobj.index = _objects.size();
_objects.add(scobj); _objects.add(scobj);
// toggle the "covered" flag on in all base tiles below this // toggle the "covered" flag on in all base tiles below this
@@ -160,6 +159,7 @@ public class EditableMisoSceneImpl
if (ocount > 0) { if (ocount > 0) {
int[] otids = new int[ocount*3]; int[] otids = new int[ocount*3];
String[] actions = new String[ocount]; String[] actions = new String[ocount];
byte[] prios = new byte[ocount];
for (int ii = 0; ii < ocount; ii++) { for (int ii = 0; ii < ocount; ii++) {
EditableSceneObject scobj = (EditableSceneObject) EditableSceneObject scobj = (EditableSceneObject)
@@ -168,11 +168,13 @@ public class EditableMisoSceneImpl
otids[3*ii+1] = scobj.y; otids[3*ii+1] = scobj.y;
otids[3*ii+2] = scobj.fqTileId; otids[3*ii+2] = scobj.fqTileId;
actions[ii] = scobj.action; actions[ii] = scobj.action;
prios[ii] = scobj.priority;
} }
// stuff the new arrays into the model // stuff the new arrays into the model
_model.objectTileIds = otids; _model.objectTileIds = otids;
_model.objectActions = actions; _model.objectActions = actions;
_model.objectPrios = prios;
} }
// and we're ready to roll // and we're ready to roll
@@ -187,12 +189,12 @@ public class EditableMisoSceneImpl
// documentation inherited // documentation inherited
protected SceneObject expandObject ( protected SceneObject expandObject (
int col, int row, int tsid, int tid, int fqTid, String action) int col, int row, int tsid, int tid, int fqTid, int objidx)
throws NoSuchTileException, NoSuchTileSetException throws NoSuchTileException, NoSuchTileSetException
{ {
// do the actual object creation // do the actual object creation
EditableSceneObject scobj = (EditableSceneObject) EditableSceneObject scobj = (EditableSceneObject)
super.expandObject(col, row, tsid, tid, fqTid, action); super.expandObject(col, row, tsid, tid, fqTid, objidx);
// we need this to track object layer mods // we need this to track object layer mods
scobj.fqTileId = fqTid; scobj.fqTileId = fqTid;
@@ -1,5 +1,5 @@
// //
// $Id: MisoSceneRuleSet.java,v 1.9 2002/05/17 19:06:23 ray Exp $ // $Id: MisoSceneRuleSet.java,v 1.10 2002/09/23 23:07:11 mdb Exp $
package com.threerings.miso.scene.tools.xml; package com.threerings.miso.scene.tools.xml;
@@ -62,6 +62,8 @@ public class MisoSceneRuleSet extends RuleSetBase
new SetFieldRule(digester, "objectTileIds")); new SetFieldRule(digester, "objectTileIds"));
digester.addRule(_prefix + "/actions", digester.addRule(_prefix + "/actions",
new SetFieldRule(digester, "objectActions")); new SetFieldRule(digester, "objectActions"));
digester.addRule(_prefix + "/priorities",
new SetFieldRule(digester, "objectPrios"));
// we have to unfuck the objectActions field in the event that // we have to unfuck the objectActions field in the event that
// there's one object in the objects element which has a blank // there's one object in the objects element which has a blank
@@ -76,14 +78,6 @@ public class MisoSceneRuleSet extends RuleSetBase
model.objectActions.length == 0) { model.objectActions.length == 0) {
model.objectActions = new String[1]; model.objectActions = new String[1];
} }
// check to see if we've read in an old-style model.
// TODO: remove this someday after all our scenes are
// converted.
if (model.vwidth == 0) {
model.convertOldSchool(10, 12);
Log.info("Converted old-school MisoSceneModel.");
}
} }
}); });
} }
@@ -1,5 +1,5 @@
// //
// $Id: MisoSceneWriter.java,v 1.7 2002/05/17 19:06:23 ray Exp $ // $Id: MisoSceneWriter.java,v 1.8 2002/09/23 23:07:11 mdb Exp $
package com.threerings.miso.scene.tools.xml; package com.threerings.miso.scene.tools.xml;
@@ -46,5 +46,7 @@ public class MisoSceneWriter
StringUtil.toString(model.objectTileIds, "", "")); StringUtil.toString(model.objectTileIds, "", ""));
writer.dataElement("actions", writer.dataElement("actions",
StringUtil.joinEscaped(model.objectActions)); StringUtil.joinEscaped(model.objectActions));
writer.dataElement("priorities",
StringUtil.toString(model.objectPrios, "", ""));
} }
} }