Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
SGNRelationshipCache.cpp
Go to the documentation of this file.
1
2
5
6namespace Divide
7{
8
10 : _isValid(false)
11 , _parentNode( parent )
12 {
13 }
14
15 bool SGNRelationshipCache::isValid() const noexcept
16 {
17 return _isValid;
18 }
19
21 {
22 _isValid = false;
23 }
24
26 {
28
33
34 _isValid = true;
35 return true;
36 }
37
39 {
41
42 assert( isValid() );
43
44 if ( GUID != _parentNode->getGUID() )
45 {
46 SharedLock<SharedMutex> r_lock( _updateMutex );
47 for ( const CacheEntry& it : _childrenRecursiveCache )
48 {
49 if ( it._guid == GUID )
50 {
51 return it._level > 0u
52 ? RelationshipType::GRANDCHILD
53 : RelationshipType::CHILD;
54 }
55 }
56
57 for ( const CacheEntry& it : _parentRecursiveCache )
58 {
59 if ( it._guid == GUID )
60 {
61 return it._level > 0u
62 ? RelationshipType::GRANDPARENT
63 : RelationshipType::PARENT;
64 }
65 }
66
67 for ( const CacheEntry& it : _siblingCache )
68 {
69 if ( it._guid == GUID )
70 {
71 return RelationshipType::SIBLING;
72 }
73 }
74 }
75
76 return RelationshipType::COUNT;
77 }
78
79 bool SGNRelationshipCache::validateRelationship( const I64 GUID, const RelationshipType type ) const noexcept
80 {
82
83 assert(isValid());
84
85 switch ( type )
86 {
87 case RelationshipType::GRANDCHILD:
88 {
89 for ( const CacheEntry& it : _childrenRecursiveCache )
90 {
91 if ( it._guid == GUID )
92 {
93 return it._level > 0u;
94 }
95 }
96 } break;
97 case RelationshipType::CHILD:
98 {
99 for ( const CacheEntry& it : _childrenRecursiveCache )
100 {
101 if ( it._guid == GUID )
102 {
103 return it._level == 0u;
104 }
105 }
106 } break;
107 case RelationshipType::GRANDPARENT:
108 {
109 for ( const CacheEntry& it : _parentRecursiveCache )
110 {
111 if ( it._guid == GUID )
112 {
113 return it._level > 0u;
114 }
115 }
116 } break;
117 case RelationshipType::PARENT:
118 {
119 for ( const CacheEntry& it : _parentRecursiveCache )
120 {
121 if ( it._guid == GUID )
122 {
123 return it._level == 0u;
124 }
125 }
126 } break;
127 case RelationshipType::SIBLING:
128 {
129 for ( const CacheEntry& it : _siblingCache )
130 {
131 if ( it._guid == GUID )
132 {
133 return true;
134 }
135 }
136 }break;
137 case RelationshipType::COUNT: break;
138 }
139
140 return false;
141 }
142
143 void SGNRelationshipCache::updateChildren( const U16 level, Cache& cache ) const
144 {
146
148 SharedLock<SharedMutex> w_lock( children._lock );
149 const U32 childCount = children._count;
150 for ( U32 i = 0u; i < childCount; ++i )
151 {
152 SceneGraphNode* child = children._data[i];
153 cache.emplace_back( CacheEntry{ child->getGUID(), level } );
155 }
156 }
157
158 void SGNRelationshipCache::updateParents( const U16 level, Cache& cache ) const
159 {
161
162 const SceneGraphNode* parent = _parentNode->parent();
163 // We ignore the root note when considering grandparent status
164 if ( parent && parent->parent() )
165 {
166 cache.emplace_back( CacheEntry{ parent->getGUID(), level } );
168 }
169 }
170
171 void SGNRelationshipCache::updateSiblings( [[maybe_unused]] const U16 level, Cache& cache ) const
172 {
174
175 const SceneGraphNode* parent = _parentNode->parent();
176 if (parent != nullptr )
177 {
178 const SceneGraphNode::ChildContainer& children = parent->getChildren();
179 SharedLock<SharedMutex> w_lock( children._lock );
180 const U32 childCount = children._count;
181 for ( U32 i = 0u; i < childCount; ++i )
182 {
183 SceneGraphNode* child = children._data[i];
184 if ( child->getGUID() != _parentNode->getGUID() )
185 {
186 cache.emplace_back( CacheEntry{ child->getGUID(), 1u});
187 }
188 }
189 }
190 }
191
192}; //namespace Divide
#define PROFILE_SCOPE_AUTO(CATEGORY)
Definition: Profiler.h:87
static const SGNRelationshipCache & relationshipCache(const SceneGraphNode *node) noexcept
FORCE_INLINE I64 getGUID() const noexcept
Definition: GUIDWrapper.h:51
ProjectManager & parent() noexcept
void updateSiblings(U16 level, Cache &cache) const
void updateParents(U16 level, Cache &cache) const
bool validateRelationship(I64 guid, RelationshipType type) const noexcept
Cache _siblingCache
pair: GUID ... level unused
RelationshipType classifyNode(I64 GUID) const noexcept
void updateChildren(U16 level, Cache &cache) const
SGNRelationshipCache(SceneGraphNode *parent) noexcept
Cache _parentRecursiveCache
pair: GUID ... parent level (0 = parent, 1 = grandparent, ...)
ChildContainer & getChildren() noexcept
constexpr Optick::Category::Type GameLogic
Definition: Profiler.h:63
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::lock_guard< mutex > LockGuard
Definition: SharedMutex.h:55
std::shared_lock< mutex > SharedLock
Definition: SharedMutex.h:49
Project & parent
Definition: DefaultScene.h:41
uint16_t U16
int64_t I64
uint32_t U32
eastl::fixed_vector< SceneGraphNode *, 32, true > _data