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;
    }
Ejemplo n.º 2
0
    void OtherCommandLogic(EntityBase entity)
    {
        PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>();
        //先取服务器缓存
        T cmd = (T)rc.GetServerCache(m_world.FrameCount);

        //没有的话预测一份
        if (cmd == null)
        {
            //Debug.Log("预测输入 id: " + entity.ID + " m_world.FrameCount " + m_world.FrameCount);
            //取最后一次输入缓存,没有的话New一个新的
            if (rc.m_lastInput == null)
            {
                cmd = new T();
            }
            else
            {
                cmd = (T)rc.m_lastInput.DeepCopy();
            }

            cmd.id    = entity.ID;
            cmd.frame = m_world.FrameCount;

            rc.m_forecastInput = cmd;
        }
        else
        {
            //Debug.Log("读取缓存 ");
        }

        rc.m_lastInput = cmd;
        rc.m_inputCache.Add(cmd);

        entity.ChangeComp(cmd);
    }
    void CheckCommandLogic(DebugMsg msg, EntityInfo entityInfo, ComponentInfo compInfo)
    {
        PlayerCommandRecordComponent pcrc      = m_world.GetEntity(entityInfo.id).GetComp <PlayerCommandRecordComponent>();
        PlayerCommandBase            compLocal = pcrc.GetInputCahae(msg.frame);

        if (compLocal == null)
        {
            return;
        }

        compLocal.time = 0;
        string content = Serializer.Serialize(compLocal);

        if (!content.Equals(compInfo.content))
        {
            string log = "error: frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + msg + " msg.id " + entityInfo.id + " comp:" + compInfo.m_compName + "\n remote:" + compInfo.content + "\n local:" + content + "\n";
            Debug.LogWarning(log);
            string record = "";

            for (int k = msg.frame; k > msg.frame - 10; k--)
            {
                PlayerCommandBase tmp = pcrc.GetInputCahae(k);

                record += "\nframe " + k + " c: " + Serializer.Serialize(tmp);
            }

            Debug.Log(record);
        }
        else
        {
            //Debug.Log(" confirm " + compInfo.content);
        }
    }
Ejemplo n.º 4
0
    public int GetCacheCount()
    {
        int count = 0;
        List <EntityBase> list = GetPlayerList();

        bool isAllMessage = true;

        for (int i = m_frameCount + 1; ; i++)
        {
            if (list.Count == 0)
            {
                break;
            }

            for (int j = 0; j < list.Count; j++)
            {
                AddRecordComponent(list[j]);
                PlayerCommandRecordComponent tmp = list[j].GetComp <PlayerCommandRecordComponent>(ComponentType.PlayerCommandRecordComponent);
                isAllMessage &= tmp.GetAllMessage(i);
            }

            if (isAllMessage)
            {
                count++;
            }
            else
            {
                break;
            }
        }
        return(count);
    }
    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);
                }
            }
        }
    }
Ejemplo n.º 6
0
    public void AddRecordComponent(EntityBase entity)
    {
        if (!entity.GetExistComp(ComponentType.PlayerCommandRecordComponent))
        {
            PlayerCommandRecordComponent rc = new PlayerCommandRecordComponent();

            //自动添加记录组件
            entity.AddComp(rc);
        }
    }
    //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);
        }
    }
