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);
            }
        }
        /**
         * Removes the provided entity from the group it is assigned to, if any.
         * @param e the entity.
         */
        public void Remove(Entity e)
        {
            int entityId = e.GetId();

            if (entityId < groupByEntity.GetCapacity())
            {
                String group = groupByEntity.Get(entityId);
                if (group != null)
                {
                    groupByEntity.Set(entityId, null);

                    Bag <Entity> entities;
                    if (entitiesByGroup.TryGetValue(group, out entities))
                    {
                        entities.Remove(e);
                    }
                }
            }
        }
        public Component GetComponent(Entity e, ComponentType type)
        {
            int             entityId = e.GetId();
            Bag <Component> bag      = componentsByType.Get(type.GetId());

            if (bag != null && entityId < bag.GetCapacity())
            {
                return(bag.Get(entityId));
            }
            return(null);
        }