Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
api.inl
1#include "gaia/config/config.h"
2
3namespace gaia {
4 namespace ecs {
5 // Component API
6
7 GAIA_NODISCARD inline const ComponentCache& comp_cache(const World& world) {
8 return world.comp_cache();
9 }
10
11 GAIA_NODISCARD inline ComponentCache& comp_cache_mut(World& world) {
12 return world.comp_cache_mut();
13 }
14
15 template <typename T>
16 GAIA_NODISCARD inline const ComponentCacheItem& comp_cache_add(World& world) {
17 return world.reg_comp<T>();
18 }
19
20 // Entity API
21
22 GAIA_NODISCARD inline const EntityContainer& fetch(const World& world, Entity entity) {
23 return world.fetch(entity);
24 }
25
26 GAIA_NODISCARD inline EntityContainer& fetch_mut(World& world, Entity entity) {
27 return world.fetch(entity);
28 }
29
30 inline void del(World& world, Entity entity) {
31 world.del(entity);
32 }
33
34 GAIA_NODISCARD inline Entity entity_from_id(const World& world, EntityId id) {
35 return world.get(id);
36 }
37
38 GAIA_NODISCARD inline bool valid(const World& world, Entity entity) {
39 return world.valid(entity);
40 }
41
42 GAIA_NODISCARD inline bool is(const World& world, Entity entity, Entity baseEntity) {
43 return world.is(entity, baseEntity);
44 }
45
46 GAIA_NODISCARD inline bool is_base(const World& world, Entity entity) {
47 return world.is_base(entity);
48 }
49
50 GAIA_NODISCARD inline Archetype* archetype_from_entity(const World& world, Entity entity) {
51 if (!world.valid(entity))
52 return nullptr;
53
54 const auto& ec = world.fetch(entity);
55 if (World::is_req_del(ec))
56 return nullptr;
57
58 return ec.pArchetype;
59 }
60
61 GAIA_NODISCARD inline util::str_view entity_name(const World& world, Entity entity) {
62 const auto name = world.name(entity);
63 if (!name.empty())
64 return name;
65
66 if (!entity.pair()) {
67 const auto display = world.display_name(entity);
68 if (!display.empty())
69 return display;
70 }
71
72 return {};
73 }
74
75 GAIA_NODISCARD inline util::str_view entity_name(const World& world, EntityId entityId) {
76 return entity_name(world, world.get(entityId));
77 }
78
79 GAIA_NODISCARD inline Entity target(const World& world, Entity entity, Entity relation) {
80 return world.target(entity, relation);
81 }
82
83 // Traversal API
84
85 template <typename Func>
86 inline void as_relations_trav(const World& world, Entity target, Func func) {
87 world.as_relations_trav(target, func);
88 }
89
90 template <typename Func>
91 inline bool as_relations_trav_if(const World& world, Entity target, Func func) {
92 return world.as_relations_trav_if(target, func);
93 }
94
95 template <typename Func>
96 inline void as_targets_trav(const World& world, Entity relation, Func func) {
97 world.as_targets_trav(relation, func);
98 }
99
100 template <typename Func>
101 inline bool as_targets_trav_if(const World& world, Entity relation, Func func) {
102 return world.as_targets_trav_if(relation, func);
103 }
104
105 template <typename Func>
106 inline void targets_trav(const World& world, Entity relation, Entity source, Func func) {
107 world.targets_trav(relation, source, func);
108 }
109
110 template <typename Func>
111 inline bool targets_trav_if(const World& world, Entity relation, Entity source, Func func) {
112 return world.targets_trav_if(relation, source, func);
113 }
114
115 GAIA_NODISCARD inline const cnt::darray<Entity>&
116 targets_trav_cache(const World& world, Entity relation, Entity source) {
117 return world.targets_trav_cache(relation, source);
118 }
119
120 template <typename Func>
121 inline void sources(const World& world, Entity relation, Entity target, Func func) {
122 world.sources(relation, target, func);
123 }
124
125 template <typename Func>
126 inline void sources_if(const World& world, Entity relation, Entity target, Func func) {
127 world.sources_if(relation, target, func);
128 }
129
130 GAIA_NODISCARD inline const cnt::darray<Entity>&
131 sources_bfs_trav_cache(const World& world, Entity relation, Entity rootTarget) {
132 return world.sources_bfs_trav_cache(relation, rootTarget);
133 }
134
135 template <typename Func>
136 inline void sources_bfs(const World& world, Entity relation, Entity rootTarget, Func func) {
137 world.sources_bfs(relation, rootTarget, func);
138 }
139
140 template <typename Func>
141 inline bool sources_bfs_if(const World& world, Entity relation, Entity rootTarget, Func func) {
142 return world.sources_bfs_if(relation, rootTarget, func);
143 }
144
145 template <typename Func>
146 inline void children(const World& world, Entity parent, Func func) {
147 world.children(parent, func);
148 }
149
150 template <typename Func>
151 inline void children_if(const World& world, Entity parent, Func func) {
152 world.children_if(parent, func);
153 }
154
155 template <typename Func>
156 inline void children_bfs(const World& world, Entity root, Func func) {
157 world.children_bfs(root, func);
158 }
159
160 template <typename Func>
161 inline bool children_bfs_if(const World& world, Entity root, Func func) {
162 return world.children_bfs_if(root, func);
163 }
164
165 // Query API
166
167 GAIA_NODISCARD inline QuerySerBuffer& query_buffer(World& world, QueryId& serId) {
168 return world.query_buffer(serId);
169 }
170
171 inline void query_buffer_reset(World& world, QueryId& serId) {
172 world.query_buffer_reset(serId);
173 }
174
175 GAIA_NODISCARD inline Entity expr_to_entity(const World& world, va_list& args, std::span<const char> exprRaw) {
176 return world.expr_to_entity(args, exprRaw);
177 }
178
179 // Locking API
180
181 inline void lock(World& world) {
182 world.lock();
183 }
184 inline void unlock(World& world) {
185 world.unlock();
186 }
187 GAIA_NODISCARD inline bool locked(const World& world) {
188 return world.locked();
189 }
190
191 // CommandBuffer API
192
193 GAIA_NODISCARD inline CommandBufferST& cmd_buffer_st_get(World& world) {
194 return world.cmd_buffer_st();
195 }
196
197 GAIA_NODISCARD inline CommandBufferMT& cmd_buffer_mt_get(World& world) {
198 return world.cmd_buffer_mt();
199 }
200
201 inline void commit_cmd_buffer_st(World& world) {
202 if (world.locked())
203 return;
204 cmd_buffer_commit(world.cmd_buffer_st());
205 }
206
207 inline void commit_cmd_buffer_mt(World& world) {
208 if (world.locked())
209 return;
210 cmd_buffer_commit(world.cmd_buffer_mt());
211 }
212 } // namespace ecs
213} // namespace gaia
Definition span_impl.h:99
static GAIA_NODISCARD bool is_req_del(const EntityContainer &ec)
Returns whether the record is already in delete-requested state. Covers both explicit per-entity dele...
Definition world.h:2314
Checks if endianess was detected correctly at compile-time.
Definition bitset.h:9