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

Method pack_entities

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

Source from the content-addressed store, hash-verified

444}
445
446void sugoi_storage_t::pack_entities()
447{
448 using namespace sugoi;
449 if (scheduler)
450 {
451 SKR_ASSERT(scheduler->is_main_thread(this));
452 scheduler->sync_storage(this);
453 }
454 skr::stl_vector<EIndex> map;
455 auto& entries = entities.entries;
456 map.resize(entries.size());
457 entities.freeEntries.clear();
458 EIndex j = 0;
459 forloop (i, 0, entries.size())
460 {
461 if (entries[i].indexInChunk != 0)
462 {
463 map[i] = j;
464 if (i != j)
465 entries[j] = entries[i];
466 j++;
467 }
468 }
469 struct mapper {
470 skr::stl_vector<EIndex>* data;
471 void move() {}
472 void reset() {}
473 void map(sugoi_entity_t& e)
474 {
475 if (e_id(e) < data->size())
476 e = e_id(e, (*data)[e_id(e)]);
477 }
478 } m;
479 m.data = &map;
480 skr::stl_vector<sugoi_group_t*> gs;
481 for (auto& pair : groups)
482 gs.push_back(pair.second);
483 groups.clear();
484 for (auto g : gs)
485 {
486 for (auto c : g->chunks)
487 {
488 iterator_ref_chunk(c, m);
489 iterator_ref_view({ c, 0, c->count }, m);
490 }
491 auto meta = g->type.meta;
492 forloop (i, 0, meta.length)
493 m.map(((sugoi_entity_t*)meta.data)[i]);
494 std::sort((sugoi_entity_t*)meta.data, (sugoi_entity_t*)meta.data + meta.length);
495 groups.insert({ g->type, g });
496 }
497}
498
499void sugoi_storage_t::cast_impl(const sugoi_chunk_view_t& view, sugoi_group_t* group, sugoi_cast_callback_t callback, void* u)
500{

Callers 1

sugoiS_pack_entitiesFunction · 0.80

Calls 11

iterator_ref_chunkFunction · 0.85
iterator_ref_viewFunction · 0.85
is_main_threadMethod · 0.80
sync_storageMethod · 0.80
sortFunction · 0.50
resizeMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45
mapMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected