//void ReceviceCmdMsg(CommandMsg msg,params object[] objs) //{ // //Debug.Log("ReceviceCmdMsg " + msg.frame); // //立即返回确认消息 // AffirmMsg amsg = new AffirmMsg(); // amsg.frame = msg.frame; // amsg.time = msg.serverTime; // ProtocolAnalysisService.SendCommand(amsg); // if (m_world.IsStart) // { // //TODO 如果全部都与本地预测相同则不再重计算 // for (int i = 0; i < msg.msg.Count; i++) // { // RecordCommand(msg.msg[i]); // } // if (m_world.FrameCount >= msg.frame) // { // Recalc(msg.frame); // } // } // else // { // //存入未执行命令列表 // Debug.Log("存入未执行命令列表"); // GameDataCacheComponent gdcc = m_world.GetSingletonComp<GameDataCacheComponent>(); // gdcc.m_noExecuteCommandList.Add(msg); // } //} void RecordCommand(CommandInfo cmd) { EntityBase entity = m_world.GetEntity(cmd.id); AddComp(entity); PlayerCommandRecordComponent pcrc = entity.GetComp <PlayerCommandRecordComponent>(); pcrc.RecordCommand(cmd.ToCommand()); }
void ReceviceCommandMsg(T cmd, params object[] objs) { //Debug.Log("ReceviceCommandMsg frame " + cmd.frame + " frame " + Serializer.Serialize(cmd)); if (SyncDebugSystem.isDebug) { SyncDebugSystem.RecordMsg("cmd_commandComponent", cmd.frame, Serializer.Serialize(cmd)); } //立即返回确认消息 AffirmMsg amsg = new AffirmMsg(); amsg.index = cmd.frame; amsg.time = cmd.time; ProtocolAnalysisService.SendCommand(amsg); if (m_world.IsStart) { EntityBase entity = m_world.GetEntity(cmd.id); AddComp(entity); //自动添加记录组件 PlayerCommandRecordComponent pcrc = entity.GetComp <PlayerCommandRecordComponent>(ComponentType.PlayerCommandRecordComponent); PlayerCommandBase record = pcrc.GetInputCahae(cmd.frame); //判断和本地的预测有没有冲突 if (record == null || !record.EqualsCmd(cmd)) { pcrc.SetConflict(cmd.frame, true); } else { pcrc.SetConflict(cmd.frame, false); } if (pcrc.lastInputFrame < cmd.frame) { pcrc.lastInputFrame = cmd.frame; } pcrc.RecordCommand(cmd); //数据完整校验 if (cmd.frame != 0 && pcrc.GetAllMessage(cmd.frame) && !pcrc.GetAllMessage(cmd.frame - 1)) { ReSendMessage(cmd.frame - 1, cmd.id); } //Recalc(); } else { GameDataCacheComponent gdcc = m_world.GetSingletonComp <GameDataCacheComponent>(); gdcc.m_noExecuteCommandList.Add(cmd); } }
void OtherCommandLogic(EntityBase entity) { AddComp(entity); PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>(); //先取服务器缓存 T cmd = (T)rc.GetInputCahae(m_world.FrameCount); //没有的话预测一份 if (cmd == null) { cmd = (T)rc.GetForecastInput(m_world.FrameCount); } rc.RecordCommand(cmd); entity.ChangeComp(cmd); }
void OtherCommandLogic(EntityBase entity) { //Debug.Log("OtherCommandLogic " + m_world.FrameCount); AddComp(entity); PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>(); //先取服务器缓存 T cmd = (T)rc.GetInputCahae(m_world.FrameCount); //没有的话预测一份 if (cmd == null) { //Debug.Log("预测本地操作 " + m_world.FrameCount + " id " + entity.ID); cmd = (T)rc.GetForecastInput(m_world.FrameCount); } rc.RecordCommand(cmd); entity.ChangeComp(cmd); //Debug.Log("Other cmd " + entity.ID + " content " + Serializer.Serialize(cmd) + " " + m_world.FrameCount); }
void SelfCommandLogic(EntityBase entity) { T comp = new T(); comp.frame = m_world.FrameCount; comp.id = entity.ID; BuildCommand(comp); entity.ChangeComp(comp); AddComp(entity); //缓存起来 PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>(); rc.RecordCommand(comp); if (!m_world.m_isLocal) { comp.time = ClientTime.GetTime(); ProtocolAnalysisService.SendCommand(comp); } }
void SelfCommandLogic(EntityBase entity) { //Debug.Log("SelfCommandLogic " + m_world.FrameCount); //先取服务器缓存 AddComp(entity); PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>(); T cmd = (T)rc.GetInputCahae(m_world.FrameCount); //没有的话构建一份 if (cmd == null) { cmd = new T(); cmd.frame = m_world.FrameCount; cmd.id = entity.ID; BuildCommand(cmd); rc.RecordCommand(cmd); //Debug.Log("Self cmd " + entity.ID + " content " + Serializer.Serialize(cmd) + " " + m_world.FrameCount); } else { //Debug.Log("读取 服务器缓存 输入"); } if (!m_world.IsLocal) { T record = (T)rc.GetInputCahae(m_world.FrameCount - 1); cmd.frame = m_world.FrameCount - 1; if (record != null && record.EqualsCmd(cmd)) { sameCmdCache.frame = m_world.FrameCount; sameCmdCache.time = ClientTime.GetTime(); sameCmdCache.id = entity.ID; if (NetworkManager.IsConnect) { ProtocolAnalysisService.SendCommand(sameCmdCache); } //Debug.Log("send same " + m_world.FrameCount + " id " + sameCmdCache.id); } else { //Debug.Log("send cmd " + m_world.FrameCount + " id " + cmd.id); cmd.frame = m_world.FrameCount; cmd.time = ClientTime.GetTime(); if (NetworkManager.IsConnect) { ProtocolAnalysisService.SendCommand(cmd); } } } entity.ChangeComp(cmd); }
void ReceviceCommandMsg(T cmd, params object[] objs) { //Debug.Log("ReceviceCommandMsg id" + cmd.id + " frame " + cmd.frame); if (m_world.IsStart) { PlayerCommandRecordComponent pcrc = m_world.GetEntity(cmd.id).GetComp <PlayerCommandRecordComponent>(); pcrc.lastInputFrame = cmd.frame; if (cmd.frame <= m_world.FrameCount) { //过去的命令 //如果与本地预测结果不一致,则重新演算 //不过要等到这一帧所有命令到齐才重计算 PlayerCommandBase record = pcrc.GetInputCahae(cmd.frame); if (record == null || !record.EqualsCmd(cmd)) { pcrc.m_isConflict = true; } else { pcrc.m_isConflict = false; } pcrc.RecordCommand(cmd); List <EntityBase> list = GetEntityList(); bool isAllMessage = false; bool isConflict = false; for (int i = 0; i < list.Count; i++) { PlayerCommandRecordComponent tmp = m_world.GetEntity(list[i].ID).GetComp <PlayerCommandRecordComponent>(); isAllMessage |= (tmp.lastInputFrame >= m_world.FrameCount); isConflict |= tmp.m_isConflict; } if (isAllMessage) { if (isConflict) { m_world.eventSystem.ClearCache(cmd.frame); //Debug.Log("消息不同重计算 "); Recalc(cmd.frame); } else { //此时派发确定性 m_world.eventSystem.DispatchCertainty(cmd.frame); } } if (isAllMessage) { } } else { pcrc.RecordCommand(cmd); } } else { //存入未执行命令列表 Debug.Log("存入未执行命令列表"); GameDataCacheComponent gdcc = m_world.GetSingletonComp <GameDataCacheComponent>(); //gdcc.m_noExecuteCommandList.Add(cmd); } }