示例#1
0
 internal EntityCollection(IComponentReferenceAccess <TEntityId, TComponentKind> componentReferenceAccess, ICollection <TEntityId> wrapped, Predicate <TEntityId> add, Predicate <TEntityId> remove)
 {
     _componentReferenceAccess = componentReferenceAccess;
     _wrapped = wrapped;
     _add     = add;
     _remove  = remove;
 }
示例#2
0
        public EntityCollection <TEntityId, TComponentKind> GetAllEntities(IComponentReferenceAccess <TEntityId, TComponentKind> componentReferenceAccess)
        {
            if (_allEntities != null)
            {
                return(_allEntities);
            }

            _allEntities = new EntityCollection <TEntityId, TComponentKind>(componentReferenceAccess, _componentKindsByEntity.Keys, _ => true, _ => true);
            return(_allEntities);
        }
示例#3
0
        private EntityCollection <TEntityId, TComponentKind> CreateEntityCollection(IEnumerable <TComponentKind> componentKinds, int queryId, IComponentReferenceAccess <TEntityId, TComponentKind> componentReferenceAccess)
        {
            var set = new HashSet <TEntityId>(_entityEqualityComparer);
            var entityCollection = _entityIdsByQueryId[queryId] = new EntityCollection <TEntityId, TComponentKind>(componentReferenceAccess, set, set.Add, set.Remove);

            foreach (var componentKind in componentKinds)
            {
                if (!_queryIdsByComponentKind.TryGetValue(componentKind, out var queryIds))
                {
                    queryIds = new HashSet <QueryId>();
                    _queryIdsByComponentKind[componentKind] = queryIds;
                }

                queryIds.Add(queryId);
            }

            foreach (var entityId in _componentKindsByEntity.Keys)
            {
                var allComponentKinds = _componentKindsByEntity[entityId];
                if (_queryManager.QueryCheck(allComponentKinds, queryId) == QueryCheckResult.Add)
                {
                    entityCollection.Add(entityId);
                }
            }

            return(entityCollection);
        }
示例#4
0
        public EntityCollection <TEntityId, TComponentKind> GetEntityCollection(IEnumerable <TComponentKind> all, IEnumerable <TComponentKind> any, IEnumerable <TComponentKind> none, IComponentReferenceAccess <TEntityId, TComponentKind> componentReferenceAccess)
        {
            var allAsICollection  = EnumerableHelper.AsICollection(all);
            var anyAsICollection  = EnumerableHelper.AsICollection(any);
            var noneAsICollection = EnumerableHelper.AsICollection(none);
            var queryId           = _queryManager.CreateQuery(allAsICollection, anyAsICollection, noneAsICollection);

            return(_entityIdsByQueryId.TryGetValue(queryId, out var entityCollection)
                ? entityCollection
                : CreateEntityCollection(EnumerableHelper.Concat(allAsICollection, anyAsICollection, noneAsICollection), queryId, componentReferenceAccess));
        }