Mirror of Svelto.ECS because we're a fan of it
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

93 líneas
4.6KB

  1. #if !DEBUG || PROFILE_SVELTO
  2. #define DONT_USE
  3. using System.Diagnostics;
  4. #endif
  5. using System;
  6. using System.Collections.Generic;
  7. namespace Svelto.ECS
  8. {
  9. /// <summary>
  10. /// Note: this check doesn't catch the case when an add and remove is done on the same entity before the nextI am
  11. /// submission. Two operations on the same entity are not allowed between submissions.
  12. /// </summary>
  13. public partial class EnginesRoot
  14. {
  15. #if DONT_USE
  16. [Conditional("MEANINGLESS")]
  17. #endif
  18. void CheckRemoveEntityID(EGID egid, Type entityDescriptorType, string caller)
  19. {
  20. if (_multipleOperationOnSameEGIDChecker.ContainsKey(egid) == true)
  21. throw new ECSException(
  22. "Executing multiple structural changes (remove) in one submission on the same entity is not supported "
  23. .FastConcat(" caller: ", caller, " ").FastConcat(egid.entityID).FastConcat(" groupid: ")
  24. .FastConcat(egid.groupID.ToName()).FastConcat(" type: ")
  25. .FastConcat(entityDescriptorType != null ? entityDescriptorType.Name : "not available")
  26. .FastConcat(" previous operation was: ")
  27. .FastConcat(_multipleOperationOnSameEGIDChecker[egid] == 1 ? "add" : "remove"));
  28. if (_idChecker.TryGetValue(egid.groupID, out var hash))
  29. {
  30. if (hash.Contains(egid.entityID) == false)
  31. throw new ECSException("Trying to remove an Entity not present in the database "
  32. .FastConcat(" caller: ", caller, " entityID ").FastConcat(egid.entityID).FastConcat(" groupid: ")
  33. .FastConcat(egid.groupID.ToName()).FastConcat(" type: ")
  34. .FastConcat(entityDescriptorType != null ? entityDescriptorType.Name : "not available"));
  35. }
  36. else
  37. {
  38. throw new ECSException("Trying to remove an Entity with a group never used so far "
  39. .FastConcat(" caller: ", caller, " entityID ").FastConcat(egid.entityID).FastConcat(" groupid: ")
  40. .FastConcat(egid.groupID.ToName()).FastConcat(" type: ")
  41. .FastConcat(entityDescriptorType != null ? entityDescriptorType.Name : "not available"));
  42. }
  43. hash.Remove(egid.entityID);
  44. _multipleOperationOnSameEGIDChecker.Add(egid, 0);
  45. }
  46. #if DONT_USE
  47. [Conditional("MEANINGLESS")]
  48. #endif
  49. void CheckAddEntityID(EGID egid, Type entityDescriptorType, string caller)
  50. {
  51. if (_multipleOperationOnSameEGIDChecker.ContainsKey(egid) == true)
  52. throw new ECSException(
  53. "Executing multiple structural changes (build) on the same entity is not supported "
  54. .FastConcat(" caller: ", caller, " ").FastConcat(egid.entityID).FastConcat(" groupid: ")
  55. .FastConcat(egid.groupID.ToName()).FastConcat(" type: ")
  56. .FastConcat(entityDescriptorType != null ? entityDescriptorType.Name : "not available")
  57. .FastConcat(" previous operation was: ")
  58. .FastConcat(_multipleOperationOnSameEGIDChecker[egid] == 1 ? "add" : "remove"));
  59. var hash = _idChecker.GetOrAdd(egid.groupID, () => new HashSet<uint>());
  60. if (hash.Contains(egid.entityID) == true)
  61. throw new ECSException("Trying to add an Entity already present in the database "
  62. .FastConcat(" caller: ", caller, " entityID ").FastConcat(egid.entityID)
  63. .FastConcat(" groupid: ").FastConcat(egid.groupID.ToName()).FastConcat(" type: ")
  64. .FastConcat(entityDescriptorType != null
  65. ? entityDescriptorType.Name
  66. : "not available"));
  67. hash.Add(egid.entityID);
  68. _multipleOperationOnSameEGIDChecker.Add(egid, 1);
  69. }
  70. #if DONT_USE
  71. [Conditional("MEANINGLESS")]
  72. #endif
  73. void RemoveGroupID(ExclusiveBuildGroup groupID)
  74. {
  75. _idChecker.Remove(groupID);
  76. }
  77. #if DONT_USE
  78. [Conditional("MEANINGLESS")]
  79. #endif
  80. void ClearDebugChecks() { _multipleOperationOnSameEGIDChecker.Clear(); }
  81. readonly Svelto.DataStructures.FasterDictionary<EGID, uint> _multipleOperationOnSameEGIDChecker;
  82. readonly Svelto.DataStructures.FasterDictionary<ExclusiveGroupStruct, HashSet<uint>> _idChecker;
  83. }
  84. }