Fixed minor bugs in failed attempts to resolve portal bindings. Check

and report errors when attempting to bind entrance portal.
Sanity-check portals in all scenes in the group after bindings are
resolved and report warnings for any still-unbound portals.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@286 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-08-21 01:15:16 +00:00
parent 4b0f742356
commit 56c48c011f
2 changed files with 78 additions and 20 deletions
@@ -1,12 +1,12 @@
//
// $Id: Portal.java,v 1.2 2001/08/16 22:05:01 shaper Exp $
// $Id: Portal.java,v 1.3 2001/08/21 01:15:16 shaper Exp $
package com.threerings.miso.scene;
/**
* The <code>Portal</code> class represents a <code>Location</code> in
* a scene that both leads to a different scene and serves as a
* potential entrance into its containing scene.
* The portal class represents a {@link Location} in a scene that both
* leads to a different scene and serves as a potential entrance into
* its containing scene.
*/
public class Portal extends Location
{
@@ -20,7 +20,7 @@ public class Portal extends Location
public Portal dest;
/**
* Construct an <code>Portal</code> object.
* Construct a portal object.
*
* @param loc the location associated with the portal.
* @param name the portal name.
@@ -44,6 +44,15 @@ public class Portal extends Location
this.dest = dest;
}
/**
* Return whether this portal has a valid destination scene and
* portal.
*/
public boolean hasDestination ()
{
return (sid != MisoScene.SID_INVALID && dest != null);
}
/**
* Return a String representation of this object.
*/
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneGroupParser.java,v 1.2 2001/08/16 22:05:01 shaper Exp $
// $Id: XMLSceneGroupParser.java,v 1.3 2001/08/21 01:15:16 shaper Exp $
package com.threerings.miso.scene.xml;
@@ -74,6 +74,9 @@ public class XMLSceneGroupParser extends DefaultHandler
// the associated scene objects, resolve bindings between
// all scenes in the group.
_info.resolveBindings();
// warn about any remaining un-bound portals
_info.checkUnboundPortals();
}
// note that we're not within a tag to avoid considering any
@@ -193,7 +196,7 @@ public class XMLSceneGroupParser extends DefaultHandler
}
/**
* Resolve portal bindings and set entrance portal for all scenes.
* Resolve the portal bindings and entrance portal for all scenes.
*/
public void resolveBindings ()
{
@@ -210,9 +213,8 @@ public class XMLSceneGroupParser extends DefaultHandler
// resolve the portal binding
resolvePortal(sinfo, pinfo);
// set the entrance portal
Portal entrance = sinfo.scene.getPortal(sinfo.entrance);
sinfo.scene.setEntrance(entrance);
// resolve the entrance portal
resolveEntrance(sinfo);
}
}
}
@@ -228,31 +230,78 @@ public class XMLSceneGroupParser extends DefaultHandler
// get the source portal object
Portal src = sinfo.scene.getPortal(pinfo.src);
if (src == null) {
Log.warning(
"Missing source portal [scene=" + sinfo.name +
", pinfo=" + pinfo + "].");
Log.warning("Missing source portal [scene=" + sinfo.name +
", pinfo=" + pinfo + "].");
return;
}
// get the destination scene
MisoScene destScene = getScene(pinfo.destScene);
if (destScene == null) {
Log.warning(
"Missing destination scene [scene=" + sinfo.name +
", pinfo=" + pinfo + "].");
Log.warning("Missing destination scene [scene=" + sinfo.name +
", pinfo=" + pinfo + "].");
return;
}
// get the destination portal object
Portal dest = destScene.getPortal(pinfo.dest);
if (dest == null) {
Log.warning(
"Missing destination portal [scene=" + sinfo.name +
", pinfo=" + pinfo + "].");
Log.warning("Missing destination portal [scene=" + sinfo.name +
", pinfo=" + pinfo + "].");
return;
}
// update source portal with full destination information
src.setDestination(destScene.getId(), dest);
}
}
/**
* Resolve the binding for the entrance portal in the given scene.
*
* @param sinfo the scene info.
*/
protected void resolveEntrance (SceneInfo sinfo)
{
Portal entrance = sinfo.scene.getPortal(sinfo.entrance);
if (entrance == null) {
Log.warning( "Missing entrance portal [scene=" + sinfo.name +
", entrance=" + sinfo.entrance + "].");
return;
}
sinfo.scene.setEntrance(entrance);
}
/**
* Scan through all scenes and output a warning message if any
* portals are found that aren't bound to a destination
* portal. Intended for calling after {@link
* #resolveBindings} is called to make sure the scene group
* description wasn't lacking a binding for some portal; or,
* that the scenes don't contain any unintended or unnecessary
* portals.
*/
public void checkUnboundPortals ()
{
int size = sceneinfo.size();
for (int ii = 0; ii < size; ii++) {
// retrieve the next scene info object
SceneInfo sinfo = (SceneInfo)sceneinfo.get(ii);
// get the portals in the scene
List portals = sinfo.scene.getPortals();
// check each portal to make sure it has a valid destination
int psize = portals.size();
for (int jj = 0; jj < size; jj++) {
Portal portal = (Portal)portals.get(jj);
if (!portal.hasDestination()) {
Log.warning("Unbound portal [scene=" + sinfo.name +
", portal=" + portal + "].");
}
}
}
}
}
/**