Mirror of Svelto.ECS because we're a fan of it
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

49 lignes
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. }