Nebula
Loading...
Searching...
No Matches
transformhierarchy.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
34//------------------------------------------------------------------------------
35#include "core/refcounted.h"
36#include "basegamefeature/components/basegamefeature.h"
40#include "game/entity.h"
41#include "math/mat4.h"
42#include "memdb/tableid.h"
43#include "util/array.h"
44#include "util/arrayallocator.h"
45#include "util/bitarray.h"
46#include "util/dictionary.h"
47
48namespace Game
49{
50class World;
51
53{
55public:
57 static constexpr uint32_t InvalidInstance = 0xFFFFFFFF;
58
61
65 void SetLocalTransform(uint32_t instance, Math::mat4 const& value);
66 void SetLocalTransform(Game::Entity entity, Math::mat4 const& value);
67 void SetLocalTransform(uint32_t instance);
69
72 void SetWorldTransform(uint32_t instance, Math::mat4 const& value);
73 void SetWorldTransform(Game::Entity entity, Math::mat4 const& value);
74 void SetWorldTransform(uint32_t instance);
76
78 Math::mat4 GetLocalTransform(uint32_t instance) const;
80 Math::mat4 GetWorldTransform(uint32_t instance) const;
82
84 void SetParent(Game::Entity entity, Game::Entity parent);
85 void SetParent(uint32_t instance, uint32_t parentInstance);
86
88 uint32_t GetParent(uint32_t instance) const;
89
91 Game::Entity GetOwner(uint32_t instance) const;
92
94 uint32_t GetFirstChild(uint32_t instance) const;
95
97 uint32_t GetNextSibling(uint32_t instance) const;
98
100 uint32_t GetPreviousSibling(uint32_t instance) const;
101
103 bool HasChildren(uint32_t instance) const;
104
106 uint32_t GetInstance(Game::Entity entity) const;
107
109 bool IsInHierarchy(Game::Entity entity) const;
110
112 uint32_t Add(Game::Entity entity, Game::Entity parent);
113
115 void Remove(Game::Entity entity);
116
118 void RemoveInstance(uint32_t instance);
119
121 void ResolvePending();
122
124 SizeT Size() const;
125 SizeT NumPending() const;
126
128 void Clear();
129
130private:
140
142 bool LinkUnderParent(uint32_t instance, uint32_t parentInstance);
143
145 void Unlink(uint32_t instance);
146
148 void Detach(uint32_t instance, ComponentPointers const& components);
149
151 void DeriveLocal(uint32_t instance, ComponentPointers const& components);
152
154 void Compute(uint32_t instance);
155
157 void Walk(uint32_t instance);
158
160 void FlushStale();
161
163 uint32_t EnsureInstance(Game::Entity entity, bool hasLocalTransform);
164
167 ComponentPointers GetComponents(Game::Entity entity, bool hasLocalTransform) const;
168
170
181
184 uint32_t,
185 uint32_t,
186 uint32_t,
187 uint32_t,
188 bool> data;
189
190 // entity.index is the array index in this map
192
193 // one bit per entity, which is what makes the test for an entity which is not in a hierarchy cheap
195
196 // the cache is filled by a const lookup, which is what makes it mutable
200
201 // instances which named an entity that is gone. They are taken out of the hierarchy after the walk, because
202 // the erasure moves another instance into the slot they free while the walk is using the slots
204};
205
206//------------------------------------------------------------------------------
211void DecayHTransform(Game::World* world, Game::Entity entity, Game::HTransform* component);
212
213} // namespace Game
214//------------------------------------------------------------------------------
The common base class of Nebula.
Definition refcounted.h:45
__DeclareClass(RefCounted)
The parent, child and sibling links of the entities in one world's hierarchy.
Definition transformhierarchy.h:53
bool LinkUnderParent(uint32_t instance, uint32_t parentInstance)
link an instance under a parent instance. False when the link would close a cycle
Definition transformhierarchy.cc:256
Game::Entity GetOwner(uint32_t instance) const
Get owner of instance.
Definition transformhierarchy.cc:106
__DeclareClass(TransformHierarchy) public void Initialize(Game::World *world)
the world this hierarchy belongs to. Set by the world which owns it
Definition transformhierarchy.cc:20
void SetWorldTransform(uint32_t instance, Math::mat4 const &value)
Set the world transform of an instance, which derives the local transform it implies through the inve...
Definition transformhierarchy.cc:717
void DeriveLocal(uint32_t instance, ComponentPointers const &components)
derive the local transform from the world transform the components hold
Definition transformhierarchy.cc:319
void Detach(uint32_t instance, ComponentPointers const &components)
make the local transform of an instance be the world transform it currently has, and detach it
Definition transformhierarchy.cc:294
Util::Array< uint32_t > stack
Definition transformhierarchy.h:198
Game::World * world
Definition transformhierarchy.h:169
Math::mat4 GetWorldTransform(uint32_t instance) const
Definition transformhierarchy.cc:846
Member
the members of the instance data
Definition transformhierarchy.h:173
@ FirstChild
Definition transformhierarchy.h:176
@ PreviousSibling
Definition transformhierarchy.h:178
@ Parent
Definition transformhierarchy.h:175
@ OwnerEntity
Definition transformhierarchy.h:174
@ HasLocalTransform
Definition transformhierarchy.h:179
@ NextSibling
Definition transformhierarchy.h:177
Util::Array< Game::Entity > pending
Definition transformhierarchy.h:199
Util::Array< uint32_t > entityToInstance
Definition transformhierarchy.h:191
uint32_t Add(Game::Entity entity, Game::Entity parent)
add an entity to the hierarchy with the parent its component names, and compute it
Definition transformhierarchy.cc:567
void Unlink(uint32_t instance)
take an instance out of the links, without touching its components
Definition transformhierarchy.cc:221
void SetLocalTransform(uint32_t instance, Math::mat4 const &value)
Set the local transform of an instance, compute the world transform it implies and propagate to the i...
Definition transformhierarchy.cc:637
bool HasChildren(uint32_t instance) const
an instance which has children is one the writer has to walk into
Definition transformhierarchy.cc:97
void RemoveInstance(uint32_t instance)
remove an instance, patching the links which name the slot the swap-erase moves into it
Definition transformhierarchy.cc:888
void SetParent(Game::Entity entity, Game::Entity parent)
Update relationships.
Definition transformhierarchy.cc:612
uint32_t GetFirstChild(uint32_t instance) const
Get first child of instance.
Definition transformhierarchy.cc:124
uint32_t GetPreviousSibling(uint32_t instance) const
Get the previous sibling of this instance.
Definition transformhierarchy.cc:142
void Compute(uint32_t instance)
compute one instance from what its components hold and put its children in the walk queue
Definition transformhierarchy.cc:387
Util::Dictionary< MemDb::TableId, MemDb::ColumnIndex > localColumn
Definition transformhierarchy.h:197
Util::BitArray entityInHierarchy
Definition transformhierarchy.h:194
uint32_t GetParent(uint32_t instance) const
Get parent of instance.
Definition transformhierarchy.cc:115
bool IsInHierarchy(Game::Entity entity) const
the fast test for a transform writer, one bit in a dense array keyed by entity.index
Definition transformhierarchy.cc:88
void Walk(uint32_t instance)
walk the instances below an instance, computing each of them
Definition transformhierarchy.cc:524
SizeT NumPending() const
Definition transformhierarchy.cc:160
SizeT Size() const
number of hierarchy instances, and number of instances waiting for their components
Definition transformhierarchy.cc:151
uint32_t GetInstance(Game::Entity entity) const
the instance of an entity, or InvalidInstance when the entity is not part of the hierarchy
Definition transformhierarchy.cc:64
Util::Array< uint32_t > stale
Definition transformhierarchy.h:203
Util::ArrayAllocator< Game::Entity, uint32_t, uint32_t, uint32_t, uint32_t, bool > data
Definition transformhierarchy.h:188
ComponentPointers GetComponents(Game::Entity entity, bool hasLocalTransform) const
the component pointers of an entity.
Definition transformhierarchy.cc:169
void ResolvePending()
compute the instances which could not be computed when they were written
Definition transformhierarchy.cc:983
uint32_t EnsureInstance(Game::Entity entity, bool hasLocalTransform)
the instance of an entity, creating it when it is not part of the hierarchy yet
Definition transformhierarchy.cc:29
uint32_t GetNextSibling(uint32_t instance) const
Get the first sibling of this instance.
Definition transformhierarchy.cc:133
void FlushStale()
take out the instances which were found to name an entity that is gone during a walk
Definition transformhierarchy.cc:541
void Clear()
clear the hierarchy
Definition transformhierarchy.cc:1009
void Remove(Game::Entity entity)
remove an entity from the hierarchy. Its children become roots with the world transform they have
Definition transformhierarchy.cc:877
Math::mat4 GetLocalTransform(uint32_t instance) const
the transforms of an instance, read from the components which own them
Definition transformhierarchy.cc:811
A container of entities, their components, and processors.
Definition world.h:88
The ArrayAllocator provides a variadic list of types which is to be contained in the allocator and fe...
Definition arrayallocator.h:34
Nebula's dynamic array class.
Definition array.h:61
Implements a growable bit array (similar to std::vector<bool>).
Definition bitarray.h:27
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:35
Game::EditorState.
Definition graphicsmanager.h:66
void DecayHTransform(Game::World *world, Game::Entity entity, Game::HTransform *component)
Component decay hook.
Definition transformhierarchy.cc:1026
An entity is essentially just an Id with some utility functions attached.
Definition entity.h:35
A component that stores the orientation of an entity.
Definition orientation.h:18
A component that stores the position of an entity in world space coordinates.
Definition position.h:19
A component that stores the scale of an entity.
Definition scale.h:18
the component pointers of an instance.
Definition transformhierarchy.h:134
Game::Position * position
Definition transformhierarchy.h:136
Game::Scale * scale
Definition transformhierarchy.h:138
Game::HTransform * local
Definition transformhierarchy.h:135
Game::Orientation * orientation
Definition transformhierarchy.h:137
A 4x4 single point precision float matrix.
Definition mat4.h:55
int SizeT
Definition types.h:42