public void RunFrameFinish() { if (GameMain.instance.OfflineModel) { ServerFrameCounter++; } //处于最新一帧发送操作才是有效的 //if(FrameCounter == ServerFrameCounter) { NetCSSynchronizateMsg msg = new NetCSSynchronizateMsg(); msg.CurFrame = FrameCounter; msg.OperationData = playerOperationData; NetThread.Instance.Send(msg); //Debug.Log("发送 " + FrameCounter); } //第一帧是没有数据的 if (frameDatas.Count > 0) { frameDatas.RemoveAt(0); } FrameCounter++; }
private static void AnalysisMsg(PlayerInfo info) { while (info.AnalysisBufferLength > 0) { int msgLength = BitConverter.ToInt32(info.AnalysisBuffer, 0); //Console.WriteLine("msg length " + msgLength); if (msgLength <= info.AnalysisBufferLength - 4) { info.NetReadBuff.Set(info.AnalysisBuffer, 4, msgLength); int messageType = BitConverter.ToInt32(info.AnalysisBuffer, 4); if (messageType != (int)EmNetMessageType.CS_SYNCHRONIZATE) { Console.WriteLine("**** 错误,消息不是同步消息 " + messageType); } else { var msg = NetMessageFactory.GetMessage(messageType); if (msg != null) { msg.Read(info.NetReadBuff); NetCSSynchronizateMsg msgg = msg as NetCSSynchronizateMsg; if (info.CurFrame == msgg.CurFrame) { info.OperationData = msgg.OperationData; info.IsOperationReceived = true; info.CurFrame++; } else { Console.WriteLine("error: player {0} frame should be {1}, receive {2}", info.PlayerId, info.CurFrame, msgg.CurFrame); } //Console.WriteLine("receve " + msg.MessageType); } else { //Console.WriteLine("wrong message type " + messageType); } } int remain = info.AnalysisBufferLength - msgLength - 4; Array.Copy(info.AnalysisBuffer, 4 + msgLength, info.AnalysisTempBuffer, 0, remain); Array.Copy(info.AnalysisTempBuffer, 0, info.AnalysisBuffer, 0, remain); info.AnalysisBufferLength = remain; //Debug.Log("remian " + remain); //Log(); } else { break; } } }