Ejemplo n.º 9
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);
    //    }
    //}

    //void RecordCommand(CommandInfo cmd)
    //{
    //    //EntityBase entity = m_world.GetEntity(cmd.id);
    //    //AddComp(entity); //自动添加记录组件

    //    //PlayerCommandRecordComponent pcrc = entity.GetComp<PlayerCommandRecordComponent>();

    //    //PlayerCommandBase remote = cmd.ToCommand();
    //    //PlayerCommandBase record = pcrc.GetInputCahae(cmd.frame);


    //    //if (entity.GetExistComp<SelfComponent>())
    //    //{
    //    //    Debug.LogWarning("set is all");
    //    //}

    //    ////判断和本地的预测有没有冲突
    //    //if (record == null || !record.EqualsCmd(remote))
    //    //{
    //    //    if (entity.GetExistComp<SelfComponent>())
    //    //    {
    //    //        Debug.LogWarning("覆盖本地指令! ");
    //    //    }

    //    //    pcrc.SetConflict(cmd.frame, true);
    //    //}
    //    //else
    //    //{
    //    //    pcrc.SetConflict(cmd.frame, false);
    //    //}

    //    //pcrc.RecordCommand(remote);
    //}

    public void AddComp(EntityBase entity)
    {
        if (!entity.GetExistComp <PlayerCommandRecordComponent>())
        {
            PlayerCommandRecordComponent rc = new PlayerCommandRecordComponent();
            rc.m_defaultInput = new T();

            //自动添加记录组件
            entity.AddComp(rc);
        }
    }
    public void AddComp(EntityBase entity)
    {
        if (!entity.GetExistComp(ComponentType.PlayerCommandRecordComponent))
        {
            //Debug.Log("OnEntityCompAdd PlayerCommandRecordComponent");

            PlayerCommandRecordComponent rc = new PlayerCommandRecordComponent();
            rc.m_defaultInput = new T();

            //自动添加记录组件
            entity.AddComp(rc);
        }
    }
Ejemplo n.º 11
0
    public bool GetIsAllMsg()
    {
        List <EntityBase> list = GetPlayerList();
        bool isAllMessage      = true;

        for (int j = 0; j < list.Count; j++)
        {
            AddRecordComponent(list[j]);
            PlayerCommandRecordComponent tmp = list[j].GetComp <PlayerCommandRecordComponent>(ComponentType.PlayerCommandRecordComponent);
            isAllMessage &= tmp.GetAllMessage(FrameCount + 1);
        }

        return(isAllMessage);
    }
Ejemplo n.º 12
0
    void ReceviceCommandMsg(T cmd, params object[] objs)
    {
        if (m_world.IsStart)
        {
            //Debug.Log("ReceviceCommandMsg " + cmd.frame + " world " + m_world.FrameCount);
            PlayerCommandRecordComponent pcrc = m_world.GetEntity(cmd.id).GetComp <PlayerCommandRecordComponent>();

            //判断帧数
            if (m_world.FrameCount >= cmd.frame)
            {
                PlayerCommandBase input = null;

                if (m_world.FrameCount == cmd.frame)
                {
                    input = pcrc.m_forecastInput;
                }
                else
                {
                    input = pcrc.GetInputCahae(cmd.frame);
                }

                //替换原来的记录
                pcrc.ReplaceCommand(cmd);

                //与本地预测做判断,如果不一致则需要重新演算
                if (!cmd.EqualsCmd(input))
                {
                    Recalc(cmd.frame);
                }
                else
                {
                    //清除以前的记录
                    m_world.ClearBefore(cmd.frame - 1);
                }
            }
            //存入缓存
            else
            {
                //Debug.Log("存入缓存");
                pcrc.m_serverCache.Add(cmd);
            }
        }
        else
        {
            //存入未执行命令列表
            GameDataCacheComponent gdcc = m_world.GetSingletonComp <GameDataCacheComponent>();
            gdcc.m_noExecuteCommandList.Add(cmd);
        }
    }
Ejemplo n.º 13
0
    /// <summary>
    /// 重演算的时候读取输入缓存
    /// </summary>
    /// <param name="frame"></param>
    /// <param name="deltaTime"></param>
    public override void OnlyCallByRecalc(int frame, int deltaTime)
    {
        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            PlayerCommandRecordComponent rc = list[i].GetComp <PlayerCommandRecordComponent>();
            T cmd = (T)rc.GetInputCahae(frame);

            if (cmd == null)
            {
                Debug.LogError("重演算没有读取到输入记录! frame:" + frame + " ID: " + list[i].ID);
                return; //TODO
            }

            list[i].ChangeComp(cmd);
        }
    }
Ejemplo n.º 14
0
    void LoadPlayerInput(int frameCount)
    {
        List <EntityBase> list = m_world.GetEntiyList(new string[] { "PlayerCommandRecordComponent", typeof(T).Name });

        for (int i = 0; i < list.Count; i++)
        {
            PlayerCommandRecordComponent pcrc = list[i].GetComp <PlayerCommandRecordComponent>();
            T cmd = (T)pcrc.GetInputCahae(frameCount);
            if (cmd != null)
            {
                list[i].ChangeComp(cmd);
            }
            else
            {
                Debug.Log("LoadPlayerInput faild frameCount:" + frameCount);
            }
        }
    }
Ejemplo n.º 15
0
    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);
    }
Ejemplo n.º 16
0
    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);
    }
Ejemplo n.º 17
0
    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);
    }
Ejemplo n.º 18
0
    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);
        }
    }
Ejemplo n.º 19
0
    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);
            }
        }
    }
Ejemplo n.º 20
0
    /// <summary>
    /// 重演算的时候读取输入缓存
    /// </summary>
    /// <param name="frame"></param>
    /// <param name="deltaTime"></param>
    public void OnlyCallByRecalc(int frame, int deltaTime)
    {
        List <EntityBase> list = GetEntityList();

        //Debug.Log("OnlyCallByRecalc count " + list.Count);

        for (int i = 0; i < list.Count; i++)
        {
            AddComp(list[i]);
            PlayerCommandRecordComponent rc = list[i].GetComp <PlayerCommandRecordComponent>();
            T cmd = (T)rc.GetInputCahae(frame);

            //Debug.Log("recalc cmd " + list[i].ID + " content " + Serializer.Serialize(cmd) + " " + m_world.FrameCount);

            if (cmd == null)
            {
                Debug.LogError("重演算没有读取到输入记录! frame:" + frame + " ID: " + list[i].ID);
            }
            else
            {
                list[i].ChangeComp(cmd);
            }
        }
    }
    //int clearFrame = 0;
    //string clearReson = "";
    //string Reson = "";

    /// <summary>
    /// 从目标帧开始重新演算
    /// </summary>
    /// <param name="frameCount"></param>
    public override void Recalc()
    {
        //Debug.Log("Recalc " + m_world.FrameCount);

        ConnectStatusComponent csc = m_world.GetSingletonComp <ConnectStatusComponent>();

        // 先判断回退的帧预测的数据和本地数据是否一致,一致则不重计算
        // 判断哪些帧是确定性数据,派发确定性
        // 其余帧继续做预测

        int  frameCount      = csc.confirmFrame;
        int  aimCount        = m_world.FrameCount;
        bool isAllMessage    = true;
        bool isConflict      = false;
        int  allMessageFrame = frameCount;

        List <EntityBase> list = GetEntityList();

        //增加目标帧
        for (int i = aimCount + 1; ; i++)
        {
            if (list.Count == 0)
            {
                break;
            }

            for (int j = 0; j < list.Count; j++)
            {
                AddComp(list[j]);
                PlayerCommandRecordComponent tmp = list[j].GetComp <PlayerCommandRecordComponent>(ComponentType.PlayerCommandRecordComponent);
                isAllMessage &= tmp.GetAllMessage(i);
            }

            if (isAllMessage)
            {
                aimCount = i;
            }
            else
            {
                break;
            }
        }

        //先判断哪些帧不需要重计算
        for (int i = frameCount + 1; i <= aimCount; i++)
        {
            isAllMessage = true;
            isConflict   = false;
            for (int j = 0; j < list.Count; j++)
            {
                AddComp(list[j]);
                PlayerCommandRecordComponent tmp = list[j].GetComp <PlayerCommandRecordComponent>(ComponentType.PlayerCommandRecordComponent);
                isAllMessage &= tmp.GetAllMessage(i);
                isConflict   |= tmp.GetConflict(i);

                //Debug.Log("GetAllMessage " + i + " -> " + tmp.GetAllMessage(i) + " isAllMessage " + isAllMessage);
            }

            if (isAllMessage)
            {
                if (!isConflict)
                {
                    frameCount          = i;
                    allMessageFrame     = i;
                    m_world.IsCertainty = true;
                    //派发确定性
                    m_world.eventSystem.DispatchCertainty(i);
                    m_world.eventSystem.ClearCache(); //之后计算的事件作废
                    csc.confirmFrame = i;

                    m_world.IsCertainty = false;

                    //CheckCertaintyFrame(i);

                    //Debug.Log("不用重计算 frame " + i);
                }
                else
                {
                    //Debug.Log("需要重计算 frame " + i);
                    m_world.eventSystem.ClearCache(); //之前计算的事件作废
                    allMessageFrame = i;
                    break;
                }
            }
            else
            {
                break;
            }
        }

        //Debug.Log(" 重计算 Recalc frameCount -> " + frameCount + " aimCount -> " + aimCount);

        //如果没有新的确定帧出现,则不再重计算
        if (frameCount == allMessageFrame)
        {
            //Debug.Log("没有新的确定帧出现,不再重计算");
            return;
        }

        //回退到最后一个确定帧
        m_world.RevertToFrame(frameCount);

        //目标帧之后的历史记录作废
        m_world.ClearAfter(frameCount);

        m_world.IsRecalc = true;
        isAllMessage     = true;

        for (int i = frameCount + 1; i <= aimCount; i++)
        {
            //确定性不能中断
            if (isAllMessage)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    PlayerCommandRecordComponent tmp = list[j].GetComp <PlayerCommandRecordComponent>(ComponentType.PlayerCommandRecordComponent);
                    isAllMessage &= tmp.GetAllMessage(i);
                }

                if (isAllMessage)
                {
                    csc.confirmFrame    = i;
                    m_world.IsCertainty = true;
                }
                else
                {
                    m_world.IsCertainty = false;
                }
            }

            if (m_world.IsCertainty)
            {
                //Debug.Log("确定帧 " + i);\
                m_world.eventSystem.ClearCacheAt(i);
            }
            else
            {
                //Debug.Log("预测帧 " + i);
            }

            //重新演算
            m_world.Recalc(i, WorldManager.IntervalTime);

            //服务器数据改动,服务器给的是确切数据,所以放在重计算之后
            ExecuteServiceMessage(i);

            m_world.ClearRecordAt(i);

            //重新保存历史记录
            m_world.Record(i);


            if (m_world.IsCertainty)
            {
                //Debug.Log("确定帧结束 " + i);
            }
            else
            {
                //Debug.Log("预测帧结束 " + i);
            }
        }

        m_world.EndRecalc();

        //重计算的结果认定为最终结果,清除历史记录
        m_world.ClearBefore(frameCount - 1);

        csc.ClearFrame      = frameCount - 1;
        m_world.IsCertainty = false;
        m_world.IsRecalc    = false;
    }
