static void ReceviceSameCmdMsg(SyncSession session, SameCommand msg) { //消息确认 AffirmMsg amsg = new AffirmMsg(); amsg.index = msg.frame; amsg.time = msg.time; ProtocolAnalysisService.SendMsg(session, amsg); ConnectionComponent connectComp = session.m_connect; if (connectComp != null) { WorldBase world = connectComp.Entity.World; //取上一帧的数据 T scmd = (T)connectComp.GetCommand(msg.frame - 1).DeepCopy(); if (msg.frame > world.FrameCount) { scmd.frame = msg.frame; connectComp.AddCommand(scmd); BroadcastSameCommand(world, connectComp, msg, true); } else { scmd.frame = world.FrameCount; connectComp.AddCommand(scmd); } ControlSpeed(connectComp, world, msg.frame); } }
static void ReceviceSameCmdMsg(SyncSession session, SameCommand msg) { //消息确认 AffirmMsg amsg = new AffirmMsg(); amsg.index = msg.frame; amsg.time = msg.time; ProtocolAnalysisService.SendMsg(session, amsg); ConnectionComponent connectComp = session.m_connect; if (connectComp != null) { WorldBase world = connectComp.Entity.World; if (world.FrameCount <= msg.frame + 4) { //取上一帧的数据 T scmd = (T)connectComp.GetCommand(msg.frame - 1).DeepCopy(); scmd.frame = world.FrameCount + 1; connectComp.AddCommand(scmd); } // //取上一帧的数据 // T scmd = (T)connectComp.GetCommand(msg.frame - 1).DeepCopy(); ////msg.frame = world.FrameCount + 1; // scmd.frame = world.FrameCount + 1; //if (connectComp.AddCommand(scmd)) // { // //BroadcastSameCommand(world, connectComp, msg, true); // } //} //else //{ // //Debug.Log("Same frame " + world.FrameCount); // //scmd.frame = world.FrameCount + 1; // //connectComp.AddCommand(scmd); //} ControlSpeed(connectComp, world, msg.frame); } }
void ReceviceSameCmdMsg(SameCommand cmd, params object[] objs) { if (m_world.IsStart) { EntityBase entity = m_world.GetEntity(cmd.id); AddComp(entity); //自动添加记录组件 PlayerCommandRecordComponent pcrc = entity.GetComp <PlayerCommandRecordComponent>(); PlayerCommandBase record = pcrc.GetInputCahae(cmd.frame - 1); if (record != null) { PlayerCommandBase sameCmd = record.DeepCopy(); sameCmd.frame = cmd.frame; ReceviceCommandMsg((T)sameCmd); } //缓存中没有数据,重新请求 else { ReSendMessage(cmd.frame, cmd.id); } } }
static void BroadcastSameCommand(WorldBase world, ConnectionComponent connectComp, SameCommand cmd, bool includeSelf) { cmd.time = ServiceTime.GetServiceTime(); List <EntityBase> list = world.GetEntityList(new string[] { "ConnectionComponent" }); for (int i = 0; i < list.Count; i++) { ConnectionComponent cp = list[i].GetComp <ConnectionComponent>(); if (cp.m_session != null) { ProtocolAnalysisService.SendMsg(cp.m_session, cmd); //Debug.Log("BroadcastSameCommand " + cmd.frame); } } }
public void SameMsgTest_1() { ResourcesConfigManager.Initialize(); WorldManager.IntervalTime = 100; LockStepEntityTestWorld world = (LockStepEntityTestWorld)WorldManager.CreateWorld <LockStepEntityTestWorld>(); world.IsClient = true; world.IsStart = true; world.IsLocal = true; ConnectStatusComponent csc = world.GetSingletonComp <ConnectStatusComponent>(); csc.confirmFrame = 0; //从目标帧之后开始计算 SelfComponent sc = new SelfComponent(); EntityBase c1 = world.CreateEntityImmediately("1", sc); LockStepInputSystem.commandCache.moveDir.x = 0; world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); TestMoveComponent mc = c1.GetComp <TestMoveComponent>(); Assert.AreEqual(0, mc.pos.x); LockStepInputSystem.commandCache.moveDir.x = 1000; world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); mc = c1.GetComp <TestMoveComponent>(); Assert.AreEqual(1000, mc.pos.x); TestCommandComponent cmd = new TestCommandComponent(); cmd.frame = 1; cmd.id = 1; cmd.moveDir.x = 1000; GlobalEvent.DispatchTypeEvent(cmd); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); mc = c1.GetComp <TestMoveComponent>(); Assert.AreEqual(1000, mc.pos.x); SameCommand sameMsg = new SameCommand(); sameMsg.id = 1; sameMsg.frame = 2; GlobalEvent.DispatchTypeEvent(sameMsg); mc = c1.GetComp <TestMoveComponent>(); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); mc = c1.GetComp <TestMoveComponent>(); Assert.AreEqual(0, mc.pos.x); }