public override void BeforeFixedUpdate(int deltaTime) { List <EntityBase> list = GetEntityList(); if (list.Count > 1) { Debug.LogError("CommandSyncSystem Error exist two selfComponet!"); return; } if (list.Count > 0) { EntityBase entity = list[0]; T comp = new T(); comp.frame = m_world.FrameCount; comp.id = entity.ID; BuildCommand(comp); entity.ChangeComp(comp); //缓存起来 RecordComponent rc = m_world.GetSingletonComp <RecordComponent>(); rc.m_inputCache = comp; ProtocolAnalysisService.SendCommand(comp); } }
public override void BeforeFixedUpdate(int deltaTime) { List <EntityBase> list = GetEntityList(); if (list.Count > 1) { Debug.LogError("CommandSyncSystem Error exist two selfComponet!"); return; } if (list.Count > 0) { EntityBase entity = list[0]; FrameCountComponent fc = m_world.GetSingletonComp <FrameCountComponent>(); T comp = new T(); BuildCommand(comp); entity.ChangeComp(comp); //缓存起来 RecordComponent rc = m_world.GetSingletonComp <RecordComponent>(); rc.m_inputCache = comp; ChangeComponentMsg msg = new ChangeComponentMsg(); msg.frame = fc.count; msg.id = entity.ID; msg.info = new ComponentInfo(); msg.info.m_compName = comp.GetType().Name; msg.info.content = Serializer.Serialize(comp); ProtocolAnalysisService.SendCommand(msg); } }
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; }
void ReceviceCmdMsg(CommandMsg msg, params object[] objs) { //Debug.Log("ReceviceCmdMsg " + msg.index + " currentframe " + m_world.FrameCount); //立即返回确认消息 AffirmMsg amsg = new AffirmMsg(); amsg.index = msg.index; amsg.time = msg.serverTime; ProtocolAnalysisService.SendCommand(amsg); if (m_world.IsStart) { //TODO 如果全部都与本地预测相同则不再重计算 for (int i = 0; i < msg.msg.Count; i++) { //Debug.Log("RecordCommand " + Serializer.Serialize(msg.msg[i])); RecordCommand(msg.msg[i]); } Recalc(); } else { //存入未执行命令列表 //Debug.Log("存入未执行命令列表"); //GameDataCacheComponent gdcc = m_world.GetSingletonComp<GameDataCacheComponent>(); //gdcc.m_noExecuteCommandList.Add(msg); } }
public override void OnUpdate() { if (NetworkManager.IsConnect) { role_login_s msg = new role_login_s(); ProtocolAnalysisService.SendCommand(msg); } }
void ReSendMessage(int frame, int id) { QueryCommand qc = new QueryCommand(); qc.frame = frame; qc.id = id; ProtocolAnalysisService.SendCommand(qc); }
void SelfCommandLogic(EntityBase entity) { //Debug.Log("SelfCommandLogic " + m_world.FrameCount); if (m_world.IsLocal) { //构建一份新指令并发送 T ncmd = new T(); ncmd.frame = m_world.FrameCount; ncmd.id = entity.ID; BuildCommand(ncmd); entity.ChangeComp(ncmd); } else { //先取服务器缓存 AddComp(entity); PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>(ComponentType.PlayerCommandRecordComponent); T cmd = (T)rc.GetInputCahae(m_world.FrameCount); cmd = (T)cmd.DeepCopy(); entity.ChangeComp(cmd); //构建一份新指令并发送 T ncmd = new T(); ncmd.frame = m_world.FrameCount + 1; ncmd.id = entity.ID; BuildCommand(ncmd); if (ncmd.EqualsCmd(cmd)) { sameCmdCache.frame = m_world.FrameCount + 1; sameCmdCache.time = ClientTime.GetTime(); sameCmdCache.id = entity.ID; if (NetworkManager.IsConnect) { ProtocolAnalysisService.SendCommand(sameCmdCache); } } else { ncmd.frame = m_world.FrameCount + 1; ncmd.time = ClientTime.GetTime(); if (NetworkManager.IsConnect) { ProtocolAnalysisService.SendCommand(ncmd); } } } }
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 SelfCommandLogic(EntityBase entity) { T comp = new T(); comp.frame = m_world.FrameCount; comp.id = entity.ID; BuildCommand(comp); entity.ChangeComp(comp); //缓存起来 PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>(); rc.m_lastInput = comp; rc.m_inputCache.Add(comp); ProtocolAnalysisService.SendCommand(comp); }
void GUI() { if (isDebug && GUILayout.Button("Print")) { OutPutDebugRecord(); } if (isDebug && GUILayout.Button("Query")) { List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { QueryCommand qc = new QueryCommand(); qc.frame = m_world.FrameCount - 10; qc.id = list[i].ID; ProtocolAnalysisService.SendCommand(qc); } } }
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); }