Example #1
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);
                    }
                }
            }
        }