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

Method construct_archetype

modules/engine/runtime/src/ecs/archetype.cpp:37–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35} // namespace sugoi
36
37sugoi::archetype_t* sugoi_storage_t::construct_archetype(const sugoi_type_set_t& inType)
38{
39 using namespace sugoi;
40 fixed_stack_scope_t _(localStack);
41 char* buffer = (char*)archetypeArena.allocate(data_size(inType), 1);
42 archetype_t& proto = *archetypeArena.allocate<archetype_t>();
43 proto.storage = this;
44 proto.type = sugoi::clone(inType, buffer);
45 proto.withMask = false;
46 proto.withDirty = false;
47 proto.sizeToPatch = 0;
48 proto.firstChunkComponent = proto.type.length;
49 forloop (i, 0, proto.type.length)
50 if(type_index_t(proto.type.data[i]).is_chunk())
51 {
52 proto.firstChunkComponent = i;
53 break;
54 }
55 forloop (i, 0, 3)
56 proto.offsets[i] = archetypeArena.allocate<uint32_t>(proto.type.length);
57 proto.elemSizes = archetypeArena.allocate<uint32_t>(proto.type.length);
58 proto.callbackFlags = archetypeArena.allocate<uint32_t>(proto.type.length);
59 proto.aligns = archetypeArena.allocate<uint32_t>(proto.type.length);
60 proto.sizes = archetypeArena.allocate<uint32_t>(proto.type.length);
61 proto.resourceFields = archetypeArena.allocate<sugoi::resource_fields_t>(proto.type.length);
62 proto.callbacks = archetypeArena.allocate<sugoi_callback_v>(proto.type.length);
63 ::memset(proto.callbacks, 0, sizeof(sugoi_callback_v) * proto.type.length);
64 proto.stableOrder = archetypeArena.allocate<SIndex>(proto.type.length);
65 auto& registry = type_registry_t::get();
66 forloop (i, 0, proto.type.length)
67 {
68 const auto& desc = registry.descriptions[type_index_t(proto.type.data[i]).index()];
69 uint32_t callbackFlag = 0;
70 if (desc.callback.constructor)
71 callbackFlag |= SUGOI_CALLBACK_FLAG_CTOR;
72 if (desc.callback.destructor)
73 callbackFlag |= SUGOI_CALLBACK_FLAG_DTOR;
74 if (desc.callback.copy)
75 callbackFlag |= SUGOI_CALLBACK_FLAG_COPY;
76 if (desc.callback.move)
77 callbackFlag |= SUGOI_CALLBACK_FLAG_MOVE;
78 proto.callbackFlags[i] = callbackFlag;
79 proto.callbacks[i] = desc.callback;
80 proto.resourceFields[i] = { desc.resourceFields, desc.resourceFieldsCount };
81 }
82 auto guids = localStack.allocate<guid_t>(proto.type.length);
83 proto.entitySize = sizeof(sugoi_entity_t);
84 uint32_t padding = 0;
85 forloop (i, 0, proto.type.length)
86 {
87 auto t = proto.type.data[i];
88 if (t == kMaskComponent)
89 proto.withMask = true;
90 if (t == kDirtyComponent)
91 proto.withDirty = true;
92 auto ti = type_index_t(t);
93 auto& desc = registry.descriptions[ti.index()];
94 proto.sizes[i] = desc.size;

Callers

nothing calls this directly

Calls 10

data_sizeFunction · 0.85
type_index_tClass · 0.85
memsetFunction · 0.85
is_chunkMethod · 0.80
cloneFunction · 0.70
getFunction · 0.50
sortFunction · 0.50
allocateMethod · 0.45
indexMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected