using System; using System.Collections.Generic; using EcsRx.Collections.Entity; using EcsRx.Entities; using EcsRx.Groups; namespace EcsRx.Collections.Database { public static class EntityCollectionLookups { public const int NoCollectionDefined = -1; public const int DefaultCollectionId = 0; } /// /// This acts as the database to store all entities, rather than containing all entities directly /// within itself, it partitions them into collections which can contain differing amounts of entities. /// public interface IEntityDatabase : INotifyingEntityCollection, IDisposable { /// /// All the entity collections that the manager contains /// IReadOnlyList Collections { get; } /// /// Fired when a collection has been added /// IObservable CollectionAdded { get; } /// /// Fired when a collection has been removed /// IObservable CollectionRemoved { get; } /// /// Gets an enumerable collection of entities for you to iterate through, /// it will by default search across ALL collections within the manager unless constrained. /// This is not cached and will always query the live data. /// /// /// So in most cases an IObservableGroup is a better option to use for repeat queries as it internally /// will update a maintained list of entities without having to enumerate the entire collection/s. /// /// The group to match entities on /// The optional collection name to use (defaults to null) /// An enumerable to access the data inside the collection/s IEnumerable GetEntitiesFor(IGroup group, int collectionId = EntityCollectionLookups.NoCollectionDefined); /// /// Creates a new collection within the database /// /// /// This is primarily useful for when you want to isolate certain entities, such as short lived ones which would /// be constantly being destroyed and recreated, like bullets etc. In most cases you will probably not need more than 1. /// /// The name to give the collection /// A newly created collection with that name IEntityCollection CreateCollection(int id); /// /// Adds an existing collection within the database /// /// /// This is mainly used for when you have persisted a collection and want to re-load it /// /// The collection to add void AddCollection(IEntityCollection collection); /// /// Gets a collection by name from within the manager, if no name is provided the default pool is returned /// /// The optional name of collection to return /// The located collection IEntityCollection GetCollection(int id = EntityCollectionLookups.DefaultCollectionId); /// /// Removes a collection from the manager /// /// The collection to remove /// if the entities should all be disposed too void RemoveCollection(int id, bool disposeEntities = true); bool IsCollection(int id); IEnumerable GetEntitiesFor(LookupGroup lookupGroup, params int[] collectionIds); IEnumerable GetEntitiesFor(IGroup group, params int[] collectionIds); } }