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.

49 lines
1.3KB

  1. using System.Runtime.CompilerServices;
  2. using Svelto.DataStructures;
  3. using Svelto.DataStructures.Experimental;
  4. using Svelto.DataStructures.Native;
  5. namespace Svelto.ECS.ResourceManager
  6. {
  7. /// <summary>
  8. /// Inherit this class to have the base functionalities to implement a custom ECS compatible resource manager
  9. /// </summary>
  10. public class ECSResourceManager<T> where T : class
  11. {
  12. protected ECSResourceManager()
  13. {
  14. _sparse = new ValueContainer<T, ManagedStrategy<T>, NativeStrategy<SparseIndex>>(16);
  15. }
  16. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  17. public ValueIndex Add(in T resource)
  18. {
  19. return _sparse.Add(resource);
  20. }
  21. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  22. public void Remove(ValueIndex index)
  23. {
  24. _sparse.Remove(index);
  25. }
  26. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  27. public void Clear()
  28. {
  29. _sparse.Clear();
  30. }
  31. public T this[ValueIndex index]
  32. {
  33. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  34. get => _sparse[index];
  35. }
  36. ~ECSResourceManager()
  37. {
  38. _sparse.Dispose();
  39. }
  40. ValueContainer<T, ManagedStrategy<T>, NativeStrategy<SparseIndex>> _sparse;
  41. }
  42. }