Exemple #1
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 ECRenderable)
                    {
                        _entity.Scene.RenderableComponents.Add(component as ECRenderable);
                    }

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

                    _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;
            }
        }
Exemple #2
0
        public void UpdateLists()
        {
            // handle removals
            if (_entitiesToRemove.Count > 0)
            {
                Utils.Swap(ref _entitiesToRemove, ref _tempEntityList);
                foreach (var entity in _tempEntityList)
                {
                    // handle the tagList
                    RemoveFromTagList(entity);

                    // handle the regular entity list
                    _entities.Remove(entity);
                    entity.OnRemovedFromScene();
                    entity.Scene = null;
                }

                _tempEntityList.Clear();
            }

            // handle additions
            if (_entitiesToAdd.Count > 0)
            {
                Utils.Swap(ref _entitiesToAdd, ref _tempEntityList);
                foreach (var entity in _tempEntityList)
                {
                    _entities.Add(entity);
                    entity.Scene = Scene;

                    // handle the tagList
                    AddToTagList(entity);
                }

                // now that all entities are added to the scene, we loop through again and call onAddedToScene
                foreach (var entity in _tempEntityList)
                {
                    entity.OnAddedToScene();
                }

                _tempEntityList.Clear();
                _isEntityListUnsorted = true;
            }

            if (_isEntityListUnsorted)
            {
                _entities.Sort();
                _isEntityListUnsorted = false;
            }

            // sort our tagList if needed
            if (_unsortedTags.Count > 0)
            {
                foreach (var tag in _unsortedTags)
                {
                    _entityDict[tag].Sort();
                }
                _unsortedTags.Clear();
            }
        }
Exemple #3
0
        internal void RemoveFromTagList(ECEntity entity)
        {
            FastList <ECEntity> list = null;

            if (_entityDict.TryGetValue(entity.Tag, out list))
            {
                list.Remove(entity);
            }
        }
Exemple #4
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 ECRenderable)
                {
                    _entity.Scene.RenderableComponents.Remove(component as ECRenderable);
                }

                // deal with IUpdatable
                if (component is IUpdatable)
                {
                    _updatableComponents.Remove(component as IUpdatable);
                }
            }
        }
Exemple #5
0
 public void Remove(IRenderable component)
 {
     _components.Remove(component);
     _componentsByRenderLayer[component.RenderLayer].Remove(component);
 }
Exemple #6
0
 /// <summary>
 /// Removes the 2 Nubs that inspects the fps and draw calls.
 /// </summary>
 public void Uninspect()
 {
     Nubs.Remove(FpsNub);
     Nubs.Remove(DrawCallNub);
 }