Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
SceneGraphNode.inl
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_SCENE_GRAPH_NODE_INL_
34#define DVD_SCENE_GRAPH_NODE_INL_
35
36#include "SceneNode.h"
37#include "SceneGraph.h"
39
40namespace Divide {
41 template<class T, typename... Args>
42 void AddSGNComponent(SceneGraphNode* node, Args... args)
43 {
44 node->template AddSGNComponent<T>(FWD(args)...);
45 }
46
47 template<class T>
49 {
50 node->template RemoveSGNComponent<T>();
51 }
52
53 FORCE_INLINE bool SceneGraphNode::hasFlag(const Flags flag) const noexcept
54 {
55 return _nodeFlags & to_base(flag);
56 }
57
58 template <>
59 inline TransformComponent* SceneGraphNode::get<TransformComponent>() const
60 {
62 }
63
64 template <>
65 inline BoundsComponent* SceneGraphNode::get<BoundsComponent>() const
66 {
68 }
69
70 template <>
71 inline RenderingComponent* SceneGraphNode::get<RenderingComponent>() const
72 {
74 }
75
76 template<typename T> requires std::is_base_of_v<SceneNode, T>
78 {
79 static_assert(GetSceneNodeType<T>() != SceneNodeType::COUNT);
81 return Handle<T>{ ._data = handle._handle._data };
82 }
83
84 template<typename T> requires std::is_base_of_v<SceneNode, T>
86 {
87 static_assert(GetSceneNodeType<T>() != SceneNodeType::COUNT);
88
89 SceneNodeHandle ret { ._type = GetSceneNodeType<T>() };
90 ret._handle._data = handle._data;
91 ret._nodePtr = Get( handle );
92 ret._deleter = [handle]() { Handle<T> handleCpy = handle; DestroyResource( handleCpy ); };
93
94 return ret;
95 }
96
97 template<bool checkInternalNode>
98 inline SceneGraphNode* SceneGraphNode::findChildInternal(const U64 nameHash, const bool recursive) const
99 {
100 if (nameHash != 0u)
101 {
103
104 for (SceneGraphNode* child : _children._data)
105 {
106 if constexpr(checkInternalNode)
107 {
108 const U64 cmpHash = _ID(child->getNode().resourceName().c_str());
109 if (cmpHash == nameHash)
110 {
111 return child;
112 }
113 }
114 else
115 {
116 if (child->nameHash() == nameHash)
117 {
118 return child;
119 }
120 }
121
122 if (recursive)
123 {
124 SceneGraphNode* recChild = child->findChildInternal<checkInternalNode>(nameHash, recursive);
125
126 if (recChild != nullptr)
127 {
128 return recChild;
129 }
130 }
131 }
132 }
133
134 return nullptr;
135 }
136
137 template<bool checkInternalNode>
138 inline SceneGraphNode* SceneGraphNode::findChildInternal(const I64 GUID, const bool recursive) const
139 {
140 if (GUID != -1)
141 {
143 for (SceneGraphNode* child : _children._data)
144 {
145 if constexpr(checkInternalNode)
146 {
147 if (child->getNode().getGUID() == GUID)
148 {
149 return child;
150 }
151 }
152 else
153 {
154 if (child->getGUID() == GUID)
155 {
156 return child;
157 }
158 }
159 if (recursive)
160 {
161 SceneGraphNode* recChild = child->findChildInternal<checkInternalNode>(GUID, true);
162 if (recChild != nullptr)
163 {
164 return recChild;
165 }
166 }
167 }
168 }
169
170 return nullptr;
171 }
172}; //namespace Divide
173
174#endif //DVD_SCENE_GRAPH_NODE_INL_
#define FWD(...)
#define DIVIDE_ASSERT(...)
#define FORCE_INLINE
FORCE_INLINE I64 getGUID() const noexcept
Definition: GUIDWrapper.h:51
ChildContainer _children
struct Divide::SceneGraphNode::hacks Hacks
T & getNode() noexcept
bool hasFlag(const Flags flag) const noexcept
Returns true only if the current node has the specified flag. Does not check children!
SceneGraphNode * findChildInternal(U64 nameHash, bool recursive=false) const
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
FORCE_INLINE void DestroyResource(Handle< T > &handle, const bool immediate=false)
std::shared_lock< mutex > SharedLock
Definition: SharedMutex.h:49
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
SceneNodeHandle FromHandle(const Handle< T > handle)
void AddSGNComponent(SceneGraphNode *node, Args... args)
void RemoveSGNComponent(SceneGraphNode *node)
int64_t I64
FORCE_INLINE T * Get(const Handle< T > handle)
uint64_t U64
Handle< T > ToHandle(const SceneNodeHandle handle)
constexpr auto to_base(const Type value) -> Type
eastl::fixed_vector< SceneGraphNode *, 32, true > _data
RenderingComponent * _renderingComponent
TransformComponent * _transformComponentCache
BoundsComponent * _boundsComponentCache
Handle< SceneNode > _handle