Gaia-ECS v1.0.0
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 GAIA_NODISCARD inline EntityContainer* try_fetch_mut(World& world, Entity entity) {
31 return world.try_fetch_record(entity);
32 }
33
34 inline void del(World& world, Entity entity) {
35 world.del(entity);
36 }
37
38#if GAIA_USE_SAFE_ENTITY
39 inline void safe_entity_acquire(World& world, Entity entity) {
40 world.safe_ref_add(entity);
41 }
42
43 inline void safe_entity_release(World& world, Entity entity) {
44 world.safe_ref_del(entity);
45 }
46#endif
47
48 GAIA_NODISCARD inline Entity entity_from_id(const World& world, EntityId id) {
49 return world.get(id);
50 }
51
52 GAIA_NODISCARD inline Entity id_entity(const World& world, Entity id) {
53 GAIA_ASSERT(!id.pair());
54 return entity_from_id(world, (EntityId)id.id());
55 }
56
57 GAIA_NODISCARD inline Entity pair_rel(const World& world, Entity pair) {
58 GAIA_ASSERT(pair.pair());
59 return entity_from_id(world, (EntityId)pair.id());
60 }
61
62 GAIA_NODISCARD inline Entity pair_tgt(const World& world, Entity pair) {
63 GAIA_ASSERT(pair.pair());
64 return entity_from_id(world, (EntityId)pair.gen());
65 }
66
67 GAIA_NODISCARD inline bool valid(const World& world, Entity entity) {
68 return world.valid(entity);
69 }
70
71 GAIA_NODISCARD inline bool is(const World& world, Entity entity, Entity baseEntity) {
72 return world.is(entity, baseEntity);
73 }
74
75 GAIA_NODISCARD inline bool is_base(const World& world, Entity entity) {
76 return world.is_base(entity);
77 }
78
79 GAIA_NODISCARD inline Archetype* archetype_from_entity(const World& world, Entity entity) {
80 const auto* pEc = world.try_live_record(entity);
81 if (pEc == nullptr)
82 return nullptr;
83
84 return pEc->pArchetype;
85 }
86
87 GAIA_NODISCARD inline util::str_view entity_name(const World& world, Entity entity) {
88 const auto name = world.name(entity);
89 if (!name.empty())
90 return name;
91
92 if (!entity.pair()) {
93 const auto display = world.display_name(entity);
94 if (!display.empty())
95 return display;
96 }
97
98 return {};
99 }
100
101 GAIA_NODISCARD inline util::str_view entity_name(const World& world, EntityId entityId) {
102 return entity_name(world, world.get(entityId));
103 }
104
105 GAIA_NODISCARD inline Entity target(const World& world, Entity entity, Entity relation) {
106 return world.target(entity, relation);
107 }
108
109 // Traversal API
110
111 template <typename Func>
112 inline void as_relations_trav(const World& world, Entity target, Func func) {
113 world.as_relations_trav(target, func);
114 }
115
116 template <typename Func>
117 inline bool as_relations_trav_if(const World& world, Entity target, Func func) {
118 return world.as_relations_trav_if(target, func);
119 }
120
121 template <typename Func>
122 inline void as_targets_trav(const World& world, Entity relation, Func func) {
123 world.as_targets_trav(relation, func);
124 }
125
126 template <typename Func>
127 inline bool as_targets_trav_if(const World& world, Entity relation, Func func) {
128 return world.as_targets_trav_if(relation, func);
129 }
130
131 template <typename Func>
132 inline void targets_trav(const World& world, Entity relation, Entity source, Func func) {
133 world.targets_trav(relation, source, func);
134 }
135
136 template <typename Func>
137 inline bool targets_trav_if(const World& world, Entity relation, Entity source, Func func) {
138 return world.targets_trav_if(relation, source, func);
139 }
140
141 GAIA_NODISCARD inline const cnt::darray<Entity>&
142 targets_trav_cache(const World& world, Entity relation, Entity source) {
143 return world.targets_trav_cache(relation, source);
144 }
145
146 template <typename Func>
147 inline void sources(const World& world, Entity relation, Entity target, Func func) {
148 world.sources(relation, target, func);
149 }
150
151 template <typename Func>
152 inline void sources_if(const World& world, Entity relation, Entity target, Func func) {
153 world.sources_if(relation, target, func);
154 }
155
156 GAIA_NODISCARD inline const cnt::darray<Entity>&
157 sources_bfs_trav_cache(const World& world, Entity relation, Entity rootTarget) {
158 return world.sources_bfs_trav_cache(relation, rootTarget);
159 }
160
161 template <typename Func>
162 inline void sources_bfs(const World& world, Entity relation, Entity rootTarget, Func func) {
163 world.sources_bfs(relation, rootTarget, func);
164 }
165
166 template <typename Func>
167 inline bool sources_bfs_if(const World& world, Entity relation, Entity rootTarget, Func func) {
168 return world.sources_bfs_if(relation, rootTarget, func);
169 }
170
171 // Query API
172
173 GAIA_NODISCARD inline QuerySerBuffer& query_buffer(World& world, QueryId& serId) {
174 return world.query_buffer(serId);
175 }
176
177 inline void query_buffer_reset(World& world, QueryId& serId) {
178 world.query_buffer_reset(serId);
179 }
180
181 GAIA_NODISCARD inline Entity expr_to_entity(const World& world, va_list& args, std::span<const char> exprRaw) {
182 return world.expr_to_entity(args, exprRaw);
183 }
184
185 // Locking API
186
187 inline void lock(World& world) {
188 world.lock();
189 }
190 inline void unlock(World& world) {
191 world.unlock();
192 }
193 GAIA_NODISCARD inline bool locked(const World& world) {
194 return world.locked();
195 }
196
197 // CommandBuffer API
198
199 GAIA_NODISCARD inline CommandBufferST& cmd_buffer_st_get(World& world) {
200 return world.cmd_buffer_st();
201 }
202
203 GAIA_NODISCARD inline CommandBufferMT& cmd_buffer_mt_get(World& world) {
204 return world.cmd_buffer_mt();
205 }
206
207 inline void commit_cmd_buffer_st(World& world) {
208 if (world.locked())
209 return;
210 cmd_buffer_commit(world.cmd_buffer_st());
211 }
212
213 inline void commit_cmd_buffer_mt(World& world) {
214 if (world.locked())
215 return;
216 cmd_buffer_commit(world.cmd_buffer_mt());
217 }
218 } // namespace ecs
219} // namespace gaia
Owns entities, components, archetypes, queries, observers, and systems.
Definition world.h:80
void del(Entity entity)
Removes an entity along with all data associated with it.
Definition world.h:6727
Identifier of an entity or component instance in the world. Packs the entity index,...
Definition id.h:231