改进Component/Manager设计,在WorkObject封装Component相关模板函数,以减化使用部分。当前版本可运行,下一版迁移旧的Renderable渲染到StaticMeshComponent.

This commit is contained in:
2025-06-14 18:47:54 +08:00
parent edaf5aa3ca
commit 92f612f675
5 changed files with 50 additions and 11 deletions

View File

@@ -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
/**