Flecs v3.1
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(m_world, m_id);
14}
15
16inline flecs::entity id::flags() const {
17 return flecs::entity(m_world, m_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(m_id);
24 if (m_world) {
25 return flecs::entity(m_world, ecs_get_alive(m_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(m_id);
33 if (m_world) {
34 return flecs::entity(m_world, ecs_get_alive(m_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(m_world, m_id | flags);
42}
43
44inline flecs::entity id::remove_flags(flecs::id_t flags) const {
45 (void)flags;
46 ecs_assert((m_id & ECS_ID_FLAGS_MASK) == flags, ECS_INVALID_PARAMETER, NULL);
47 return flecs::entity(m_world, m_id & ECS_COMPONENT_MASK);
48}
49
51 return flecs::entity(m_world, m_id & ECS_COMPONENT_MASK);
52}
53
55 return flecs::entity(m_world, static_cast<uint32_t>(m_id));
56}
57
58inline flecs::world id::world() const {
59 return flecs::world(m_world);
60}
61
62inline flecs::entity id::type_id() const {
63 return flecs::entity(m_world, ecs_get_typeid(m_world, m_id));
64}
65
66
67// Id mixin implementation
68
69template <typename T>
70inline flecs::id world::id() const {
71 return flecs::id(m_world, _::cpp_type<T>::id(m_world));
72}
73
74template <typename ... Args>
75inline flecs::id world::id(Args&&... args) const {
76 return flecs::id(m_world, FLECS_FWD(args)...);
77}
78
79template <typename First, typename Second>
80inline flecs::id world::pair() const {
81 return flecs::id(
82 m_world,
83 ecs_pair(
84 _::cpp_type<First>::id(m_world),
85 _::cpp_type<Second>::id(m_world)));
86}
87
88template <typename First>
89inline flecs::id world::pair(entity_t o) const {
90 return flecs::id(
91 m_world,
92 ecs_pair(
93 _::cpp_type<First>::id(m_world),
94 o));
95}
96
97inline flecs::id world::pair(entity_t r, entity_t o) const {
98 return flecs::id(
99 m_world,
100 ecs_pair(r, o));
101}
102
103}
#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:53
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:113
flecs::id pair() const
Get pair id from relationship, object.