Flecs: include/flecs/addons/cpp/mixins/observer/impl.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
impl.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "builder.hpp"
9
10namespace flecs
11{
12
13 struct observer final : entity
14{
15 using entity::entity;
16
17 explicit observer() : entity() { }
18
19 observer(flecs::world_t *world, ecs_observer_desc_t *desc) {
20 world_ = world;
21 id_ = ecs_observer_init(world, desc);
22 }
23
24 void ctx(void *ctx) {
25 ecs_observer_desc_t desc = {};
26 desc.entity = id_;
27 desc.ctx = ctx;
28 ecs_observer_init(world_, &desc);
29 }
30
31 void* ctx() const {
32 return ecs_observer_get(world_, id_)->ctx;
33 }
34
35 flecs::query<> query() const {
36 return flecs::query<>(ecs_observer_get(world_, id_)->query);
37 }
38};
39
40// Mixin implementation
41 inline observer world::observer(flecs::entity e) const {
42 return flecs::observer(world_, e);
43}
44
45template <typename... Comps, typename... Args>
46inline observer_builder<Comps...> world::observer(Args &&... args) const {
47 return flecs::observer_builder<Comps...>(world_, FLECS_FWD(args)...);
48}
49
50} // namespace flecs
flecs::world::observer
flecs::observer observer(flecs::entity e) const
Observer builder.
Definition impl.hpp:41
ecs_observer_init
ecs_entity_t ecs_observer_init(ecs_world_t *world, const ecs_observer_desc_t *desc)
Create observer.
ecs_observer_get
const ecs_observer_t * ecs_observer_get(const ecs_world_t *world, ecs_entity_t observer)
Get observer object.
builder.hpp
Observer builder.
ecs_observer_desc_t
Used with ecs_observer_init().
Definition flecs.h:1330
ecs_observer_desc_t::entity
ecs_entity_t entity
Existing entity to associate with observer (optional)
Definition flecs.h:1335
ecs_observer_desc_t::ctx
void * ctx
User context to pass to callback.
Definition flecs.h:1359
ecs_observer_t::ctx
void * ctx
Observer context.
Definition flecs.h:870
flecs::entity
Entity.
Definition entity.hpp:30
flecs::id::entity
flecs::entity entity() const
Return id as entity (only allowed when id is valid entity)
Definition impl.hpp:10
flecs::observer_builder
Observer builder.
Definition builder.hpp:24
flecs::observer
Definition impl.hpp:14
flecs::query
Definition impl.hpp:196
flecs::world
The world.
Definition world.hpp:150