fix: call callback after update dictionary in host (#1476)

When the callback for SyncDictionary is called in the server
for set or add
it is getting called before the syncdictionary is updated.

In the client this happens after.  

Example:

```cs
   public void OnScoreUpdatedCallback(ScoreSyncDict.Operation op, uint ident, int score) 
   {
       if (op == ScoreSyncDict.Operation.OP_SET) 
              Debug.Log($"The value in the dictionary is {scoreDict[ident]}");
   }
```

In host mode this prints the previous value.   In client mode this prints the current value.  This PR fixes this problem and makes both print the current value
This commit is contained in:
Paul Pacheco 2020-02-02 20:29:31 -06:00 committed by GitHub
parent d07f847e28
commit 1736bb0c42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -229,13 +229,14 @@ public TValue this[TKey i]
{
if (ContainsKey(i))
{
objects[i] = value;
AddOperation(Operation.OP_SET, i, value);
}
else
{
objects[i] = value;
AddOperation(Operation.OP_ADD, i, value);
}
objects[i] = value;
}
}

View File

@ -159,12 +159,31 @@ public void CallbackTest()
Assert.That(op, Is.EqualTo(SyncDictionaryIntString.Operation.OP_ADD));
Assert.That(index, Is.EqualTo(3));
Assert.That(item, Is.EqualTo("yay"));
Assert.That(clientSyncDictionary[index], Is.EqualTo("yay"));
};
serverSyncDictionary.Add(3, "yay");
SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
Assert.That(called, Is.True);
}
[Test]
public void ServerCallbackTest()
{
bool called = false;
serverSyncDictionary.Callback += (op, index, item) =>
{
called = true;
Assert.That(op, Is.EqualTo(SyncDictionaryIntString.Operation.OP_ADD));
Assert.That(index, Is.EqualTo(3));
Assert.That(item, Is.EqualTo("yay"));
Assert.That(serverSyncDictionary[index], Is.EqualTo("yay"));
};
serverSyncDictionary[3] = "yay";
Assert.That(called, Is.True);
}
[Test]
public void CallbackRemoveTest()
{