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 Entity id_entity(const World& world, Entity id) {
39 GAIA_ASSERT(!id.pair());
40 return entity_from_id(world, (EntityId)id.id());
41 }
42
43 GAIA_NODISCARD inline Entity pair_rel(const World& world, Entity pair) {
44 GAIA_ASSERT(pair.pair());
45 return entity_from_id(world, (EntityId)pair.id());
46 }
47
48 GAIA_NODISCARD inline Entity pair_tgt(const World& world, Entity pair) {
49 GAIA_ASSERT(pair.pair());
50 return entity_from_id(world, (EntityId)pair.gen());
51 }
52
53 GAIA_NODISCARD inline bool valid(const World& world, Entity entity) {
54 return world.valid(entity);
55 }
56
57 GAIA_NODISCARD inline bool is(const World& world, Entity entity, Entity baseEntity) {
58 return world.is(entity, baseEntity);
59 }
60
61 GAIA_NODISCARD inline bool is_base(const World& world, Entity entity) {
62 return world.is_base(entity);
63 }
64
65 GAIA_NODISCARD inline Archetype* archetype_from_entity(const World& world, Entity entity) {
66 if (!world.valid(entity))
67 return nullptr;
68
69 const auto& ec = world.fetch(entity);
70 if (World::is_req_del(ec))
71 return nullptr;
72
73 return ec.pArchetype;
74 }
75
76 GAIA_NODISCARD inline util::str_view entity_name(const World& world, Entity entity) {
77 const auto name = world.name(entity);
78 if (!name.empty())
79 return name;
80
81 if (!entity.pair()) {
82 const auto display = world.display_name(entity);
83 if (!display.empty())
84 return display;
85 }
86
87 return {};
88 }
89
90 GAIA_NODISCARD inline util::str_view entity_name(const World& world, EntityId entityId) {
91 return entity_name(world, world.get(entityId));
92 }
93
94 GAIA_NODISCARD inline Entity target(const World& world, Entity entity, Entity relation) {
95 return world.target(entity, relation);
96 }
97
98 // Traversal API
99
100 template <typename Func>
101 inline void as_relations_trav(const World& world, Entity target, Func func) {
102 world.as_relations_trav(target, func);
103 }
104
105 template <typename Func>
106 inline bool as_relations_trav_if(const World& world, Entity target, Func func) {
107 return world.as_relations_trav_if(target, func);
108 }
109
110 template <typename Func>
111 inline void as_targets_trav(const World& world, Entity relation, Func func) {
112 world.as_targets_trav(relation, func);
113 }
114
115 template <typename Func>
116 inline bool as_targets_trav_if(const World& world, Entity relation, Func func) {
117 return world.as_targets_trav_if(relation, func);
118 }
119
120 template <typename Func>
121 inline void targets_trav(const World& world, Entity relation, Entity source, Func func) {
122 world.targets_trav(relation, source, func);
123 }
124
125 template <typename Func>
126 inline bool targets_trav_if(const World& world, Entity relation, Entity source, Func func) {
127 return world.targets_trav_if(relation, source, func);
128 }
129
130 GAIA_NODISCARD inline const cnt::darray<Entity>&
131 targets_trav_cache(const World& world, Entity relation, Entity source) {
132 return world.targets_trav_cache(relation, source);
133 }
134
135 template <typename Func>
136 inline void sources(const World& world, Entity relation, Entity target, Func func) {
137 world.sources(relation, target, func);
138 }
139
140 template <typename Func>
141 inline void sources_if(const World& world, Entity relation, Entity target, Func func) {
142 world.sources_if(relation, target, func);
143 }
144
145 GAIA_NODISCARD inline const cnt::darray<Entity>&
146 sources_bfs_trav_cache(const World& world, Entity relation, Entity rootTarget) {
147 return world.sources_bfs_trav_cache(relation, rootTarget);
148 }
149
150 template <typename Func>
151 inline void sources_bfs(const World& world, Entity relation, Entity rootTarget, Func func) {
152 world.sources_bfs(relation, rootTarget, func);
153 }
154
155 template <typename Func>
156 inline bool sources_bfs_if(const World& world, Entity relation, Entity rootTarget, Func func) {
157 return world.sources_bfs_if(relation, rootTarget, func);
158 }
159
160 template <typename Func>
161 inline void children(const World& world, Entity parent, Func func) {
162 world.children(parent, func);
163 }
164
165 template <typename Func>
166 inline void children_if(const World& world, Entity parent, Func func) {
167 world.children_if(parent, func);
168 }
169
170 template <typename Func>
171 inline void children_bfs(const World& world, Entity root, Func func) {
172 world.children_bfs(root, func);
173 }
174
175 template <typename Func>
176 inline bool children_bfs_if(const World& world, Entity root, Func func) {
177 return world.children_bfs_if(root, func);
178 }
179
180 // Query API
181
182 GAIA_NODISCARD inline QuerySerBuffer& query_buffer(World& world, QueryId& serId) {
183 return world.query_buffer(serId);
184 }
185
186 inline void query_buffer_reset(World& world, QueryId& serId) {
187 world.query_buffer_reset(serId);
188 }
189
190 GAIA_NODISCARD inline Entity expr_to_entity(const World& world, va_list& args, std::span<const char> exprRaw) {
191 return world.expr_to_entity(args, exprRaw);
192 }
193
194 // Locking API
195
196 inline void lock(World& world) {
197 world.lock();
198 }
199 inline void unlock(World& world) {
200 world.unlock();
201 }
202 GAIA_NODISCARD inline bool locked(const World& world) {
203 return world.locked();
204 }
205
206 // CommandBuffer API
207
208 GAIA_NODISCARD inline CommandBufferST& cmd_buffer_st_get(World& world) {
209 return world.cmd_buffer_st();
210 }
211
212 GAIA_NODISCARD inline CommandBufferMT& cmd_buffer_mt_get(World& world) {
213 return world.cmd_buffer_mt();
214 }
215
216 inline void commit_cmd_buffer_st(World& world) {
217 if (world.locked())
218 return;
219 cmd_buffer_commit(world.cmd_buffer_st());
220 }
221
222 inline void commit_cmd_buffer_mt(World& world) {
223 if (world.locked())
224 return;
225 cmd_buffer_commit(world.cmd_buffer_mt());
226 }
227 } // namespace ecs
228} // 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:977
Checks if endianess was detected correctly at compile-time.
Definition bitset.h:9