Ejemplo n.º 1
0
        internal void DeregisterAllComponents()
        {
            for (var i = 0; i < _components.Length; i++)
            {
                var component = _components.Buffer[i];

                // deal with renderLayer list if necessary
                if (component is RenderableComponent)
                {
                    _entity.Scene.RenderableComponents.Remove(component as RenderableComponent);
                }

                // deal with IUpdatable
                if (component is IUpdatable)
                {
                    _updatableComponents.Remove(component as IUpdatable);
                }

                if (Core.entitySystemsEnabled)
                {
                    _entity.componentBits.Set(ComponentTypeManager.GetIndexFor(component.GetType()), false);
                    _entity.Scene.EntityProcessors.OnComponentRemoved(_entity);
                }
            }
        }
Ejemplo n.º 2
0
        public Matcher One(params Type[] types)
        {
            foreach (var type in types)
            {
                oneSet.Set(ComponentTypeManager.GetIndexFor(type));
            }

            return(this);
        }
Ejemplo n.º 3
0
        internal void RegisterAllComponents()
        {
            for (var i = 0; i < _components.Length; i++)
            {
                var component = _components.Buffer[i];
                if (component is RenderableComponent)
                {
                    _entity.Scene.RenderableComponents.Add(component as RenderableComponent);
                }

                if (component is IUpdatable)
                {
                    _updatableComponents.Add(component as IUpdatable);
                }

                if (Core.entitySystemsEnabled)
                {
                    _entity.componentBits.Set(ComponentTypeManager.GetIndexFor(component.GetType()));
                    _entity.Scene.EntityProcessors.OnComponentAdded(_entity);
                }
            }
        }
Ejemplo n.º 4
0
        void HandleRemove(Component component)
        {
            // deal with renderLayer list if necessary
            if (component is RenderableComponent)
            {
                _entity.Scene.RenderableComponents.Remove(component as RenderableComponent);
            }

            // deal with IUpdatable
            if (component is IUpdatable)
            {
                _updatableComponents.Remove(component as IUpdatable);
            }

            if (Core.entitySystemsEnabled)
            {
                _entity.componentBits.Set(ComponentTypeManager.GetIndexFor(component.GetType()), false);
                _entity.Scene.EntityProcessors.OnComponentRemoved(_entity);
            }

            component.OnRemovedFromEntity();
            component.Entity = null;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// handles any Components that need to be removed or added
        /// </summary>
        void UpdateLists()
        {
            // handle removals
            if (_componentsToRemove.Count > 0)
            {
                for (int i = 0; i < _componentsToRemove.Count; i++)
                {
                    HandleRemove(_componentsToRemove[i]);
                    _components.Remove(_componentsToRemove[i]);
                }
                _componentsToRemove.Clear();
            }

            // handle additions
            if (_componentsToAdd.Count > 0)
            {
                for (int i = 0, count = _componentsToAdd.Count; i < count; i++)
                {
                    var component = _componentsToAdd[i];
                    if (component is RenderableComponent)
                    {
                        _entity.Scene.RenderableComponents.Add(component as RenderableComponent);
                    }

                    if (component is IUpdatable)
                    {
                        _updatableComponents.Add(component as IUpdatable);
                    }

                    if (Core.entitySystemsEnabled)
                    {
                        _entity.componentBits.Set(ComponentTypeManager.GetIndexFor(component.GetType()));
                        _entity.Scene.EntityProcessors.OnComponentAdded(_entity);
                    }

                    _components.Add(component);
                    _tempBufferList.Add(component);
                }

                // clear before calling onAddedToEntity in case more Components are added then
                _componentsToAdd.Clear();
                _isComponentListUnsorted = true;

                // now that all components are added to the scene, we loop through again and call onAddedToEntity/onEnabled
                for (var i = 0; i < _tempBufferList.Count; i++)
                {
                    var component = _tempBufferList[i];
                    component.OnAddedToEntity();

                    // component.enabled checks both the Entity and the Component
                    if (component.Enabled)
                    {
                        component.OnEnabled();
                    }
                }

                _tempBufferList.Clear();
            }

            if (_isComponentListUnsorted)
            {
                _updatableComponents.Sort(compareUpdatableOrder);
                _isComponentListUnsorted = false;
            }
        }