public void AddComponent(Entity e, Component component)
        {
            ComponentType type = ComponentTypeManager.GetTypeFor(component.GetType());

            if (type.GetId() >= componentsByType.GetCapacity())
            {
                componentsByType.Set(type.GetId(), null);
            }

            Bag <Component> components = componentsByType.Get(type.GetId());

            if (components == null)
            {
                components = new Bag <Component>();
                componentsByType.Set(type.GetId(), components);
            }

            components.Set(e.GetId(), component);

            e.AddTypeBit(type.GetBit());
            if (AddedComponentEvent != null)
            {
                AddedComponentEvent(e, component);
            }
        }
예제 #2
0
        /// <summary>
        /// Add the given component to the given entity
        /// </summary>
        /// <param name="e">Entty for which you want to add the component</param>
        /// <param name="component">Component you want to add</param>
        internal void AddComponent(Entity e, Component component)
        {
            System.Diagnostics.Debug.Assert(e != null);
            System.Diagnostics.Debug.Assert(component != null);
            ComponentType type = ComponentTypeManager.GetTypeFor(component.GetType());

            if (type.Id >= componentsByType.Capacity)
            {
                componentsByType.Set(type.Id, null);
            }

            Bag <Component> components = componentsByType.Get(type.Id);

            if (components == null)
            {
                components = new Bag <Component>();
                componentsByType.Set(type.Id, components);
            }

            components.Set(e.Id, component);

            e.AddTypeBit(type.Bit);
            if (AddedComponentEvent != null)
            {
                AddedComponentEvent(e, component);
            }
        }
        /**
         * Set the group of the entity.
         *
         * @param group group to set the entity into.
         * @param e entity to set into the group.
         */
        public void Set(String group, Entity e)
        {
            Remove(e);             // Entity can only belong to one group.

            Bag <Entity> entities;

            if (!entitiesByGroup.TryGetValue(group, out entities))
            {
                entities = new Bag <Entity>();
                entitiesByGroup.Add(group, entities);
            }
            entities.Add(e);

            groupByEntity.Set(e.GetId(), group);
        }
예제 #4
0
        /**
         * Set the group of the entity.
         *
         * @param group group to set the entity into.
         * @param e entity to set into the group.
         */
        internal void Set(String group, Entity e)
        {
            System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(group));
            System.Diagnostics.Debug.Assert(e != null);
            Remove(e);             // Entity can only belong to one group.

            Bag <Entity> entities;

            if (!entitiesByGroup.TryGetValue(group, out entities))
            {
                entities = new Bag <Entity>();
                entitiesByGroup.Add(group, entities);
            }
            entities.Add(e);

            groupByEntity.Set(e.Id, group);
        }
        public void RemoveComponent(Entity e, ComponentType type)
        {
            int             entityId   = e.GetId();
            Bag <Component> components = componentsByType.Get(type.GetId());

            if (RemovedComponentEvent != null)
            {
                RemovedComponentEvent(e, components.Get(entityId));
            }
            components.Set(entityId, null);
            e.RemoveTypeBit(type.GetBit());
        }
        public Entity Create()
        {
            Entity e = removedAndAvailable.RemoveLast();

            if (e == null)
            {
                e = new Entity(world, nextAvailableId++);
            }
            else
            {
                e.Reset();
            }
            e.SetUniqueId(uniqueEntityId++);
            activeEntities.Set(e.GetId(), e);
            count++;
            totalCreated++;
            if (AddedEntityEvent != null)
            {
                AddedEntityEvent(e);
            }
            return(e);
        }
예제 #7
0
        /// <summary>
        /// Create a new, "blank" entity
        /// </summary>
        /// <returns>New entity</returns>
        public Entity Create()
        {
            Entity e = removedAndAvailable.RemoveLast();

            if (e == null)
            {
                e = new Entity(world, nextAvailableId++);
            }
            else
            {
                e.Reset();
            }
            e.UniqueId = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
            activeEntities.Set(e.Id, e);
            count++;
            totalCreated++;
            if (AddedEntityEvent != null)
            {
                AddedEntityEvent(e);
            }
            return(e);
        }
예제 #8
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);
        }
        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);
                }
            }
        }
예제 #10
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);
                }
            }
        }