entttree 0.1.0
Hierarchical entity management for EnTT
Loading...
Searching...
No Matches
hierarchy_types.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <geomc/linalg/AffineTransform.h>
9#include <geomc/Hash.h>
10
11#include <entttree/defs.h>
12#include <entttree/position.h>
13#include <entttree/traverse.h>
14
15namespace entttree {
16
17
18/****************************
19 * Source-of-truth component: one per hierarchy tag
20 ****************************/
21
34template <typename HTag>
36 entt::entity parent = entt::null;
38
39 bool operator==(const ParentConnection& other) const = default;
40};
41
42
43/****************************
44 * Optional layered components
45 ****************************/
46
58template <typename HTag, typename T, size_t N, typename XTag=HTag>
61
62 bool operator==(const LocalTransform& other) const = default;
63};
64
65
78template <typename HTag, typename T, size_t N, typename BTag=HTag>
81
82 bool operator==(const IntrinsicBounds& other) const = default;
83};
84
85
86/****************************
87 * Query / traversal node types
88 ****************************/
89
95struct NodeEntry {
96 entt::entity node_id;
97 entt::entity parent_id;
99};
100
107 entt::entity eid;
109
110 std::strong_ordering operator<=>(const ChildEntry& other) const {
111 auto cmp = position <=> other.position;
112 if (cmp != std::strong_ordering::equal) return cmp;
113 return entt::to_integral(eid) <=> entt::to_integral(other.eid);
114 }
115
116 bool operator==(const ChildEntry& other) const = default;
117 bool operator<(const ChildEntry& other) const {
118 return (*this <=> other) == std::strong_ordering::less;
119 }
120};
121
123using ChildList = std::vector<ChildEntry>;
124
131struct TreePath : public SmallStorage<entt::entity, 6> {};
132
133
145template <typename Node, typename T, size_t N>
147 using InnerNode = Node;
148 Node node;
150};
151
153template <typename Traversal, typename T, size_t N>
155 Traversal,
156 TransformedNode<typename std::remove_cvref_t<Traversal>::Node::InnerNode,T,N>
157>;
158
159
170template <typename Node, typename T, size_t N>
171struct BoundedNode : public TransformedNode<Node,T,N> {
172 std::optional<Rect<T,N>> intrinsic_bounds;
173 std::optional<Rect<T,N>> computed_bounds;
174};
175
177template <typename Traversal, typename T, size_t N>
179 Traversal,
180 BoundedNode<typename std::remove_cvref_t<Traversal>::Node::InnerNode,T,N>
181>;
182
183
193template <typename Node, typename T, size_t N>
194struct PointSearchNode : public BoundedNode<Node,T,N> {
196};
197
207template <typename Node, typename T, size_t N>
212
213
214} // namespace entttree
Concept satisfied by traversals whose node type is BoundedNode<...,T,N>.
Concept satisfied by traversals whose node type is TransformedNode<...,T,N>.
Satisfied by types that have a root and a successors function yielding Node.
Definition traverse.h:108
Common type aliases, enumerations, and utility functions used throughout entttree.
std::vector< ChildEntry > ChildList
Sorted list of children for a single parent.
Fractional-index type for ordering siblings in a hierarchy.
A traversal node augmented with transform and bounding information.
std::optional< Rect< T, N > > intrinsic_bounds
The entity's own bounds, if set.
std::optional< Rect< T, N > > computed_bounds
Union of intrinsic + children bounds, if any.
Internal representation of a child in the sorted children cache.
Position position
Sibling ordering key.
entt::entity eid
Child entity.
A system for maintaining parent-child relationships on entities.
Definition hierarchy.h:37
ECS component storing an entity's own (intrinsic) bounding box.
Rect< T, N > bounds
Axis-aligned bounding box in local coordinates.
ECS component storing an entity's local (child-to-parent) affine transform.
AffineTransform< T, N > child_to_parent
Transform from this node's space to its parent's.
A node handle yielded by hierarchy traversals and queries.
entt::entity parent_id
The parent entity, or entt::null for root traversal entries.
entt::entity node_id
The entity this entry represents.
Position position
Sibling ordering key within the parent.
ECS component storing an entity's parent and sibling position.
entt::entity parent
Parent entity, or entt::null for roots.
Position position
Sibling ordering key.
A bounded node augmented with a point transformed into local coordinates.
Vec< T, N > local_point
The query point in this node's local coordinate system.
A fractional index with strong ordering, used for sibling positioning.
Definition position.h:27
A bounded node augmented with a ray and hit interval in local coordinates.
Rect< T, 1 > interval
Parameter interval where the ray intersects the computed bounds.
Ray< T, N > local_ray
The query ray in this node's local coordinate system.
A traversal node augmented with a cumulative affine transform.
Node node
The underlying node handle.
AffineTransform< T, N > node_to_root
Cumulative transform from node space to root space.
A path from a root entity down to a descendant.
Lazy, composable graph traversal framework built on C++20 generators.