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
8namespace flecs {
9
10inline flecs::entity id::entity() const {
11 ecs_assert(!is_pair(), ECS_INVALID_OPERATION, NULL);
12 ecs_assert(!flags(), ECS_INVALID_OPERATION, NULL);
13 return flecs::entity(world_, id_);
14}
15
16inline flecs::entity id::flags() const {
17 return flecs::entity(world_, id_ & ECS_ID_FLAGS_MASK);
18}
19
20inline flecs::entity id::first() const {
21 ecs_assert(is_pair(), ECS_INVALID_OPERATION, NULL);
22
23 flecs::entity_t e = ECS_PAIR_FIRST(id_);
24 if (world_) {
25 return flecs::entity(world_, ecs_get_alive(world_, e));
26 } else {
27 return flecs::entity(e);
28 }
29}
30
31inline flecs::entity id::second() const {
32 flecs::entity_t e = ECS_PAIR_SECOND(id_);
33 if (world_) {
34 return flecs::entity(world_, ecs_get_alive(world_, e));
35 } else {
36 return flecs::entity(e);
37 }
38}
39
40inline flecs::entity id::add_flags(flecs::id_t flags) const {
41 return flecs::entity(world_, id_ | flags);
42}
43
44inline flecs::entity id::remove_flags(flecs::id_t flags) const {
45 (void)flags;
46 ecs_assert((id_ & ECS_ID_FLAGS_MASK) == flags, ECS_INVALID_PARAMETER, NULL);
47 return flecs::entity(world_, id_ & ECS_COMPONENT_MASK);
48}
49
51 return flecs::entity(world_, id_ & ECS_COMPONENT_MASK);
52}
53
55 return flecs::entity(world_, static_cast<uint32_t>(id_));
56}
57
58inline flecs::world id::world() const {
59 return flecs::world(world_);
60}
61
62inline flecs::entity id::type_id() const {
63 return flecs::entity(world_, ecs_get_typeid(world_, id_));
64}
65
66
67// Id mixin implementation
68
69template <typename T>
70inline flecs::id world::id() const {
71 return flecs::id(world_, _::type<T>::id(world_));
72}
73
74template <typename ... Args>
75inline flecs::id world::id(Args&&... args) const {
76 return flecs::id(world_, FLECS_FWD(args)...);
77}
78
79template <typename First, typename Second>
80inline flecs::id world::pair() const {
81 return flecs::id(
82 world_,
83 ecs_pair(
84 _::type<First>::id(world_),
85 _::type<Second>::id(world_)));
86}
87
88template <typename First>
89inline flecs::id world::pair(entity_t o) const {
90 ecs_assert(!ECS_IS_PAIR(o), ECS_INVALID_PARAMETER,
91 "cannot create nested pairs");
92
93 return flecs::id(
94 world_,
95 ecs_pair(
96 _::type<First>::id(world_),
97 o));
98}
99
100inline flecs::id world::pair(entity_t r, entity_t o) const {
101 ecs_assert(!ECS_IS_PAIR(r) && !ECS_IS_PAIR(o), ECS_INVALID_PARAMETER,
102 "cannot create nested pairs");
103
104 return flecs::id(
105 world_,
106 ecs_pair(r, o));
107}
108
109}
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
ecs_entity_t ecs_get_typeid(const ecs_world_t *world, ecs_id_t id)
Get the type for an id.
ecs_entity_t ecs_get_alive(const ecs_world_t *world, ecs_entity_t e)
Get alive identifier.
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
bool is_pair() const
Test if id is pair (has first, second)
Definition decl.hpp:57
flecs::entity entity() const
Return id as entity (only allowed when id is valid entity)
Definition impl.hpp:10
flecs::entity flags() const
Return id flags set on id.
Definition impl.hpp:16
flecs::entity remove_flags() const
Return id without role.
Definition impl.hpp:50
flecs::entity type_id() const
Return component type of id.
Definition impl.hpp:62
flecs::entity add_flags(flecs::id_t flags) const
Return id with role added.
Definition impl.hpp:40
flecs::entity second() const
Get second element from a pair.
Definition impl.hpp:31
flecs::entity first() const
Get first element from a pair.
Definition impl.hpp:20
flecs::entity remove_generation() const
Return id without role.
Definition impl.hpp:54
The world.
Definition world.hpp:137
flecs::id pair() const
Get pair id from relationship, object.