Cleanup() public method

public Cleanup ( ) : void
return void
        void Update()
        {
            if (PhotonNetwork.isMasterClient)
            {
                if (!_serverSystemsInitialized)
                {
                    _serverSystemsInitialized = true;
                    _serverSystems.Initialize();
                }
                _serverSystems.Execute();
                _serverSystems.Cleanup();
            }


            _systems.Execute();
            _systems.Cleanup();
        }
        public void RemoveDeletedEntities()
        {
            //
            // Remove game entities, all children are included
            //
            if (Global.GameEntityToDestroy.Count > 0)
            {
                foreach (KeyValuePair <Entity, bool> ent in Global.GameEntityToDestroy)
                {
                    ent.Key.RemoveAllComponents();
                    ent.Key.Destroy();                                                          //release entity automatically

                    //GameEntities.Remove(ent.Key);
                }
                Global.GameEntityToDestroy = new Dictionary <Entity, bool>();
            }
            //
            // Remove Scene specific entities (UI?)
            //
            if (Global.SceneEntityToDestroy.Count > 0)
            {
                foreach (KeyValuePair <Entity, bool> ent in Global.SceneEntityToDestroy)
                {
                    ent.Key.RemoveAllComponents();
                    ent.Key.Destroy();

                    //GameEntities.Remove(ent.Key);
                }
                Global.SceneEntityToDestroy = new Dictionary <Entity, bool>();
            }
            //
            // Do ECS update/cleanup
            //
            //EntitySystems.Execute();
            EntitySystems.Cleanup();
        }
    void Start()
    {
        _contexts = new Contexts();
        _contexts.visualDebugging = new Context(
            VisualDebuggingComponentIds.TotalComponents, 0,
            new ContextInfo(
                "Systems Context",
                VisualDebuggingComponentIds.componentNames,
                VisualDebuggingComponentIds.componentTypes
            )
        );

        #if(!ENTITAS_DISABLE_VISUAL_DEBUGGING && UNITY_EDITOR)
        new ContextObserver(_contexts.visualDebugging);
        #endif

        _systems = createNestedSystems();

        //// Test call
        _systems.Initialize();
        _systems.Execute();
        _systems.Cleanup();
        _systems.TearDown();

        _contexts.visualDebugging.CreateEntity().AddMyString("");
    }
