Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
7.7KB

  1. using Svelto.DataStructures;
  2. namespace Svelto.ECS
  3. {
  4. public interface IEntitiesDB
  5. {
  6. /// <summary>
  7. /// All the EntityView related methods are left for back compatibility, but
  8. /// shouldn't be used anymore. Always pick EntityViewStruct or EntityStruct
  9. /// over EntityView
  10. /// </summary>
  11. ReadOnlyCollectionStruct<T> QueryEntityViews<T>(int group) where T : class, IEntityStruct;
  12. ReadOnlyCollectionStruct<T> QueryEntityViews<T>(ExclusiveGroup.ExclusiveGroupStruct group) where T : class, IEntityStruct;
  13. /// <summary>
  14. /// All the EntityView related methods are left for back compatibility, but
  15. /// shouldn't be used anymore. Always pick EntityViewStruct or EntityStruct
  16. /// over EntityView
  17. /// </summary>
  18. bool TryQueryEntityView<T>(EGID egid, out T entityView) where T : class, IEntityStruct;
  19. bool TryQueryEntityView<T>(int id, ExclusiveGroup.ExclusiveGroupStruct group, out T entityView) where T : class, IEntityStruct;
  20. /// <summary>
  21. /// All the EntityView related methods are left for back compatibility, but
  22. /// shouldn't be used anymore. Always pick EntityViewStruct or EntityStruct
  23. /// over EntityView
  24. /// </summary>
  25. T QueryEntityView<T>(EGID egid) where T : class, IEntityStruct;
  26. T QueryEntityView<T>(int id, ExclusiveGroup.ExclusiveGroupStruct group) where T : class, IEntityStruct;
  27. /// <summary>
  28. /// Fast and raw (therefore not safe) return of entities buffer
  29. /// Modifying a buffer would compromise the integrity of the whole DB
  30. /// so they are meant to be used only in performance critical path
  31. /// </summary>
  32. /// <param name="count"></param>
  33. /// <typeparam name="T"></typeparam>
  34. /// <returns></returns>
  35. T[] QueryEntities<T>(int group, out int count) where T : IEntityStruct;
  36. T[] QueryEntities<T>(ExclusiveGroup.ExclusiveGroupStruct groupStruct, out int targetsCount) where T : IEntityStruct;
  37. /// <summary>
  38. /// this version returns a mapped version of the entity array so that is possible to find the
  39. /// index of the entity inside the returned buffer through it's EGID
  40. /// However mapping can be slow so it must be used for not performance critical paths
  41. /// </summary>
  42. /// <param name="groupID"></param>
  43. /// <param name="mapper"></param>
  44. /// <typeparam name="T"></typeparam>
  45. /// <returns></returns>
  46. EGIDMapper<T> QueryMappedEntities<T>(int groupID) where T : IEntityStruct;
  47. EGIDMapper<T> QueryMappedEntities<T>(ExclusiveGroup.ExclusiveGroupStruct groupStructId) where T : IEntityStruct;
  48. /// <summary>
  49. /// Execute an action on entities. Be sure that the action is not capturing variables
  50. /// otherwise you will allocate memory which will have a great impact on the execution performance.
  51. /// ExecuteOnEntities can be used to iterate safely over entities, several checks are in place
  52. /// to be sure that everything will be done correctly.
  53. /// Cache friendliness is guaranteed if only Entity Structs are used, but
  54. /// </summary>
  55. /// <param name="egid"></param>
  56. /// <param name="action"></param>
  57. /// <typeparam name="T"></typeparam>
  58. void ExecuteOnEntities<T>(int groupID, EntitiesAction<T> action) where T : IEntityStruct;
  59. void ExecuteOnEntities<T>(ExclusiveGroup.ExclusiveGroupStruct groupStructId, EntitiesAction<T> action) where T : IEntityStruct;
  60. void ExecuteOnEntities<T, W>(int groupID, ref W value, EntitiesAction<T, W> action) where T : IEntityStruct;
  61. void ExecuteOnEntities<T, W>(ExclusiveGroup.ExclusiveGroupStruct groupStructId, ref W value, EntitiesAction<T, W> action) where T : IEntityStruct;
  62. /// <summary>
  63. /// Execute an action on ALL the entities regardless the group. This function doesn't guarantee cache
  64. /// friendliness even if just EntityStructs are used.
  65. /// Safety checks are in place
  66. /// </summary>
  67. /// <param name="damageableGroups"></param>
  68. /// <param name="action"></param>
  69. /// <typeparam name="T"></typeparam>
  70. void ExecuteOnAllEntities<T>(AllEntitiesAction<T> action) where T : IEntityStruct;
  71. void ExecuteOnAllEntities<T, W>(ref W value, AllEntitiesAction<T, W> action) where T : IEntityStruct;
  72. void ExecuteOnAllEntities<T>(ExclusiveGroup[] groups, EntitiesAction<T> action) where T : IEntityStruct;
  73. void ExecuteOnAllEntities<T, W>(ExclusiveGroup[] groups, ref W value, EntitiesAction<T, W> action) where T : IEntityStruct;
  74. /// <summary>
  75. /// ECS is meant to work on a set of Entities. Working on a single entity is sometime necessary, but using
  76. /// the following functions inside a loop would be a mistake as performance can be significantly impacted
  77. /// return the buffer and the index of the entity inside the buffer using the input EGID
  78. /// </summary>
  79. /// <param name="entityGid"></param>
  80. /// <param name="index"></param>
  81. /// <typeparam name="T"></typeparam>
  82. /// <returns></returns>
  83. T[] QueryEntitiesAndIndex<T>(EGID entityGid, out uint index) where T : IEntityStruct;
  84. bool TryQueryEntitiesAndIndex<T>(EGID entityGid, out uint index, out T[] array) where T : IEntityStruct;
  85. T[] QueryEntitiesAndIndex<T>(int id, ExclusiveGroup.ExclusiveGroupStruct group, out uint index) where T : IEntityStruct;
  86. bool TryQueryEntitiesAndIndex<T>(int id, ExclusiveGroup.ExclusiveGroupStruct group, out uint index, out T[] array) where T : IEntityStruct;
  87. /// <summary>
  88. /// ECS is meant to work on a set of Entities. Working on a single entity is sometime necessary, but using
  89. /// the following functions inside a loop would be a mistake as performance can be significantly impacted
  90. /// Execute an action on a specific Entity. Be sure that the action is not capturing variables
  91. /// otherwise you will allocate memory which will have a great impact on the execution performance
  92. /// </summary>
  93. /// <param name="egid"></param>
  94. /// <param name="action"></param>
  95. /// <typeparam name="T"></typeparam>
  96. void ExecuteOnEntity<T>(EGID egid, EntityAction<T> action) where T : IEntityStruct;
  97. void ExecuteOnEntity<T>(int id, int groupid, EntityAction<T> action) where T : IEntityStruct;
  98. void ExecuteOnEntity<T>(int id, ExclusiveGroup.ExclusiveGroupStruct groupid, EntityAction<T> action) where T : IEntityStruct;
  99. void ExecuteOnEntity<T, W>(EGID egid, ref W value, EntityAction<T, W> action) where T : IEntityStruct;
  100. void ExecuteOnEntity<T, W>(int id, int groupid, ref W value, EntityAction<T, W> action) where T : IEntityStruct;
  101. void ExecuteOnEntity<T, W>(int id, ExclusiveGroup.ExclusiveGroupStruct groupid, ref W value, EntityAction<T, W> action) where T : IEntityStruct;
  102. bool Exists<T>(EGID egid) where T : IEntityStruct;
  103. bool Exists (ExclusiveGroup.ExclusiveGroupStruct gid);
  104. bool HasAny<T>(int group) where T:IEntityStruct;
  105. bool HasAny<T>(ExclusiveGroup.ExclusiveGroupStruct groupStruct) where T:IEntityStruct;
  106. }
  107. public delegate void EntityAction<T, W>(ref T target, ref W value);
  108. public delegate void EntityAction<T>(ref T target);
  109. public delegate void AllEntitiesAction<T, W>(ref T target, ref W value, IEntitiesDB entitiesDb);
  110. public delegate void AllEntitiesAction<T>(ref T target, IEntitiesDB entitiesDb);
  111. public delegate void EntitiesAction<T, W>(ref T target, ref W value, IEntitiesDB entitiesDb, int index);
  112. public delegate void EntitiesAction<T>(ref T target, IEntitiesDB entitiesDb, int index);
  113. }