35template<component_reference... Args>
39 static constexpr bool is_const = detail::view_arguments<Args...>::is_const;
42 using value_type = std::tuple<Args...>;
45 using registry_type = std::conditional_t<is_const, const registry&, registry&>;
64 auto single() -> std::optional<std::tuple<Args...>>
68 for (
auto entry :
chunk) {
81 for (
auto entry :
chunk) {
90 auto each() ->
decltype(
auto)
93 return chunks(_registry.archetypes()) | detail::views::join;
98 auto each() const -> decltype(auto)
101 return chunks(_registry.archetypes()) | detail::views::join;
109 for (
auto chunk :
chunks(_registry.archetypes())) {
110 for (
auto entry :
chunk) {
111 std::apply(func, entry);
123 for (
auto chunk :
chunks(_registry.archetypes())) {
124 for (
auto entry :
chunk) {
125 std::apply(func, entry);
136 [&func](
auto chunk) { std::ranges::for_each(
chunk, [&](
auto&& elem) { std::apply(func, elem); }); });
147 [&func](
auto chunk) { std::ranges::for_each(
chunk, [&](
auto&& elem) { std::apply(func, elem); }); });
153 return chunks(_registry.archetypes());
159 return chunks(_registry.archetypes());
163 template<component C>
164 constexpr static bool match(
auto&
archetype) {
165 if constexpr (std::is_same_v<C, entity>) {
168 return archetype->template contains<C>();
172 constexpr static auto chunks(
auto&& archetypes) ->
decltype(
auto) {
173 auto filter_archetypes = [](
auto& archetype) ->
bool {
174 return (match<decay_component_t<Args>>(archetype) && ...);
176 auto into_chunks = [](
auto& archetype) ->
decltype(
auto) {
return archetype->chunks(); };
177 auto as_typed_chunk = [](
auto& chunk) ->
decltype(
auto) {
return chunk_view<Args...>(chunk); };
180 | detail::views::values
181 | detail::views::filter(filter_archetypes)
182 | detail::views::transform(into_chunks)
183 | detail::views::join
184 | detail::views::transform(as_typed_chunk);
187 registry_type _registry;
Archetype groups entities that share the same types of components. Archetype has a list of fixed size...
Definition archetype.hpp:15
Chunk holds a 16 Kb block of memory that holds components in blocks: |A1|A2|A3|......
Definition chunk.hpp:37
Registry is a container for all our entities and components. Components are stored in continuously in...
Definition registry.hpp:13
A view lets you get a range over components of Args out of a registry.
Definition view.hpp:36
auto chunks() const -> decltype(auto)
Gets the const chunks range.
Definition view.hpp:158
auto each() -> decltype(auto) requires(!is_const)
Returns an iterator that yields a std::tuple<Args...>.
Definition view.hpp:90
auto each() const -> decltype(auto) requires(is_const)
Returns an iterator that yields a std::tuple<Args...> (const version).
Definition view.hpp:98
auto single() const -> std::optional< std::tuple< Args... > > requires(is_const)
Returns a single tuple of components matching Args, if available in the view (const version).
Definition view.hpp:77
void par_each(auto &&func)
Runs a function on every entity that matches the Args requirement in parallel.
Definition view.hpp:132
void each(auto &&func)
Runs a function on every entity that matches the Args requirement.
Definition view.hpp:106
view(registry_type registry) noexcept
Constructs a new view object.
Definition view.hpp:50
void each(auto &&func) const
Runs a function on every entity that matches the Args requirement (const version).
Definition view.hpp:120
void par_each(auto &&func) const
Runs a function on every entity that matches the Args requirement in parallel (const version).
Definition view.hpp:143
auto single() -> std::optional< std::tuple< Args... > > requires(!is_const)
Returns a single tuple of components matching Args, if available in the view.
Definition view.hpp:64
auto chunks() -> decltype(auto)
Gets the chunks range.
Definition view.hpp:152
Definition archetype.hpp:11
void parallel_for(R &&range, auto &&func)
Parallelize func over elements in range.
Definition parallel_for.hpp:13