From 1c0260198d36a23934b69d82c8368df6a8c1da61 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 31 Mar 2005 19:40:55 +0000 Subject: [PATCH] The adding of portals to scenes needs to be handled somewhat differently now that all the scene updating stuff has been cleaned up. Basically we can't rely on the updating process itself to assign a portal id, updates must be created with all the information they need before they are applied to the scene. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3451 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/stage/data/StageScene.java | 6 ++++ .../stage/tools/editor/PortalTool.java | 1 + .../whirled/spot/data/SpotScene.java | 13 ++++++-- .../whirled/spot/data/SpotSceneImpl.java | 30 +++++++++++-------- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/java/com/threerings/stage/data/StageScene.java b/src/java/com/threerings/stage/data/StageScene.java index 899144977..c4ff4de5c 100644 --- a/src/java/com/threerings/stage/data/StageScene.java +++ b/src/java/com/threerings/stage/data/StageScene.java @@ -161,6 +161,12 @@ public class StageScene extends SceneImpl return _sdelegate.getPortals(); } + // documentation inherited from interface + public short getNextPortalId () + { + return _sdelegate.getNextPortalId(); + } + // documentation inherited from interface public Portal getDefaultEntrance () { diff --git a/src/java/com/threerings/stage/tools/editor/PortalTool.java b/src/java/com/threerings/stage/tools/editor/PortalTool.java index 0757b6e3b..01a4537f1 100644 --- a/src/java/com/threerings/stage/tools/editor/PortalTool.java +++ b/src/java/com/threerings/stage/tools/editor/PortalTool.java @@ -119,6 +119,7 @@ public class PortalTool extends MouseInputAdapter _portal.name = name; // add the portal to the scene and pop up the editor dialog + _portal.portalId = _scene.getNextPortalId(); _scene.addPortal(_portal); _panel.editPortal(_portal); } diff --git a/src/java/com/threerings/whirled/spot/data/SpotScene.java b/src/java/com/threerings/whirled/spot/data/SpotScene.java index 412fd5e34..54b60dbe1 100644 --- a/src/java/com/threerings/whirled/spot/data/SpotScene.java +++ b/src/java/com/threerings/whirled/spot/data/SpotScene.java @@ -1,5 +1,5 @@ // -// $Id: SpotScene.java,v 1.2 2004/08/27 02:20:46 mdb Exp $ +// $Id$ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -45,6 +45,12 @@ public interface SpotScene */ public Iterator getPortals (); + /** + * Returns the portal id that should be assigned to the next portal + * added to this scene. + */ + public short getNextPortalId (); + /** * Returns the portal that represents the default entrance to this * scene. If a body enters the scene at logon time rather than @@ -55,8 +61,9 @@ public interface SpotScene /** * Adds a portal to this scene, immediately making the requisite - * modifications to the underlying scene model. A portal id will be - * assigned to the portal by this method. + * modifications to the underlying scene model. The portal id should + * have already been assigned using the value obtained from {@link + * #getNextPortalId}. */ public void addPortal (Portal portal); diff --git a/src/java/com/threerings/whirled/spot/data/SpotSceneImpl.java b/src/java/com/threerings/whirled/spot/data/SpotSceneImpl.java index b24787269..e26e77e21 100644 --- a/src/java/com/threerings/whirled/spot/data/SpotSceneImpl.java +++ b/src/java/com/threerings/whirled/spot/data/SpotSceneImpl.java @@ -1,5 +1,5 @@ // -// $Id: SpotSceneImpl.java,v 1.4 2004/08/27 02:20:46 mdb Exp $ +// $Id$ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -78,6 +78,18 @@ public class SpotSceneImpl return _portals.values().iterator(); } + // documentation inherited from interface + public short getNextPortalId () + { + // compute a new portal id for our friend the portal + for (short ii = 1; ii < MAX_PORTAL_ID; ii++) { + if (!_portals.containsKey(ii)) { + return ii; + } + } + return (short)-1; + } + // documentation inherited from interface public Portal getDefaultEntrance () { @@ -87,21 +99,13 @@ public class SpotSceneImpl // documentation inherited from interface public void addPortal (Portal portal) { - // compute a new portal id for our friend the portal - portal.portalId = 0; - for (short ii = 1; ii < MAX_PORTAL_ID; ii++) { - if (!_portals.containsKey(ii)) { - portal.portalId = ii; - break; - } - } - if (portal.portalId == 0) { - Log.warning("Unable to assign id to new portal " + - "[scene=" + this + "]."); + if (portal.portalId <= 0) { + Log.warning("Refusing to add zero-id portal " + + "[scene=" + this + ", portal=" + portal + "]."); return; } - // add this beyotch to our model + // add it to our model _smodel.addPortal(portal); // and slap it into our table