Example #4
0
 private void Update()
 {
     systems.Execute();
     systems.Cleanup();
 }
    void when_systems()
    {
        Contexts contexts = null;

        before = () => {
            contexts = new Contexts { test = new Context(10) };
        };

        context["fixtures"] = () => {

            it["initializes InitializeSystemSpy"] = () => {
                var system = new InitializeSystemSpy();
                system.didInitialize.should_be(0);
                system.Initialize();
                system.didInitialize.should_be(1);
            };

            it["executes ExecuteSystemSpy"] = () => {
                var system = new ExecuteSystemSpy();
                system.didExecute.should_be(0);
                system.Execute();
                system.didExecute.should_be(1);
            };

            it["cleans up CleanupSystemSpy"] = () => {
                var system = new CleanupSystemSpy();
                system.didCleanup.should_be(0);
                system.Cleanup();
                system.didCleanup.should_be(1);
            };

            it["tears down TearDownSystemSpy"] = () => {
                var system = new TearDownSystemSpy();
                system.didTearDown.should_be(0);
                system.TearDown();
                system.didTearDown.should_be(1);
            };

            it["initializes, executes, cleans up and tears down system"] = () => {
                var system = new ReactiveSystemSpy(contexts.test.CreateCollector(Matcher.AllOf(CID.ComponentA)));
                contexts.test.CreateEntity().AddComponentA();

                system.didInitialize.should_be(0);
                system.Initialize();
                system.didInitialize.should_be(1);

                system.didExecute.should_be(0);
                system.Execute();
                system.didExecute.should_be(1);

                system.didCleanup.should_be(0);
                system.Cleanup();
                system.didCleanup.should_be(1);

                system.didTearDown.should_be(0);
                system.TearDown();
                system.didTearDown.should_be(1);
            };

            it["executes ReactiveSystemSpy"] = () => {
                var system = createReactiveSystem(contexts);

                system.Execute();

                system.entities.Length.should_be(1);
            };
        };

        context["systems"] = () => {

            Systems systems = null;

            before = () => {
                systems = new Systems();
            };

            it["returns systems when adding system"] = () => {
                systems.Add(new InitializeSystemSpy()).should_be_same(systems);
            };

            it["initializes IInitializeSystem"] = () => {
                var system = new InitializeSystemSpy();
                systems.Add(system);
                systems.Initialize();
                system.didInitialize.should_be(1);
            };

            it["executes IExecuteSystem"] = () => {
                var system = new ExecuteSystemSpy();
                systems.Add(system);
                systems.Execute();
                system.didExecute.should_be(1);
            };

            it["wraps IReactiveSystem in a ReactiveSystem"] = () => {
                var system = new ReactiveSystemSpy(contexts.test.CreateCollector(Matcher.AllOf(CID.ComponentA)));
                systems.Add(system);
                contexts.test.CreateEntity().AddComponentA();
                systems.Execute();
                system.didExecute.should_be(1);
            };

            it["adds ReactiveSystem"] = () => {
                var system = new ReactiveSystemSpy(contexts.test.CreateCollector(Matcher.AllOf(CID.ComponentA)));
                systems.Add(system);
                contexts.test.CreateEntity().AddComponentA();
                systems.Execute();
                system.didExecute.should_be(1);
            };

            it["cleans up ICleanupSystem"] = () => {
                var system = new CleanupSystemSpy();
                systems.Add(system);
                systems.Cleanup();
                system.didCleanup.should_be(1);
            };

            it["initializes, executes, cleans up and tears down InitializeExecuteCleanupTearDownSystemSpy"] = () => {
                var system = new ReactiveSystemSpy(contexts.test.CreateCollector(Matcher.AllOf(CID.ComponentA)));
                contexts.test.CreateEntity().AddComponentA();

                systems.Add(system);

                system.didInitialize.should_be(0);
                systems.Initialize();
                system.didInitialize.should_be(1);

                system.didExecute.should_be(0);
                systems.Execute();
                system.didExecute.should_be(1);

                system.didCleanup.should_be(0);
                systems.Cleanup();
                system.didCleanup.should_be(1);

                system.didTearDown.should_be(0);
                systems.TearDown();
                system.didTearDown.should_be(1);
            };

            it["initializes, executes, cleans up and tears down ReactiveSystem"] = () => {
                var system = createReactiveSystem(contexts);

                systems.Add(system);

                system.didInitialize.should_be(0);
                systems.Initialize();
                system.didInitialize.should_be(1);

                system.didExecute.should_be(0);
                systems.Execute();
                systems.Execute();
                system.didExecute.should_be(1);

                system.didCleanup.should_be(0);
                systems.Cleanup();
                system.didCleanup.should_be(1);

                system.didTearDown.should_be(0);
                systems.TearDown();
                system.didTearDown.should_be(1);
            };

            it["initializes, executes, cleans up and tears down systems recursively"] = () => {
                var system = createReactiveSystem(contexts);

                systems.Add(system);

                var parentSystems = new Systems();
                parentSystems.Add(systems);

                system.didInitialize.should_be(0);
                parentSystems.Initialize();
                system.didInitialize.should_be(1);

                system.didExecute.should_be(0);
                parentSystems.Execute();
                parentSystems.Execute();
                system.didExecute.should_be(1);

                system.didCleanup.should_be(0);
                parentSystems.Cleanup();
                system.didCleanup.should_be(1);

                system.didTearDown.should_be(0);
                parentSystems.TearDown();
                system.didTearDown.should_be(1);
            };

            it["clears reactive systems"] = () => {
                var system = createReactiveSystem(contexts);

                systems.Add(system);

                systems.Initialize();
                system.didInitialize.should_be(1);

                systems.ClearReactiveSystems();
                systems.Execute();
                system.didExecute.should_be(0);
            };

            it["clears reactive systems recursively"] = () => {
                var system = createReactiveSystem(contexts);
                systems.Add(system);

                var parentSystems = new Systems();
                parentSystems.Add(systems);

                parentSystems.Initialize();
                system.didInitialize.should_be(1);

                parentSystems.ClearReactiveSystems();
                parentSystems.Execute();
                system.didExecute.should_be(0);
            };

            it["deactivates reactive systems"] = () => {
                var system = createReactiveSystem(contexts);

                systems.Add(system);

                systems.Initialize();
                system.didInitialize.should_be(1);

                systems.DeactivateReactiveSystems();
                systems.Execute();
                system.didExecute.should_be(0);
            };

            it["deactivates reactive systems recursively"] = () => {
                var system = createReactiveSystem(contexts);
                systems.Add(system);

                var parentSystems = new Systems();
                parentSystems.Add(systems);

                parentSystems.Initialize();
                system.didInitialize.should_be(1);

                parentSystems.DeactivateReactiveSystems();
                parentSystems.Execute();
                system.didExecute.should_be(0);
            };

            it["activates reactive systems"] = () => {
                var system = createReactiveSystem(contexts);

                systems.Add(system);

                systems.Initialize();
                system.didInitialize.should_be(1);

                systems.DeactivateReactiveSystems();
                systems.ActivateReactiveSystems();
                systems.Execute();
                system.didExecute.should_be(0);

                contexts.test.CreateEntity().AddComponentA();
                systems.Execute();

                system.didExecute.should_be(1);
            };

            it["activates reactive systems recursively"] = () => {
                var system = createReactiveSystem(contexts);
                systems.Add(system);

                var parentSystems = new Systems();
                parentSystems.Add(systems);

                parentSystems.Initialize();
                system.didInitialize.should_be(1);

                parentSystems.DeactivateReactiveSystems();
                parentSystems.ActivateReactiveSystems();
                parentSystems.Execute();
                system.didExecute.should_be(0);

                contexts.test.CreateEntity().AddComponentA();
                systems.Execute();

                system.didExecute.should_be(1);
            };
        };
    }
Example #6
0
 // Update is called once per frame
 void Update()
 {
     _systems.Execute();
     _systems.Cleanup();
 }