(Scene) Added CreateNode and Clear methods
Former-commit-id: de92f4a4be45e5cbd1d2d83191300e0b46764f0e
This commit is contained in:
@@ -10,12 +10,14 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/Updatable.hpp>
|
||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/SceneRoot.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class NzAbstractRenderQueue;
|
||||
@@ -37,6 +39,12 @@ class NAZARA_API NzScene
|
||||
|
||||
void AddToVisibilityList(NzUpdatable* object);
|
||||
|
||||
template<typename T, typename... Args> T* CreateNode(Args&&... args);
|
||||
template<typename T, typename... Args> T* CreateNode(const NzString& name, Args&&... args);
|
||||
template<typename T, typename... Args> T* CreateNode(const NzString& name, const NzString& templateNodeName);
|
||||
|
||||
void Clear();
|
||||
|
||||
void Cull();
|
||||
void Draw();
|
||||
|
||||
@@ -78,10 +86,13 @@ class NAZARA_API NzScene
|
||||
operator const NzSceneNode&() const;
|
||||
|
||||
private:
|
||||
bool RegisterSceneNode(const NzString& name, NzSceneNode* node);
|
||||
void RecursiveFrustumCull(NzAbstractRenderQueue* renderQueue, const NzFrustumf& frustum, NzNode* node);
|
||||
|
||||
mutable std::unique_ptr<NzAbstractBackground> m_background;
|
||||
mutable std::unique_ptr<NzAbstractRenderTechnique> m_renderTechnique;
|
||||
std::unordered_map<NzString, NzSceneNode*> m_nodeMap;
|
||||
std::vector<std::unique_ptr<NzSceneNode>> m_nodes;
|
||||
std::vector<NzUpdatable*> m_updateList;
|
||||
std::vector<NzUpdatable*> m_visibleUpdateList;
|
||||
NzClock m_updateClock;
|
||||
@@ -96,4 +107,6 @@ class NAZARA_API NzScene
|
||||
unsigned int m_updatePerSecond;
|
||||
};
|
||||
|
||||
#include <Nazara/Graphics/Scene.inl>
|
||||
|
||||
#endif // NAZARA_SCENE_HPP
|
||||
|
||||
107
include/Nazara/Graphics/Scene.inl
Normal file
107
include/Nazara/Graphics/Scene.inl
Normal file
@@ -0,0 +1,107 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
///TODO: Déplacer vers SceneNode et exposer
|
||||
|
||||
// Pour être sûr que ce code soit à jour
|
||||
static_assert(nzSceneNodeType_Max == 6, "Please update the code below");
|
||||
|
||||
class NzLight;
|
||||
class NzModel;
|
||||
class NzParticleEmitter;
|
||||
class NzSceneRoot;
|
||||
class NzSprite;
|
||||
class NzTextSprite;
|
||||
|
||||
template<typename T>
|
||||
constexpr nzSceneNodeType NzImplGetType()
|
||||
{
|
||||
return nzSceneNodeType_User;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline constexpr nzSceneNodeType NzImplGetType<NzLight>()
|
||||
{
|
||||
return nzSceneNodeType_Light;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline constexpr nzSceneNodeType NzImplGetType<NzModel>()
|
||||
{
|
||||
return nzSceneNodeType_Model;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline constexpr nzSceneNodeType NzImplGetType<NzParticleEmitter>()
|
||||
{
|
||||
return nzSceneNodeType_ParticleEmitter;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline constexpr nzSceneNodeType NzImplGetType<NzSceneRoot>()
|
||||
{
|
||||
return nzSceneNodeType_Root;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline constexpr nzSceneNodeType NzImplGetType<NzSprite>()
|
||||
{
|
||||
return nzSceneNodeType_Sprite;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline constexpr nzSceneNodeType NzImplGetType<NzTextSprite>()
|
||||
{
|
||||
return nzSceneNodeType_TextSprite;
|
||||
}
|
||||
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T* NzScene::CreateNode(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<T> node(new T(std::forward<Args>(args)...));
|
||||
if (!RegisterSceneNode(NzString(), node.get()))
|
||||
return nullptr;
|
||||
|
||||
return node.release();
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T* NzScene::CreateNode(const NzString& name, Args&&... args)
|
||||
{
|
||||
std::unique_ptr<T> node(new T(std::forward<Args>(args)...));
|
||||
if (!RegisterSceneNode(name, node.get()))
|
||||
return nullptr;
|
||||
|
||||
return node.release();
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T* NzScene::CreateNode(const NzString& name, const NzString& templateNodeName)
|
||||
{
|
||||
auto it = m_nodeMap.find(templateNodeName);
|
||||
if (it == m_nodeMap.end())
|
||||
{
|
||||
NazaraError("Node \"" + templateNodeName + "\" is not registred");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NzSceneNode* sceneNode = it->second;
|
||||
if (NzImplGetType<T>() != 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;
|
||||
}
|
||||
|
||||
std::unique_ptr<T> node(static_cast<T*>(sceneNode)->Copy());
|
||||
if (!RegisterSceneNode(name, node.get()))
|
||||
return nullptr;
|
||||
|
||||
return node.release();
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user