void OnResponseSyncKeyframes(Notification note) { ByteBuffer buff = new ByteBuffer(note.GetBytes()); PtKeyFrameCollection collection = PtKeyFrameCollection.Read(buff.ReadBytes()); QueueKeyFrameCollection.Enqueue(collection); KeyframesCount++; AllFramesCount += collection.KeyFrames.Count; //Debug.Log(string.Format("[client receive] frameIdx:{0}", collection.FrameIdx)); }
void OnRequestSyncClientKeyframes(Notification note) { int serverFrameIdx = SimulationManager.Instance.GetSimulation(Const.SERVER_SIMULATION_ID).GetBehaviour <ServerLogicFrameBehaviour>().CurrentFrameIdx; Message msg = note.GetMessage(); ByteBuffer buffer = new ByteBuffer(note.GetBytes()); PtKeyFrameCollection collection = PtKeyFrameCollection.Read(buffer.ReadBytes()); foreach (var item in collection.KeyFrames) { item.Idx = serverFrameIdx; } collection.FrameIdx = serverFrameIdx; QueueKeyFrameCollection.Enqueue(collection); //GameServerNetwork.Instance.Broadcast(PtMessagePackage.Build((int)S2CMessageId.ResponseSyncKeyframes, // new ByteBuffer().WriteBytes(PtKeyFrameCollection.Write(collection)).Getbuffer(),false)); }
private void OnClientMsg(object[] args) { string playerId = args[0] as string; string msg = args[1] as string; var msgList = ListCache <string> .Acquire(); msgList.AddRange(msg.Split('|')); var msgType = msgList[0]; switch (msgType) { case (ClientMsgType.ReConnect): StringBuilder sb = new StringBuilder(); sb.Append(ClientMsgType.ReConnectRsp); sb.Append("|"); sb.Append(GetTimeStamp()); sb.Append("|"); var sim = SimulationManager.Instance.GetSimulation(Const.CLIENT_SIMULATION_ID); var frameDatas = sim.GetBehaviour <ComponentsBackupBehaviour>().GetEntityWorldFrameData(); var frameIdx = sim.GetBehaviour <LogicFrameBehaviour>().CurrentFrameIdx; sb.Append(frameIdx); sb.Append("|"); var frameData = frameDatas[frameIdx]; sb.Append(EntityWorldFrameData.Serilize(frameData)); sb.Append("|"); var arrKF = MgobeHelper.QueueKeyFrameCollection.ToArray(); if (arrKF.Length > 0) { for (int i = 0; i < arrKF.Length; i++) { if (i > 0) { sb.Append("&"); } sb.Append(Encoding.UTF8.GetString(PtKeyFrameCollection.Write(arrKF[i]))); } } var list = new List <string>() { playerId }; MgobeHelper.SendToClient(list, RecvType.RoomSome, sb.ToString()); break; case (ClientMsgType.ReConnectRsp): var idx = msgList[1]; var timestamp = ulong.Parse(msgList[2]); var frameStr = msgList[3]; var kfStr = msgList[4]; var entData = EntityWorldFrameData.DeSerilize(frameStr); var queueKeyFrameCollection = new ConcurrentQueue <PtKeyFrameCollection>(); if (!string.IsNullOrEmpty(kfStr)) { var kfStrs = kfStr.Split('&'); for (int i = 0; i < kfStrs.Length; i++) { queueKeyFrameCollection.Enqueue(PtKeyFrameCollection.Read(Encoding.UTF8.GetBytes(kfStrs[i]))); } } MgobeHelper.QueueKeyFrameCollection = queueKeyFrameCollection; OnAddClient(); var sim2 = SimulationManager.Instance.GetSimulation(Const.CLIENT_SIMULATION_ID); sim2.GetBehaviour <LogicFrameBehaviour>().CurrentFrameIdx = int.Parse(idx); sim2.GetEntityWorld().RollBack(entData, null); OnAllReady(null); SimulationManager.Instance.Start(timestamp); break; default: break; } ListCache <string> .Release(msgList); }