コード例 #1
0
    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);
        }
    }
コード例 #2
0
    static void ReceviceSyncMsg(SyncSession session, T msg)
    {
        //Debug.Log("ReceviceSyncMsg " + msg.id + " content " +  Serializer.Serialize(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 (msg.frame > world.FrameCount)
            {
                //广播这帧
                BroadcastCommand(world, connectComp, msg, false);
                connectComp.AddCommand(msg);
            }
            else
            {
                //当成最新的一帧来处理
                msg.frame = world.FrameCount;
                connectComp.AddCommand(msg);
            }

            ControlSpeed(connectComp, world, msg.frame);
        }
    }
コード例 #3
0
    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;
    }
コード例 #4
0
    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);
        }
    }
コード例 #5
0
    void ReceviceAffirmMsg(AffirmMsg msg, params object[] objs)
    {
        ConnectStatusComponent csc = m_world.GetSingletonComp <ConnectStatusComponent>();

        csc.rtt = ClientTime.GetTime() - msg.time;

        //TODO 服务器确认后这里可以清除下缓存
    }
コード例 #6
0
    static void ReceviceSyncMsg(SyncSession session, T msg)
    {
        //Debug.Log("ReceviceSyncMsg " + msg.id + " content " +  Serializer.Serialize(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)
            {
                connectComp.AddCommand(msg);
            }

            //msg.frame = world.FrameCount + 1;

            //    //广播这帧
            //    if(connectComp.AddCommand(msg))
            //    {
            //        //BroadcastCommand(world, connectComp, msg, false);
            //    }
            //}
            //else
            //{
            //    //Debug.Log("丢弃掉 " + msg.frame);

            //    //直接丢弃掉落后帧

            //    //Debug.Log("帧相等! " + msg.frame);

            //    //if (!connectComp.m_isInframe)
            //    //{
            //    //    //当成最新的一帧来处理
            //    //    msg.frame = world.FrameCount + 1;
            //    //    connectComp.AddCommand(msg);
            //    //}
            //    //else
            //    //{
            //    //    Debug.Log("在一帧之内插入了数据! " + msg.frame);

            //    //    msg.frame = world.FrameCount + 1;
            //    //    connectComp.AddCommand(msg);
            //    //}
            //}

            ControlSpeed(connectComp, world, msg.frame);
        }
    }
コード例 #7
0
    static void ReceviceAffirmMsg(SyncSession session, AffirmMsg msg)
    {
        ConnectionComponent commandComp = session.m_connect;

        int nowTime = ServiceTime.GetServiceTime();

        commandComp.rtt = nowTime - msg.time;

        //Debug.Log(" 收到确认消息 frame: " + msg.index + " id: " + commandComp.Entity.ID + " rtt " + commandComp.rtt);
    }
コード例 #8
0
    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);
        }
    }
コード例 #9
0
    static void ReceviceAffirmMsg(SyncSession session, AffirmMsg msg)
    {
        ConnectionComponent commandComp = session.m_connect;

        commandComp.ClearForecast(msg.frame);

        int nowTime = ServiceTime.GetServiceTime();

        commandComp.rtt = nowTime - msg.time;

        //Debug.Log("rtt " + commandComp.rtt);
    }
コード例 #10
0
    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);
            }
        }
    }
コード例 #11
0
    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);
        }
    }
コード例 #12
0
    void ReceviceAffirmMsg(AffirmMsg msg, params object[] objs)
    {
        SyncDebugData data = GetSyncData(msg.index);

        data.AffirmMsgCount++;
    }