Mirror of Svelto.ECS because we're a fan of it
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

56 рядки
2.3KB

  1. #if UNITY_ECS
  2. using Unity.Collections;
  3. using Unity.Entities;
  4. namespace Svelto.ECS.SveltoOnDOTS
  5. {
  6. /// <summary>
  7. /// Automatic Svelto Group -> DOTS archetype synchronization when necessary
  8. /// </summary>
  9. /// <typeparam name="DOTSEntityComponent"></typeparam>
  10. public class SveltoOnDOTSHandleLifeTimeEngine<DOTSEntityComponent>: ISveltoOnDOTSStructuralEngine, IReactOnRemoveEx<DOTSEntityComponent>,
  11. IReactOnSwapEx<DOTSEntityComponent> where DOTSEntityComponent : unmanaged, IEntityComponentForDOTS
  12. {
  13. public void Remove((uint start, uint end) rangeOfEntities, in EntityCollection<DOTSEntityComponent> entities, ExclusiveGroupStruct groupID)
  14. {
  15. //todo burstify all of this if DOTS 1.0 is on
  16. var (buffer, _) = entities;
  17. var nativeArray = new NativeArray<Entity>((int)(rangeOfEntities.end - rangeOfEntities.start), Allocator.Temp);
  18. int counter = 0;
  19. for (uint i = rangeOfEntities.start; i < rangeOfEntities.end; i++)
  20. nativeArray[counter++] = buffer[i].dotsEntity;
  21. DOTSOperations.DestroyEntitiesBatched(nativeArray);
  22. }
  23. public void MovedTo((uint start, uint end) rangeOfEntities, in EntityCollection<DOTSEntityComponent> entities,
  24. ExclusiveGroupStruct _, ExclusiveGroupStruct toGroup)
  25. {
  26. //todo burstify all of this if DOTS 1.0 is on
  27. var (buffer, ids, _) = entities;
  28. var nativeArray = new NativeArray<Entity>((int)(rangeOfEntities.end - rangeOfEntities.start), Allocator.Temp);
  29. int counter = 0;
  30. for (uint i = rangeOfEntities.start; i < rangeOfEntities.end; i++)
  31. nativeArray[counter++] = buffer[i].dotsEntity;
  32. DOTSOperations.SetSharedComponentBatched(nativeArray, new DOTSSveltoGroupID(toGroup));
  33. counter = 0;
  34. for (uint i = rangeOfEntities.start; i < rangeOfEntities.end; i++)
  35. DOTSOperations.SetComponent(nativeArray[counter++], new DOTSSveltoEGID(new EGID(ids[i], toGroup)));
  36. }
  37. public void OnOperationsReady() {}
  38. public void OnPostSubmission() {}
  39. public DOTSOperationsForSvelto DOTSOperations { get; set; }
  40. public string name => nameof(SveltoOnDOTSHandleLifeTimeEngine<DOTSEntityComponent>);
  41. }
  42. }
  43. #endif