|
- #pragma once
-
- #include <bitset>
- #include <ecs/config.h>
- #include <ecs/core/mp/list.h>
-
- beg_namespace_ecs_core_utils
- {
-
- template<typename T_settings>
- struct bitset
- {
- private:
- static constexpr decltype(auto) csl() noexcept
- { return (T_settings { }).component_signatures(); }
-
- static constexpr decltype(auto) all_components() noexcept
- { return csl().all_components(); }
-
- public:
- static constexpr decltype(auto) component_count() noexcept
- { return hana::size(all_components()); }
-
- template<typename T_component_tag>
- static constexpr decltype(auto) component_id(T_component_tag ct) noexcept
- { return mp::list::index_of(all_components(), ct); }
-
- using bitset_type = std::bitset<component_count()>;
-
- private:
- bitset_type _bitset;
-
- public:
- inline void clear() noexcept
- { _bitset.reset(); }
-
- template<typename T_other>
- inline bool contains(const T_other& other) const noexcept
- { return (_bitset & other._bitset) == _bitset; }
-
- template<typename T_component_tag>
- inline bool has_component(T_component_tag ct) const
- { return _bitset.test(component_id(ct)); }
-
- template<typename T_component_tag>
- inline void set_component(T_component_tag ct, bool value)
- { _bitset.set(component_id(ct), value); }
- };
-
- }
- end_namespace_ecs_core_utils
|