MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / instantiate_prefab

Method instantiate_prefab

modules/engine/runtime/src/ecs/storage.cpp:185–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183}
184
185void sugoi_storage_t::instantiate_prefab(const sugoi_entity_t* src, uint32_t size, uint32_t count, sugoi_view_callback_t callback, void* u)
186{
187 using namespace sugoi;
188 skr::stl_vector<sugoi_entity_t> ents;
189 ents.resize(count * size);
190 entities.new_entities(ents.data(), (EIndex)ents.size());
191 struct mapper_t {
192 sugoi_entity_t* base;
193 sugoi_entity_t* curr;
194 uint32_t size;
195 void move() { curr += size; }
196 void reset() { curr = base; }
197 void map(sugoi_entity_t& ent)
198 {
199 if (e_id(ent) > size || !e_transient(ent))
200 return;
201 ent = curr[e_id(ent)];
202 }
203 } m;
204 m.size = size;
205 skr::stl_vector<sugoi_entity_t> localEnts;
206 localEnts.resize(count);
207 forloop (i, 0, size)
208 {
209 forloop (j, 0, count)
210 localEnts[j] = ents[j * size + i];
211 auto view = entity_view(src[i]);
212 auto group = view.chunk->group->cloned;
213 auto localCount = 0;
214 while (localCount != count)
215 {
216 sugoi_chunk_view_t v = allocate_view(group, count - localCount);
217 entities.fill_entities(v, localEnts.data() + localCount);
218 duplicate_view(v, view.chunk, view.start);
219 m.base = m.curr = ents.data() + localCount * size;
220 localCount += v.count;
221 iterator_ref_view(v, m);
222 if (callback)
223 callback(u, &v);
224 }
225 }
226}
227
228void sugoi_storage_t::instantiate(const sugoi_entity_t src, uint32_t count, sugoi_view_callback_t callback, void* u)
229{

Callers

nothing calls this directly

Calls 7

duplicate_viewFunction · 0.85
iterator_ref_viewFunction · 0.85
new_entitiesMethod · 0.80
fill_entitiesMethod · 0.80
resizeMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected