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.

128 lines
3.9 KiB

  1. #pragma once
  2. #include <bitset>
  3. #include <ecs/config.h>
  4. #include <ecs/core/mp/list.h>
  5. namespace ecs {
  6. namespace core {
  7. namespace utils {
  8. /**
  9. * bitset to store components flags in
  10. *
  11. * @tparam T_settings settings type the environmant is configured with
  12. */
  13. template<typename T_settings>
  14. struct bitset
  15. {
  16. private:
  17. /**
  18. * get the component signature list
  19. *
  20. * @return component signature list
  21. */
  22. static constexpr decltype(auto) csl() noexcept
  23. { return (T_settings { }).component_signatures(); }
  24. /**
  25. * get the tags of all components
  26. *
  27. * @return list of all component tags
  28. */
  29. static constexpr decltype(auto) all_components() noexcept
  30. { return csl().all_components(); }
  31. public:
  32. /**
  33. * get the number of components
  34. *
  35. * @return integral constant with number of components
  36. */
  37. static constexpr decltype(auto) component_count() noexcept
  38. { return hana::size(all_components()); }
  39. /**
  40. * get the ID of the given component tag
  41. *
  42. * @tparam T_component_tag component tag type to get ID for
  43. *
  44. * @param ct component tag to get the ID for
  45. *
  46. * @return integral constant with the ID of the requested component tag
  47. */
  48. template<typename T_component_tag>
  49. static constexpr decltype(auto) component_id(T_component_tag&& ct) noexcept;
  50. /**
  51. * get the bitset from the given system signature
  52. *
  53. * @tparam T_system_signature system signature type to get bitmask for
  54. *
  55. * @param ssig system signature to get bitmask for
  56. *
  57. * @return bitmask for the passed system signature
  58. */
  59. template<typename T_system_signature>
  60. static constexpr decltype(auto) from_system_signature(T_system_signature&& ssig) noexcept;
  61. /**
  62. * internal bitset type that contains all components
  63. */
  64. using bitset_type = std::bitset<component_count()>;
  65. private:
  66. bitset_type _bitset;
  67. public:
  68. /**
  69. * return a string representation of the bitset
  70. *
  71. * @return string representation of the bitset
  72. */
  73. inline decltype(auto) to_string() const;
  74. /**
  75. * clear all bits of the bitset
  76. */
  77. inline void clear() noexcept;
  78. /**
  79. * check if the bitset contains another bitset
  80. *
  81. * @tparam T_other type of the other bitset
  82. *
  83. * @param other bitset to compare with
  84. *
  85. * @retval TRUE if this bitset contains the passed bitset
  86. * @retval FALSE if this bitset does not contain the passed bitset
  87. */
  88. template<typename T_other>
  89. inline bool contains(const T_other& other) const noexcept;
  90. /**
  91. * check if the bitset contains the given component
  92. *
  93. * @tparam T_component_tag component tag type to check
  94. *
  95. * @param ct component tag to check
  96. *
  97. * @retval TRUE if this bitset contains the passed component tag
  98. * @retval FALSE if this bitset does not contain the passed component tag
  99. */
  100. template<typename T_component_tag>
  101. inline bool has_component(T_component_tag ct) const;
  102. /**
  103. * set the bit value of the passed component tag
  104. *
  105. * @tparam T_component_tag component tag type to set
  106. *
  107. * @param ct component tag to set
  108. * @param value new bit value of the component inside the bitset
  109. */
  110. template<typename T_component_tag>
  111. inline void set_component(T_component_tag ct, bool value);
  112. };
  113. } } }