/// <summary> /// Add snapshot to buffer if snapshot with same timestamp exists in buffer. /// </summary> public void addSnapshot(Snapshot snapshot) { if (!Snapshots.ContainsKey(snapshot.Time)) { Snapshots.Add(snapshot.Time, snapshot); } }
private IEnumerable <string> Compare(DataSnapshot dataSnapshot) { var missing = false; //TODO: do we need to create a buffer for the hash sets? HashSet <string> changedKeys = null; foreach (var(key, value) in Snapshots) { if (dataSnapshot.Snapshots.TryGetValue(key, out var snapShotValue)) { if (snapShotValue < value) { if (changedKeys == null) { changedKeys = new HashSet <string>(); } changedKeys.Add(key); } } else { missing = true; if (changedKeys == null) { changedKeys = new HashSet <string>(); } changedKeys.Add(key); } } if (missing || Snapshots.Count != dataSnapshot.Snapshots.Count ) // snapshot contains at least one removed key or has a different size, we need to notify the player about that { //TODO: is the removed key also just a changed key, because then we have to deliver a null mvalue as well, yeah why not foreach (var(key, _) in dataSnapshot.Snapshots) { if (!Snapshots.ContainsKey(key)) { if (changedKeys == null) { changedKeys = new HashSet <string>(); } changedKeys.Add(key); } } } return(changedKeys); }
public void CleanErrors(IEnumerable <string> files) { CheckThread(); //Benchmark.Log($"In CleanErrors: There are {files.Length} files, {Snapshots.Count} snapshots, {_managers.Count} managers."); Benchmark.Log($"In CleanErrors: There are {Snapshots.Count} snapshots, {_managers.Count} managers."); foreach (string file in files) { if (Snapshots.ContainsKey(file)) { Snapshots[file].Dispose(); Snapshots.Remove(file); } } foreach (var manager in _managers) { manager.RemoveSnapshots(files); } UpdateAllSinks(); }
/// <summary> /// Checks which keys have changed for the input data snapshot to stay in sync /// </summary> /// <param name="networkingClient">The networking client to compare, we need the client not the snapshot to keep reference for possible overflow</param> /// <param name="keys"></param> /// <returns>the changed keys, returns null when no changes</returns> public void CompareWithClient(LinkedList <string> keys, IClient networkingClient) { if (Snapshots == null || Snapshots.IsEmpty) { return; // entity snapshot should never be null } lastClients.Add(networkingClient); var clientDataSnapshot = networkingClient.Snapshot; if (clientDataSnapshot.TryGetSnapshotForEntity(entity, out var entitySnapshotFromClient) ) // client visited entity before { //changedKeys = Compare(entitySnapshotFromClient); #region Compare var missing = false; foreach (var(key, value) in Snapshots) { if (entitySnapshotFromClient.Snapshots.TryGetValue(key, out var snapShotValue)) { if (snapShotValue < value) { keys.AddLast(key); } } else { missing = true; keys.AddLast(key); } } if (missing || Snapshots.Count != entitySnapshotFromClient.Snapshots.Count ) // snapshot contains at least one removed key or has a different size, we need to notify the player about that { //TODO: is the removed key also just a changed key, because then we have to deliver a null mvalue as well, yeah why not foreach (var(key, _) in entitySnapshotFromClient.Snapshots) { if (!Snapshots.ContainsKey(key)) { keys.AddLast(key); } } } #endregion // Here we align client and entity snapshot with same data entitySnapshotFromClient.Snapshots.Clear(); foreach (var(key, value) in Snapshots) { entitySnapshotFromClient.Snapshots[key] = value; } } else // client never visited entity before { //changedKeys = Snapshots.Keys.ToArray(); foreach (var key in Snapshots.Keys) { keys.AddLast(key); } clientDataSnapshot.SetSnapshotForEntity(entity, new DataSnapshot(new ConcurrentDictionary <string, ulong>(Snapshots))); } //return changedKeys; }
public bool HasErrors(string fileName) { CheckThread(); return(Snapshots.ContainsKey(fileName)); }