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

Function duplicate_impl

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

Source from the content-addressed store, hash-verified

251}
252
253static void duplicate_impl(sugoi_chunk_view_t dstV, const sugoi_chunk_t* srcC, uint32_t srcIndex, type_index_t type, EIndex offset, EIndex dstOffset, uint32_t size, uint32_t align, uint32_t elemSize, resource_fields_t resourceFields, void (*copy)(sugoi_chunk_t* chunk, EIndex index, char* dst, sugoi_chunk_t* schunk, EIndex sindex, const char* src))
254{
255 SKR_ASSERT(!type.is_chunk());
256 char* dst = dstV.chunk->data() + (size_t)dstOffset + (size_t)size * dstV.start;
257 const char* src = srcC->data() + (size_t)offset + (size_t)size * srcIndex;
258 if (type == kGuidComponent)
259 {
260 auto guidDst = (guid_t*)dst;
261 auto& registry = type_registry_t::get();
262 forloop (j, 0, dstV.count)
263 guidDst[j] = registry.make_guid();
264 return;
265 }
266 auto storage = dstV.chunk->type->storage;
267 auto patchResources = [&](char* data)
268 {
269 forloop(k, 0, resourceFields.count)
270 {
271 auto field = ((intptr_t*)resourceFields.offsets)[k];
272 auto* resource = (skr_resource_handle_t*)(data + field);
273 if(resource->is_resolved())
274 {
275 new (resource) skr_resource_handle_t(*resource, (uint64_t)storage, SKR_REQUESTER_ENTITY);
276 }
277 }
278 };
279 if (copy)
280 {
281 if (type.is_buffer())
282 {
283 forloop (j, 0, dstV.count)
284 {
285 auto arrayDst = (sugoi_array_comp_t*)((size_t)j * size + dst);
286 auto arraySrc = (sugoi_array_comp_t*)src;
287 if (!is_array_small(arraySrc))
288 {
289 size_t cap = (char*)arraySrc->EndX - (char*)arraySrc->BeginX;
290 arrayDst->BeginX = sugoi_array_comp_t::allocate(cap);
291 arrayDst->EndX = arrayDst->CapacityX = (char*)arrayDst->BeginX + cap;
292 }
293 else
294 {
295 new_array(arrayDst, size, elemSize, align);
296 arrayDst->EndX = (char*)arrayDst->BeginX + arraySrc->size_in_bytes();
297 }
298
299 for (char *currDst = (char*)arrayDst->BeginX, *currSrc = (char*)arraySrc->BeginX;
300 currDst != arrayDst->EndX; currDst += elemSize, currSrc += elemSize)
301 copy(dstV.chunk, dstV.start + j, currDst, (sugoi_chunk_t*)srcC, srcIndex, currSrc);
302 }
303 }
304 else
305 forloop (j, 0, dstV.count)
306 copy(dstV.chunk, dstV.start + j, (size_t)j * size + dst, (sugoi_chunk_t*)srcC, srcIndex, src);
307 }
308 else
309 {
310

Callers 1

duplicate_viewFunction · 0.85

Calls 13

is_array_smallFunction · 0.85
new_arrayFunction · 0.85
memcpyFunction · 0.85
memdupFunction · 0.85
is_chunkMethod · 0.80
make_guidMethod · 0.80
is_resolvedMethod · 0.80
is_bufferMethod · 0.80
getFunction · 0.50
allocateFunction · 0.50
copyFunction · 0.50
dataMethod · 0.45

Tested by

no test coverage detected