| 190 | } |
| 191 | |
| 192 | sugoi_group_t* sugoi_storage_t::construct_group(const sugoi_entity_type_t& inType) |
| 193 | { |
| 194 | using namespace sugoi; |
| 195 | fixed_stack_scope_t _(localStack); |
| 196 | sugoi_type_set_t structure; |
| 197 | SIndex firstTag = 0; |
| 198 | for (; firstTag < inType.type.length; ++firstTag) |
| 199 | if (type_index_t(inType.type.data[firstTag]).is_tag()) |
| 200 | break; |
| 201 | structure.data = inType.type.data; |
| 202 | structure.length = firstTag; |
| 203 | archetype_t* archetype = get_archetype(structure); |
| 204 | const auto typeSize = static_cast<uint32_t>(data_size(inType)); |
| 205 | SKR_ASSERT((sizeof(sugoi_group_t) + typeSize) < kGroupBlockSize);(void)typeSize; |
| 206 | sugoi_group_t& proto = *new (groupPool.allocate()) sugoi_group_t(); |
| 207 | char* buffer = (char*)(&proto + 1); |
| 208 | proto.firstFree = 0; |
| 209 | sugoi_entity_type_t type = sugoi::clone(inType, buffer); |
| 210 | proto.type = type; |
| 211 | auto toClean = localStack.allocate<TIndex>(proto.type.type.length + 1); |
| 212 | SIndex toCleanCount = 0; |
| 213 | auto toClone = localStack.allocate<TIndex>(proto.type.type.length + 1); |
| 214 | SIndex toCloneCount = 0; |
| 215 | proto.isDead = false; |
| 216 | proto.disabled = false; |
| 217 | bool hasTracked = false; |
| 218 | forloop (i, 0, proto.type.type.length) |
| 219 | { |
| 220 | type_index_t t = proto.type.type.data[i]; |
| 221 | if(t > kDeadComponent) |
| 222 | toClean[toCleanCount++] = kDeadComponent; |
| 223 | toClean[toCleanCount++] = t; |
| 224 | if (!t.is_tracked()) |
| 225 | toClone[toCloneCount++] = t; |
| 226 | else |
| 227 | hasTracked = true; |
| 228 | if (t == kDeadComponent) |
| 229 | proto.isDead = true; |
| 230 | if (t == kDisableComponent) |
| 231 | proto.disabled = true; |
| 232 | } |
| 233 | if(toCleanCount == proto.type.type.length) |
| 234 | toClean[toCleanCount++] = kDeadComponent; |
| 235 | // std::sort(&toClean[0], &toClean[toCleanCount]); dead is always smaller |
| 236 | proto.archetype = archetype; |
| 237 | proto.size = 0; |
| 238 | proto.timestamp = 0; |
| 239 | proto.dead = nullptr; |
| 240 | proto.cloned = proto.isDead ? nullptr : &proto; |
| 241 | groups.insert({ type, &proto }); |
| 242 | update_query_cache(&proto, true); |
| 243 | if (hasTracked && !proto.isDead) |
| 244 | { |
| 245 | auto deadType = make_zeroed<sugoi_entity_type_t>(); |
| 246 | deadType.type = { toClean, toCleanCount }; |
| 247 | proto.dead = get_group(deadType); |
| 248 | sugoi_entity_type_t cloneType = make_zeroed<sugoi_entity_type_t>(); |
| 249 | cloneType.type = { toClone, toCloneCount }; |
nothing calls this directly
no test coverage detected