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

Method clone_archetype

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

Source from the content-addressed store, hash-verified

147}
148
149sugoi::archetype_t* sugoi_storage_t::clone_archetype(archetype_t *src)
150{
151 using namespace sugoi;
152 if(auto a = try_get_archetype(src->type))
153 return a;
154 char* buffer = (char*)archetypeArena.allocate(data_size(src->type), 1);
155 archetype_t& proto = *archetypeArena.allocate<archetype_t>();
156 proto.storage = this;
157 proto.type = sugoi::clone(src->type, buffer);
158 proto.withMask = src->withMask;
159 proto.withDirty = src->withMask;
160 proto.sizeToPatch = src->sizeToPatch;
161 proto.firstChunkComponent = src->withMask;
162 forloop (i, 0, 3)
163 {
164 proto.offsets[i] = archetypeArena.allocate<uint32_t>(proto.type.length);
165 memcpy(proto.offsets[i], src->offsets[i], sizeof(uint32_t) * proto.type.length);
166 }
167 proto.elemSizes = archetypeArena.allocate<uint32_t>(proto.type.length);
168 memcpy(proto.elemSizes, src->elemSizes, sizeof(uint32_t) * proto.type.length);
169 proto.callbackFlags = archetypeArena.allocate<uint32_t>(proto.type.length);
170 memcpy(proto.callbackFlags, src->callbackFlags, sizeof(uint32_t) * proto.type.length);
171 proto.aligns = archetypeArena.allocate<uint32_t>(proto.type.length);
172 memcpy(proto.aligns, src->aligns, sizeof(uint32_t) * proto.type.length);
173 proto.sizes = archetypeArena.allocate<uint32_t>(proto.type.length);
174 memcpy(proto.sizes, src->sizes, sizeof(uint32_t) * proto.type.length);
175 proto.resourceFields = archetypeArena.allocate<sugoi::resource_fields_t>(proto.type.length);
176 memcpy(proto.resourceFields, src->resourceFields, sizeof(sugoi::resource_fields_t) * proto.type.length);
177 proto.callbacks = archetypeArena.allocate<sugoi_callback_v>(proto.type.length);
178 memcpy(proto.callbacks, src->callbacks, sizeof(sugoi_callback_v) * proto.type.length);
179 proto.stableOrder = archetypeArena.allocate<SIndex>(proto.type.length);
180 memcpy(proto.stableOrder, src->stableOrder, sizeof(SIndex) * proto.type.length);
181 proto.entitySize = src->entitySize;
182 proto.versionOffset[0] = src->versionOffset[0];
183 proto.versionOffset[1] = src->versionOffset[1];
184 proto.versionOffset[2] = src->versionOffset[2];
185 proto.chunkCapacity[0] = src->chunkCapacity[0];
186 proto.chunkCapacity[1] = src->chunkCapacity[1];
187 proto.chunkCapacity[2] = src->chunkCapacity[2];
188
189 return archetypes.insert({ proto.type, &proto }).first->second;
190}
191
192sugoi_group_t* sugoi_storage_t::construct_group(const sugoi_entity_type_t& inType)
193{

Callers

nothing calls this directly

Calls 5

data_sizeFunction · 0.85
memcpyFunction · 0.85
cloneFunction · 0.70
allocateMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected