コード例 #1
0
    /// <summary>
    /// 绘制单例组件
    /// </summary>
    /// <param name="world"></param>
    private void ShowSingleComponentGUI(WorldBase world)
    {
        List <SingletonComponent> components = new List <SingletonComponent>(world.m_singleCompDict.Values);
        List <string>             names      = new List <string>();

        foreach (var item in components)
        {
            names.Add(GetTypeName(item));
            //  DrawComponent(item);
        }
        selectInt0 = ShowLeftPartWindow("Components", names, selectInt0);
        if (selectInt0 != -1)
        {
            ShowRightPartWindow(() =>
            {
                if (components.Count == 0)
                {
                    return;
                }
                if (selectInt0 >= components.Count)
                {
                    selectInt0 = components.Count - 1;
                }

                SingletonComponent component = components[selectInt0];
                DrawComponent(component);
            });
        }
    }
コード例 #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);
        }
    }
コード例 #3
0
    public T GetSingletonComp <T>() where T : SingletonComponent, new()
    {
        Type type = typeof(T);

        string key = typeof(T).Name;

        if (type.IsGenericType)
        {
            key += type.GetGenericArguments()[0].Name;
        }

        SingletonComponent comp = null;

        if (m_singleCompDict.ContainsKey(key))
        {
            comp = m_singleCompDict[key];
        }
        else
        {
            comp = new T();
            comp.Init();
            m_singleCompDict.Add(key, comp);
        }

        return((T)comp);
    }
コード例 #4
0
        public void Compose()
        {
            var component      = new SingletonComponent <ITestComponent, TestComponent>();
            var composeResultA = component.Compose(this.Composer, false, this.ConstructorSelector);
            var composeResultB = component.Compose(this.Composer, false, this.ConstructorSelector);

            Assert.Equal(composeResultA, composeResultB);
        }
コード例 #5
0
    void ExecuteChangeSingletonCompMsg(ChangeSingletonComponentMsg msg)
    {
        //Debug.Log("msg.info.m_compName " + msg.info.m_compName + " " + Type.GetType(msg.info.m_compName));

        SingletonComponent comp = (SingletonComponent)deserializer.Deserialize(msg.info.m_compName, msg.info.content);

        m_world.ChangeSingleComp(msg.info.m_compName, comp);
    }
コード例 #6
0
        public IComponentContainerRegisterAsSingletonSyntax <TComponentType, TImplementation> AsSingleton()
        {
            var component = new SingletonComponent <TComponentType, TImplementation>();

            this.Container.ReplaceRegisteredComponent <TComponentType>(component);

            return(new ComponentContainerRegisterAsSingletonSyntax <TComponentType, TImplementation>(this.Container));
        }
コード例 #7
0
 public void Register_singleton_should_be_supported()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         var singleton = new SingletonComponent();
         builder.RegisterInstance <ISingletonComponent, SingletonComponent>(singleton);
         Assert.AreEqual(builder.Resolve <ISingletonComponent>(), singleton);
     }
 }
コード例 #8
0
        public void Dispose()
        {
            var component = new SingletonComponent <ITestComponent, TestComponent>();

            component.Dispose();

            Assert.Throws <ObjectDisposedException>(
                () => component.Compose(this.Composer, false, this.ConstructorSelector));
        }
コード例 #9
0
        public void PrepareCompositionWithNullConstructorSelector()
        {
            Assert.Throws <ArgumentNullException>(
                () =>
            {
                var component = new SingletonComponent <ITestComponent, TestComponent>();

                component.PrepareComposition(this.Composer, null);
            });
        }
コード例 #10
0
        public void ComposeWithNullComposer()
        {
            Assert.Throws <ArgumentNullException>(
                () =>
            {
                var component = new SingletonComponent <ITestComponent, TestComponent>();

                component.Compose(null, false, this.ConstructorSelector);
            });
        }
コード例 #11
0
        public void PushSingletonComp(SyncSession session, string compName)
        {
            SingletonComponent          comp = m_world.GetSingletonComp(compName);
            ChangeSingletonComponentMsg msg  = new ChangeSingletonComponentMsg();

            msg.info.m_compName = compName;
            msg.info.content    = Serializer.Serialize(comp);
            msg.frame           = m_world.FrameCount;

            session.SendMsg(msg);
        }
コード例 #12
0
 public void ChangeSingleComp(string compName, SingletonComponent comp)
 {
     if (m_singleCompDict.ContainsKey(compName))
     {
         m_singleCompDict[compName] = comp;
     }
     else
     {
         m_singleCompDict.Add(compName, comp);
     }
 }
