diff --git a/src/as/com/threerings/ezgame/EZGameControl.as b/src/as/com/threerings/ezgame/EZGameControl.as index 3ab03010..eda63957 100644 --- a/src/as/com/threerings/ezgame/EZGameControl.as +++ b/src/as/com/threerings/ezgame/EZGameControl.as @@ -265,6 +265,29 @@ public class EZGameControl extends BaseControl callEZCode("testAndSetProperty_v1", propName, newValue, testValue, index); } + /** + * Execute the specified function as a batch of commands that will be sent to the server + * together. This is no different from executing the commands outside of a batch, but + * may result in better use of the network and should be used if setting a number of things + * at once. + * + * Example: + * _ctrl.doBatch(function () :void { + * _ctrl.set("board", new Array()); + * _ctrl.set("scores", new Array()); + * _ctrl.set("captures", 0); + * }); + */ + public function doBatch (fn :Function) :void + { + callEZCode("startTransaction"); + try { + fn(); + } finally { + callEZCode("commitTransaction"); + } + } + /** * Get the names of all currently-set properties that begin with the specified prefix. */ diff --git a/src/as/com/threerings/ezgame/client/GameControlBackend.as b/src/as/com/threerings/ezgame/client/GameControlBackend.as index 42ad96a8..a52c399a 100644 --- a/src/as/com/threerings/ezgame/client/GameControlBackend.as +++ b/src/as/com/threerings/ezgame/client/GameControlBackend.as @@ -218,6 +218,9 @@ public class GameControlBackend o["getPlayers_v1"] = getPlayers_v1; o["getPlayerPosition_v1"] = getPlayerPosition_v1; o["getMyPosition_v1"] = getMyPosition_v1; + + o["startTransaction"] = startTransaction_v1; + o["commitTransaction"] = commitTransaction_v1; } /** @@ -590,6 +593,23 @@ public class GameControlBackend _container.setFocus(); } + /** + * Start a dobj transaction on the game object. + */ + public function startTransaction_v1 () :void + { + validateConnected(); + _ezObj.startTransaction(); + } + + /** + * Commit a dobj transaction on the game object. + */ + public function commitTransaction_v1 () :void + { + _ezObj.commitTransaction(); + } + /** * Convenience function to get our name. */