From 68af441fbf318adf8a48450a7ffd35948f03dc1d Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 23 Sep 2002 23:07:11 +0000 Subject: [PATCH] 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 --- .../threerings/miso/client/DirtyItemList.java | 12 +++---- .../miso/client/DisplayMisoSceneImpl.java | 28 +++++++-------- .../miso/client/DisplayObjectInfo.java | 6 ++-- .../threerings/miso/data/MisoSceneModel.java | 36 ++++--------------- .../miso/tools/EditableMisoSceneImpl.java | 10 +++--- .../miso/tools/xml/MisoSceneRuleSet.java | 12 ++----- .../miso/tools/xml/MisoSceneWriter.java | 4 ++- 7 files changed, 41 insertions(+), 67 deletions(-) diff --git a/src/java/com/threerings/miso/client/DirtyItemList.java b/src/java/com/threerings/miso/client/DirtyItemList.java index 0b70eea9d..0bbc3e8e9 100644 --- a/src/java/com/threerings/miso/client/DirtyItemList.java +++ b/src/java/com/threerings/miso/client/DirtyItemList.java @@ -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; @@ -525,16 +525,16 @@ public class DirtyItemList } // if the two objects are scene objects and they overlap, we - // compare them solely based on the order in which they were - // added to the scene; this allows the scene creator to avoid - // all sorts of sticky business wherein the render order - // between two overlapping objects cannot be determined + // compare them solely based on their human assigned render + // priority scene; this allows us to avoid all sorts of sticky + // business wherein the render order between two overlapping + // objects cannot be determined without a z-buffer if ((da.obj instanceof SceneObject) && (db.obj instanceof SceneObject)) { SceneObject soa = (SceneObject)da.obj; SceneObject sob = (SceneObject)db.obj; if (IsoUtil.objectFootprintsOverlap(soa, sob)) { - return (soa.index - sob.index); + return (soa.priority - sob.priority); } } diff --git a/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java b/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java index 543951c37..2d912373d 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.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; @@ -138,17 +138,14 @@ public class DisplayMisoSceneImpl for (int ii = 0; ii < ocount; ii+= 3) { int col = _model.objectTileIds[ii]; int row = _model.objectTileIds[ii+1]; - String action = _model.objectActions[ii/3]; int fqTid = _model.objectTileIds[ii+2]; - int tsid = (fqTid >> 16) & 0xFFFF; - int tid = (fqTid & 0xFFFF); + int tsid = (fqTid >> 16) & 0xFFFF, tid = (fqTid & 0xFFFF); try { - expandObject(col, row, tsid, tid, fqTid, action); + expandObject(col, row, tsid, tid, fqTid, ii/3); } catch (TileException te) { Log.warning("Scene contains non-existent object tile " + "[tsid=" + tsid + ", tid=" + tid + - ", col=" + col + ", row=" + row + - ", action=" + action + "]."); + ", col=" + col + ", row=" + row + "]."); } } } @@ -162,14 +159,20 @@ public class DisplayMisoSceneImpl * tables). */ 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 { // create and initialize an object info record for this object SceneObject scobj = createSceneObject( 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 @@ -177,9 +180,6 @@ public class DisplayMisoSceneImpl // sprites from walking on those tiles) setObjectTileFootprint(scobj.tile, col, row, true); - // assign the object its index - scobj.index = _objects.size(); - // add the info record to the list _objects.add(scobj); @@ -209,8 +209,6 @@ public class DisplayMisoSceneImpl SceneObject scobj = (SceneObject)_objects.get(ii); if (region.contains(scobj.x, scobj.y)) { set.insert(scobj); - } else { - System.err.println("Skipping " + scobj + ", not in " + region + "."); } } } diff --git a/src/java/com/threerings/miso/client/DisplayObjectInfo.java b/src/java/com/threerings/miso/client/DisplayObjectInfo.java index 1f5589311..812852c01 100644 --- a/src/java/com/threerings/miso/client/DisplayObjectInfo.java +++ b/src/java/com/threerings/miso/client/DisplayObjectInfo.java @@ -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; @@ -20,8 +20,8 @@ public class SceneObject /** The x and y tile coordinates of the object. */ public int x = -1, y = -1; - /** The object's index in the scene object list. */ - public int index = -1; + /** The object's render priority. */ + public byte priority = 0; /** The action associated with this object or null if it has no * action. */ diff --git a/src/java/com/threerings/miso/data/MisoSceneModel.java b/src/java/com/threerings/miso/data/MisoSceneModel.java index aefdf6b7a..2cfe0c746 100644 --- a/src/java/com/threerings/miso/data/MisoSceneModel.java +++ b/src/java/com/threerings/miso/data/MisoSceneModel.java @@ -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; @@ -44,6 +44,10 @@ public class MisoSceneModel extends SimpleStreamableObject * empty string during serialization. */ 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 * 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. */ @@ -165,6 +141,7 @@ public class MisoSceneModel extends SimpleStreamableObject model.baseTileIds = (int[])baseTileIds.clone(); model.objectTileIds = (int[])objectTileIds.clone(); model.objectActions = (String[])objectActions.clone(); + model.objectPrios = (byte[])objectPrios.clone(); return model; } @@ -204,5 +181,6 @@ public class MisoSceneModel extends SimpleStreamableObject model.allocateBaseTileArray(); model.objectTileIds = new int[0]; model.objectActions = new String[0]; + model.objectPrios = new byte[0]; } } diff --git a/src/java/com/threerings/miso/tools/EditableMisoSceneImpl.java b/src/java/com/threerings/miso/tools/EditableMisoSceneImpl.java index 725aa70e1..f4b5b063d 100644 --- a/src/java/com/threerings/miso/tools/EditableMisoSceneImpl.java +++ b/src/java/com/threerings/miso/tools/EditableMisoSceneImpl.java @@ -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; @@ -118,7 +118,6 @@ public class EditableMisoSceneImpl EditableSceneObject scobj = (EditableSceneObject) createSceneObject(x, y, tile); scobj.fqTileId = fqTileId; - scobj.index = _objects.size(); _objects.add(scobj); // toggle the "covered" flag on in all base tiles below this @@ -160,6 +159,7 @@ public class EditableMisoSceneImpl if (ocount > 0) { int[] otids = new int[ocount*3]; String[] actions = new String[ocount]; + byte[] prios = new byte[ocount]; for (int ii = 0; ii < ocount; ii++) { EditableSceneObject scobj = (EditableSceneObject) @@ -168,11 +168,13 @@ public class EditableMisoSceneImpl otids[3*ii+1] = scobj.y; otids[3*ii+2] = scobj.fqTileId; actions[ii] = scobj.action; + prios[ii] = scobj.priority; } // stuff the new arrays into the model _model.objectTileIds = otids; _model.objectActions = actions; + _model.objectPrios = prios; } // and we're ready to roll @@ -187,12 +189,12 @@ public class EditableMisoSceneImpl // documentation inherited 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 { // do the actual object creation 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 scobj.fqTileId = fqTid; diff --git a/src/java/com/threerings/miso/tools/xml/MisoSceneRuleSet.java b/src/java/com/threerings/miso/tools/xml/MisoSceneRuleSet.java index df13f023e..947d93f4d 100644 --- a/src/java/com/threerings/miso/tools/xml/MisoSceneRuleSet.java +++ b/src/java/com/threerings/miso/tools/xml/MisoSceneRuleSet.java @@ -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; @@ -62,6 +62,8 @@ public class MisoSceneRuleSet extends RuleSetBase new SetFieldRule(digester, "objectTileIds")); digester.addRule(_prefix + "/actions", new SetFieldRule(digester, "objectActions")); + digester.addRule(_prefix + "/priorities", + new SetFieldRule(digester, "objectPrios")); // we have to unfuck the objectActions field in the event that // 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 = 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."); - } } }); } diff --git a/src/java/com/threerings/miso/tools/xml/MisoSceneWriter.java b/src/java/com/threerings/miso/tools/xml/MisoSceneWriter.java index 9427b45f4..c0395fd8d 100644 --- a/src/java/com/threerings/miso/tools/xml/MisoSceneWriter.java +++ b/src/java/com/threerings/miso/tools/xml/MisoSceneWriter.java @@ -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; @@ -46,5 +46,7 @@ public class MisoSceneWriter StringUtil.toString(model.objectTileIds, "", "")); writer.dataElement("actions", StringUtil.joinEscaped(model.objectActions)); + writer.dataElement("priorities", + StringUtil.toString(model.objectPrios, "", "")); } }