Allow portals to have a targetPortalId of -1, which means simply

"whatever the default entrance is of the target scene".


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@12 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Ray Greenwell
2006-07-07 00:36:02 +00:00
parent 2933846516
commit c9a8c1d117
3 changed files with 15 additions and 4 deletions
@@ -47,7 +47,8 @@ public class Portal extends SimpleStreamableObject
public int targetSceneId; public int targetSceneId;
/** The portal identifier of the portal at which a body will enter /** The portal identifier of the portal at which a body will enter
* the target scene when they "use" this portal. */ * the target scene when they "use" this portal, or -1 to specify
* that the body enters on the default portal, whatever id it is. */
public short targetPortalId; public short targetPortalId;
/** /**
@@ -78,7 +79,9 @@ public class Portal extends SimpleStreamableObject
*/ */
public boolean isValid () public boolean isValid ()
{ {
return (targetSceneId > 0) && (targetPortalId > 0); return (targetSceneId > 0) &&
// the target portal must be positive, or -1
((targetPortalId > 0) || (targetPortalId == -1));
} }
/** /**
@@ -63,6 +63,9 @@ public class SpotSceneImpl
// documentation inherited from interface // documentation inherited from interface
public Portal getPortal (int portalId) public Portal getPortal (int portalId)
{ {
if (portalId == -1) {
portalId = _smodel.defaultEntranceId;
}
return (Portal)_portals.get(portalId); return (Portal)_portals.get(portalId);
} }
@@ -93,7 +96,7 @@ public class SpotSceneImpl
// documentation inherited from interface // documentation inherited from interface
public Portal getDefaultEntrance () public Portal getDefaultEntrance ()
{ {
return getPortal(_smodel.defaultEntranceId); return getPortal(-1); // -1 is a shortcut meaning "default"
} }
// documentation inherited from interface // documentation inherited from interface
@@ -91,7 +91,12 @@ public class SpotSceneManager extends SceneManager
*/ */
public void mapEnteringBody (BodyObject body, int portalId) public void mapEnteringBody (BodyObject body, int portalId)
{ {
_enterers.put(body.getOid(), portalId); // small optimization: don't save portalId -1, because it simply means
// "use the default entrance" and retrieving an unset value will
// return -1 anyway
if (portalId != -1) {
_enterers.put(body.getOid(), portalId);
}
} }
/** /**