コード例 #13
0
 public void Register_singleton_should_be_supported()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         var singleton = new SingletonComponent();
         builder.RegisterSingleton(typeof(ISingletonComponent), singleton);
         builder.RegisterSingleton(typeof(SingletonComponent), singleton);
         Assert.AreEqual(builder.Build(typeof(SingletonComponent)), singleton);
         Assert.AreEqual(builder.Build(typeof(ISingletonComponent)), singleton);
     }
 }
コード例 #14
0
        public void PrepareComposition()
        {
            var composer  = Mock.Of <IComponentComposer>();
            var component = new SingletonComponent <ITestComponent, TestComponent>();

            component.PrepareComposition(composer, this.ConstructorSelector);

            var mockComposer = Mock.Get(composer);

            mockComposer.Verify(
                c => c.PrepareToComposeUsingConstructor(typeof(TestComponent), this.ConstructorSelector),
                Times.Once);
        }
コード例 #15
0
        public void Register_singleton_should_be_supported()
        {
            var singleton         = new SingletonComponent();
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton(typeof(ISingletonComponent), singleton);
            serviceCollection.AddSingleton(typeof(SingletonComponent), singleton);

            var builder = BuildContainer(serviceCollection);

            Assert.AreEqual(builder.GetService(typeof(SingletonComponent)), singleton);
            Assert.AreEqual(builder.GetService(typeof(ISingletonComponent)), singleton);
        }
コード例 #16
0
        public void Register_singleton_should_be_supported()
        {
            var singleton           = new SingletonComponent();
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

            configureComponents.RegisterSingleton(typeof(ISingletonComponent), singleton);
            configureComponents.RegisterSingleton(typeof(SingletonComponent), singleton);

            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            Assert.AreEqual(builder.GetService(typeof(SingletonComponent)), singleton);
            Assert.AreEqual(builder.GetService(typeof(ISingletonComponent)), singleton);
        }
コード例 #17
0
    public void PushSingletonComp(SyncSession session, string compName)
    {
        Debug.Log("PushSingletonComp " + compName);

        SingletonComponent          comp = m_world.GetSingletonComp(compName);
        ChangeSingletonComponentMsg msg  = new ChangeSingletonComponentMsg();

        msg.info            = new ComponentInfo();
        msg.info.m_compName = compName;
        msg.info.content    = Serializer.Serialize(comp);
        msg.frame           = m_world.FrameCount;

        ProtocolAnalysisService.SendMsg(session, msg);
    }
コード例 #18
0
    public void ChangeSingleComp(string compName, SingletonComponent comp)
    {
        if (m_singleCompDict.ContainsKey(compName))
        {
            int index = componentType.GetComponentIndex(compName);
            heapComponentPool.PutObject(index, m_singleCompDict[compName]);
            m_singleCompDict[compName] = comp;
        }
        else
        {
            m_singleCompDict.Add(compName, comp);
        }

        comp.World = this;
    }
コード例 #19
0
        public void Run()
        {
            UInt32 SDLStart  = SDL2.SDL.SDL_GetTicks();
            UInt32 LastValue = SDL2.SDL.SDL_GetTicks();

            GameTimeUpdateComponent Value = SingletonComponent <GameTimeUpdateComponent> .Get();

            while (!QuitLoop)
            {
                SDLStart = SDL2.SDL.SDL_GetTicks();
                Value.UpdateTime((SDLStart - LastValue) / 1000f);
                SDL2.SDL.SDL_PumpEvents();
                myWorldManager.Update();
                LastValue = SDL2.SDL.SDL_GetTicks();
            }
        }
コード例 #20
0
        public void Should_not_dispose_singletons_when_container_goes_out_of_scope()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                var singletonInMainContainer = new SingletonComponent();

                builder.RegisterSingleton(typeof(ISingletonComponent), singletonInMainContainer);
                builder.Configure(typeof(ComponentThatDependsOfSingleton), DependencyLifecycle.InstancePerUnitOfWork);

                using (var nestedContainer = builder.BuildChildContainer())
                {
                    nestedContainer.Build(typeof(ComponentThatDependsOfSingleton));
                }
                Assert.False(SingletonComponent.DisposeCalled);
            }
        }
コード例 #21
0
        public void Should_not_dispose_singletons_when_container_goes_out_of_scope()
        {
            var serviceCollection        = new ServiceCollection();
            var singletonInMainContainer = new SingletonComponent();

            serviceCollection.AddSingleton(typeof(ISingletonComponent), singletonInMainContainer);
            serviceCollection.ConfigureComponent(typeof(ComponentThatDependsOfSingleton), DependencyLifecycle.InstancePerUnitOfWork);

            var builder = BuildContainer(serviceCollection);

            using (var scope = builder.CreateScope())
            {
                scope.ServiceProvider.GetService(typeof(ComponentThatDependsOfSingleton));
            }
            Assert.False(SingletonComponent.DisposeCalled);
        }
コード例 #22
0
    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);
        }
    }
コード例 #23
0
    public T GetSingletonComp <T>()  where T : SingletonComponent, new()
    {
        string key = typeof(T).Name;

        SingletonComponent comp = null;

        if (m_singleCompDict.ContainsKey(key))
        {
            comp = m_singleCompDict[key];
        }
        else
        {
            comp = new T();
            m_singleCompDict.Add(key, comp);
        }

        return((T)comp);
    }
コード例 #24
0
    public SingletonComponent GetSingletonComp(string compName)
    {
        SingletonComponent comp = null;

        if (m_singleCompDict.ContainsKey(compName))
        {
            comp = m_singleCompDict[compName];
        }
        else
        {
            Type compType = Type.GetType(compName);

            comp = (SingletonComponent)compType.Assembly.CreateInstance(compType.FullName);
            m_singleCompDict.Add(compName, comp);
        }

        return(comp);
    }
コード例 #25
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);
            }
        }
    }
コード例 #26
0
    public SingletonComponent GetSingletonComp(string compName)
    {
        //int index = componentType.GetComponentIndex(compName);
        SingletonComponent comp = null;

        if (m_singleCompDict.ContainsKey(compName))
        {
            comp = m_singleCompDict[compName];
        }
        else
        {
            Type compType = Type.GetType(compName);

            comp = (SingletonComponent)compType.Assembly.CreateInstance(compType.FullName);
            comp.Init();
            comp.World = this;
            //singletonComponents[index] = comp;
            m_singleCompDict.Add(compName, comp);
        }

        return(comp);
    }
コード例 #27
0
    public override void EndFrame(int deltaTime)
    {
        if (!isDebug)
        {
            return;
        }

        DebugMsg msg = new DebugMsg();

        msg.frame          = m_world.FrameCount;
        msg.seed           = m_world.m_RandomSeed;
        msg.infos          = new List <EntityInfo>();
        msg.singleCompInfo = new List <ComponentInfo>();

        for (int i = 0; i < m_world.m_entityList.Count; i++)
        {
            msgCache.Append(m_world.m_entityList[i].ID + "\n");
        }

        msg.msg = msgCache.ToString();

        msgCache.Clear();

        for (int i = 0; i < m_world.m_entityList.Count; i++)
        {
            EntityBase eb = m_world.m_entityList[i];

            bool isFilter = false;
            if (isPlayerOnly &&
                !eb.GetExistComp(ComponentType.ConnectionComponent))
            {
                isFilter = true;
            }

            if (isFlyObject &&
                !eb.GetExistComp(ComponentType.FlyObjectComponent))
            {
                isFilter = true;
            }

            if (isFilter)
            {
                continue;
            }

            EntityInfo einfo = new EntityInfo();
            einfo.id = eb.ID;

            einfo.infos = new List <ComponentInfo>();

            foreach (var item in eb.comps)
            {
                if (item == null)
                {
                    continue;
                }

                if (item.GetType().IsSubclassOf(typeof(PlayerCommandBase)))
                {
                    CommandComponent cc   = (CommandComponent)item;
                    ComponentInfo    info = new ComponentInfo();
                    cc.time         = 0;
                    cc.id           = eb.ID;
                    cc.frame        = m_world.FrameCount;
                    info.m_compName = item.GetType().Name;
                    info.content    = Serializer.Serialize(item);

                    einfo.infos.Add(info);
                }
                else if (IsFilter(item.GetType().Name))
                {
                    ComponentInfo info = new ComponentInfo();
                    info.m_compName = item.GetType().Name;
                    info.content    = Serializer.Serialize(item);

                    einfo.infos.Add(info);
                }
            }

            if (einfo.infos.Count > 0)
            {
                msg.infos.Add(einfo);
            }
        }

        for (int i = 0; i < SingleCompFilter.Length; i++)
        {
            SingletonComponent sc   = m_world.GetSingletonComp(SingleCompFilter[i]);
            ComponentInfo      info = new ComponentInfo();

            info.m_compName = SingleCompFilter[i];
            info.content    = Serializer.Serialize(sc);

            if (info.m_compName == "MapGridStateComponent")
            {
                MapGridStateComponent lmsc = (MapGridStateComponent)sc;
                MapGridStateComponent msc  = des.Deserialize <MapGridStateComponent>(info.content);

                if (!JudgeDict(msc.globalRandomCellHaveItemList, lmsc.globalRandomCellHaveItemList))
                {
                    Debug.Log("验证错误" + m_world.FrameCount);
                }
                else
                {
                    Debug.Log("验证通过 " + m_world.FrameCount);
                }
            }

            msg.singleCompInfo.Add(info);
        }

        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent cc = list[i].GetComp <ConnectionComponent>();
            ProtocolAnalysisService.SendMsg(cc.m_session, msg);
        }
    }
