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

Function cast_view

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

Source from the content-addressed store, hash-verified

436}
437
438void cast_view(const sugoi_chunk_view_t& dstV, sugoi_chunk_t* srcC, EIndex srcStart) noexcept
439{
440 archetype_t* srcType = srcC->type;
441 archetype_t* dstType = dstV.chunk->type;
442 EIndex* srcOffsets = srcType->offsets[srcC->pt];
443 EIndex* dstOffsets = dstType->offsets[dstV.chunk->pt];
444 uint32_t* srcSizes = srcType->sizes;
445 uint32_t* srcAligns = srcType->aligns;
446 uint32_t* dstAligns = dstType->aligns;
447 uint32_t* dstSizes = dstType->sizes;
448 uint32_t* srcElemSizes = srcType->elemSizes;
449 uint32_t* dstElemSizes = dstType->elemSizes;
450 sugoi_type_set_t srcTypes = srcType->type;
451 sugoi_type_set_t dstTypes = dstType->type;
452 uint32_t* srcCallbackFlags = srcType->callbackFlags;
453 uint32_t* dstCallbackFlags = dstType->callbackFlags;
454 uint32_t maskValue = uint32_t(1 << dstTypes.length) - 1;
455
456 std::bitset<32>*srcMasks = nullptr, *dstMasks = nullptr;
457 if (srcType->withMask && dstType->withMask)
458 {
459 SIndex srcMaskId = srcType->index(kMaskComponent);
460 SIndex dstMaskId = dstType->index(kMaskComponent);
461 dstMasks = (std::bitset<32>*)(dstV.chunk->data() + (size_t)dstOffsets[dstMaskId] + (size_t)dstSizes[dstMaskId] * dstV.start);
462 srcMasks = (std::bitset<32>*)(srcC->data() + (size_t)srcOffsets[srcMaskId] + (size_t)srcSizes[srcMaskId] * srcStart);
463 std::memset(dstMasks, 0, sizeof(uint32_t) * dstV.count);
464 }
465
466 std::bitset<32>*srcDirtys = nullptr, *dstDirtys = nullptr;
467 if (srcType->withDirty && dstType->withDirty)
468 {
469 SIndex srcMaskId = srcType->index(kDirtyComponent);
470 SIndex dstMaskId = dstType->index(kDirtyComponent);
471 dstDirtys = (std::bitset<32>*)(dstV.chunk->data() + (size_t)dstOffsets[dstMaskId] + (size_t)dstSizes[dstMaskId] * dstV.start);
472 srcDirtys = (std::bitset<32>*)(srcC->data() + (size_t)srcOffsets[srcMaskId] + (size_t)srcSizes[srcMaskId] * srcStart);
473 std::memset(dstDirtys, 0, sizeof(uint32_t) * dstV.count);
474 }
475
476 SIndex srcI = 0, dstI = 0;
477
478 while (srcI < srcType->firstChunkComponent && dstI < dstType->firstChunkComponent)
479 {
480 type_index_t srcT = srcTypes.data[srcI];
481 type_index_t dstT = dstTypes.data[dstI];
482 if (srcT < dstT) // destruct
483 {
484 decltype(srcType->callbacks[srcI].destructor) callback = nullptr;
485 if((srcCallbackFlags[srcI] & SUGOI_CALLBACK_FLAG_CTOR) != 0) SUGOI_UNLIKELY
486 callback = srcType->callbacks[srcI].destructor;
487 destruct_impl({ srcC, srcStart, dstV.count }, srcT, srcOffsets[srcI], srcSizes[srcI], srcElemSizes[srcI], srcType->resourceFields[srcI], callback);
488 ++srcI;
489 }
490 else if (srcT > dstT) // construct
491 {
492 decltype(dstType->callbacks[dstI].constructor) callback = nullptr;
493 if((dstCallbackFlags[dstI] & SUGOI_CALLBACK_FLAG_CTOR) != 0) SUGOI_UNLIKELY
494 callback = dstType->callbacks[dstI].constructor;
495 construct_impl(dstV, dstT, dstOffsets[dstI], dstSizes[dstI], dstAligns[dstI], dstElemSizes[dstI], maskValue, callback);

Callers 1

cast_implMethod · 0.85

Calls 8

memsetFunction · 0.85
construct_implFunction · 0.85
move_implFunction · 0.85
destruct_implFunction · 0.70
indexMethod · 0.45
dataMethod · 0.45
setMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected