MCPcopy Create free account
hub / github.com/Illation/ETEngine / FindOrCreateArchetype

Method FindOrCreateArchetype

Engine/source/EtFramework/ECS/EcsController.cpp:531–566  ·  view source on GitHub ↗

-------------------------------------- EcsController::FindOrCreateArchetype Get the associated archetype or create a new one

Source from the content-addressed store, hash-verified

529// Get the associated archetype or create a new one
530//
531Archetype* EcsController::FindOrCreateArchetype(ComponentSignature const& sig, uint8 const layer)
532{
533 T_Hash const sigId = sig.GenId();
534
535 // ensure we have an archetype container for the hierachy layer we are on
536 while (m_HierachyLevels.size() <= static_cast<size_t>(layer))
537 {
538 m_HierachyLevels.emplace_back(ArchetypeContainer());
539 }
540
541 // find or create
542 ArchetypeContainer& cont = m_HierachyLevels[layer];
543 auto foundA = cont.archetypes.find(sigId);
544 if (foundA == cont.archetypes.cend())
545 {
546 auto res = cont.archetypes.emplace(sigId, new Archetype(sig));
547 ET_ASSERT(res.second == true);
548 foundA = res.first;
549
550 // upon creation, check if there are any systems that should iterate this archetype
551 for (RegisteredSystem* const sys : m_Systems)
552 {
553 if (foundA->second->GetSignature().Contains(sys->signature))
554 {
555 while (sys->matchingArchetypes.size() <= static_cast<size_t>(layer)) // ensure we have enough layers
556 {
557 sys->matchingArchetypes.push_back(RegisteredSystem::ArchetypeLayer());
558 }
559
560 sys->matchingArchetypes[layer].archetypes.push_back(foundA->second);
561 }
562 }
563 }
564
565 return foundA->second;
566}
567
568//------------------------------
569// EcsController::MoveArchetype

Callers

nothing calls this directly

Calls 5

ArchetypeContainerClass · 0.85
ArchetypeLayerClass · 0.85
GenIdMethod · 0.80
emplaceMethod · 0.80
ContainsMethod · 0.80

Tested by

no test coverage detected