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

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

Loading...
Searching...
No Matches
builder_i.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "../query/builder_i.hpp"
9
10namespace flecs {
11
16template<typename Base, typename ... Components>
17 struct observer_builder_i : query_builder_i<Base, Components ...> {
18 using BaseClass = query_builder_i<Base, Components ...>;
20 observer_builder_i()
21 : BaseClass(nullptr)
22 , desc_(nullptr)
23 , event_count_(0) { }
24
26 observer_builder_i(ecs_observer_desc_t *desc)
27 : BaseClass(&desc->query)
28 , desc_(desc)
29 , event_count_(0) { }
30
34 Base& event(entity_t evt) {
35 desc_->events[event_count_ ++] = evt;
36 return *this;
37 }
38
42 template <typename E>
43 Base& event() {
44 desc_->events[event_count_ ++] = _::type<E>().id(world_v());
45 return *this;
46 }
47
49 Base& yield_existing(bool value = true) {
50 desc_->yield_existing = value;
51 return *this;
52 }
53
55 Base& observer_flags(ecs_flags32_t flags) {
56 desc_->flags_ |= flags;
57 return *this;
58 }
59
61 Base& ctx(void *ptr) {
62 desc_->ctx = ptr;
63 return *this;
64 }
65
67 Base& run(ecs_iter_action_t action) {
68 desc_->run = action;
69 return *this;
70 }
71
72protected:
73 virtual flecs::world_t* world_v() override = 0;
74
75private:
76 operator Base&() {
77 return *static_cast<Base*>(this);
78 }
79
80 ecs_observer_desc_t *desc_;
81 int32_t event_count_;
82};
83
84}
flecs::entity_t
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
flecs::world_t
ecs_world_t world_t
World type.
Definition c_types.hpp:18
ecs_iter_action_t
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:577
builder_i.hpp
Query builder interface.
ecs_observer_desc_t
Used with ecs_observer_init().
Definition flecs.h:1349
flecs::_::type
Definition flecs.hpp:39
flecs::observer_builder_i::event
Base & event()
Specify the event(s) for when the observer should run.
Definition builder_i.hpp:43
flecs::observer_builder_i::observer_builder_i
observer_builder_i()
Default constructor.
Definition builder_i.hpp:20
flecs::observer_builder_i::ctx
Base & ctx(void *ptr)
Set the observer context.
Definition builder_i.hpp:61
flecs::observer_builder_i::yield_existing
Base & yield_existing(bool value=true)
Invoke the observer for anything that matches its query on creation.
Definition builder_i.hpp:49
flecs::observer_builder_i::run
Base & run(ecs_iter_action_t action)
Set the observer run callback.
Definition builder_i.hpp:67
flecs::observer_builder_i::event
Base & event(entity_t evt)
Specify the event(s) for when the observer should run.
Definition builder_i.hpp:34
flecs::observer_builder_i::observer_builder_i
observer_builder_i(ecs_observer_desc_t *desc)
Construct from an observer descriptor.
Definition builder_i.hpp:26
flecs::observer_builder_i::observer_flags
Base & observer_flags(ecs_flags32_t flags)
Set the observer flags.
Definition builder_i.hpp:55
flecs::query_builder_i< Base, Components ... >::query_builder_i
query_builder_i(ecs_query_desc_t *desc, int32_t term_index=0)
Definition builder_i.hpp:20
flecs::query
Typed query.
Definition impl.hpp:220
flecs::term_builder_i::desc
Base & desc()
Use with cascade() to iterate results in descending (bottom-to-top) order.
Definition builder_i.hpp:264
flecs::term_ref_builder_i::flags
Base & flags(flecs::flags64_t flags)
Override the term ID flags.
Definition builder_i.hpp:74