Flecs
v4.1
A fast entity component system (ECS) for C & C++
Toggle main menu visibility
Loading...
Searching...
No Matches
impl.hpp
Go to the documentation of this file.
1
5
6
#pragma once
7
8
namespace
flecs {
9
10
inline
flecs::entity
id::entity
()
const
{
11
ecs_assert
(!
is_pair
(),
ECS_INVALID_OPERATION
,
nullptr
);
12
ecs_assert
(!
flags
(),
ECS_INVALID_OPERATION
,
nullptr
);
13
return
flecs::entity
(
world_
,
id_
);
14
}
15
16
inline
flecs::entity
id::flags
()
const
{
17
return
flecs::entity
(
world_
,
id_
& ECS_ID_FLAGS_MASK);
18
}
19
20
inline
flecs::entity
id::first
()
const
{
21
ecs_assert
(
is_pair
(),
ECS_INVALID_OPERATION
,
nullptr
);
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
31
inline
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
40
inline
flecs::entity
id::add_flags
(
flecs::id_t
flags
)
const
{
41
return
flecs::entity
(
world_
,
id_
|
flags
);
42
}
43
44
inline
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
,
nullptr
);
47
return
flecs::entity
(
world_
,
id_
& ECS_COMPONENT_MASK);
48
}
49
50
inline
flecs::entity
id::remove_flags
()
const
{
51
return
flecs::entity
(
world_
,
id_
& ECS_COMPONENT_MASK);
52
}
53
54
inline
flecs::entity
id::remove_generation
()
const
{
55
return
flecs::entity
(
world_
,
static_cast<
uint32_t
>
(
id_
));
56
}
57
58
inline
flecs::world
id::world
()
const
{
59
return
flecs::world
(
world_
);
60
}
61
62
inline
flecs::entity
id::type_id
()
const
{
63
return
flecs::entity
(
world_
,
ecs_get_typeid
(
world_
,
id_
));
64
}
65
66
67
// ID mixin implementation
68
69
template
<
typename
T>
70
inline
flecs::id
world::id
()
const
{
71
return
flecs::id
(
world_
,
_::type<T>::id
(
world_
));
72
}
73
74
template
<
typename
... Args>
75
inline
flecs::id
world::id
(Args&&... args)
const
{
76
return
flecs::id
(
world_
, FLECS_FWD(args)...);
77
}
78
79
template
<
typename
First,
typename
Second>
80
inline
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
88
template
<
typename
First>
89
inline
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
100
inline
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
}
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition
log.h:473
ECS_INVALID_OPERATION
#define ECS_INVALID_OPERATION
Invalid operation error code.
Definition
log.h:669
ECS_INVALID_PARAMETER
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition
log.h:671
flecs::id_t
ecs_id_t id_t
ID type.
Definition
c_types.hpp:20
flecs::entity_t
ecs_entity_t entity_t
Entity type.
Definition
c_types.hpp:21
ecs_get_typeid
ecs_entity_t ecs_get_typeid(const ecs_world_t *world, ecs_id_t component)
Get the type for a component.
ecs_get_alive
ecs_entity_t ecs_get_alive(const ecs_world_t *world, ecs_entity_t e)
Get an alive identifier.
flecs::_::type
Definition
flecs.hpp:39
flecs::entity
Entity.
Definition
entity.hpp:30
flecs::id
Class that wraps around a flecs::id_t.
Definition
decl.hpp:27
flecs::id::is_pair
bool is_pair() const
Test if ID is a pair (has first, second).
Definition
decl.hpp:57
flecs::id::entity
flecs::entity entity() const
Return ID as entity (only allowed when ID is a valid entity).
Definition
impl.hpp:10
flecs::id::world
flecs::world world() const
Get the world.
Definition
impl.hpp:58
flecs::id::flags
flecs::entity flags() const
Return ID flags set on ID.
Definition
impl.hpp:16
flecs::id::remove_flags
flecs::entity remove_flags() const
Return ID without flags.
Definition
impl.hpp:50
flecs::id::type_id
flecs::entity type_id() const
Return component type of ID.
Definition
impl.hpp:62
flecs::id::add_flags
flecs::entity add_flags(flecs::id_t flags) const
Return ID with flags added.
Definition
impl.hpp:40
flecs::id::id_
flecs::id_t id_
The raw ID value.
Definition
decl.hpp:149
flecs::id::second
flecs::entity second() const
Get second element from a pair.
Definition
impl.hpp:31
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::id::first
flecs::entity first() const
Get first element from a pair.
Definition
impl.hpp:20
flecs::id::remove_generation
flecs::entity remove_generation() const
Return ID without generation.
Definition
impl.hpp:54
flecs::world
The world.
Definition
world.hpp:246
flecs::world::world_
world_t * world_
Pointer to the underlying C world.
Definition
world.hpp:1540
flecs::world::pair
flecs::id pair() const
Get pair ID from relationship and object.
Definition
impl.hpp:80
flecs::world::id
flecs::id id() const
Get ID from a type.
Definition
impl.hpp:70