コード例 #1
0
        public void InitializesExecutesCleansUpAndTearsDownSystemsRecursively()
        {
            var system = CreateReactiveSystem(_ctx);

            _systems.Add(system);

            var parentSystems = new Systems();

            parentSystems.Add(_systems);

            Assert.AreEqual(0, system.DidInitialize);
            parentSystems.Initialize();
            Assert.AreEqual(1, system.DidInitialize);

            Assert.AreEqual(0, system.DidExecute);
            parentSystems.Execute();
            parentSystems.Execute();
            Assert.AreEqual(1, system.DidExecute);

            Assert.AreEqual(0, system.DidCleanup);
            parentSystems.Cleanup();
            Assert.AreEqual(1, system.DidCleanup);

            Assert.AreEqual(0, system.DidTearDown);
            parentSystems.TearDown();
            Assert.AreEqual(1, system.DidTearDown);
        }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (_contexts.game.GetGroup(GameMatcher.Restart).GetEntities().Length != 0)
        {
            foreach (var ent in _contexts.game.GetEntities())
            {
                ent.isDestroy = true;
            }
            _systems.Execute();
            _systems.DeactivateReactiveSystems();
            _systems.TearDown();
            _systems.ClearReactiveSystems();
            _contexts.Reset();
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }

        if (_contexts.game.GetGroup(GameMatcher.SetMainMenu).GetEntities().Length != 0)
        {
            foreach (var ent in _contexts.game.GetEntities())
            {
                ent.isDestroy = true;
            }
            _systems.Execute();
            _systems.DeactivateReactiveSystems();
            _systems.TearDown();
            _systems.ClearReactiveSystems();
            _contexts.Reset();
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
        }

        _systems.Execute();
    }
コード例 #3
0
        private static void RunGenericEntitasBenchmark()
        {
            // register scopes & components
            ScopeManager.RegisterScopes <Simulation, Input>();
            ComponentTypeManager <Simulation> .Autoscan();

            var contexts          = new Contexts(AERCFactories.UnsafeAERCFactory);
            var systems           = new Systems().Add(new MoveSystem(contexts));
            var simulationContext = contexts.Get <Simulation>();

            for (var i = 0; i < EntitiesCount; i++)
            {
                simulationContext.CreateEntity()
                .Add(new Position(new Vector3(1, 2, 0), 0))
                .Add(new Velocity(new Vector3(2, 2, 1), 0.01f));
            }

            // Warm up
            systems.Execute();

            Measure("Generic Entity", () => {
                for (var i = 0; i < RepeatCount; i++)
                {
                    systems.Execute();
                }
            });
        }
コード例 #4
0
    void OnGUI()
    {
        var size      = 100;
        var buttonnum = 0;
        var offset    = 0;

        if (GUI.Button(new Rect(offset, buttonnum * size, size, size), "Init Shmid\n All Sys"))
        {
            var t0 = Time.realtimeSinceStartup;
            _systems = SchmidSystemCreator.CreateAllSystems();
            _systems.Initialize();
            Debug.Log("Init Schmid All Sys " + (Time.realtimeSinceStartup - t0));
        }
        buttonnum++;

        if (GUI.Button(new Rect(offset, buttonnum * size, size, size), "Init Shmid\n Only Run Sys"))
        {
            var t0 = Time.realtimeSinceStartup;
            _systems = SchmidSystemCreator.CreateOnlyRunSystems();
            _systems.Initialize();
            Debug.Log("Init Schmid Only Run Sys " + (Time.realtimeSinceStartup - t0));
        }
        buttonnum++;

        if (GUI.Button(new Rect(offset, buttonnum * size, size, size), "Add entitys"))
        {
            var t0 = Time.realtimeSinceStartup;
            SchmidEntitiesCreator.CreateEntitys(Contexts.sharedInstance.game);
            Debug.Log("Add Schmid entitys " + (Time.realtimeSinceStartup - t0));
        }
        buttonnum++;

        // for test creation cashes time
        if (GUI.Button(new Rect(offset, buttonnum * size, size, size), "Run 1"))
        {
            var t0 = Time.realtimeSinceStartup;
            _systems.Execute();
            Debug.Log("Run Schmid Single Run time " + (Time.realtimeSinceStartup - t0));
        }
        buttonnum++;

        if (GUI.Button(new Rect(offset, buttonnum * size, size, size), "Run " + Iterations))
        {
            var t0 = Time.realtimeSinceStartup;
            for (int i = 0; i < Iterations; i++)
            {
                _systems.Execute();
            }
            Debug.Log("Run Schmid Iterations_" + Iterations + " time " + (Time.realtimeSinceStartup - t0));
        }
        buttonnum++;
    }
コード例 #5
0
 public void _Update()
 {
     OnUpdate();
     m_EntitySystems.Execute();
     m_EntitySystems.Cleanup();
     OnLateUpdate();
 }
コード例 #6
0
ファイル: EcsIntegrationTests.cs プロジェクト: bmjoy/Osnowa
        public void LoadTest()
        {
            var gameContext   = new GameContext();
            int entitiesCount = 1000;
            int segments      = 100;

            var random = new Random();

            for (int i = 0; i < entitiesCount; i++)
            {
                GameEntity entity = gameContext.CreateEntity();
                entity.AddEnergy(0.2f, (float)random.NextDouble());
            }

            var systems = new Systems()
                          //.Add(new IncreaseEnergySystem(gameContext))
                          //.Add(new PreTurnSystem(Contexts.sharedInstance.game))
                          //.Add(new InitiativeGivingSystem(Contexts.sharedInstance.game))
                          //.Add(new PostTurnSystem(Contexts.sharedInstance.game))
            ;

            var stopwatch = Stopwatch.StartNew();

            for (int segment = 0; segment < segments; segment++)
            {
                systems.Execute();
            }

            Console.WriteLine($"{stopwatch.ElapsedMilliseconds}");
        }
コード例 #7
0
 private void Update()
 {
     if (_contexts.game.GetEntities().Length > 0)
     {
         _systems.Execute();
     }
 }
コード例 #8
0
        private static async Task <int> RunContext(int number)
        {
            GameContext context = new GameContext();

            GameMatcher matcher = new GameMatcher(new MatcherInstance <GameEntity>());

            var entity = context.CreateEntity();

            entity.AddPosition(new Vector3Int(0, 0, 0));

            var systems = new Systems().Add(new CreateEntitySystem(context)).Add(new MoveEntitySystem(matcher, context, number));

            systems.Initialize();

            int iterationCount = 0;

            int endIterationCount = ITERATION_COUNT * number;

            while (iterationCount < endIterationCount)
            {
                systems.Execute();

                iterationCount++;

                await Task.Delay(20);
            }

            return(number);
        }
コード例 #9
0
ファイル: AGameController.cs プロジェクト: Jadugarr/Flicker
 private void LateUpdate()
 {
     lateUpdateSystems.Execute();
     updateSystems.Cleanup();
     fixedUpdateSystems.Cleanup();
     lateUpdateSystems.Cleanup();
 }
コード例 #10
0
ファイル: GameController.cs プロジェクト: Arpple/projectend
    void Update()
    {
        if (!_sceneLoader.IsReady())
        {
            return;
        }
        if (!_isInitialized)
        {
            Initialize();
            return;
        }
        if (!_isStart)
        {
            return;
        }
        Assert.IsNotNull(_systems);

        _systems.Execute();
        _systems.Cleanup();

        if (_isGameEnd)
        {
            EndGame();
        }
    }
コード例 #11
0
    void Update()
    {
        systems.Execute();
        systems.Cleanup();

        counts = gameRoot.transform.childCount;
    }
コード例 #12
0
        void Update()
        {
            Assert.IsTrue(_systems != null);

            _systems.Execute();
            _systems.Cleanup();
        }
