Mirror of Svelto.ECS because we're a fan of it
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

43 rindas
2.2KB

  1. #if UNITY_NATIVE
  2. using Svelto.ECS.DataStructures;
  3. namespace Svelto.ECS.Native
  4. {
  5. public readonly struct NativeEntityFactory
  6. {
  7. internal NativeEntityFactory(AtomicNativeBags addOperationQueue, int index, EnginesRoot.EntityReferenceMap entityLocator)
  8. {
  9. _index = index;
  10. _addOperationQueue = addOperationQueue;
  11. _entityLocator = entityLocator;
  12. }
  13. public NativeEntityInitializer BuildEntity
  14. (uint eindex, ExclusiveBuildGroup exclusiveBuildGroup, int threadIndex)
  15. {
  16. EntityReference reference = _entityLocator.ClaimReference();
  17. NativeBag bagPerEntityPerThread = _addOperationQueue.GetBuffer(threadIndex + 1);
  18. bagPerEntityPerThread.Enqueue(_index); //each native ECS native operation is stored in an array, each request to perform a native operation in a queue. _index is the index of the operation in the array that will be dequeued later
  19. bagPerEntityPerThread.Enqueue(new EGID(eindex, exclusiveBuildGroup));
  20. bagPerEntityPerThread.Enqueue(reference);
  21. //NativeEntityInitializer is quite a complex beast. It holds the starting values of the component set by the user. These components must be later dequeued and in order to know how many components
  22. //must be dequeued, a count must be used. The space to hold the count is then reserved in the queue and index will be used access the count later on through NativeEntityInitializer so it can increment it.
  23. //index is not the number of components of the entity, it's just the number of components that the user decide to initialise
  24. bagPerEntityPerThread.ReserveEnqueue<uint>(out var index) = 0;
  25. return new NativeEntityInitializer(bagPerEntityPerThread, index, reference);
  26. }
  27. public NativeEntityInitializer BuildEntity(EGID egid, int threadIndex)
  28. {
  29. return BuildEntity(egid.entityID, egid.groupID, threadIndex);
  30. }
  31. readonly EnginesRoot.EntityReferenceMap _entityLocator;
  32. readonly AtomicNativeBags _addOperationQueue;
  33. readonly int _index;
  34. }
  35. }
  36. #endif