From c0dde2751c8659895c6daea13a4bd5824ee4b8a8 Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Fri, 18 Jan 2008 22:23:58 +0000 Subject: [PATCH] Break out registration of scene resolution listeners into its own function so it's easily accessible to subclasses that are managing scene loading in their own special ways. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@549 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../whirled/server/SceneRegistry.java | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/java/com/threerings/whirled/server/SceneRegistry.java b/src/java/com/threerings/whirled/server/SceneRegistry.java index b01f7290..8eacac88 100644 --- a/src/java/com/threerings/whirled/server/SceneRegistry.java +++ b/src/java/com/threerings/whirled/server/SceneRegistry.java @@ -138,7 +138,7 @@ public class SceneRegistry SceneManager scmgr = getSceneManager(sceneId); return (scmgr == null) ? ("null:" + sceneId) : scmgr.where(); } - + /** * Requests that the specified scene be resolved, which means loaded into the server and * initialized if the scene is not currently active. The supplied callback instance will be @@ -164,18 +164,9 @@ public class SceneRegistry // otherwise we've got to resolve the scene and call them back later; we can manipulate the // penders table with impunity here because we only do so on the dobjmgr thread - ArrayList penders = _penders.get(sceneId); - - // if we're already in the process of resolving this scene, just add these guys to the list - // to be notified when it finally is resolved - if (penders != null) { - penders.add(target); - - } else { - // otherwise we've got to initiate the resolution process, create the penders list - _penders.put(sceneId, penders = new ArrayList()); - penders.add(target); - + + // Add this guy to be notified, and if nobody has yet, start resolving the scene + if (addResolutionListener(sceneId, target)) { // i don't like cluttering up method declarations with final keywords... final int fsceneId = sceneId; @@ -250,6 +241,26 @@ public class SceneRegistry // remove them from their occupied place (clears out scene info as well) CrowdServer.plreg.locprov.leaveOccupiedPlace(source); } + + /** + * Adds a callback for when the scene is resolved. Returns true if this is the first such + * thing (and thusly, the caller should actually fire off scene resolution) or false if we've + * already got a list and have just added this listener to it. + */ + protected boolean addResolutionListener (int sceneId, ResolutionListener rl) + { + ArrayList penders = _penders.get(sceneId); + boolean newList = false; + + if (penders == null) { + _penders.put(sceneId, penders = new ArrayList()); + newList = true; + } + + penders.add(rl); + return newList; + } + /** * Called when the scene resolution has completed successfully.