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

Method merge

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

Source from the content-addressed store, hash-verified

642}
643
644void sugoi_storage_t::merge(sugoi_storage_t& src)
645{
646 using namespace sugoi;
647 if (scheduler)
648 {
649 SKR_ASSERT(scheduler->is_main_thread(this));
650 scheduler->sync_storage(&src);
651 }
652 auto& sents = src.entities;
653 skr::stl_vector<sugoi_entity_t> map;
654 map.resize(sents.entries.size());
655 EIndex moveCount = 0;
656 for (auto& e : sents.entries)
657 if (e.chunk != nullptr)
658 moveCount++;
659 skr::stl_vector<sugoi_entity_t> newEnts;
660 newEnts.resize(moveCount);
661 entities.new_entities(newEnts.data(), moveCount);
662 int j = 0;
663 for (int i = 0; i < sents.entries.size(); ++i)
664 if (sents.entries[i].chunk != nullptr)
665 map[i] = newEnts[j++];
666
667 sents.reset();
668 struct mapper {
669 uint32_t count;
670 sugoi_entity_t* data;
671 void move() {}
672 void reset() {}
673 void map(sugoi_entity_t& e)
674 {
675 if (e_id(e) > count) SUGOI_UNLIKELY
676 {
677 e = kEntityNull;
678 return;
679 }
680 e = data[e_id(e)];
681 }
682 } m;
683 m.count = (uint32_t)map.size();
684 m.data = map.data();
685 skr::stl_vector<sugoi_chunk_t*> chunks;
686 struct payload_t {
687 mapper* m;
688 uint32_t start, end;
689 };
690 skr::stl_vector<payload_t> payloads;
691 payload_t payload;
692 payload.m = &m;
693 payload.start = payload.end = 0;
694 uint32_t sizePerBatch = 1024 * 16;
695 uint32_t sizeRemain = sizePerBatch;
696 for (auto& i : src.groups)
697 {
698 sugoi_group_t* g = i.second;
699 for (auto c : g->chunks)
700 {
701 chunks.push_back(c);

Callers 1

sugoiS_mergeFunction · 0.45

Calls 15

parallel_forFunction · 0.85
iterator_ref_chunkFunction · 0.85
iterator_ref_viewFunction · 0.85
is_main_threadMethod · 0.80
sync_storageMethod · 0.80
new_entitiesMethod · 0.80
add_chunkMethod · 0.80
destruct_groupMethod · 0.80
resizeMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected