public StateObject GetObject(int id, int localId) { if (id != -1) { if (!objects.ContainsKey(id)) { Burntime.Platform.Log.Warning("state object not found in container " + debugName); return(null); } return(objects[id]); } if (!added.ContainsKey(localId)) { Burntime.Platform.Log.Warning("state object not found in container " + debugName); return(null); } return(added[localId]); }
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(); }