using Svelto.DataStructures; namespace Svelto.ECS { public interface IEntitiesDB { /// /// All the EntityView related methods are left for back compatibility, but /// shouldn't be used anymore. Always pick EntityViewStruct or EntityStruct /// over EntityView /// ReadOnlyCollectionStruct QueryEntityViews(int group) where T : class, IEntityStruct; /// /// All the EntityView related methods are left for back compatibility, but /// shouldn't be used anymore. Always pick EntityViewStruct or EntityStruct /// over EntityView /// bool TryQueryEntityView(EGID egid, out T entityView) where T : class, IEntityStruct; /// /// All the EntityView related methods are left for back compatibility, but /// shouldn't be used anymore. Always pick EntityViewStruct or EntityStruct /// over EntityView /// T QueryEntityView(EGID egid) where T : class, IEntityStruct; /// /// Fast and raw (therefore not safe) return of entities buffer /// Modifying a buffer would compromise the integrity of the whole DB /// so they are meant to be used only in performance critical path /// /// /// /// T[] QueryEntities(int group, out int count) where T : IEntityStruct; T[] QueryEntities(ExclusiveGroup @group, out int targetsCount) where T : IEntityStruct; /// /// this version returns a mapped version of the entity array so that is possible to find the /// index of the entity inside the returned buffer through it's EGID /// However mapping can be slow so it must be used for not performance critical paths /// /// /// /// /// EGIDMapper QueryMappedEntities(int groupID) where T : IEntityStruct; EGIDMapper QueryMappedEntities(ExclusiveGroup groupID) where T : IEntityStruct; /// /// Execute an action on entities. Be sure that the action is not capturing variables /// otherwise you will allocate memory which will have a great impact on the execution performance. /// ExecuteOnEntities can be used to iterate safely over entities, several checks are in place /// to be sure that everything will be done correctly. /// Cache friendliness is guaranteed if only Entity Structs are used, but /// /// /// /// void ExecuteOnEntities(int groupID, EntitiesAction action) where T : IEntityStruct; void ExecuteOnEntities(ExclusiveGroup groupID, EntitiesAction action) where T : IEntityStruct; void ExecuteOnEntities(int groupID, ref W value, EntitiesAction action) where T : IEntityStruct; void ExecuteOnEntities(ExclusiveGroup groupID, ref W value, EntitiesAction action) where T : IEntityStruct; /// /// Execute an action on ALL the entities regardless the group. This function doesn't guarantee cache /// friendliness even if just EntityStructs are used. /// Safety checks are in place /// /// /// /// void ExecuteOnAllEntities(ExclusiveGroup[] damageableGroups, AllEntitiesAction action) where T : IEntityStruct; void ExecuteOnAllEntities(ref W value, AllEntitiesAction action) where T : IEntityStruct; void ExecuteOnAllEntities(ExclusiveGroup[] groups, EntitiesAction action) where T : IEntityStruct; void ExecuteOnAllEntities(ExclusiveGroup[] groups, ref W value, EntitiesAction action) where T : IEntityStruct; /// /// ECS is meant to work on a set of Entities. Working on a single entity is sometime necessary, but using /// the following functions inside a loop would be a mistake as performance can be significantly impacted /// return the buffer and the index of the entity inside the buffer using the input EGID /// /// /// /// /// T[] QueryEntitiesAndIndex(EGID entityGid, out uint index) where T : IEntityStruct; bool TryQueryEntitiesAndIndex(EGID entityGid, out uint index, out T[] array) where T : IEntityStruct; /// /// ECS is meant to work on a set of Entities. Working on a single entity is sometime necessary, but using /// the following functions inside a loop would be a mistake as performance can be significantly impacted /// Execute an action on a specific Entity. Be sure that the action is not capturing variables /// otherwise you will allocate memory which will have a great impact on the execution performance /// /// /// /// void ExecuteOnEntity(EGID egid, EntityAction action) where T : IEntityStruct; void ExecuteOnEntity(int id, int groupid, EntityAction action) where T : IEntityStruct; void ExecuteOnEntity(int id, ExclusiveGroup groupid, EntityAction action) where T : IEntityStruct; void ExecuteOnEntity(EGID egid, ref W value, EntityAction action) where T : IEntityStruct; void ExecuteOnEntity(int id, int groupid, ref W value, EntityAction action) where T : IEntityStruct; void ExecuteOnEntity(int id, ExclusiveGroup groupid, ref W value, EntityAction action) where T : IEntityStruct; bool Exists(EGID egid) where T : IEntityStruct; bool HasAny(int group) where T:IEntityStruct; bool HasAny(ExclusiveGroup group) where T:IEntityStruct; } public delegate void EntityAction(ref T target, ref W value); public delegate void EntityAction(ref T target); public delegate void AllEntitiesAction(ref T target, ref W value, IEntitiesDB entitiesDb); public delegate void AllEntitiesAction(ref T target, IEntitiesDB entitiesDb); public delegate void EntitiesAction(ref T target, ref W value, IEntitiesDB entitiesDb, int index); public delegate void EntitiesAction(ref T target, IEntitiesDB entitiesDb, int index); }