void ReceviceStartSyncMsg(StartSyncMsg msg, params object[] objs)
    {
        Debug.Log("Start Msg " + msg.frame);

        m_world.FrameCount  = msg.frame;
        m_world.IsStart     = true;
        m_world.EntityIndex = msg.createEntityIndex;
        m_world.SyncRule    = msg.SyncRule;

        m_world.m_isRecalc = true;

        WorldManager.IntervalTime = msg.intervalTime;

        //立即执行创建操作
        m_world.LazyExecuteEntityOperation();

        //执行未处理的命令
        GameDataCacheComponent gdcc = m_world.GetSingletonComp <GameDataCacheComponent>();

        for (int i = 0; i < gdcc.m_noExecuteCommandList.Count; i++)
        {
            for (int j = 0; j < gdcc.m_noExecuteCommandList[i].msg.Count; j++)
            {
                RecordCommand(gdcc.m_noExecuteCommandList[i].msg[j]);
            }
        }

        m_world.m_isRecalc = false;

        AdvanceCalc(msg.frame + msg.advanceCount); //提前计算一帧

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

        csc.aheadFrame = msg.advanceCount;
    }
    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);
        }
    }
示例#3
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);
        }
    }
示例#4
0
    void ReceviceStartSyncMsg(StartSyncMsg msg, params object[] objs)
    {
        Debug.Log("StartSyncMsg " + msg.frame);

        m_world.FrameCount  = msg.frame;
        m_world.IsStart     = true;
        m_world.EntityIndex = msg.createEntityIndex;
        m_world.SyncRule    = msg.SyncRule;

        WorldManager.IntervalTime = msg.intervalTime;

        //执行未处理的命令
        GameDataCacheComponent gdcc = m_world.GetSingletonComp <GameDataCacheComponent>();

        for (int i = 0; i < gdcc.m_noExecuteCommandList.Count; i++)
        {
            ReceviceCommandMsg((T)gdcc.m_noExecuteCommandList[i]);
        }

        AdvanceCalc(msg.frame + msg.advanceCount); //提前计算一帧
    }
    void ReceviceStartSyncMsg(StartSyncMsg msg, params object[] objs)
    {
        ConnectStatusComponent csc = m_world.GetSingletonComp <ConnectStatusComponent>();

        csc.confirmFrame = msg.frame; //从目标帧之后开始计算

        //Debug.Log("ReceviceStartSyncMsg " + csc.confirmFrame);

        m_world.FrameCount = msg.frame;
        m_world.IsStart    = true;
        //m_world.EntityIndex = msg.createEntityIndex;
        m_world.SyncRule = msg.SyncRule;

        WorldManager.IntervalTime = msg.intervalTime;
        m_world.IsCertainty       = true;
        //立即执行创建操作
        m_world.LazyExecuteEntityOperation();
        m_world.IsCertainty = false;

        m_world.m_RandomSeed = msg.randomSeed;

        m_world.ClearAll();

        //执行未处理的命令
        GameDataCacheComponent gdcc = m_world.GetSingletonComp <GameDataCacheComponent>();

        for (int i = 0; i < gdcc.m_noExecuteCommandList.Count; i++)
        {
            ReceviceCommandMsg((T)gdcc.m_noExecuteCommandList[i]);
        }

        m_world.Record(m_world.FrameCount);

        Recalc();
        AdvanceCalc(msg.frame + msg.advanceCount); //提前计算一帧

        csc.aheadFrame = msg.advanceCount;
    }
    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);
        }
    }