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.

40 lines
1011B

  1. using Svelto.DataStructures;
  2. namespace Svelto.ECS.Experimental
  3. {
  4. // struct ECSResources<T>
  5. // {
  6. // internal uint id;
  7. //
  8. // public static implicit operator T(ECSResources<T> ecsString) { return ResourcesECSDB<T>.FromECS(ecsString.id); }
  9. // }
  10. /// <summary>
  11. /// To do. Or we reuse the ID or we need to clear this
  12. /// </summary>
  13. /// <typeparam name="T"></typeparam>
  14. static class ResourcesECSDB<T>
  15. {
  16. static readonly FasterList<T> _resources = new FasterList<T>();
  17. internal static ref T resources(uint id)
  18. {
  19. return ref _resources[(int) id - 1];
  20. }
  21. internal static uint ToECS(in T resource)
  22. {
  23. _resources.Add(resource);
  24. return (uint)_resources.count;
  25. }
  26. public static T FromECS(uint id)
  27. {
  28. if (id - 1 < _resources.count)
  29. return _resources[(int) id - 1];
  30. return default;
  31. }
  32. }
  33. }