public override void RevertToFrame(int frame)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        for (int i = 0; i < rc.m_record.Count; i++)
        {
            T record = rc.m_record[i];

            if (record.Frame == frame)
            {
                if (m_world.GetEntityIsExist(record.ID))
                {
                    EntityBase entity = m_world.GetEntity(record.ID);
                    entity.ChangeComp(hashCode, record.DeepCopy());
                }
                else if (m_world.GetIsExistDispatchDestroyCache(record.ID))
                {
                    EntityBase entity = m_world.GetDispatchDestroyCache(record.ID);
                    entity.ChangeComp(hashCode, record.DeepCopy());
                }
                else if (m_world.GetIsExistDispatchCreateCache(record.ID))
                {
                    EntityBase entity = m_world.GetDispatchCreateCache(record.ID);
                    entity.ChangeComp(hashCode, record.DeepCopy());
                }
            }
        }
    }
    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);
        }
    }
示例#3
0
    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);
        }
    }
    public override void ClearBefore(int frame)
    {
        //return;

        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        rc.ClearBefore(frame);
    }
    public override void ClearAll()
    {
        //return;

        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        rc.m_record.Clear();
    }
    public override void RevertToFrame(int frame)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        List <T> list = rc.GetRecordList(frame);

        //if (SyncDebugSystem.IsFilter(typeof(T).Name))
        //{
        //    Debug.Log("数据回滚  frame:" + frame + " Count:" + list.Count);
        //}

        for (int i = 0; i < list.Count; i++)
        {
            if (m_world.GetEntityIsExist(list[i].ID))
            {
                //if (SyncDebugSystem.IsFilter(typeof(T).Name))
                //{
                //    Debug.Log("在游戏中 " + list[i].ID);
                //}

                EntityBase entity = m_world.GetEntity(list[i].ID);
                entity.ChangeComp((T)list[i].DeepCopy());
            }
            else if (m_world.GetIsExistDispatchDestroyCache(list[i].ID))
            {
                //if (SyncDebugSystem.IsFilter(typeof(T).Name))
                //{
                //    Debug.Log("在回滚创建列表 " + list[i].ID);
                //}
                EntityBase entity = m_world.GetDispatchDestroyCache(list[i].ID);
                entity.ChangeComp((T)list[i].DeepCopy());
            }
            else if (m_world.GetIsExistDispatchCreateCache(list[i].ID))
            {
                //if (SyncDebugSystem.IsFilter(typeof(T).Name))
                //{
                //    Debug.Log("在回滚删除列表 " + list[i].ID);
                //}
                EntityBase entity = m_world.GetDispatchCreateCache(list[i].ID);
                entity.ChangeComp((T)list[i].DeepCopy());
            }
            else
            {
                //if (SyncDebugSystem.IsFilter(typeof(T).Name))
                //{
                //    Debug.Log("没有找到回滚对象 " + list[i].ID + " frame " + frame);
                //}
            }

            //if (SyncDebugSystem.IsFilter(typeof(T).Name))
            //{
            //    Debug.Log("数据回滚 ID:" + list[i].ID + " frame:" + list[i].Frame + " conent:" + Serializer.Serialize(list[i]));
            //}
        }
    }
    public override void ClearBefore(int frame)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        rc.ClearBefore(frame);

        if (SyncDebugSystem.isDebug)
        {
            Debug.Log("ClearBefore frame:" + frame);
        }
    }
示例#8
0
    public override void OnEntityDestroy(EntityBase entity)
    {
        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        ChangeRecordInfo info = new ChangeRecordInfo();

        info.m_type    = ChangeType.DestroyEntity;
        info.m_EnityID = entity.ID;

        rc.m_changeCache.Add(info);
    }
示例#9
0
 private void GenerateToplist(List <RecordModel> toplist)
 {
     for (int i = 0; i < toplist.Count && i < TOP; i++)
     {
         RecordComponent comp = Instantiate(Record, Toplist);
         comp.gameObject.name = $"${i+1}";
         comp.Get().localPosition = new Vector2(0, -i * RECORD_SIZE - (i > 0 ? RECORD_SIZE * .2f : 0) + START);
         comp.Set(i + 1, toplist[i]);
         comps.Add(comp);
     }
 }
示例#10
0
    void LoadPlayerInput(int frameCount)
    {
        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        for (int i = 0; i < rc.m_recordList.Count; i++)
        {
            if (rc.m_recordList[i].frame == frameCount)
            {
                //todo something
            }
        }
    }
示例#11
0
    void LoadPlayerInput(int frameCount)
    {
        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        for (int i = 0; i < rc.m_recordList.Count; i++)
        {
            if (rc.m_recordList[i].frame == frameCount)
            {
                ExecuteCommand((T)rc.m_recordList[i].m_inputCmd);
            }
        }
    }
示例#12
0
    public void ClearRecordInfo(int frameCount)
    {
        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        for (int i = 0; i < rc.m_recordList.Count; i++)
        {
            if (rc.m_recordList[i].frame >= frameCount)
            {
                rc.m_recordList.RemoveAt(i);
                i--;
            }
        }
    }
示例#13
0
    public override void OnEntityCompRemove(EntityBase entity, string compName, ComponentBase component)
    {
        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        ChangeRecordInfo info = new ChangeRecordInfo();

        info.m_type     = ChangeType.RemoveComp;
        info.m_EnityID  = entity.ID;
        info.m_compName = compName;
        info.m_comp     = component;

        rc.m_changeCache.Add(info);
    }
    public override void RevertToFrame(int frame)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        List <T> list = rc.GetRecordList(frame);

        for (int i = 0; i < list.Count; i++)
        {
            EntityBase entity = m_world.GetEntity(list[i].ID);
            entity.ChangeComp((T)list[i].DeepCopy());

            //Debug.Log("数据回滚 ID:" + list[i].ID + " frame:"+ list[i].Frame +" conent:"+  Serializer.Serialize(list[i]));
        }
    }
示例#15
0
    public void ShowCircles(List <Point> valueList)
    {
        float graphHeight = graphContainer.sizeDelta.y;
        float graphWidth  = graphContainer.sizeDelta.x;

        for (int i = 0; i < valueList.Count; i++)
        {
            float           xPosition        = ((valueList[i].x - xMinimum) / (xMaximum - xMinimum)) * graphWidth;
            float           yPosition        = ((valueList[i].y - yMinimum) / (yMaximum - yMinimum)) * graphHeight;
            GameObject      circleGameObject = CreateCircle(new Vector2(xPosition, yPosition));
            RecordComponent rc = circleGameObject.AddComponent <RecordComponent>();
            rc.r = valueList[i].record;
        }
    }
示例#16
0
    void ExecuteCommand(int frameCount)
    {
        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        for (int i = 0; i < rc.m_recordList.Count; i++)
        {
            if (rc.m_recordList[i].frame == frameCount)
            {
                for (int j = 0; j < rc.m_recordList[i].m_commandList.Count; j++)
                {
                    ExecuteCommand((T)rc.m_recordList[i].m_commandList[j]);
                }
            }
        }
    }
示例#17
0
    public override void LateFixedUpdate(int deltaTime)
    {
        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        RecordInfo info = new RecordInfo();

        info.frame        = m_world.FrameCount;
        info.m_inputCmd   = rc.m_inputCache;
        info.m_changeData = rc.m_changeCache;

        rc.m_recordList.Add(info);

        //清空缓存
        rc.ClearCache();
    }
示例#18
0
    public override MomentComponentBase GetRecord(int id, int frame)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        for (int i = 0; i < rc.m_record.Count; i++)
        {
            if (rc.m_record[i].ID == id &&
                rc.m_record[i].Frame == frame)
            {
                return(rc.m_record[i]);
            }
        }

        return(null);
    }
示例#19
0
    public override void PrintRecord(int id)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        string content = "compName : " + typeof(T).Name + "\n";

        for (int i = 0; i < rc.m_record.Count; i++)
        {
            if (id == -1 || rc.m_record[i].ID == id)
            {
                content += " ID:" + rc.m_record[i].ID + " Frame:" + rc.m_record[i].Frame + " content:" + Serializer.Serialize(rc.m_record[i]) + "\n";
            }
        }
        Debug.LogWarning("PrintRecord:" + content);
    }
示例#20
0
    List <ServiceMessageInfo> LoadMessage(int frameCount)
    {
        List <ServiceMessageInfo> list = new List <ServiceMessageInfo>();
        RecordComponent           rc   = m_world.GetSingletonComp <RecordComponent>();

        for (int i = 0; i < rc.m_messageList.Count; i++)
        {
            if (frameCount == rc.m_messageList[i].m_frame)
            {
                list.Add(rc.m_messageList[i]);
            }
        }

        return(list);
    }
    public override void Record(int frame)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> > ();

        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            T record = (T)list[i].GetComp <T>(hashCode).DeepCopy();
            record.Frame = frame;
            record.ID    = list[i].ID;

            rc.m_record.Add(record);
        }
    }
示例#22
0
    public List <RecordInfo> GetRecordInfo(int frameCount)
    {
        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        List <RecordInfo> list = new List <RecordInfo>();

        for (int i = 0; i < rc.m_recordList.Count; i++)
        {
            if (rc.m_recordList[i].frame >= frameCount)
            {
                list.Add(rc.m_recordList[i]);
            }
        }

        return(list);
    }
示例#23
0
    void ReceviceChangeSingletonCompMsg(ChangeSingletonComponentMsg msg, params object[] objs)
    {
        Debug.Log("ChangeSingletonCompMsg");

        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        ServiceMessageInfo info = new ServiceMessageInfo();

        info.m_frame = msg.frame;
        info.m_type  = MessageType.ChangeSingletonComponent;
        info.m_msg   = msg;

        rc.m_messageList.Add(info);

        Recalc(msg.frame);
    }
示例#24
0
    void ReceviceSyncEntity(SyncEntityMsg msg, params object[] objs)
    {
        Debug.Log("ReceviceSyncEntity");

        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        ServiceMessageInfo info = new ServiceMessageInfo();

        info.m_frame = msg.frame;
        info.m_type  = MessageType.SyncEntity;
        info.m_msg   = msg;

        rc.m_messageList.Add(info);

        Recalc(msg.frame);
    }
示例#25
0
    public RecordInfo GetRecordInfo(int frameCount)
    {
        RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();

        List <RecordInfo> list = new List <RecordInfo>();

        for (int i = 0; i < rc.m_recordList.Count; i++)
        {
            if (rc.m_recordList[i].frame == frameCount)
            {
                return(rc.m_recordList[i]);
            }
        }

        throw new Exception("GetRecordInfo Exception not find record by " + frameCount);
    }
    public override void Record(int frame)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> > ();

        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            T record = (T)list[i].GetComp <T>().DeepCopy();
            record.Frame = frame;
            record.ID    = list[i].ID;

            rc.m_record.Add(record);

            //Debug.Log("数据记录 ID:" + list[i].ID + " frame:" + frame + " conent:" + Serializer.Serialize(record));
        }
    }
示例#27
0
    public override void RevertToFrame(int frame)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        List <T> list = rc.GetRecordList(frame);

        if (SyncDebugSystem.IsFilter(typeof(T).Name))
        {
            Debug.Log("数据回滚  frame:" + frame + " Count:" + list.Count);
        }

        for (int i = 0; i < list.Count; i++)
        {
            if (m_world.GetEntityIsExist(list[i].ID))
            {
                EntityBase entity = m_world.GetEntity(list[i].ID);
                entity.ChangeComp((T)list[i].DeepCopy());
            }
            else if (m_world.GetIsExistCreateRollbackCache(list[i].ID))
            {
                Debug.Log("GetIsExistCreateRollbackCache " + list[i].ID);

                EntityBase entity = m_world.GetCreateRollbackCache(list[i].ID);
                entity.ChangeComp((T)list[i].DeepCopy());
            }
            else if (m_world.GetIsExistDestroyRollbackCache(list[i].ID))
            {
                Debug.Log("GetIsExistDestroyRollbackCache " + list[i].ID);

                EntityBase entity = m_world.GetDestroyRollbackCache(list[i].ID);
                entity.ChangeComp((T)list[i].DeepCopy());
            }
            else
            {
                Debug.Log("没有找到回滚对象 " + list[i].ID + " frame " + frame);
            }

            if (SyncDebugSystem.IsFilter(typeof(T).Name))
            {
                Debug.Log("数据回滚 ID:" + list[i].ID + " frame:" + list[i].Frame + " conent:" + Serializer.Serialize(list[i]));
            }
        }
    }
示例#28
0
    public void ShowGraph(List <Point> valueList)
    {
        float graphHeight = graphContainer.sizeDelta.y - 20f;
        float graphWidth  = graphContainer.sizeDelta.x - 20f;

        //float xSize = 50f;
        foreach (Transform child in graphContainer.transform)
        {
            if (child.name != "background")
            {
                Destroy(child.gameObject);
            }
        }

        GameObject lastCircle = null;

        for (int i = 0; i < valueList.Count; i++)
        {
            float           xPosition        = ((valueList[i].x - xMinimum) / (xMaximum - xMinimum)) * graphWidth;
            float           yPosition        = ((valueList[i].y - yMinimum) / (yMaximum - yMinimum)) * graphHeight;
            GameObject      circleGameObject = CreateCircle(new Vector2(xPosition, yPosition), Color.green);
            RecordComponent rc = circleGameObject.AddComponent <RecordComponent>();
            rc.r = valueList[i].record;

            if (lastCircle == null)
            {
                CreateDotConnection(new Vector2(circleGameObject.GetComponent <RectTransform>().anchoredPosition.x, 10000), circleGameObject.GetComponent <RectTransform>().anchoredPosition);
            }
            if (lastCircle != null)
            {
                CreateDotConnection(lastCircle.GetComponent <RectTransform>().anchoredPosition,
                                    new Vector2(circleGameObject.GetComponent <RectTransform>().anchoredPosition.x, lastCircle.GetComponent <RectTransform>().anchoredPosition.y));
                CreateDotConnection(new Vector2(circleGameObject.GetComponent <RectTransform>().anchoredPosition.x, lastCircle.GetComponent <RectTransform>().anchoredPosition.y),
                                    circleGameObject.GetComponent <RectTransform>().anchoredPosition);
            }
            if (i == valueList.Count - 1)
            {
                CreateDotConnection(circleGameObject.GetComponent <RectTransform>().anchoredPosition, new Vector2(10000, circleGameObject.GetComponent <RectTransform>().anchoredPosition.y));
            }
            lastCircle = circleGameObject;
        }
    }
示例#29
0
    void ReceviceCommandMsg(T cmd, params object[] objs)
    {
        //判断帧数
        if (m_world.FrameCount > cmd.frame)
        {
            RecordInfo info = GetRecordInfo(cmd.frame);
            info.m_commandList.Add(cmd);

            //与本地预测做判断,如果不一致则需要重新演算
            if (!info.GetForecastCmd(cmd.id).Equals(cmd))
            {
                Recalc(cmd.frame);
            }
        }
        //存入缓存
        else
        {
            RecordComponent rc = m_world.GetSingletonComp <RecordComponent>();
            rc.m_commandList.Add(cmd);
        }
    }
示例#30
0
    public override void ClearAfter(int frame)
    {
        RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >();

        rc.ClearAfter(frame);
    }