コード例 #28
0
        public void Should_not_dispose_singletons_when_container_goes_out_of_scope()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                var singletonInMainContainer = new SingletonComponent();

                builder.RegisterSingleton(typeof(ISingletonComponent), singletonInMainContainer);
                builder.Configure(typeof(ComponentThatDependsOfSingleton), DependencyLifecycle.InstancePerUnitOfWork);

                using (var nestedContainer = builder.BuildChildContainer())
                {
                    nestedContainer.Build(typeof(ComponentThatDependsOfSingleton));
                }
                Assert.False(SingletonComponent.DisposeCalled);
            }
        }
コード例 #29
0
		public SingletonDependency(SingletonComponent c)
		{
		}
コード例 #30
0
    public override void EndFrame(int deltaTime)
    {
        if (!isDebug)
        {
            return;
        }

        DebugMsg msg = new DebugMsg();

        msg.frame          = m_world.FrameCount;
        msg.seed           = m_world.m_RandomSeed;
        msg.infos          = new List <EntityInfo>();
        msg.singleCompInfo = new List <ComponentInfo>();

        for (int i = 0; i < m_world.m_entityList.Count; i++)
        {
            EntityBase eb = m_world.m_entityList[i];

            if (isPlayerOnly &&
                !eb.GetExistComp <ConnectionComponent>())
            {
                continue;
            }

            EntityInfo einfo = new EntityInfo();
            einfo.id = eb.ID;

            einfo.infos = new List <ComponentInfo>();

            foreach (var item in eb.CompDict)
            {
                if (item.Value.GetType().IsSubclassOf(typeof(PlayerCommandBase)))
                {
                    CommandComponent cc   = (CommandComponent)item.Value;
                    ComponentInfo    info = new ComponentInfo();
                    cc.time         = 0;
                    cc.id           = eb.ID;
                    cc.frame        = m_world.FrameCount;
                    info.m_compName = item.Value.GetType().Name;
                    info.content    = Serializer.Serialize(item.Value);

                    einfo.infos.Add(info);
                }
                else if (IsFilter(item.Value.GetType().Name))
                {
                    ComponentInfo info = new ComponentInfo();
                    info.m_compName = item.Value.GetType().Name;
                    info.content    = Serializer.Serialize(item.Value);

                    einfo.infos.Add(info);
                }
            }

            if (einfo.infos.Count > 0)
            {
                msg.infos.Add(einfo);
            }
        }

        for (int i = 0; i < SingleCompFilter.Length; i++)
        {
            SingletonComponent sc   = m_world.GetSingletonComp(SingleCompFilter[i]);
            ComponentInfo      info = new ComponentInfo();

            info.m_compName = SingleCompFilter[i];
            info.content    = Serializer.Serialize(sc);

            msg.singleCompInfo.Add(info);
        }

        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent cc = list[i].GetComp <ConnectionComponent>();
            ProtocolAnalysisService.SendMsg(cc.m_session, msg);
        }
    }
コード例 #31
0
        public OneToManySystem(World myBase, int SystemLevel = 1) : base(SystemLevel)
        {
            myReferenceSingleton = SingletonComponent <T> .Get();

            myIterator = new EntityIteratorDefault <U>(myBase);
        }
コード例 #32
0
    void ExecuteChangeSingletonCompMsg(ChangeSingletonComponentMsg msg)
    {
        SingletonComponent comp = (SingletonComponent)deserializer.Deserialize(msg.info.m_compName, msg.info.content);

        m_world.ChangeSingleComp(msg.info.m_compName, comp);
    }