(Scene) Added FindNode(As) and RemoveNode methods
Former-commit-id: 35b0d6a61e99383fffa8048b3c0f6a48b8f0f66c
This commit is contained in:
parent
9ebd023848
commit
6d8b266b4c
|
|
@ -44,6 +44,11 @@ class NAZARA_API NzScene
|
||||||
|
|
||||||
void EnableBackground(bool enable);
|
void EnableBackground(bool enable);
|
||||||
|
|
||||||
|
NzSceneNode* FindNode(const NzString& name);
|
||||||
|
const NzSceneNode* FindNode(const NzString& name) const;
|
||||||
|
template<typename T> T* FindNodeAs(const NzString& name);
|
||||||
|
template<typename T> const T* FindNodeAs(const NzString& name) const;
|
||||||
|
|
||||||
NzColor GetAmbientColor() const;
|
NzColor GetAmbientColor() const;
|
||||||
NzAbstractBackground* GetBackground() const;
|
NzAbstractBackground* GetBackground() const;
|
||||||
NzVector3f GetBackward() const;
|
NzVector3f GetBackward() const;
|
||||||
|
|
@ -63,6 +68,9 @@ class NAZARA_API NzScene
|
||||||
|
|
||||||
void RegisterForUpdate(NzUpdatable* object);
|
void RegisterForUpdate(NzUpdatable* object);
|
||||||
|
|
||||||
|
void RemoveNode(NzSceneNode* node);
|
||||||
|
void RemoveNode(const NzString& name);
|
||||||
|
|
||||||
void RenderFrame();
|
void RenderFrame();
|
||||||
|
|
||||||
void SetAmbientColor(const NzColor& color);
|
void SetAmbientColor(const NzColor& color);
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ T* NzScene::CreateNode(const NzString& name, const NzString& templateNodeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
NzSceneNode* sceneNode = it->second;
|
NzSceneNode* sceneNode = it->second;
|
||||||
if (NzImplGetType<T>() != sceneNode->GetSceneNodeType())
|
if (sceneNode->GetSceneNodeType() != NzImplGetType<T>())
|
||||||
{
|
{
|
||||||
NazaraError("Scene node type of T (" + NzString::Number(NzImplGetType<T>()) + ") doesn't match template scene node type (" + NzString::Number(sceneNode->GetSceneNodeType()) + ")");
|
NazaraError("Scene node type of T (" + NzString::Number(NzImplGetType<T>()) + ") doesn't match template scene node type (" + NzString::Number(sceneNode->GetSceneNodeType()) + ")");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -104,4 +104,36 @@ T* NzScene::CreateNode(const NzString& name, const NzString& templateNodeName)
|
||||||
return node.release();
|
return node.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* NzScene::FindNodeAs(const NzString& name)
|
||||||
|
{
|
||||||
|
NzSceneNode* sceneNode = FindNode(name);
|
||||||
|
if (!sceneNode)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (sceneNode->GetSceneNodeType() != NzImplGetType<T>())
|
||||||
|
{
|
||||||
|
NazaraError("Scene node type of T (" + NzString::Number(NzImplGetType<T>()) + ") doesn't match \"" + name + "\" scene node type (" + NzString::Number(sceneNode->GetSceneNodeType()) + ")");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<T*>(sceneNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
const T* NzScene::FindNodeAs(const NzString& name) const
|
||||||
|
{
|
||||||
|
const NzSceneNode* sceneNode = FindNode(name);
|
||||||
|
if (!sceneNode)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (sceneNode->GetSceneNodeType() != NzImplGetType<T>())
|
||||||
|
{
|
||||||
|
NazaraError("Scene node type of T (" + NzString::Number(NzImplGetType<T>()) + ") doesn't match \"" + name + "\" scene node type (" + NzString::Number(sceneNode->GetSceneNodeType()) + ")");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<const T*>(sceneNode);
|
||||||
|
}
|
||||||
|
|
||||||
#include <Nazara/Graphics/DebugOff.hpp>
|
#include <Nazara/Graphics/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,24 @@ void NzScene::EnableBackground(bool enable)
|
||||||
m_backgroundEnabled = enable;
|
m_backgroundEnabled = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NzSceneNode* NzScene::FindNode(const NzString& name)
|
||||||
|
{
|
||||||
|
auto it = m_nodeMap.find(name);
|
||||||
|
if (it == m_nodeMap.end())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NzSceneNode* NzScene::FindNode(const NzString& name) const
|
||||||
|
{
|
||||||
|
auto it = m_nodeMap.find(name);
|
||||||
|
if (it == m_nodeMap.end())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
NzColor NzScene::GetAmbientColor() const
|
NzColor NzScene::GetAmbientColor() const
|
||||||
{
|
{
|
||||||
return m_ambientColor;
|
return m_ambientColor;
|
||||||
|
|
@ -227,6 +245,47 @@ bool NzScene::IsBackgroundEnabled() const
|
||||||
return m_backgroundEnabled;
|
return m_backgroundEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzScene::RegisterForUpdate(NzUpdatable* object)
|
||||||
|
{
|
||||||
|
#if NAZARA_GRAPHICS_SAFE
|
||||||
|
if (!object)
|
||||||
|
{
|
||||||
|
NazaraError("Invalid object");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
m_updateList.push_back(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzScene::RemoveNode(NzSceneNode* node)
|
||||||
|
{
|
||||||
|
if (!node)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// C'est moche mais je n'ai pas d'autre choix que d'utiliser un std::unique_ptr pour utiliser std::find
|
||||||
|
std::unique_ptr<NzSceneNode> ptr(node);
|
||||||
|
auto it = std::find(m_nodes.begin(), m_nodes.end(), ptr);
|
||||||
|
ptr.release();
|
||||||
|
|
||||||
|
if (it == m_nodes.end())
|
||||||
|
{
|
||||||
|
NazaraError("This scene node doesn't belong to this scene");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NzString nodeName = node->GetName();
|
||||||
|
if (!nodeName.IsEmpty())
|
||||||
|
m_nodeMap.erase(nodeName);
|
||||||
|
|
||||||
|
m_nodes.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzScene::RemoveNode(const NzString& name)
|
||||||
|
{
|
||||||
|
RemoveNode(FindNode(name));
|
||||||
|
}
|
||||||
|
|
||||||
void NzScene::RenderFrame()
|
void NzScene::RenderFrame()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -243,19 +302,6 @@ void NzScene::RenderFrame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzScene::RegisterForUpdate(NzUpdatable* object)
|
|
||||||
{
|
|
||||||
#if NAZARA_GRAPHICS_SAFE
|
|
||||||
if (!object)
|
|
||||||
{
|
|
||||||
NazaraError("Invalid object");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_updateList.push_back(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NzScene::SetAmbientColor(const NzColor& color)
|
void NzScene::SetAmbientColor(const NzColor& color)
|
||||||
{
|
{
|
||||||
m_ambientColor = color;
|
m_ambientColor = color;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue