public ECSGroupManager(WorldBase world)
    {
        for (int i = 0; i < world.m_systemList.Count; i++)
        {
            SystemBase system = world.m_systemList[i];
            int        key    = StringArrayToInt(system.Filter);
            if (allGroupDic.ContainsKey(key))
            {
                //Debug.Log("System :"+ system.GetType().FullName+ "  Filter :" + string.Join(",", system.Filter) + " Dic :"+string.Join(",",allGroupDic[key].Components));
                continue;
            }
            ECSGroup group = new ECSGroup(key, system.Filter);
            allGroupDic.Add(key, group);
            groupToEntityDic.Add(group, new List <EntityBase>());
        }
        for (int i = 0; i < world.m_recordList.Count; i++)
        {
            RecordSystemBase system = world.m_recordList[i];

            int key = StringArrayToInt(system.Filter);
            if (allGroupDic.ContainsKey(key))
            {
                //Debug.Log("System :" + system.GetType().FullName + "  Filter :" + string.Join(",", system.Filter) + " Dic :" + string.Join(",", allGroupDic[key].Components));
                continue;
            }

            ECSGroup group = new ECSGroup(key, system.Filter);
            allGroupDic.Add(key, group);
            groupToEntityDic.Add(group, new List <EntityBase>());
        }
    }
Beispiel #2
0
    void CheckSingleComponentLogic(DebugMsg msg, ComponentInfo info)
    {
        RecordSystemBase   rsb = m_world.GetRecordSystemBase(info.m_compName);
        SingletonComponent sc  = rsb.GetSingletonRecord(msg.frame);

        if (sc == null)
        {
            //Debug.LogWarning("");
            return;
        }

        string content = Serializer.Serialize(sc);

        if (!content.Equals(info.content))
        {
            string log = "error: frame" + msg.frame + " currentFrame:" + m_world.FrameCount + " HashCode " + sc.GetHashCode() + " singleComp:" + info.m_compName + "\n remote:" + info.content + "\n local:" + content + "\n";
            Debug.LogWarning(log);
            rsb.PrintRecord(0);

            Time.timeScale = 0;
            OutPutDebugRecord();
        }
        else
        {
            //Debug.Log("singleComp correct ! frame " + msg.frame + " m_world:" + m_world.FrameCount + "\ncontent " + info.content);
        }
    }
Beispiel #3
0
    //void CheckCurrentFrame(DebugMsg msg)
    //{
    //    //Debug.Log("CheckCurrentFrame " + msg.frame);
    //    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")
    //                {
    //                    CheckCommandLogic(msg, msg.infos[i], msg.infos[i].infos[j]);
    //                }
    //                else
    //                {
    //                    CheckCurrentComponentLogic(msg, entity, msg.infos[i], msg.infos[i].infos[j]);
    //                }
    //            }
    //        }
    //        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;
    //        }
    //    }

    //    for (int i = 0; i < msg.singleCompInfo.Count; i++)
    //    {
    //        CheckCurrentSingleComponentLogic(msg, msg.singleCompInfo[i]);
    //    }
    //}

    //void CheckHistotryFrame(DebugMsg msg)
    //{
    //    //Debug.Log("CheckHistotryFrame");
    //    for (int i = 0; i < msg.infos.Count; i++)
    //    {
    //        if (m_world.GetEntityIsExist(msg.infos[i].id))
    //        {
    //            for (int j = 0; j < msg.infos[i].infos.Count; j++)
    //            {
    //                if (msg.infos[i].infos[j].m_compName == "CommandComponent")
    //                {
    //                    CheckCommandLogic(msg, msg.infos[i], msg.infos[i].infos[j]);
    //                }
    //                else
    //                {
    //                    CheckComponentLogic(msg, msg.infos[i], msg.infos[i].infos[j]);
    //                }
    //            }
    //        }
    //        else
    //        {
    //            //string log = "error not find entity frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + msg.infos[i].id + "\n";
    //            //Debug.LogWarning(log);
    //        }
    //    }

    //    for (int i = 0; i < msg.singleCompInfo.Count; i++)
    //    {
    //        CheckSingleComponentLogic(msg, msg.singleCompInfo[i]);
    //    }
    //}

    //void CheckCurrentCommandLogic(DebugMsg msg, EntityBase entity, EntityInfo entityInfo, ComponentInfo compInfo)
    //{

    //}

    void CheckCurrentComponentLogic(DebugMsg msg, EntityBase entity, EntityInfo entityInfo, ComponentInfo compInfo)
    {
        //Debug.Log("CheckCurrentComponentLogic");

        if (!m_world.GetExistRecordSystem(compInfo.m_compName))
        {
            return;
        }

        ComponentBase compLocal = entity.GetComp(compInfo.m_compName);

        if (IsFilter(compInfo.m_compName))
        {
            string content = Serializer.Serialize(compLocal);

            if (!content.Equals(compInfo.content))
            {
                RecordSystemBase rsb = m_world.GetRecordSystemBase(compInfo.m_compName);

                string log = "error: frame" + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + entity.ID + " msg.id " + entityInfo.id + " comp:" + compInfo.m_compName + "\n remote:" + compInfo.content + "\n local:" + content + "\n";
                Debug.LogWarning(log);
                rsb.PrintRecord(entity.ID);

                //派发冲突
                GlobalEvent.DispatchEvent(c_isConflict, msg.frame);

                Time.timeScale = 0;
                OutPutDebugRecord();
            }
            else
            {
                //Debug.Log("ReceviceDebugMsg  correct! frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + entity.ID + " msg.id " + entityInfo.id + " comp:" + compInfo.m_compName + " content :" + compInfo.content);
            }
        }
    }
Beispiel #4
0
    public void Init(bool isView)
    {
        m_isView = isView;
        try
        {
            Type[] types = GetSystemTypes();

            for (int i = 0; i < types.Length; i++)
            {
                SystemBase tmp = (SystemBase)types[i].Assembly.CreateInstance(types[i].FullName);
                m_systemList.Add(tmp);
                tmp.m_world = this;
                tmp.Init();
            }

            //初始化RecordSystemBase

            types = GetRecordSystemTypes();
            for (int i = 0; i < types.Length; i++)
            {
                Type type = typeof(RecordSystem <>);
                type = type.MakeGenericType(types[i]);

                RecordSystemBase tmp = (RecordSystemBase)Activator.CreateInstance(type);;
                m_recordList.Add(tmp);
                m_recordDict.Add(types[i].Name, tmp);
                tmp.m_world = this;
                tmp.Init();
            }
        }
        catch (Exception e)
        {
            Debug.LogError("WorldBase Init Exception:" + e.ToString());
        }
    }
    void CheckComponentLogic(DebugMsg msg, EntityInfo entityInfo, ComponentInfo compInfo)
    {
        //Debug.Log("CheckComponentLogic");

        if (!m_world.GetExistRecordSystem(compInfo.m_compName))
        {
            return;
        }

        RecordSystemBase rsb       = m_world.GetRecordSystemBase(compInfo.m_compName);
        ComponentBase    compLocal = rsb.GetRecord(entityInfo.id, msg.frame);

        if (IsFilter(compInfo.m_compName))
        {
            if (compLocal != null)
            {
                string content = Serializer.Serialize(compLocal);

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

                    Time.timeScale = 0;
                    Record(log);
                    OutPutDebugRecord();
                }
                else
                {
                    //Debug.Log("ReceviceDebugMsg  correct! frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + entityInfo.id + " comp:" + compInfo.m_compName + " content :" + compInfo.content);
                }

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

                //Debug.LogWarning(log);
                //syncLog += log;
            }
        }
        else
        {
            Debug.Log("Not is filter " + compInfo.m_compName);
        }
    }
Beispiel #6
0
    void InitRecordSystem()
    {
        //初始化RecordSystem
        Type[] types = GetRecordTypes();
        for (int i = 0; i < types.Length; i++)
        {
            Type type = typeof(RecordSystem <>);
            type = type.MakeGenericType(types[i]);

            RecordSystemBase tmp = (RecordSystemBase)Activator.CreateInstance(type);;
            m_recordList.Add(tmp);
            m_recordDict.Add(types[i].Name, tmp);
            tmp.m_world = this;
            tmp.Init();
        }
    }
    void CheckCurrentSingleComponentLogic(DebugMsg msg, ComponentInfo info)
    {
        SingletonComponent sc = m_world.GetSingletonComp(info.m_compName);

        string content = Serializer.Serialize(sc);

        if (!content.Equals(info.content))
        {
            RecordSystemBase rsb = m_world.GetRecordSystemBase(info.m_compName);
            string           log = "error: frame" + msg.frame + " currentFrame:" + m_world.FrameCount + " singleComp:" + info.m_compName + "\n remote:" + info.content + "\n local:" + content + "\n";
            Debug.LogWarning(log);
            rsb.PrintRecord(0);
        }
        else
        {
            Debug.Log("singleComp correct ! frame " + msg.frame + " m_world:" + m_world.FrameCount + "\ncontent " + info.content);
        }
    }
    void InitRecordSystem()
    {
        //初始化RecordSystem
        Type[] types = GetRecordTypes();
        for (int i = 0; i < types.Length; i++)
        {
            if (types[i].IsSubclassOf(typeof(MomentComponentBase)))
            {
                Type type = typeof(RecordSystem <>);
                type = type.MakeGenericType(types[i]);

                RecordSystemBase tmp = (RecordSystemBase)Activator.CreateInstance(type);;
                m_recordList.Add(tmp);
                m_recordDict.Add(types[i].Name, tmp);
                tmp.m_world = this;
                tmp.Init();
            }
            else
            {
                Debug.LogError(types[i].FullName + " not is MomentComponent!");
            }
        }

        types = GetRecordSingletonTypes();
        for (int i = 0; i < types.Length; i++)
        {
            if (types[i].IsSubclassOf(typeof(MomentSingletonComponent)))
            {
                Type type = typeof(RecordSingletonSystem <>);
                type = type.MakeGenericType(types[i]);

                RecordSystemBase tmp2 = (RecordSystemBase)Activator.CreateInstance(type);;
                m_recordList.Add(tmp2);
                m_recordDict.Add(types[i].Name, tmp2);
                tmp2.m_world = this;
                tmp2.Init();
            }
            else
            {
                Debug.LogError(types[i].FullName + " not is MomentSingletonComponent!");
            }
        }
    }
