コード例 #1
0
        /// <summary>
        /// Gets the entities.
        /// </summary>
        /// <param name="aspect">The aspect.</param>
        /// <returns>The filled Bag{Entity}.</returns>
        public Bag <Entity> GetEntities(Aspect aspect)
        {
            Bag <Entity> entitiesBag = new Bag <Entity>();

            for (int index = 0; index < this.ActiveEntities.Count; ++index)
            {
                Entity entity = this.ActiveEntities.Get(index);
                if (entity != null &&
                    aspect.Interests(entity))
                {
                    entitiesBag.Add(entity);
                }
            }

            return(entitiesBag);
        }
コード例 #2
0
        /// <summary>
        /// Sets the system.
        /// </summary>
        /// <param name="layers">The layers.</param>
        /// <param name="system">The system.</param>
        /// <param name="layer">The layer.</param>
        /// <param name="executionType">Type of the execution.</param>
        private static void SetSystem(
            ref IDictionary <int, SystemLayer> layers,
            EntitySystem system,
            int layer,
            ExecutionType executionType)
        {
            if (!layers.ContainsKey(layer))
            {
                layers[layer] = new SystemLayer();
            }

            Bag <EntitySystem> updateBag = layers[layer][executionType];

            if (!updateBag.Contains(system))
            {
                updateBag.Add(system);
            }

            layers = (from d in layers orderby d.Key ascending select d).ToDictionary(keySelector: pair => pair.Key, elementSelector: pair => pair.Value);
        }
コード例 #3
0
        /// <summary>
        /// Get all components assigned to an entity.
        /// </summary>
        /// <param name="entity">Entity for which you want the components.</param>
        /// <returns>Bag of components</returns>
        public Bag <IEntityComponent> GetComponents(Entity entity)
        {
            Debug.Assert(entity != null, "Entity must not be null.");
            //Debug.Assert(entity.entityManager == this, "");  // TODO

            Bag <IEntityComponent> entityComponents = new Bag <IEntityComponent>();
            int entityId = entity.Index;

            for (int index = 0, b = this.componentsByType.Count; b > index; ++index)
            {
                Bag <IEntityComponent> components = this.componentsByType.Get(index);
                if (components != null &&
                    entityId < components.Count)
                {
                    IEntityComponent component = components.Get(entityId);
                    if (component != null)
                    {
                        entityComponents.Add(component);
                    }
                }
            }

            return(entityComponents);
        }