Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
builder_i.hpp
Go to the documentation of this file.
1
6#pragma once
7
9
10namespace flecs {
11
16template<typename Base, typename ... Components>
17struct observer_builder_i : query_builder_i<Base, Components ...> {
18 using BaseClass = query_builder_i<Base, Components ...>;
20 : BaseClass(nullptr)
21 , desc_(nullptr)
22 , event_count_(0) { }
23
25 : BaseClass(&desc->query)
26 , desc_(desc)
27 , event_count_(0) { }
28
32 Base& event(entity_t evt) {
33 desc_->events[event_count_ ++] = evt;
34 return *this;
35 }
36
40 template <typename E>
41 Base& event() {
42 desc_->events[event_count_ ++] = _::type<E>().id(world_v());
43 return *this;
44 }
45
47 Base& yield_existing(bool value = true) {
48 desc_->yield_existing = value;
49 return *this;
50 }
51
53 Base& observer_flags(ecs_flags32_t flags) {
54 desc_->flags_ |= flags;
55 return *this;
56 }
57
59 Base& ctx(void *ptr) {
60 desc_->ctx = ptr;
61 return *this;
62 }
63
65 Base& run(ecs_iter_action_t action) {
66 desc_->run = action;
67 return *this;
68 }
69
70protected:
71 virtual flecs::world_t* world_v() override = 0;
72
73private:
74 operator Base&() {
75 return *static_cast<Base*>(this);
76 }
77
79 int32_t event_count_;
80};
81
82}
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:547
Query builder interface.
Used with ecs_observer_init().
Definition flecs.h:1236
ecs_entity_t events[(8)]
Events to observe (OnAdd, OnRemove, OnSet)
Definition flecs.h:1247
void * ctx
User context to pass to callback.
Definition flecs.h:1265
ecs_query_desc_t query
Query for observer.
Definition flecs.h:1244
bool yield_existing
When observer is created, generate events from existing data.
Definition flecs.h:1251
ecs_run_action_t run
Callback invoked on an event.
Definition flecs.h:1262
Observer builder interface.
Definition builder_i.hpp:17
Base & event()
Specify the event(s) for when the observer should run.
Definition builder_i.hpp:41
Base & ctx(void *ptr)
Set observer context.
Definition builder_i.hpp:59
Base & yield_existing(bool value=true)
Invoke observer for anything that matches its query on creation.
Definition builder_i.hpp:47
Base & run(ecs_iter_action_t action)
Set observer run callback.
Definition builder_i.hpp:65
Base & event(entity_t evt)
Specify the event(s) for when the observer should run.
Definition builder_i.hpp:32
Base & observer_flags(ecs_flags32_t flags)
Set observer flags.
Definition builder_i.hpp:53
Query builder interface.
Definition builder_i.hpp:18