Mirror of Svelto.ECS because we're a fan of it
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

EntityStream.cs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Svelto.DataStructures;
  2. namespace Svelto.ECS
  3. {
  4. internal interface ITypeSafeStream
  5. {
  6. void Dispose();
  7. }
  8. public class EntityStream<T> : ITypeSafeStream where T : unmanaged, IEntityComponent
  9. {
  10. readonly ThreadSafeFasterList<Consumer<T>> _consumers;
  11. internal EntityStream()
  12. {
  13. _consumers = new ThreadSafeFasterList<Consumer<T>>();
  14. }
  15. ~EntityStream()
  16. {
  17. for (var i = 0; i < _consumers.count; i++)
  18. _consumers[i].Free();
  19. }
  20. public void Dispose()
  21. { }
  22. internal void PublishEntity(ref T entity, EGID egid)
  23. {
  24. for (var i = 0; i < _consumers.count; i++)
  25. unsafe
  26. {
  27. if (*(bool*) _consumers[i].mustBeDisposed)
  28. {
  29. _consumers[i].Free();
  30. _consumers.UnorderedRemoveAt((uint) i);
  31. --i;
  32. continue;
  33. }
  34. if (_consumers[i].hasGroup)
  35. {
  36. if (egid.groupID == _consumers[i].@group)
  37. _consumers[i].Enqueue(entity, egid);
  38. }
  39. else
  40. {
  41. _consumers[i].Enqueue(entity, egid);
  42. }
  43. }
  44. }
  45. internal Consumer<T> GenerateConsumer(string name, uint capacity)
  46. {
  47. var consumer = new Consumer<T>(name, capacity);
  48. _consumers.Add(consumer);
  49. return consumer;
  50. }
  51. internal Consumer<T> GenerateConsumer(ExclusiveGroupStruct group, string name, uint capacity)
  52. {
  53. var consumer = new Consumer<T>(group, name, capacity);
  54. _consumers.Add(consumer);
  55. return consumer;
  56. }
  57. }
  58. }