Beispiel #9
0
    public ECSGroupManager(WorldBase world)
    {
        //this.world = world;

        for (int i = 0; i < world.m_systemList.Count; i++)
        {
            SystemBase system = world.m_systemList[i];
            string     name   = system.GetType().FullName;
            ECSGroup   group  = new ECSGroup(name, system.Filter);
            allGroupDic.Add(name, group);
            groupToEntityDic.Add(group, new List <EntityBase>());
        }
        for (int i = 0; i < world.m_recordList.Count; i++)
        {
            RecordSystemBase system = world.m_recordList[i];
            string           name   = system.GetType().FullName;
            ECSGroup         group  = new ECSGroup(name, system.Filter);
            allGroupDic.Add(name, group);
            groupToEntityDic.Add(group, new List <EntityBase>());
        }
    }
Beispiel #10
0
    void CheckCurrentSingleComponentLogic(DebugMsg msg, ComponentInfo info)
    {
        SingletonComponent sc = m_world.GetSingletonComp(info.m_compName);

        if (info.m_compName == "MapGridStateComponent")
        {
            //MapGridStateComponent lmsc = (MapGridStateComponent)sc;

            //MapGridStateComponent msc = des.Deserialize<MapGridStateComponent>(info.content);

            //if(!JudgeDict(msc.globalRandomCellHaveItemList, lmsc.globalRandomCellHaveItemList))
            //{
            //    string content = Serializer.Serialize(sc);
            //    string log = "error: frame" + msg.frame + " currentFrame:" + m_world.FrameCount + " singleComp:" + info.m_compName + "\n remote:" + info.content + "\n local:" + content + "\n";
            //    Debug.LogWarning(log);

            //    OutPutDebugRecord();
            //}
        }
        else
        {
            string content = Serializer.Serialize(sc);

            if (!content.Equals(info.content))
            {
                RecordSystemBase rsb = m_world.GetRecordSystemBase(info.m_compName);
                string           log = "error: frame" + msg.frame + " currentFrame:" + m_world.FrameCount + " singleComp:" + info.m_compName + "\n remote:" + info.content + "\n local:" + content + "\n";
                Debug.LogWarning(log);
                rsb.PrintRecord(0);

                Time.timeScale = 0;
                OutPutDebugRecord();
            }
            else
            {
                //Debug.Log("singleComp correct ! frame " + msg.frame + " m_world:" + m_world.FrameCount + "\ncontent " + info.content);
            }
        }
    }
    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;
        }
    }
Beispiel #12
0
    public void ReceviceDebugMsg(DebugMsg msg, params object[] objs)
    {
        if (!isDebug)
        {
            return;
        }

        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);

                        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);

                            Debug.LogWarning("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);
                            rsb.PrintRecord(entity.ID);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("error not find entity frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + msg.infos[i].id);
                }
            }
        }
        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++)
                    {
                        RecordSystemBase rsb = m_world.GetRecordSystemBase(msg.infos[i].infos[j].m_compName);

                        ComponentBase compLocal = rsb.GetRecord(msg.infos[i].id, msg.frame);

                        if (compLocal != null)
                        {
                            string content = Serializer.Serialize(compLocal);

                            if (!content.Equals(msg.infos[i].infos[j].content))
                            {
                                Debug.LogWarning("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);
                                rsb.PrintRecord(entity.ID);
                            }
                        }
                        else
                        {
                            Debug.LogWarning("not find Record ->> frame:" + msg.frame + " id " + msg.infos[i].id + " compName: " + msg.infos[i].infos[j].m_compName);
                            rsb.PrintRecord(entity.ID);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("error not find entity frame " + msg.frame + " currentFrame:" + m_world.FrameCount + " id:" + msg.infos[i].id);
                }
            }
        }
        else
        {
            Debug.LogWarning("服务器超前 msg:" + msg.frame + " m_world:" + m_world.FrameCount);
        }
    }