void HandleNewTurn(Pack pack) { PlayFrame turn = ProtoBuf.Serializer.Deserialize <PlayFrame>(new MemoryStream(pack.buffer)); GameMatch match = GameSystem.Instance.mClient.mCurMatch; match.turnManager.NewTurn(turn); //Logger.Log("HandleNewTurn, " + turn.frameNum); }
//新的一帧到来 public void NewTurn(PlayFrame playFrame) { if (headIdx == -1) { headIdx = 0; } //计算需求的空间 int maxTurnID = (int)playFrame.frames[playFrame.frames.Count - 1].frameNum; int turnNum = maxTurnID - curExecTurnID; if (turnNum > turnQ.Capacity) //当前turnQ空间已经存不下,分配更多空间 { ReallocTurnQ(turnNum); } foreach (FrameInfo turn in playFrame.frames) { int turnID = (int)turn.frameNum; int diff = turnID - curServerTurnID; //帧编号差距 int index = WrapIncIndex(tailIdx, diff); //安放位置 turnQ[index] = turn; //安放 if (diff > 1) //丢包,请求重发 { List <uint> missedTurnIDs = new List <uint>(); for (int i = curServerTurnID + 1; i < turnID; ++i) { missedTurnIDs.Add((uint)i); } GameMsgSender.SendMissTurnReq(missedTurnIDs); } if (diff > 0) //非补帧 { tailIdx = index; curServerTurnID = (int)turn.frameNum; } //Logger.Log("Receive new turn: " + info.frameNum + " " + Time.time); /* * foreach (ClientInput input in turn.info) * { * Logger.Log(string.Format("New turn:{0} Acc:{1} Dir:{2} Cmd:{3}", * // Logger.Log("Input: " + input.acc_id + " " + input.dir + " " + input.cmd); * } * //*/ //通知 if (onNewTurn != null) { onNewTurn(turn); } } CalcAverageTurnInterval(Time.time); }
//For virtual game server public static void SendTurn(PlayFrame turn) { NetworkConn conn = GameSystem.Instance.mNetworkManager.m_gameConn; if (conn == null) { return; } conn.SendPack <PlayFrame>(0, turn, MsgID.PlayFrameID); //Debug.Log("VirtualGameServer, SendTurn " + turn.frameNum); //如果使用的是虚拟连接,保证消息立即传回客户端 if (conn.m_type == NetworkConn.Type.eVirtualServer) { conn.Update(0f); } }
void NewTurn() { FrameInfo turn = new FrameInfo(); turn.frameNum = curTurnID++; foreach (KeyValuePair <uint, ClientInput> pair in lastInputs) { ClientInput input = new ClientInput(); input.acc_id = pair.Value.acc_id; input.dir = pair.Value.dir; input.cmd = pair.Value.cmd; turn.info.Add(input); } turn.time = Time.time; PlayFrame playFrame = new PlayFrame(); playFrame.frames.Add(turn); turns.Add(turn); GameMsgSender.SendTurn(playFrame); }