Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

51 wiersze
1.4 KiB

  1. #pragma once
  2. #include <bitset>
  3. #include <ecs/config.h>
  4. #include <ecs/core/mp/list.h>
  5. beg_namespace_ecs_core_utils
  6. {
  7. template<typename T_settings>
  8. struct bitset
  9. {
  10. private:
  11. static constexpr decltype(auto) csl() noexcept
  12. { return (T_settings { }).component_signatures(); }
  13. static constexpr decltype(auto) all_components() noexcept
  14. { return csl().all_components(); }
  15. public:
  16. static constexpr decltype(auto) component_count() noexcept
  17. { return hana::size(all_components()); }
  18. template<typename T_component_tag>
  19. static constexpr decltype(auto) component_id(T_component_tag ct) noexcept
  20. { return mp::list::index_of(all_components(), ct); }
  21. using bitset_type = std::bitset<component_count()>;
  22. private:
  23. bitset_type _bitset;
  24. public:
  25. inline void clear() noexcept
  26. { _bitset.reset(); }
  27. template<typename T_other>
  28. inline bool contains(const T_other& other) const noexcept
  29. { return (_bitset & other._bitset) == _bitset; }
  30. template<typename T_component_tag>
  31. inline bool has_component(T_component_tag ct) const
  32. { return _bitset.test(component_id(ct)); }
  33. template<typename T_component_tag>
  34. inline void set_component(T_component_tag ct, bool value)
  35. { _bitset.set(component_id(ct), value); }
  36. };
  37. }
  38. end_namespace_ecs_core_utils