public void Synchronize(bool resetChangeRecord) { if (resetChangeRecord) { if (added.Count != 0) { throw new BurntimeLogicException(); // DEBUG } // swap change record changeRecord.Dequeue(); // garbage collection changeRecord.Add(objects.CollectGarbage(root, externalReferences)); // save back up syncCopy = objects.Clone(); } objects.Add(added, externalReferences); added.Clear(); if (!resetChangeRecord) { changeRecord.Add(objects.Compare(syncCopy)); } UpdateDebugInfo(); }
public void Update(Stream sync) { StateFormatter bf = new StateFormatter(); List <object> list = new List <object>(); int rootId = -1; Burntime.Platform.Log.Debug("begin sync"); int countNew = 0; int countUpdate = 0; int countDelete = 0; SyncCode code = (SyncCode)bf.Deserialize(sync); while (code != SyncCode.End) { switch (code) { case SyncCode.New: { object obj = bf.Deserialize(sync); list.Add(obj); StateObject state = (StateObject)obj; if (state.ID == -1) { throw new Exception("unvalid ID"); } SetContainerLinks(state); state.AfterDeserialization(); if (objects.ContainsKey(state.ID)) { objects[state.ID] = state; } else { objects.Add(state); } countNew++; // Burntime.Platform.Log.Debug("update new: " + state); } break; case SyncCode.Update: { object obj = bf.Deserialize(sync); list.Add(obj); StateObject state = (StateObject)obj; if (state.ID == -1) { throw new Exception("unvalid ID"); } SetContainerLinks(state); state.AfterDeserialization(); if (objects.ContainsKey(state.ID)) { objects[state.ID] = state; } else { added.Remove(state.localID); objects.Add(state); } countUpdate++; // Burntime.Platform.Log.Debug("update update: " + state); } break; case SyncCode.Delete: { int key = (int)bf.Deserialize(sync); if (objects.ContainsKey(key)) { // Burntime.Platform.Log.Debug("update delete: " + objects[key]); objects.Remove(key); } countDelete++; } break; case SyncCode.RootId: rootId = (int)bf.Deserialize(sync); objects.Clear(); added.Clear(); syncCopy.Clear(); break; } code = (SyncCode)bf.Deserialize(sync); } if (rootId != -1) { root = objects[rootId] as WorldState; } // CheckConsistency(); // DEBUG UpdateDebugInfo(); }