From 44ad4f517d389089d1ec0c89ce49b66e28a49232 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Mon, 26 Feb 2007 19:20:15 +0000 Subject: [PATCH] Wait until the usercode has connected to the GameControlBackend prior to sending a playerReady notification to the server. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@212 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../ezgame/client/EZGameController.as | 26 +++++++++++++++++++ .../threerings/ezgame/client/EZGamePanel.as | 2 +- .../ezgame/client/GameControlBackend.as | 17 +++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/as/com/threerings/ezgame/client/EZGameController.as b/src/as/com/threerings/ezgame/client/EZGameController.as index 80889491..ae7e51f4 100644 --- a/src/as/com/threerings/ezgame/client/EZGameController.as +++ b/src/as/com/threerings/ezgame/client/EZGameController.as @@ -26,6 +26,7 @@ import flash.events.Event; import com.threerings.util.Name; import com.threerings.crowd.client.PlaceView; +import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.PlaceConfig; import com.threerings.crowd.data.PlaceObject; import com.threerings.crowd.util.CrowdContext; @@ -50,6 +51,15 @@ public class EZGameController extends GameController addDelegate(_turnDelegate = new TurnGameControllerDelegate(this)); } + /** + * This is called by the GameControlBackend once it has initialized + * and made contact with usercode. + */ + public function userCodeIsConnected () :void + { + playerReady(); + } + override public function willEnterPlace (plobj :PlaceObject) :void { _ezObj = (plobj as EZGameObject); @@ -70,6 +80,22 @@ public class EZGameController extends GameController _panel.backend.turnDidChange(); } + override protected function playerReady () :void + { + // we require the user to be connected, and we redundantly only + // do this if the user is in the players array + if (_panel.backend.isConnected()) { + var bobj :BodyObject = + (_ctx.getClient().getClientObject() as BodyObject); + if (_gobj.getPlayerIndex(bobj.getVisibleName()) != -1) { + super.playerReady(); + } + + } else { + log.debug("Waiting to call playerReady, userCode not yet connected."); + } + } + override protected function gameDidStart () :void { super.gameDidStart(); diff --git a/src/as/com/threerings/ezgame/client/EZGamePanel.as b/src/as/com/threerings/ezgame/client/EZGamePanel.as index 0e30201b..f9dda844 100644 --- a/src/as/com/threerings/ezgame/client/EZGamePanel.as +++ b/src/as/com/threerings/ezgame/client/EZGamePanel.as @@ -89,7 +89,7 @@ public class EZGamePanel extends Canvas */ protected function createBackend () :GameControlBackend { - return new GameControlBackend(_ctx, _ezObj); + return new GameControlBackend(_ctx, _ezObj, _ctrl); } protected var _ctx :CrowdContext; diff --git a/src/as/com/threerings/ezgame/client/GameControlBackend.as b/src/as/com/threerings/ezgame/client/GameControlBackend.as index a8f6e382..a3659090 100644 --- a/src/as/com/threerings/ezgame/client/GameControlBackend.as +++ b/src/as/com/threerings/ezgame/client/GameControlBackend.as @@ -89,10 +89,11 @@ public class GameControlBackend public var log :Log = Log.getLog(this); public function GameControlBackend ( - ctx :CrowdContext, ezObj :EZGameObject) + ctx :CrowdContext, ezObj :EZGameObject, ctrl :EZGameController) { _ctx = ctx; _ezObj = ezObj; + _ctrl = ctrl; _gameData = new GameData(setProperty_v1, _ezObj.getUserProps()); _ezObj.addListener(this); @@ -104,6 +105,14 @@ public class GameControlBackend disp.addEventListener("ezgameQuery", handleEZQuery); } + /** + * Are we connected to the usercode on the front-end? + */ + public function isConnected () :Boolean + { + return (_userFuncs != null); + } + public function setContainer (container :GameContainer) :void { _container = container; @@ -120,6 +129,9 @@ public class GameControlBackend setUserCodeProperties(evt.userProps); evt.ezProps = new Object(); populateProperties(evt.ezProps); + + // ok, we're now hooked-up with the game code + _ctrl.userCodeIsConnected(); } protected function setUserCodeProperties (o :Object) :void @@ -813,6 +825,9 @@ public class GameControlBackend protected var _ezObj :EZGameObject; + /** Handles trusted clientside control. */ + protected var _ctrl :EZGameController; + protected var _userFuncs :Object; /** The function on the EZGameControl which we can use to directly