示例#1
0
        public int GetFutureComponentIdx(IComponent component)
        {
            var typeId = component.TypeId;
            var id     = _componentIndex.GetTypeIndex(component.TypeId);

            if (id == -1)
            {
                // компонент не содержится в текущем реакторе.
                // Данная ветка необходима для определение "будущего" идентификатора в следующем реакторе
                ReactorConnection connection;
                if (!_outConnectionIndex.TryGetValue(typeId, out connection))
                {
                    var typeList = new List <Type>(TargetTypesSet)
                    {
                        component.Type
                    };
                    SystemReactor nextReactor = _systemExecutor.GetOrCreateConcreteSystemReactor(typeList);
                    connection = new ReactorConnection(component.Type, nextReactor, this);
                    _outConnectionIndex.Add(component, connection);
                    nextReactor._inConnectionIndex.Add(component, connection);
                }
                id = connection.UpReactor.GetComponentIdx(typeId);
            }
            return(id);
        }
示例#2
0
 public ReactorConnection(SystemReactor upReactor, SystemReactor downReactor)
 {
     UpReactor               = upReactor;
     DownReactor             = downReactor;
     SetupSystems            = upReactor.SetupSystems.Except(downReactor.SetupSystems).ToArray();
     EntityReactionSystems   = upReactor.EntityReactionSystems.Except(downReactor.EntityReactionSystems).ToArray();
     GroupReactionSystems    = upReactor.GroupReactionSystems.Except(downReactor.GroupReactionSystems).ToArray();
     InteractReactionSystems = upReactor.InteractReactionSystems.Except(downReactor.InteractReactionSystems).ToArray();
     TeardownSystems         = upReactor.TeardownSystems.Except(downReactor.TeardownSystems).ToArray();
 }
示例#3
0
        public void RemoveComponent(IEntity entity, Type componenType)
        {
            ReactorConnection connection;

            if (!_connections.TryGetValue(componenType, out connection))
            {
                var           set     = new HashSet <Type>(TargetTypes);
                SystemReactor reactor = _systemExecutor.GetSystemReactor(set);
                connection = new ReactorConnection(this, reactor);
                this.AddReactorsConnection(componenType, connection, reactor);
            }
            entity.Reactor = connection.DownReactor;
            _systemExecutor.RemoveSystemsFromEntity(entity, connection);
        }
示例#4
0
        public void RemoveComponent(IEntity entity, IComponent component)
        {
            var typeId = component.TypeId;

            if (!_inConnectionIndex.TryGetValue(typeId, out var connection))
            {
                var typeList = new List <Type>(TargetTypesSet);
                typeList.Remove(component.Type);
                SystemReactor prevReactor = _systemExecutor.GetOrCreateConcreteSystemReactor(typeList);
                connection = new ReactorConnection(component.Type, this, prevReactor);
                _inConnectionIndex.Add(component, connection);
                prevReactor._outConnectionIndex.Add(component, connection);
            }
            _systemExecutor.RemoveSystemsFromEntity(entity, connection);
            entity.Reactor = connection.DownReactor;
        }
示例#5
0
        public void AddComponent(IEntity entity, Type componenType)
        {
            ReactorConnection connection;

            if (!_connections.TryGetValue(componenType, out connection))
            {
                var set = new HashSet <Type>(TargetTypes)
                {
                    componenType
                };
                SystemReactor reactor = _systemExecutor.GetSystemReactor(set);
                connection = new ReactorConnection(reactor, this);
                this.AddReactorsConnection(componenType, connection, reactor);
            }
            entity.Reactor = connection.UpReactor;
            _systemExecutor.AddSystemsToEntity(entity, connection);
        }
示例#6
0
        public void AddComponent(IEntity entity, IComponent component)
        {
            var typeId = component.TypeId;

            if (!_outConnectionIndex.TryGetValue(typeId, out var connection))
            {
                var typeList = new List <Type>(TargetTypesSet)
                {
                    component.Type
                };
                SystemReactor nextReactor = _systemExecutor.GetOrCreateConcreteSystemReactor(typeList);
                connection = new ReactorConnection(component.Type, nextReactor, this);
                _outConnectionIndex.Add(component, connection);
                nextReactor._inConnectionIndex.Add(component, connection);
            }
            entity.Reactor = connection.UpReactor;
            _systemExecutor.AddSystemsToEntity(entity, connection);
        }
示例#7
0
        public ReactorConnection(Type componentType, SystemReactor upReactor, SystemReactor downReactor)
        {
            ComponenType            = componentType;
            UpReactor               = upReactor;
            DownReactor             = downReactor;
            GroupAccessors          = upReactor.GroupAccessors.Except(downReactor.GroupAccessors).ToArray();
            SetupSystems            = upReactor.SetupSystems.Except(downReactor.SetupSystems).OrderByPriority().ToArray();
            EntityReactionSystems   = upReactor.EntityReactionSystems.Except(downReactor.EntityReactionSystems).OrderByPriority().ToArray();
            GroupReactionSystems    = upReactor.GroupReactionSystems.Except(downReactor.GroupReactionSystems).OrderByPriority().ToArray();
            InteractReactionSystems = upReactor.InteractReactionSystems.Except(downReactor.InteractReactionSystems).OrderByPriority().ToArray();
            TeardownSystems         = upReactor.TeardownSystems.Except(downReactor.TeardownSystems).OrderByPriority().ToArray();

            HasGroupOrSystems =
                GroupAccessors.Length > 0 ||
                SetupSystems.Length > 0 ||
                EntityReactionSystems.Length > 0 ||
                GroupReactionSystems.Length > 0 ||
                InteractReactionSystems.Length > 0 ||
                TeardownSystems.Length > 0;
        }
示例#8
0
 public void AddReactorsConnection(Type componenType, ReactorConnection connection, SystemReactor reactor)
 {
     if (!_connections.ContainsKey(componenType))
     {
         _connections.Add(componenType, connection);
         reactor.AddReactorsConnection(componenType, connection, this);
     }
 }