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.

61 lines
2.1KB

  1. using System;
  2. using Svelto.DataStructures;
  3. namespace Svelto.ECS.Internal
  4. {
  5. partial class EntitiesDB
  6. {
  7. public void ExecuteOnAllEntities<T>(Action<T[], ExclusiveGroup.ExclusiveGroupStruct, uint, IEntitiesDB> action)
  8. where T : struct, IEntityStruct
  9. {
  10. var type = typeof(T);
  11. if (_groupsPerEntity.TryGetValue(new RefWrapper<Type>(type), out var dictionary))
  12. {
  13. foreach (var pair in dictionary)
  14. {
  15. var entities = (pair.Value as TypeSafeDictionary<T>).GetValuesArray(out var innerCount);
  16. if (innerCount > 0)
  17. action(entities, new ExclusiveGroup.ExclusiveGroupStruct(pair.Key), innerCount, this);
  18. }
  19. }
  20. }
  21. public void ExecuteOnAllEntities
  22. <T, W>(W value, Action<T[], ExclusiveGroup.ExclusiveGroupStruct, uint, IEntitiesDB, W> action)
  23. where T : struct, IEntityStruct
  24. {
  25. var type = typeof(T);
  26. if (_groupsPerEntity.TryGetValue(new RefWrapper<Type>(type), out var dic))
  27. {
  28. foreach (var pair in dic)
  29. {
  30. var entities = (pair.Value as TypeSafeDictionary<T>).GetValuesArray(out var innerCount);
  31. if (innerCount > 0)
  32. action(entities, new ExclusiveGroup.ExclusiveGroupStruct(pair.Key), innerCount, this, value);
  33. }
  34. }
  35. }
  36. public void ExecuteOnAllEntities
  37. <T, W>(ref W value, ExecuteOnAllEntitiesAction<T, W> action)
  38. where T : struct, IEntityStruct
  39. {
  40. var type = typeof(T);
  41. if (_groupsPerEntity.TryGetValue(new RefWrapper<Type>(type), out var dic))
  42. {
  43. foreach (var pair in dic)
  44. {
  45. var entities = (pair.Value as TypeSafeDictionary<T>).GetValuesArray(out var innerCount);
  46. if (innerCount > 0)
  47. action(entities, new ExclusiveGroup.ExclusiveGroupStruct(pair.Key), innerCount, this, ref value);
  48. }
  49. }
  50. }
  51. }
  52. }