GetEntities() public method

public GetEntities ( ) : Entitas.Entity[]
return Entitas.Entity[]
示例#1
1
 static void moveSystem(Context context) {
     var entities = context.GetEntities(Matcher.AllOf(Matcher.Move, Matcher.Position));
     foreach(var entity in entities) {
         var move = entity.move;
         var pos = entity.position;
         entity.ReplacePosition(pos.x, pos.y + move.speed);
     }
 }
示例#2
0
    public void ensures_same_deterministic_order_when_getting_entities_after_DestroyAllEntities()
    {
        var context = new Context(1);

        const int numEntities = 10;
        for (int i = 0; i < numEntities; i++) {
            context.CreateEntity();
        }

        var order1 = new int[numEntities];
        var entities1 = context.GetEntities();
        for (int i = 0; i < numEntities; i++) {
            order1[i] = entities1[i].creationIndex;
        }

        context.DestroyAllEntities();
        context.ResetCreationIndex();

        for (int i = 0; i < numEntities; i++) {
            context.CreateEntity();
        }

        var order2 = new int[numEntities];
        var entities2 = context.GetEntities();
        for (int i = 0; i < numEntities; i++) {
            order2[i] = entities2[i].creationIndex;
        }

        for (int i = 0; i < numEntities; i++) {
            var index1 = order1[i];
            var index2 = order2[i];

            Assert.AreEqual(index1, index2);
        }
    }
        /// <summary>
        /// mmGame calls this Update() method every frame
        /// </summary>
        public virtual void Update()
        {
            //-------------------
            // Z O O M
            //-------------------
            if (Global.DebugRenderEnabled && CameraEnabled)
            {
                // Camera zoom controls
                Camera.zoom += ((float)Raylib.GetMouseWheelMove() * 0.05f);

                if (Camera.zoom > 3.0f)
                {
                    Camera.zoom = 3.0f;
                }
                else if (Camera.zoom < 0.1f)
                {
                    Camera.zoom = 0.1f;
                }

                if (Raylib.IsKeyPressed(KeyboardKey.KEY_R))                                     // Camera reset (zoom and rotation)
                {
                    Camera.zoom     = 1.0f;
                    Camera.rotation = 0.0f;
                }
            }
            deltaTime        = Raylib.GetFrameTime();
            Global.DeltaTime = deltaTime;
            //
            // Find all Entities
            //
            GameEntities  = EntityContext.GetEntities().Where(e => e.EntityType == 0).ToList();
            SceneEntities = EntityContext.GetEntities().Where(e => e.EntityType == 1).ToList();

            //-----------------------------------------------------------------------
            // Update game entities (Todo: Update order ? like the RenderLayer)
            //-----------------------------------------------------------------------
            foreach (Entity ent in GameEntities)
            {
                if (!ent.Get <Transform>().Enabled)
                {
                    continue;
                }

                Entitas.IComponent[] allComp = ent.GetComponents();                         //all entity components
                foreach (Entitas.IComponent comp in allComp)
                {
                    if (comp is IRenderable)
                    {
                        //
                        // Renderable components get the transform component of the Entity
                        //
                        RenderComponent myComp = (RenderComponent)comp;
                        myComp.CompEntity = ent;
                        myComp.Update(deltaTime);
                    }
                    else
                    {
                        Component myComp = (Component)comp;
                        myComp.CompEntity = ent;
                        myComp.Update(deltaTime);
                    }
                }
            }

            //
            // Update scene UI entities
            //
            foreach (Entity ent in SceneEntities)
            {
                if (!ent.Get <Transform>().Enabled)
                {
                    continue;
                }

                Entitas.IComponent[] allComp = ent.GetComponents();                         //this entity's component
                foreach (Entitas.IComponent comp in allComp)
                {
                    if (comp is IRenderable)
                    {
                        //
                        // Renderable components need to know what happened to Entity Transform
                        //
                        RenderComponent myComp = (RenderComponent)comp;
                        myComp.CompEntity = ent;
                        myComp.Update(deltaTime);
                    }
                    else
                    {
                        Component myComp = (Component)comp;
                        myComp.CompEntity = ent;
                        myComp.Update(deltaTime);                                                  //force it to update()
                    }
                }
            }

            //SceneSystems.Execute();
            //SceneSystems.Cleanup();

            EntitySystems.Execute();                                                    //run IExecuteSystems
            //
            // If user wants out of this scene
            //
            if (ForceEndScene)
            {
                Global.StateOfGame = GameState.ForcedExit;
            }
        }