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
6#pragma once
7
8#include "builder.hpp"
9
10namespace flecs
11{
12
13struct 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
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::observer observer(flecs::entity e) const
Observer builder.
ecs_entity_t ecs_observer_init(ecs_world_t *world, const ecs_observer_desc_t *desc)
Create observer.
const ecs_observer_t * ecs_observer_get(const ecs_world_t *world, ecs_entity_t observer)
Get observer object.
Observer builder.
Used with ecs_observer_init().
Definition flecs.h:1274
ecs_entity_t entity
Existing entity to associate with observer (optional)
Definition flecs.h:1279
void * ctx
User context to pass to callback.
Definition flecs.h:1303
void * ctx
Observer context.
Definition flecs.h:843
Entity.
Definition entity.hpp:30
Observer builder.
Definition builder.hpp:24
The world.
Definition world.hpp:137