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 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); } } } }
/// <summary> /// Registers the type <typeparamref name="T"/> so <see cref="SubscribeAttribute"/> can freely be used on method like the delegate <see cref="MessageHandler{T}"/> to automatically subscribe when using <see cref="IPublisherExtension"/> on a <see cref="World"/> instance. /// </summary> /// <typeparam name="T">The type of message.</typeparam> public static void RegisterMessage <T>() { using World world = new World(); world.Subscribe(default(MessageHandler <T>)); }
public static void Subscribe <T>(MessageHandler <T> handler) { World.Subscribe(handler); }
public TriggerResolveSystem(World world) { ecsContext = world; ecsContext.Subscribe(this); collisions = new ConcurrentQueue <ICollision>(); }