Flecs: include/flecs/addons/cpp/mixins/id/impl.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| 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
10 inline 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
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, 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
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, NULL);
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
58inline 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
69template <typename T>
70 inline flecs::id world::id() const {
71 return flecs::id(world_, _::type<T>::id(world_));
72}
73
74template <typename ... Args>
75 inline flecs::id world::id(Args&&... args) const {
76 return flecs::id(world_, FLECS_FWD(args)...);
77}
78
79template <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
88template <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:352
ecs_get_typeid
ecs_entity_t ecs_get_typeid(const ecs_world_t *world, ecs_id_t id)
Get the type for an id.
ecs_get_alive
ecs_entity_t ecs_get_alive(const ecs_world_t *world, ecs_entity_t e)
Get alive identifier.
flecs::_::type
Definition flecs.hpp:38
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 pair (has first, second)
Definition decl.hpp:57
flecs::id::entity
flecs::entity entity() const
Return id as entity (only allowed when id is valid entity)
Definition impl.hpp:10
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 role.
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 role added.
Definition impl.hpp:40
flecs::id::second
flecs::entity second() const
Get second element from a pair.
Definition impl.hpp:31
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 role.
Definition impl.hpp:54
flecs::world
The world.
Definition world.hpp:137
flecs::world::pair
flecs::id pair() const
Get pair id from relationship, object.
Definition impl.hpp:80
flecs::world::id
flecs::id id() const
Get id from a type.
Definition impl.hpp:70