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.

38 lines
1.0KB

  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;
  4. using Svelto.DataStructures;
  5. namespace Svelto.ECS
  6. {
  7. public struct EGIDMapper<T> where T : struct, IEntityStruct
  8. {
  9. internal FasterDictionary<uint, T> map;
  10. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  11. public ref T Entity(uint entityID)
  12. {
  13. #if DEBUG && !PROFILER
  14. if (map.TryFindIndex(entityID, out var findIndex) == false)
  15. throw new Exception("Entity not found in this group ".FastConcat(typeof(T).ToString()));
  16. #else
  17. map.TryFindIndex(entityID, out var findIndex);
  18. #endif
  19. return ref map.valuesArray[findIndex];
  20. }
  21. public bool TryGetEntity(uint entityID, out T value)
  22. {
  23. if (map.TryFindIndex(entityID, out var index))
  24. {
  25. value = map.GetDirectValue(index);
  26. return true;
  27. }
  28. value = default;
  29. return false;
  30. }
  31. }
  32. }