63 lines
1.3 KiB
C++
63 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "dvc_config.h"
|
|
#include "dvc_pre_declare.h"
|
|
|
|
DV_CORE_BEGIN_NAMESPACE
|
|
|
|
class DV_CORE_API Scene
|
|
{
|
|
public:
|
|
void init(void);
|
|
void clear(void);
|
|
|
|
public:
|
|
SceneNodePtr newSceneNode(const std::string& name);
|
|
SceneNodePtr getRootSceneNode() const;
|
|
void buildRenderableQueue(RenderPipe& pipe) const;
|
|
|
|
public:
|
|
template<typename ComponentType>
|
|
SceneNodeConstPtr getNodeWithComponent(const char* name = nullptr) const
|
|
{
|
|
return getNodeWithComponent<ComponentType>(name, getRootSceneNode());
|
|
}
|
|
|
|
template<typename ComponentType>
|
|
SceneNodeConstPtr getNodeWithComponent(const char* name, SceneNodeConstPtr node) const
|
|
{
|
|
size_t counts = node->getChildCounts();
|
|
for (size_t i = 0; i < counts; i++)
|
|
{
|
|
SceneNodeConstPtr childNodePtr = node->getChild(i);
|
|
if (name != nullptr && childNodePtr->getName() != name)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
std::shared_ptr<const ComponentType> component = childNodePtr->getComponent<ComponentType>();
|
|
if (component)
|
|
{
|
|
return childNodePtr;
|
|
}
|
|
|
|
//get from child
|
|
SceneNodeConstPtr cameraNode = getNodeWithComponent<ComponentType>(name, childNodePtr);
|
|
if (cameraNode != nullptr)
|
|
{
|
|
return cameraNode;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
protected:
|
|
SceneNodePtr m_rootSceneNode;
|
|
|
|
public:
|
|
Scene();
|
|
~Scene();
|
|
};
|
|
|
|
DV_CORE_END_NAMESPACE
|