コード例 #13
0
    void Update()
    {
        bool            isReload        = false;
        GameEventEntity gameEventEntity = null;

        GameEventEntity[] entitiesGameEvent = _groupGameEvent.GetEntities();
        if (entitiesGameEvent.Length != 0)
        {
            gameEventEntity = entitiesGameEvent[0];
            if (gameEventEntity.stateEvent.state == "Reload Ready")
            {
                isReload = true;
            }
        }

        if (isReload)
        {
            gameEventEntity.Destroy();
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
        else
        {
            _systems.Execute();
        }
    }
コード例 #14
0
 private void Update()
 {
     //执行系统集中的所有Execute方法
     _systems.Execute();
     //执行系统集中的所有Cleanup方法
     _systems.Cleanup();
 }
コード例 #15
0
        void Update()

        {
            if (_coreServices.InputController.IsKeyDown(KeyId.D))
            {
                var grid = _contexts.grid.GetEntityWithId(0);
                grid.isGridChanged = !grid.isGridChanged;
            }

            if (_coreServices.Input.IsKeyDown(KeyId.S))
            {
                var objectB = _contexts.game.CreateEntity();
                _coreServices.View.LoadAsset(_contexts, objectB, "Tile");
                objectB.AddPosition(2, 2);
                objectB.AddVisible(true);
                objectB.AddGridPosition(new Vector2(2, 3));
                objectB.AddGridTileType(GlobalVariables.ObjectType.JoinTypes(ObjectType.OBJECT_CATEGORY_DEBUG,
                                                                             ObjectType.OBJECT_CATEGORY_TILE));
                var reqB = _contexts.action.CreateActionRequest(0);
                reqB.AddActionRequestAddEntityToGrid(objectB.id.value, _contexts.grid.GetEntityWithId(0).id.value,
                                                     Random.Range(0, 5));
            }

            _systems.Execute();
            _systems.Cleanup();
        }
コード例 #16
0
ファイル: GameController.cs プロジェクト: xclouder/chengsanqi
//	void Start()
//	{
//		var e = Contexts.sharedInstance.game.CreateEntity();
//		e.isResetGame = true;
//	}

    void Update()
    {
        // call Execute() on all the IExecuteSystems and
        // ReactiveSystems that were triggered last frame
        _systems.Execute();
        // call cleanup() on all the ICleanupSystems
        _systems.Cleanup();
    }
コード例 #17
0
 private void Update()
 {
     if (null == _systems)
     {
         return;
     }
     _systems.Execute();
 }
コード例 #18
0
 private void Update()
 {
     //llama Execute en todos los sistemas IExecute y ReactiveSystems
     // que fueron ejecutados en este frame.
     _systems.Execute();
     // Llama Cleanup() en todos los ICleanUpSystems.
     _systems.Cleanup();
 }
コード例 #19
0
 private void Update()
 {
     if (systems != null)
     {
         systems.Execute();
         systems.Cleanup();
     }
 }
コード例 #20
0
 /// <summary>
 /// This is called when the game should draw itself.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Draw(GameTime gameTime)
 {
     graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
     spriteBatch.Begin();
     renderSystems.Execute();
     spriteBatch.End();
     base.Draw(gameTime);
 }
コード例 #21
0
 protected void Update()
 {
     if (systems != null)
     {
         systems.Execute();
         systems.Cleanup();
     }
 }
コード例 #22
0
    void Update()
    {
        _contexts.game.GetGroup(GameMatcher.MyString).GetSingleEntity()
        .ReplaceMyString(Random.value.ToString());

        _systems.Execute();
        _systems.Cleanup();
    }
コード例 #23
0
        public void WrapsReactiveSystemInIReactiveSystem()
        {
            var system = new ReactiveSystemSpy(_ctx.CreateCollector(Matcher <MyTestEntity> .AllOf(MyTestComponentsLookup.ComponentA)));

            _systems.Add(system);
            _ctx.CreateEntity().AddComponentA();
            _systems.Execute();

            Assert.AreEqual(1, system.DidExecute);
        }
コード例 #24
0
    public void CreateIngredientsViewTest()
    {
        var contexts = new Contexts();
        var game     = contexts.game;

        game.SetGameField(10, 10);

        var factory = new GameObject().AddComponent <IngredientViewFactory>();

        factory.Inject(contexts);

        factory.Descs = new IngredientViewFactory.IngredientDesc[]
        {
            new IngredientViewFactory.IngredientDesc()
            {
                Type = IngredientsType.Ingot,
                View = new GameObject()
            },
            new IngredientViewFactory.IngredientDesc()
            {
                Type = IngredientsType.Plant,
                View = new GameObject()
            }
        };

        var systems = new Systems().Add(new GenerateItemsSystem(contexts))
                      .Add(new CreateIngredientViewSystem(contexts));

        systems.Initialize();

        Assert.IsTrue(game.hasGameField);

        var generationDescription = new GenerationDescription();

        generationDescription.Ingredients = new List <GenerationItem>()
        {
            new GenerationItem()
            {
                Amount = 5,
                Type   = IngredientsType.Ingot
            },
            new GenerationItem()
            {
                Amount = 3,
                Type   = IngredientsType.Plant
            }
        };

        game.gameFieldEntity.ReplaceGenerationDescription(generationDescription);
        game.gameFieldEntity.isNeedRegenerate = true;

        systems.Execute();

        var ingredientsEntities = game.GetGroup(GameMatcher.AllOf(GameMatcher.Ingredient, GameMatcher.GameObject));

        Assert.AreEqual(8, ingredientsEntities.count);
    }
コード例 #25
0
    public void TwoItemCorrectRecipe()
    {
        var contexts        = new Contexts();
        var createWorkbench = new Systems()
                              .Add(new CraftingSystem(contexts))
                              .Add(new DestroySystem(contexts));

        ;

        var boss       = new Boss();
        var bossEntity = contexts.game.SetCurrentBoss(boss);

        bossEntity.AddRecipe(new Recipe()
        {
            Ingredients = new List <RequiredIngredientDesc>()
            {
                new RequiredIngredientDesc()
                {
                    Amount = 1,
                    Color  = ColorType.Blue,
                    Type   = IngredientsType.Crystal
                },
                new RequiredIngredientDesc()
                {
                    Amount = 1, Color = ColorType.Green, Type = IngredientsType.Ingot
                }
            },
            ProjectilePrefab = new GameObject(),
            Damage           = 10,
            Liquid           = LiquidType.Alcohol,
            Name             = "Smoothie"
        });

        var projectileItemsGroup = contexts.game.GetGroup(GameMatcher.AllOf(GameMatcher.Usage));

        Assert.AreEqual(0, projectileItemsGroup.count);

        {
            var ingredient = contexts.game.CreateEntity();
            ingredient.AddIngredient(IngredientsType.Crystal);
            ingredient.AddColor(ColorType.Blue);
            ingredient.AddUsage(UsageType.Craft);
            ingredient.isInsideWorkbench = true;
        }
        {
            var ingredient = contexts.game.CreateEntity();
            ingredient.AddIngredient(IngredientsType.Ingot);
            ingredient.AddColor(ColorType.Green);
            ingredient.AddUsage(UsageType.Craft);
            ingredient.isInsideWorkbench = true;
        }

        createWorkbench.Execute();

        Assert.AreEqual(0, projectileItemsGroup.GetEntities().Where(x => x.usage.value == UsageType.Craft).Count());
        Assert.AreEqual(1, projectileItemsGroup.GetEntities().Where(x => x.usage.value == UsageType.Weapon).Count());
    }
コード例 #26
0
 void Update()
 {
     scoreText.text = "KILLS: " + playerScore;
     if (currentState == GameState.GameStarted)
     {
         _systems.Execute();
         _systems.Cleanup();
     }
 }
コード例 #27
0
 public void Update()
 {
     if (!_started || _ended)
     {
         throw new Exception("Universe not running");
     }
     Systems.Execute();
     Systems.Cleanup();
 }
コード例 #28
0
 private IEnumerator SpawnBalloons()
 {
     while (true)
     {
         _systems.Execute();
         _systems.Cleanup();
         yield return(waitForSeconds);
     }
 }
コード例 #29
0
        private void Update()
        {
            _contexts.VisualDebug.GetGroup(VisualDebugMatcher.MyString)
            .GetSingleEntity()
            .ReplaceMyString(Random.value.ToString());

            _systems.Update();
            _systems.Execute();
        }
コード例 #30
0
ファイル: GameController.cs プロジェクト: soulhez/ECS
        // Use this for initialization
        void Start()
        {
            var contexts = Contexts.sharedInstance;

            systems = new Feature("Systems").Add(new TutorialSystems(contexts));
            systems.Initialize();

            contexts.game.CreateEntity().AddECSGameLog("Hello World!");
            systems.Execute();
        }