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); } } } }
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); }
internal EntitySortedSet( bool needClearing, World world, Predicate <ComponentEnum> filter, Predicate <int> predicate, List <Func <EntityContainerWatcher, World, IDisposable> > subscriptions, IComparer <TComponent> comparer) { _needClearing = needClearing; _worldId = world.WorldId; _worldMaxCapacity = world.MaxCapacity == int.MaxValue ? int.MaxValue : (world.MaxCapacity + 1); EntityContainerWatcher container = new(this, filter, predicate); _subscriptions = Enumerable .Repeat(world.Subscribe <ComponentChangedMessage <TComponent> >(On), 1) .Concat(subscriptions.Select(s => s(container, world))) .Merge(); comparer ??= Comparer <TComponent> .Default; ComponentPool <TComponent> components = ComponentManager <TComponent> .GetOrCreate(_worldId); _comparer = Comparer <Entity> .Create((e1, e2) => comparer.Compare(components.Get(e1.EntityId), components.Get(e2.EntityId))); _mapping = EmptyArray <int> .Value; _entities = EmptyArray <Entity> .Value; Count = 0; if (!_needClearing) { IEntityContainer @this = this; for (int i = 1; i <= Math.Min(world.EntityInfos.Length, world.LastEntityId); ++i) { if (filter(world.EntityInfos[i].Components) && predicate(i)) { @this.Add(i); } } } }