Nez.Portable/ECS/InternalUtils/ComponentList.cs
/// <summary>
/// handles any Components that need to be removed or added
/// </summary>
handles any Components that need to be removed or added
handles any Components that need to be removed or added
void updateLists()
        {
            if (_componentsToRemove.Count > 0)
            {
                for (int i = 0, count = _componentsToRemove.Count; i < count; i++)
                {
                    handleRemove(_componentsToRemove[i]);
                    _components.remove(_componentsToRemove[i]);
                }
                _componentsToRemove.Clear();
            }
            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);
                }
                _componentsToAdd.Clear();
                _isComponentListUnsorted = true;
                for (var i = 0; i < _tempBufferList.Count; i++)
                {
                    var component = _tempBufferList[i];
                    component.onAddedToEntity();
                    if (component.enabled)
                        component.onEnabled();
                }
                _tempBufferList.Clear();
            }
            if (_isComponentListUnsorted)
            {
                _updatableComponents.sort(compareUpdatableOrder);
                _isComponentListUnsorted = false;
            }
        }
void updateLists ( ) { if ( _componentsToRemove . Count > 0 ) { for ( int i = 0 , count = _componentsToRemove . Count ; i < count ; i ++ ) { handleRemove ( _componentsToRemove [ i ] ) ; _components . remove ( _componentsToRemove [ i ] ) ; } _componentsToRemove . Clear ( ) ; } 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 ) ; } _componentsToAdd . Clear ( ) ; _isComponentListUnsorted = true ; for ( var i = 0 ; i < _tempBufferList . Count ; i ++ ) { var component = _tempBufferList [ i ] ; component . onAddedToEntity ( ) ; if ( component . enabled ) component . onEnabled ( ) ; } _tempBufferList . Clear ( ) ; } if ( _isComponentListUnsorted ) { _updatableComponents . sort ( compareUpdatableOrder ) ; _isComponentListUnsorted = false ; } }
handles any Components that need to be removed or added
handles any Components that need to be removed or added
// handle removals // handle additions // clear before calling onAddedToEntity in case more Components are added then // now that all components are added to the scene, we loop through again and call onAddedToEntity/onEnabled // component.enabled checks both the Entity and the Component