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

Function duplicate_view

modules/engine/runtime/src/ecs/chunk_view.cpp:570–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568
569
570void duplicate_view(const sugoi_chunk_view_t& dstV, const sugoi_chunk_t* srcC, EIndex srcStart) noexcept
571{
572 archetype_t* srcType = srcC->type;
573 archetype_t* dstType = dstV.chunk->type;
574 EIndex* srcOffsets = srcType->offsets[srcC->pt];
575 EIndex* dstOffsets = dstType->offsets[dstV.chunk->pt];
576 uint32_t* srcSizes = srcType->sizes;
577 uint32_t* srcAligns = srcType->aligns;
578 uint32_t* dstAligns = dstType->aligns;
579 uint32_t* dstSizes = dstType->sizes;
580 uint32_t* srcElemSizes = srcType->elemSizes;
581 uint32_t* dstElemSizes = dstType->elemSizes;
582 sugoi_type_set_t srcTypes = srcType->type;
583 sugoi_type_set_t dstTypes = dstType->type;
584 uint32_t* srcCallbackFlags = srcType->callbackFlags;
585 uint32_t* dstCallbackFlags = dstType->callbackFlags;
586 uint32_t maskValue = uint32_t(1 << dstTypes.length) - 1;
587
588 std::bitset<32>*srcMasks = nullptr, *dstMasks = nullptr;
589 if (srcType->withMask && dstType->withMask)
590 {
591 SIndex srcMaskId = srcType->index(kMaskComponent);
592 SIndex dstMaskId = dstType->index(kMaskComponent);
593 dstMasks = (std::bitset<32>*)(dstV.chunk->data() + (size_t)dstOffsets[dstMaskId] + (size_t)dstSizes[dstMaskId] * dstV.start);
594 srcMasks = (std::bitset<32>*)(srcC->data() + (size_t)srcOffsets[srcMaskId] + (size_t)srcSizes[srcMaskId] * srcStart);
595 std::memset(dstMasks, 1, sizeof(uint32_t) * dstV.count);
596 }
597
598 std::bitset<32>* dstDirtys = nullptr;
599 if (srcType->withDirty && dstType->withDirty)
600 {
601 SIndex dstMaskId = dstType->index(kDirtyComponent);
602 dstDirtys = (std::bitset<32>*)(dstV.chunk->data() + (size_t)dstOffsets[dstMaskId] + (size_t)dstSizes[dstMaskId] * dstV.start);
603 std::memset(dstDirtys, 1, sizeof(uint32_t) * dstV.count);
604 }
605
606 SIndex srcI = 0, dstI = 0;
607
608 while (srcI < srcType->firstChunkComponent && dstI < dstType->firstChunkComponent)
609 {
610 type_index_t srcT = srcTypes.data[srcI];
611 type_index_t dstT = dstTypes.data[dstI];
612 if (srcT < dstT) // ignore
613 {
614 ++srcI;
615 }
616 else if (srcT > dstT) // construct
617 {
618 decltype(dstType->callbacks[dstI].constructor) callback = nullptr;
619 if((dstCallbackFlags[dstI] & SUGOI_CALLBACK_FLAG_CTOR) != 0) SUGOI_UNLIKELY
620 callback = dstType->callbacks[dstI].constructor;
621 construct_impl(dstV, dstT, dstOffsets[dstI], dstSizes[dstI], dstAligns[dstI], dstElemSizes[dstI], maskValue, callback);
622 if (dstMasks)
623 forloop (i, 0, dstV.count)
624 dstMasks[i]
625 .set(dstI);
626 if (dstDirtys)
627 forloop (i, 0, dstV.count)

Callers 2

instantiate_prefabMethod · 0.85
instantiateMethod · 0.85

Calls 7

memsetFunction · 0.85
construct_implFunction · 0.85
duplicate_implFunction · 0.85
indexMethod · 0.45
dataMethod · 0.45
setMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected