protected void Awake() { INSTANCE = this; this.sendList = new List <Snapshot>(); this.checkList = new List <Snapshot>(); this.syncList = new List <List <Snapshot> >(); this.client = new Client(); }
private void Sync(byte msgId, NetworkReader reader, IPEndPoint ep) { if (ServerMgr.Active) { return; } var msg = new Msg.Sync() { syncList = this.syncList }; msg.Deserialize(reader, this.fd); var list = msg.selfList; var serverList = msg.serverList; int index = list.Count; for (int i = 0; i < list.Count; i++) { if (!list[i].Equals(this.checkList[i])) { index = i; print(i); break; } } if (index == list.Count) // Agreement { this.checkList.RemoveRange(0, list.Count); } else { var frame = list[list.Count - 1].frame; for (int i = this.checkList.Count - 1; i >= 0; i--) { if (this.checkList[i].frame <= frame) { this.checkList.RemoveAt(i); } } ClientMgr.Resolve(this.fd, list, index); ClientMgr.Resolve(this.fd, this.checkList, 0); } ClientMgr.Resolve(this.fd, serverList, 0); }
protected void FixedUpdate() { this.server.Update(Time.fixedDeltaTime); if (this.server.Active) { this.frameCount++; if (this.frameCount % INTERVAL == 0) { this.server.SendToAll(MsgId.Sync, new Msg.Sync() { syncList = this.syncList }); this.syncList.Clear(); } var list = new List <Snapshot>(); foreach (var i in this.unitMap) { int frame = -1; var sl = i.Value.list; while (sl.Count > 0 && (i.Value.count > INTERVAL || (frame == -1 || sl[0].frame == frame))) { var s = sl[0]; list.Add(s); sl.RemoveAt(0); if (frame != s.frame) { frame = s.frame; i.Value.count--; } } } if (list.Count > 0) { ClientMgr.AddSync(list); this.syncList.Add(list); } } }