Example #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;
            }
        }
Example #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();
            }
        }
Example #3
0
        public void UpdateLists()
        {
            if (_componentsNeedSort)
            {
                _components.Sort(CompareUpdatableOrder);
                _componentsNeedSort = false;
            }

            if (_unsortedRenderLayers.Count > 0)
            {
                for (int i = 0, count = _unsortedRenderLayers.Count; i < count; i++)
                {
                    if (_componentsByRenderLayer.TryGetValue(_unsortedRenderLayers[i], out var renderLayerComponents))
                    {
                        renderLayerComponents.Sort(CompareUpdatableOrder);
                    }
                }

                _unsortedRenderLayers.Clear();
            }
        }