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.

69 lines
2.3KB

  1. using System.Runtime.CompilerServices;
  2. using Svelto.Common;
  3. namespace Svelto.ECS.DataStructures
  4. {
  5. public struct NativeDynamicArrayCast<T> where T : struct
  6. {
  7. public NativeDynamicArrayCast(uint size, Allocator allocator)
  8. {
  9. _array = NativeDynamicArray.Alloc<T>(allocator, size);
  10. }
  11. public NativeDynamicArrayCast(NativeDynamicArray array) : this() { _array = array; }
  12. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  13. public int Count() => _array.Count<T>();
  14. public int count
  15. {
  16. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  17. get => _array.Count<T>();
  18. }
  19. public int capacity
  20. {
  21. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  22. get => _array.Capacity<T>();
  23. }
  24. public ref T this[int index]
  25. {
  26. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  27. get => ref _array.Get<T>((uint) index);
  28. }
  29. public ref T this[uint index]
  30. {
  31. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  32. get => ref _array.Get<T>(index);
  33. }
  34. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  35. public void Add(in T id) { _array.Add(id); }
  36. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  37. public void UnorderedRemoveAt(uint index) { _array.UnorderedRemoveAt<T>(index); }
  38. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  39. public void RemoveAt(uint index) { _array.RemoveAt<T>(index); }
  40. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  41. public void Clear() { _array.FastClear(); }
  42. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  43. public void Dispose() { _array.Dispose(); }
  44. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  45. public ref T AddAt(uint lastIndex) { return ref _array.AddAt<T>(lastIndex); }
  46. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  47. public void Resize(uint newSize) { _array.Resize<T>(newSize); }
  48. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  49. public NativeDynamicArray ToNativeArray() { return _array; }
  50. public bool isValid => _array.isValid;
  51. NativeDynamicArray _array;
  52. }
  53. }