改进Component/Manager设计,在WorkObject封装Component相关模板函数,以减化使用部分。当前版本可运行,下一版迁移旧的Renderable渲染到StaticMeshComponent.
This commit is contained in:
@@ -122,6 +122,44 @@ namespace hgl
|
||||
graph::MaterialInstance *mi,
|
||||
graph::Pipeline *pipeline,
|
||||
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
|
||||
|
||||
public: //Component 相关
|
||||
|
||||
template<typename C,typename ...ARGS>
|
||||
inline C *CreateComponent(ARGS...args)
|
||||
{
|
||||
auto manager=C::GetDefaultManager(); //取得默认管理器
|
||||
|
||||
if(!manager)
|
||||
{
|
||||
// LOG_ERROR(OS_TEXT("CreateComponent failed, no default manager!"));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
return manager->CreateComponent(args...); //创建组件
|
||||
}
|
||||
|
||||
template<typename C,typename ...ARGS>
|
||||
inline C *CreateComponent(graph::SceneNode *parent_node,ARGS...args)
|
||||
{
|
||||
if(!parent_node)
|
||||
{
|
||||
// LOG_ERROR(OS_TEXT("CreateComponent failed, parent node is null!"));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
C *c=this->CreateComponent<C>(args...); //创建组件
|
||||
|
||||
if(!c)
|
||||
{
|
||||
// LOG_ERROR(OS_TEXT("CreateComponent failed, create component failed!"));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
parent_node->AttachComponent(c); //将组件附加到父节点
|
||||
|
||||
return c;
|
||||
}
|
||||
};//class WorkObject
|
||||
|
||||
/**
|
||||
|
@@ -45,13 +45,13 @@ public:
|
||||
|
||||
StaticMeshComponentManager()=default;
|
||||
|
||||
StaticMeshComponent *CreateStaticMeshComponent(StaticMeshComponentData *data);
|
||||
StaticMeshComponent *CreateComponent(StaticMeshComponentData *data);
|
||||
|
||||
StaticMeshComponent *CreateStaticMeshComponent(Mesh *m)
|
||||
StaticMeshComponent *CreateComponent(Mesh *m)
|
||||
{
|
||||
auto sm_cd=new StaticMeshComponentData(m);
|
||||
|
||||
return CreateStaticMeshComponent(sm_cd);
|
||||
return CreateComponent(sm_cd);
|
||||
}
|
||||
|
||||
virtual Component *CreateComponent(ComponentData *data) override;
|
||||
@@ -71,6 +71,11 @@ public:
|
||||
|
||||
virtual ~StaticMeshComponent()=default;
|
||||
|
||||
static StaticMeshComponentManager *GetDefaultManager()
|
||||
{
|
||||
return StaticMeshComponentManager::GetDefaultManager();
|
||||
}
|
||||
|
||||
static constexpr const size_t StaticHashCode()
|
||||
{
|
||||
return hgl::GetTypeHash<StaticMeshComponent>();
|
||||
|
Reference in New Issue
Block a user