For EZ property sets, added a setter that performs an "atomic" test-and-set:

it's atomic in the sense that a single server event will test the variable, 
and only set it if the previous value was null (i.e. didn't exist). 
This allows for a level of elementary synchronization between the clients.

The new function on EZGameControl is:
  _gameCtrl.testAndSet (propertyName, newValue[, index])

I hoped to generalize this to test against arbitrary values, but that's 
significantly harder, since properties accept numerous types as values,
and those can have different representations on the client and the server.
So it remains a check against null until we need to generalize it. :)





git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@193 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Robert Zubeck
2007-02-15 21:55:49 +00:00
parent 720a409185
commit bdfcd156ab
17 changed files with 136 additions and 91 deletions
@@ -72,7 +72,7 @@ public class GameControlBackend
{
_ctx = ctx;
_ezObj = ezObj;
_gameData = new GameData(setProperty_v1, _ezObj.getUserProps());
_gameData = new GameData(setProperty_v2, _ezObj.getUserProps());
_ezObj.addListener(this);
_ctx.getClient().getClientObject().addListener(_userListener);
@@ -136,7 +136,7 @@ public class GameControlBackend
o["gameData"] = _gameData;
// functions
o["setProperty_v1"] = setProperty_v1;
o["setProperty_v2"] = setProperty_v2;
o["mergeCollection_v1"] = mergeCollection_v1;
o["setTicker_v1"] = setTicker_v1;
o["sendChat_v1"] = sendChat_v1;
@@ -163,18 +163,18 @@ public class GameControlBackend
o["getPlayers_v1"] = getPlayers_v1;
}
public function setProperty_v1 (
propName :String, value :Object, index :int) :void
public function setProperty_v2 (
propName :String, value :Object, index :int, testAndSet :Boolean) :void
{
validatePropertyChange(propName, value, index);
var encoded :Object = EZObjectMarshaller.encode(value, (index == -1));
_ezObj.ezGameService.setProperty(
_ctx.getClient(), propName, encoded, index,
_ctx.getClient(), propName, encoded, index, testAndSet,
createLoggingConfirmListener("setProperty"));
// set it immediately in the game object
_ezObj.applyPropertySet(propName, value, index);
_ezObj.applyPropertySet(propName, value, index, testAndSet);
}
public function mergeCollection_v1 (