Flecs: include/flecs/addons/cpp/mixins/query/builder.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.0 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
builder.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "../../utils/builder.hpp"
9#include "builder_i.hpp"
10
11namespace flecs {
12namespace _ {
13 template <typename ... Components>
14 using query_builder_base = builder<
15 query, ecs_query_desc_t, query_builder<Components...>,
16 query_builder_i, Components ...>;
17}
18
23template <typename ... Components>
24 struct query_builder final : _::query_builder_base<Components...> {
25 query_builder(flecs::world_t* world, flecs::entity query_entity)
26 : _::query_builder_base<Components...>(world)
27 {
28 _::sig<Components...>(world).populate(this);
29 this->desc_.entity = query_entity.id();
30 }
31
32 query_builder(flecs::world_t* world, const char *name = nullptr)
33 : _::query_builder_base<Components...>(world)
34 {
35 _::sig<Components...>(world).populate(this);
36 if (name != nullptr) {
37 ecs_entity_desc_t entity_desc = {};
38 entity_desc.name = name;
39 entity_desc.sep = "::";
40 entity_desc.root_sep = "::";
41 this->desc_.entity = ecs_entity_init(world, &entity_desc);
42 }
43 }
44
45 template <typename Func>
46 void each(Func&& func) {
47 this->build().each(FLECS_FWD(func));
48 }
49};
50
51}
ecs_entity_init
ecs_entity_t ecs_entity_init(ecs_world_t *world, const ecs_entity_desc_t *desc)
Find or create an entity.
ecs_query_desc_t
struct ecs_query_desc_t ecs_query_desc_t
Used with ecs_query_init().
flecs::_
Int to enum.
Definition component.hpp:18
builder_i.hpp
Query builder interface.
ecs_entity_desc_t
Used with ecs_entity_init().
Definition flecs.h:1018
ecs_entity_desc_t::sep
const char * sep
Optional custom separator for hierarchical names.
Definition flecs.h:1030
ecs_entity_desc_t::root_sep
const char * root_sep
Optional, used for identifiers relative to root.
Definition flecs.h:1034
ecs_entity_desc_t::name
const char * name
Name of the entity.
Definition flecs.h:1025
flecs::_::builder
Definition builder.hpp:19
flecs::_::sig
Definition signature.hpp:38
flecs::entity_view::id
entity_t id() const
Get entity id.
Definition entity_view.hpp:50
flecs::entity
Entity.
Definition entity.hpp:30
flecs::world
The world.
Definition world.hpp:158
flecs::world::query_builder
flecs::query_builder< Comps... > query_builder(Args &&... args) const
Create a query builder.
flecs::world::query
flecs::query< Comps... > query(Args &&... args) const
Create a query.
builder.hpp
Builder base class.