Ejemplo n.º 22
0
    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);
    }
Ejemplo n.º 23
0
    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);
        }
    }
Ejemplo n.º 24
0
    public void DebugLogic(DebugMsg msg)
    {
        if (msg.frame == m_world.FrameCount)
        {
            for (int i = 0; i < msg.infos.Count; i++)
            {
                if (m_world.GetEntityIsExist(msg.infos[i].id))
                {
                    EntityBase entity = m_world.GetEntity(msg.infos[i].id);

                    for (int j = 0; j < msg.infos[i].infos.Count; j++)
                    {
                        ComponentBase compLocal = entity.GetComp(msg.infos[i].infos[j].m_compName);

                        if (IsFilter(msg.infos[i].infos[j].m_compName))
                        {
                            string content = Serializer.Serialize(compLocal);

                            if (!content.Equals(msg.infos[i].infos[j].content))
                            {
                                RecordSystemBase rsb = m_world.GetRecordSystemBase(msg.infos[i].infos[j].m_compName);

                                string log = "error: frame" + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + entity.ID + " msg.id " + msg.infos[i].id + " comp:" + msg.infos[i].infos[j].m_compName + "\n remote:" + msg.infos[i].infos[j].content + "\n local:" + content + "\n";
                                Debug.LogWarning(log);
                                rsb.PrintRecord(entity.ID);
                                syncLog += log;

                                //派发冲突
                                GlobalEvent.DispatchEvent(c_isConflict, msg.frame);
                            }
                            else
                            {
                                //Debug.Log("ReceviceDebugMsg  correct! frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + entity.ID + " msg.id " + msg.infos[i].id + " comp:" + msg.infos[i].infos[j].m_compName + " content :"+ msg.infos[i].infos[j].content);
                            }
                        }
                    }
                }
                else
                {
                    string log = "error not find entity frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + msg.infos[i].id + "\n";
                    Debug.LogWarning(log);
                    syncLog += log;
                }
            }
        }
        else if (msg.frame < m_world.FrameCount)
        {
            for (int i = 0; i < msg.infos.Count; i++)
            {
                if (m_world.GetEntityIsExist(msg.infos[i].id))
                {
                    EntityBase entity = m_world.GetEntity(msg.infos[i].id);

                    for (int j = 0; j < msg.infos[i].infos.Count; j++)
                    {
                        if (msg.infos[i].infos[j].m_compName == "CommandComponent")
                        {
                            PlayerCommandRecordComponent pcrc      = m_world.GetEntity(msg.infos[i].id).GetComp <PlayerCommandRecordComponent>();
                            PlayerCommandBase            compLocal = pcrc.GetInputCahae(msg.frame);

                            if (compLocal == null)
                            {
                                return;
                            }

                            compLocal.time = 0;
                            string content = Serializer.Serialize(compLocal);

                            if (!content.Equals(msg.infos[i].infos[j].content))
                            {
                                string log = "error: frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + entity.ID + " msg.id " + msg.infos[i].id + " comp:" + msg.infos[i].infos[j].m_compName + "\n remote:" + msg.infos[i].infos[j].content + "\n local:" + content + "\n";
                                Debug.LogWarning(log);
                                string record = "";

                                for (int k = msg.frame; k > msg.frame - 10; k--)
                                {
                                    PlayerCommandBase tmp = pcrc.GetInputCahae(k);

                                    record += "\nframe " + k + " c: " + Serializer.Serialize(tmp);
                                }

                                Debug.Log(record);
                            }
                            else
                            {
                                //Debug.Log(" confirm " + msg.infos[i].infos[j].content);
                            }
                        }
                        else
                        {
                            RecordSystemBase rsb       = m_world.GetRecordSystemBase(msg.infos[i].infos[j].m_compName);
                            ComponentBase    compLocal = rsb.GetRecord(msg.infos[i].id, msg.frame);

                            if (IsFilter(msg.infos[i].infos[j].m_compName))
                            {
                                if (compLocal != null)
                                {
                                    string content = Serializer.Serialize(compLocal);

                                    if (!content.Equals(msg.infos[i].infos[j].content))
                                    {
                                        string log = "error: frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + entity.ID + " msg.id " + msg.infos[i].id + " comp:" + msg.infos[i].infos[j].m_compName + "\n remote:" + msg.infos[i].infos[j].content + "\n local:" + content + "\n";
                                        Debug.LogWarning(log);
                                        rsb.PrintRecord(entity.ID);

                                        syncLog += log;
                                    }
                                    else
                                    {
                                        //Debug.Log("ReceviceDebugMsg  correct! frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + entity.ID + " msg.id " + msg.infos[i].id + " comp:" + msg.infos[i].infos[j].m_compName + " content :" + msg.infos[i].infos[j].content);
                                    }

                                    //派发冲突
                                    GlobalEvent.DispatchEvent(c_isConflict, msg.frame);
                                }
                                else
                                {
                                    string log = "not find Record ->> frame:" + msg.frame + " id " + msg.infos[i].id + " compName: " + msg.infos[i].infos[j].m_compName + " currentframe: " + m_world.FrameCount + " content " + msg.infos[i].infos[j].content;

                                    //Debug.LogWarning(log);
                                    syncLog += log;
                                }
                            }
                        }
                    }
                }
                else
                {
                    //string log = "error not find entity frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + msg.infos[i].id + "\n";
                    //Debug.LogWarning(log);

                    //syncLog += log;
                }
            }
        }
        else
        {
            string log = "服务器超前 msg:" + msg.frame + " m_world:" + m_world.FrameCount + "\n";
            //Debug.LogWarning(log);
            syncLog += log;
        }
    }