11#include <unordered_map>
18 std::vector<Entity> candidates;
21 candidates.push_back(entity);
23 if (candidates.size() <= 1)
return candidates;
25 std::unordered_map<Entity, u8> ancestry;
26 ancestry.reserve(candidates.size());
27 for (
Entity entity : candidates) ancestry.emplace(entity, 3);
28 std::vector<Entity> roots;
29 std::vector<Entity>
trail;
30 for (
Entity entity : candidates) {
35 while (registry.
valid(ancestor)) {
36 auto [entry, inserted] = ancestry.emplace(ancestor, 1);
38 nested = entry->second == 3;
41 trail.push_back(ancestor);
45 for (
Entity visited :
trail) ancestry[visited] = nested ? 3 : 2;
46 if (!nested) roots.push_back(entity);
Canvas component for 2D game resolution management.
Hierarchy components for parent-child relationships.
Central ECS registry for entity and component management.
Central container for all entities and components.
void each(Func &&func)
Executes a function for each entity with specified components.
bool has(Entity entity) const
Checks if an entity has a specific component.
bool valid(Entity entity) const
Checks if an entity is currently valid.
T * tryGet(Entity entity)
Tries to get a component from an entity.
std::vector< Entity > canvasRoots(Registry ®istry, bool layoutOnly)
constexpr Entity INVALID_ENTITY
Invalid entity sentinel value.
Entity identifier with packed index + generation.
Canvas component for 2D game resolution management.
Parent reference component.
Entity entity
Parent entity ID.
UINode — the CSS box-model layout input (the CSS/Flex primary layout model).