Пример #1
0
        internal EntitySet(
            bool needClearing,
            World world,
            Predicate <ComponentEnum> filter,
            Predicate <int> predicate,
            List <Func <EntityContainerWatcher, World, IDisposable> > subscriptions)
        {
            _needClearing     = needClearing;
            _worldId          = world.WorldId;
            _worldMaxCapacity = world.MaxCapacity;
            _container        = new EntityContainerWatcher(this, filter, predicate);
            _subscriptions    = subscriptions.Select(s => s(_container, world)).Merge();

            _mapping  = EmptyArray <int> .Value;
            _entities = EmptyArray <Entity> .Value;
            Count     = 0;

            if (!_needClearing)
            {
                IEntityContainer @this = this;
                for (int i = 0; i <= Math.Min(world.EntityInfos.Length, world.LastEntityId); ++i)
                {
                    if (filter(world.EntityInfos[i].Components) && predicate(i))
                    {
                        @this.Add(i);
                    }
                }
            }

            _sortedIndex = Math.Max(0, Count - 1);
            world.Add(this);
        }
Пример #2
0
        internal EntityMap(
            bool needClearing,
            World world,
            Predicate <ComponentEnum> filter,
            List <Predicate <int> > predicates,
            List <Func <EntityContainerWatcher, World, IDisposable> > subscriptions,
            IEqualityComparer <TKey> comparer)
        {
            _needClearing     = needClearing;
            _worldId          = world.WorldId;
            _worldMaxCapacity = world.MaxCapacity;
            _container        = new EntityContainerWatcher(this, filter, predicates);
            _subscriptions    = Enumerable.Repeat(world.Subscribe <ComponentChangedMessage <TKey> >(OnChange), 1).Concat(subscriptions.Select(s => s(_container, world))).Merge();

            _previousComponents = ComponentManager <TKey> .GetOrCreatePrevious(_worldId);

            _components = ComponentManager <TKey> .GetOrCreate(_worldId);

            _entities = new Dictionary <TKey, Entity>(comparer);

            _entityIds = EmptyArray <bool> .Value;

            if (!_needClearing)
            {
                IEntityContainer @this = this as IEntityContainer;
                foreach (Entity entity in _components.GetEntities())
                {
                    if (filter(entity.Components))
                    {
                        @this.Add(entity.EntityId);
                    }
                }
            }
        }