From fca91d350b6a267d7c0dfc4cc50aa1158677f3b4 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 9 Feb 2002 11:23:49 +0000 Subject: [PATCH] Added facilities for being notified when the parlor director receives a game ready notification and for taking charge of the process of entering the game room. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@980 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../parlor/client/GameReadyObserver.java | 25 ++++++++++++ .../parlor/client/ParlorDirector.java | 38 +++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 src/java/com/threerings/parlor/client/GameReadyObserver.java diff --git a/src/java/com/threerings/parlor/client/GameReadyObserver.java b/src/java/com/threerings/parlor/client/GameReadyObserver.java new file mode 100644 index 000000000..83d3a466f --- /dev/null +++ b/src/java/com/threerings/parlor/client/GameReadyObserver.java @@ -0,0 +1,25 @@ +// +// $Id: GameReadyObserver.java,v 1.1 2002/02/09 11:23:49 mdb Exp $ + +package com.threerings.parlor.client; + +/** + * Used to inform interested parties when the {@link ParlorDirector} + * receives a game ready notification. The observers can ratify the + * decision to head directly into the game or can take responsibility + * themselves for doing so. + */ +public interface GameReadyObserver +{ + /** + * Called when a game ready notification is received. + * + * @param gameOid the place oid of the ready game. + * + * @return if the observer returns true from this method, the parlor + * director assumes they will take care of entering the game room + * after performing processing of their own. If all observers return + * false, the director will enter the game room automatically. + */ + public boolean receivedGameReady (int gameOid); +} diff --git a/src/java/com/threerings/parlor/client/ParlorDirector.java b/src/java/com/threerings/parlor/client/ParlorDirector.java index 5777275ed..5db5560d3 100644 --- a/src/java/com/threerings/parlor/client/ParlorDirector.java +++ b/src/java/com/threerings/parlor/client/ParlorDirector.java @@ -1,5 +1,5 @@ // -// $Id: ParlorDirector.java,v 1.13 2001/10/23 02:22:16 mdb Exp $ +// $Id: ParlorDirector.java,v 1.14 2002/02/09 11:23:49 mdb Exp $ package com.threerings.parlor.client; @@ -54,6 +54,24 @@ public class ParlorDirector _handler = handler; } + /** + * Adds the specified observer to the list of entities that are + * notified when we receive a game ready notification. + */ + public void addGameReadyObserver (GameReadyObserver observer) + { + _grobs.add(observer); + } + + /** + * Removes the specified observer from the list of entities that are + * notified when we receive a game ready notification. + */ + public void removeGameReadyObserver (GameReadyObserver observer) + { + _grobs.remove(observer); + } + /** * Requests that the named user be invited to a game described by the * supplied game config. @@ -196,8 +214,18 @@ public class ParlorDirector { Log.info("Handling game ready [goid=" + gameOid + "]."); - // go there - _ctx.getLocationDirector().moveTo(gameOid); + // see what our observers have to say about it + boolean handled = false; + for (int i = 0; i < _grobs.size(); i++) { + GameReadyObserver grob = (GameReadyObserver)_grobs.get(i); + handled = grob.receivedGameReady(gameOid) || handled; + } + + // if none of the observers took matters into their own hands, + // then we'll head on over to the game room ourselves + if (!handled) { + _ctx.getLocationDirector().moveTo(gameOid); + } } /** @@ -476,4 +504,8 @@ public class ParlorDirector /** A counter used to assign a unique id to every invitation. */ protected static int _localInvitationId = 0; + + /** We notify the entities on this list when we get a game ready + * notification. */ + protected ArrayList _grobs = new ArrayList(); }