示例#1
0
        /// <summary>
        /// Reemoves the given component type from the given entity
        /// </summary>
        /// <param name="e">The entity for which you want to remove the component</param>
        /// <param name="type">The component type you want to remove</param>
        internal void RemoveComponent(Entity e, ComponentType type)
        {
            System.Diagnostics.Debug.Assert(e != null);
            System.Diagnostics.Debug.Assert(type != null);
            int             entityId   = e.Id;
            Bag <Component> components = componentsByType.Get(type.Id);

            if (RemovedComponentEvent != null)
            {
                RemovedComponentEvent(e, components.Get(entityId));
            }
            components.Set(entityId, null);
            e.RemoveTypeBit(type.Bit);
        }
 void UpdatebagASSync(Bag <EntitySystem> temp)
 {
     tasks.Clear();
     for (int i = 0, j = temp.Size(); i < j; i++)
     {
         EntitySystem es = temp.Get(i);
         tasks.Add(factory.StartNew(
                       () =>
         {
             es.Process();
         }
                       ));
     }
     Task.WaitAll(tasks.ToArray());
 }
        private void RemoveComponentsOfEntity(Entity e)
        {
            int entityId = e.GetId();

            for (int a = 0, b = componentsByType.Size(); b > a; a++)
            {
                Bag <Component> components = componentsByType.Get(a);
                if (components != null && entityId < components.Size())
                {
                    if (RemovedComponentEvent != null)
                    {
                        RemovedComponentEvent(e, components.Get(entityId));
                    }
                    components.Set(entityId, null);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Get the component instance of the given component type for the given entity
        /// </summary>
        /// <param name="e">The entity for which you want to get the component</param>
        /// <param name="type">The desired component type</param>
        /// <returns>Component instance</returns>
        internal Component GetComponent(Entity e, ComponentType type)
        {
            System.Diagnostics.Debug.Assert(e != null);
            System.Diagnostics.Debug.Assert(type != null);
            int             entityId = e.Id;
            Bag <Component> bag      = componentsByType.Get(type.Id);

            if (type.Id >= componentsByType.Capacity)
            {
                return(null);
            }
            if (bag != null && entityId < bag.Capacity)
            {
                return(bag.Get(entityId));
            }
            return(null);
        }
示例#5
0
        /// <summary>
        /// Strips all components from the given entity
        /// </summary>
        /// <param name="e">Entity for which you want to remove all components</param>
        internal void RemoveComponentsOfEntity(Entity e)
        {
            System.Diagnostics.Debug.Assert(e != null);
            int entityId = e.Id;

            for (int a = 0, b = componentsByType.Size; b > a; a++)
            {
                Bag <Component> components = componentsByType.Get(a);
                if (components != null && entityId < components.Size)
                {
                    if (RemovedComponentEvent != null)
                    {
                        RemovedComponentEvent(e, components.Get(entityId));
                    }
                    components.Set(entityId, null);
                }
            }
        }
        public Bag <Component> GetComponents(Entity e)
        {
            entityComponents.Clear();
            int entityId = e.GetId();

            for (int a = 0, b = componentsByType.Size(); b > a; a++)
            {
                Bag <Component> components = componentsByType.Get(a);
                if (components != null && entityId < components.Size())
                {
                    Component component = components.Get(entityId);
                    if (component != null)
                    {
                        entityComponents.Add(component);
                    }
                }
            }
            return(entityComponents);
        }
示例#7
0
        /// <summary>
        /// Get all components assigned to an entity
        /// </summary>
        /// <param name="e">Entity for which you want the components</param>
        /// <returns>Bag of components</returns>
        public Bag <Component> GetComponents(Entity e)
        {
            System.Diagnostics.Debug.Assert(e != null);
            entityComponents.Clear();
            int entityId = e.Id;

            for (int a = 0, b = componentsByType.Size; b > a; a++)
            {
                Bag <Component> components = componentsByType.Get(a);
                if (components != null && entityId < components.Size)
                {
                    Component component = components.Get(entityId);
                    if (component != null)
                    {
                        entityComponents.Add(component);
                    }
                }
            }
            return(entityComponents);
        }
示例#8
0
        public void LoadEntityState(String tag, String groupName, Bag <Component> components)
        {
            Entity e;

            if (tag != null)
            {
                e = this.CreateEntity(tag);
            }
            else
            {
                e = this.CreateEntity();
            }
            if (groupName != null)
            {
                this.groupManager.Set(groupName, e);
            }
            for (int i = 0, j = components.Size(); i < j; i++)
            {
                e.AddComponent(components.Get(i));
            }
        }
示例#9
0
        public void LoopStart()
        {
            if (!refreshed.IsEmpty())
            {
                for (int i = 0, j = refreshed.Size(); j > i; i++)
                {
                    entityManager.Refresh(refreshed.Get(i));
                }
                refreshed.Clear();
            }

            if (!deleted.IsEmpty())
            {
                for (int i = 0, j = deleted.Size(); j > i; i++)
                {
                    Entity e = deleted.Get(i);
                    entityManager.Remove(e);
                }
                deleted.Clear();
            }
        }
示例#10
0
        /// <summary>
        /// Loads the state of the entity.
        /// </summary>
        /// <param name="templateTag">The template tag. Can be null</param>
        /// <param name="groupName">Name of the group. Can be null</param>
        /// <param name="components">The components.</param>
        /// <param name="templateArgs">Params for entity template</param>
        public void LoadEntityState(String templateTag, String groupName, Bag <Component> components, params object[] templateArgs)
        {
            System.Diagnostics.Debug.Assert(components != null);
            Entity e;

            if (!String.IsNullOrEmpty(templateTag))
            {
                e = CreateEntity(templateTag, templateArgs);
            }
            else
            {
                e = CreateEntity();
            }
            if (String.IsNullOrEmpty(groupName))
            {
                groupManager.Set(groupName, e);
            }
            for (int i = 0, j = components.Size; i < j; i++)
            {
                e.AddComponent(components.Get(i));
            }
        }
示例#11
0
        /**
         * Removes from this Bag all of its elements that are contained in the
         * specified Bag.
         *
         * @param bag
         *            Bag containing elements to be removed from this Bag
         * @return {@code true} if this Bag changed as a result of the call
         */
        public bool RemoveAll(Bag <E> bag)
        {
            bool modified = false;

            for (int i = 0, bagSize = bag.Size(); i < bagSize; i++)
            {
                Object o1 = bag.Get(i);

                for (int j = 0; j < size; j++)
                {
                    Object o2 = data[j];

                    if (o1 == o2)
                    {
                        Remove(j);
                        j--;
                        modified = true;
                        break;
                    }
                }
            }

            return(modified);
        }
 /**
  * Check if this entity is active, or has been deleted, within the framework.
  *
  * @param entityId
  * @return active or not.
  */
 public bool IsActive(int entityId)
 {
     return(activeEntities.Get(entityId) != null);
 }