Flecs: include/flecs/addons/cpp/mixins/observer/builder_i.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_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 ...>;
19 observer_builder_i()
20 : BaseClass(nullptr)
21 , desc_(nullptr)
22 , event_count_(0) { }
23
24 observer_builder_i(ecs_observer_desc_t *desc)
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
78 ecs_observer_desc_t *desc_;
79 int32_t event_count_;
80};
81
82}
ecs_iter_action_t
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:556
builder_i.hpp
Query builder interface.
ecs_observer_desc_t
Used with ecs_observer_init().
Definition flecs.h:1325
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:41
flecs::observer_builder_i::ctx
Base & ctx(void *ptr)
Set observer context.
Definition builder_i.hpp:59
flecs::observer_builder_i::yield_existing
Base & yield_existing(bool value=true)
Invoke observer for anything that matches its query on creation.
Definition builder_i.hpp:47
flecs::observer_builder_i::run
Base & run(ecs_iter_action_t action)
Set observer run callback.
Definition builder_i.hpp:65
flecs::observer_builder_i::event
Base & event(entity_t evt)
Specify the event(s) for when the observer should run.
Definition builder_i.hpp:32
flecs::observer_builder_i::observer_flags
Base & observer_flags(ecs_flags32_t flags)
Set observer flags.
Definition builder_i.hpp:53