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.

82 lines
2.6KB

  1. #if DEBUG && !PROFILER
  2. using System.Collections.Generic;
  3. using Svelto.DataStructures;
  4. #else
  5. using System.Diagnostics;
  6. #endif
  7. namespace Svelto.ECS
  8. {
  9. public partial class EnginesRoot
  10. {
  11. #if DEBUG && !PROFILER
  12. void CheckRemoveEntityID(EGID egid)
  13. {
  14. // Console.LogError("<color=orange>removed</color>".FastConcat(egid.ToString()));
  15. if (_idCheckers.TryGetValue(egid.groupID, out var hash))
  16. {
  17. if (hash.Contains(egid.entityID) == false)
  18. throw new ECSException("Entity with not found ID is about to be removed: id: "
  19. .FastConcat(egid.entityID)
  20. .FastConcat(" groupid: ")
  21. .FastConcat(egid.groupID));
  22. hash.Remove(egid.entityID);
  23. if (hash.Count == 0)
  24. _idCheckers.Remove(egid.groupID);
  25. }
  26. else
  27. {
  28. throw new ECSException("Entity with not found ID is about to be removed: id: "
  29. .FastConcat(egid.entityID)
  30. .FastConcat(" groupid: ")
  31. .FastConcat(egid.groupID));
  32. }
  33. }
  34. void CheckAddEntityID(EGID egid)
  35. {
  36. // Console.LogError("<color=orange>added</color> ".FastConcat(egid.ToString()));
  37. if (_idCheckers.TryGetValue(egid.groupID, out var hash) == false)
  38. hash = _idCheckers[egid.groupID] = new HashSet<uint>();
  39. else
  40. {
  41. if (hash.Contains(egid.entityID))
  42. throw new ECSException("Entity with used ID is about to be built: '"
  43. .FastConcat("' id: '")
  44. .FastConcat(egid.entityID)
  45. .FastConcat("' groupid: '")
  46. .FastConcat(egid.groupID)
  47. .FastConcat("'"));
  48. }
  49. hash.Add(egid.entityID);
  50. }
  51. void RemoveGroupID(ExclusiveGroup.ExclusiveGroupStruct groupID)
  52. {
  53. _idCheckers.Remove(groupID);
  54. }
  55. readonly FasterDictionary<uint, HashSet<uint>> _idCheckers = new FasterDictionary<uint, HashSet<uint>>();
  56. #else
  57. [Conditional("_CHECKS_DISABLED")]
  58. void CheckRemoveEntityID(EGID egid)
  59. {
  60. }
  61. [Conditional("_CHECKS_DISABLED")]
  62. void CheckAddEntityID(EGID egid)
  63. {
  64. }
  65. [Conditional("_CHECKS_DISABLED")]
  66. void RemoveGroupID(ExclusiveGroup.ExclusiveGroupStruct groupID)
  67. {
  68. }
  69. #endif
  70. }
  71. }