Flecs: include/flecs/addons/cpp/mixins/observer/impl.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
impl.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "builder.hpp"
9
10namespace flecs
11{
12
17 struct observer final : entity
18{
19 using entity::entity;
20
22 explicit observer() : entity() { }
23
25 observer(flecs::world_t *world, ecs_observer_desc_t *desc) {
26 world_ = world;
27 id_ = ecs_observer_init(world, desc);
28 }
29
31 void ctx(void *ctx) {
32 ecs_observer_desc_t desc = {};
33 desc.entity = id_;
34 desc.ctx = ctx;
35 ecs_observer_init(world_, &desc);
36 }
37
39 void* ctx() const {
40 return ecs_observer_get(world_, id_)->ctx;
41 }
42
44 flecs::query<> query() const {
45 return flecs::query<>(ecs_observer_get(world_, id_)->query);
46 }
47};
48
50 inline observer world::observer(flecs::entity e) const {
51 return flecs::observer(world_, e);
52}
53
54template <typename... Comps, typename... Args>
55inline observer_builder<Comps...> world::observer(Args &&... args) const {
56 return flecs::observer_builder<Comps...>(world_, FLECS_FWD(args)...);
57}
58
59} // namespace flecs
flecs::world_t
ecs_world_t world_t
World type.
Definition c_types.hpp:18
flecs::world::observer
flecs::observer observer(flecs::entity e) const
Observer world mixin.
Definition impl.hpp:50
ecs_observer_init
ecs_entity_t ecs_observer_init(ecs_world_t *world, const ecs_observer_desc_t *desc)
Create an observer.
ecs_observer_get
const ecs_observer_t * ecs_observer_get(const ecs_world_t *world, ecs_entity_t observer)
Get the observer object.
builder.hpp
Observer builder.
ecs_observer_desc_t
Used with ecs_observer_init().
Definition flecs.h:1349
ecs_observer_desc_t::entity
ecs_entity_t entity
Existing entity to associate with an observer (optional).
Definition flecs.h:1354
ecs_observer_desc_t::ctx
void * ctx
User context to pass to callback.
Definition flecs.h:1383
ecs_observer_t::ctx
void * ctx
Observer context.
Definition flecs.h:887
flecs::entity
Entity.
Definition entity.hpp:30
flecs::entity::entity
entity()
Default constructor.
Definition entity.hpp:32
flecs::id::id_
flecs::id_t id_
The raw ID value.
Definition decl.hpp:149
flecs::id::world_
flecs::world_t * world_
World is optional, but guarantees that entity identifiers extracted from the ID are valid.
Definition decl.hpp:147
flecs::observer_builder
Observer builder.
Definition builder.hpp:24
flecs::observer
Observer.
Definition impl.hpp:18
flecs::observer::ctx
void * ctx() const
Get the observer context.
Definition impl.hpp:39
flecs::observer::observer
observer()
Default constructor.
Definition impl.hpp:22
flecs::observer::observer
observer(flecs::world_t *world, ecs_observer_desc_t *desc)
Construct from a world and an observer descriptor.
Definition impl.hpp:25
flecs::observer::ctx
void ctx(void *ctx)
Set the observer context.
Definition impl.hpp:31
flecs::observer::entity
entity()
Default constructor.
Definition entity.hpp:32
flecs::observer::query
flecs::query query() const
Get the query for this observer.
Definition impl.hpp:44
flecs::query
Typed query.
Definition impl.hpp:220
flecs::world
The world.
Definition world.hpp:246
flecs::world::world_
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1545