void RecevicePursueMsg(PursueMsg msg, params object[] objs) { //立即返回确认消息 AffirmMsg amsg = new AffirmMsg(); amsg.frame = msg.frame; amsg.time = msg.serverTime; ProtocolAnalysisService.SendCommand(amsg); PlayerCommandRecordComponent pcrc = m_world.GetEntity(msg.id).GetComp <PlayerCommandRecordComponent>(); //for (int i = 0; i < msg.m_commandList.Count; i++) //{ // pcrc.RecordCommand(deserializer.Deserialize<T>( msg.m_commandList[i])); //} Recalc(msg.recalcFrame); //从接收到命令的第一帧开始重计算 clearReson = "RecevicePursueMsg"; AdvanceCalc(msg.frame + msg.advanceCount); //提前计算 ConnectStatusComponent csc = m_world.GetSingletonComp <ConnectStatusComponent>(); csc.aheadFrame = msg.advanceCount; }
static void SendPursueMsg(ConnectionComponent connectComp, float speed) { if (connectComp.UpdateSpeed != speed) { PursueMsg pmsg = new PursueMsg(); pmsg.updateSpeed = speed; pmsg.advanceCount = CalcAdvanceFrame(connectComp); connectComp.UpdateSpeed = speed; ProtocolAnalysisService.SendMsg(connectComp.m_session, pmsg); } }
void RecevicePursueMsg(PursueMsg msg, params object[] objs) { //Debug.Log("RecevicePursueMsg " + msg.frame + " UpdateSpped " + msg.updateSpeed); //调整游戏速度 WorldManager.UpdateSpped = msg.updateSpeed; ConnectStatusComponent csc = m_world.GetSingletonComp <ConnectStatusComponent>(); csc.aheadFrame = msg.advanceCount; return; }
static void ReceviceSyncMsg(SyncSession session, T msg) { ConnectionComponent commandComp = session.m_connect; WorldBase world = session.m_connect.Entity.World; if (commandComp != null) { PlayerCommandBase comp = msg; comp.frame = msg.frame; if (msg.frame > world.FrameCount) { commandComp.m_commandList.Add(comp); //TODO 与预测一致不广播节约带宽 List <EntityBase> list = world.GetEntiyList(new string[] { "ConnectionComponent" }); for (int i = 0; i < list.Count; i++) { ConnectionComponent cp = list[i].GetComp <ConnectionComponent>(); if (cp != commandComp) { ProtocolAnalysisService.SendMsg(cp.m_session, msg); } } } else { //潜在的不同步威胁 Debug.Log("帧数落后 丢弃玩家操作 world.FrameCount: " + world.FrameCount + " msg frame:" + msg.frame); //发送给玩家自己 服务器给他预测的操作, for (int i = 0; i < commandComp.m_forecastList.Count; i++) { ProtocolAnalysisService.SendMsg(session, commandComp.m_forecastList[i]); } commandComp.m_forecastList.Clear(); //并且让这个玩家提前 commandComp.m_lastInputCache = comp; PursueMsg pmsg = new PursueMsg(); pmsg.frame = world.FrameCount; pmsg.advanceCount = 1; ProtocolAnalysisService.SendMsg(session, pmsg); } } }
static void ReceviceSyncMsg(SyncSession session, T msg) { //Debug.Log("ReceviceSyncMsg " + msg.id); ConnectionComponent connectComp = session.m_connect; WorldBase world = session.m_connect.Entity.World; if (connectComp != null) { if (msg.frame > world.FrameCount) { //消息确认 AffirmMsg amsg = new AffirmMsg(); amsg.frame = msg.frame; amsg.time = msg.time; BroadcastCommand(world, connectComp, msg, false); ProtocolAnalysisService.SendMsg(session, amsg); connectComp.m_commandList.Add(msg); connectComp.lastInputFrame = msg.frame; } else { //把玩家的这次上报当做最新的操作并转发 Debug.Log("帧数落后 world.FrameCount: " + world.FrameCount + " msg frame:" + msg.frame + " 预测列表计数 " + connectComp.m_forecastList.Count); //Debug.Log("接收玩家数据 " + Serializer.Serialize(msg)); connectComp.m_lastInputCache = msg; connectComp.lastInputFrame = world.FrameCount; //并且让这个玩家提前 PursueMsg pmsg = new PursueMsg(); pmsg.id = msg.id; pmsg.recalcFrame = msg.frame; pmsg.frame = world.FrameCount; pmsg.advanceCount = CalcAdvanceFrame(connectComp); pmsg.serverTime = ServiceTime.GetServiceTime(); ProtocolAnalysisService.SendMsg(session, pmsg); } } }
void RecevicePursueMsg(PursueMsg msg, params object[] objs) { AdvanceCalc(msg.frame + msg.advanceCount); //提前计算 }
void RecevicePursueMsg(PursueMsg msg, params object[] objs) { SyncDebugData data = GetSyncData(msg.frame); data.PursueCount++; }