From 52509d6f5781a98b6a07989de04eab0e4e97f32b Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 25 Jun 2025 02:02:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=BA=E7=AB=8BCreateComponentInfo=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E7=94=A8=E4=BA=8ECreateComponent=E6=97=B6?= =?UTF-8?q?=E4=BC=A0=E9=80=92=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/WorkObject.h | 4 +- inc/hgl/graph/RenderFramework.h | 85 +++++++++++++++++---------------- 2 files changed, 47 insertions(+), 42 deletions(-) diff --git a/inc/hgl/WorkObject.h b/inc/hgl/WorkObject.h index 20721c97..3869e9e7 100644 --- a/inc/hgl/WorkObject.h +++ b/inc/hgl/WorkObject.h @@ -106,9 +106,9 @@ namespace hgl public: //Component 相关 template - inline C *CreateComponent(ARGS...args) + inline C *CreateComponent(const graph::CreateComponentInfo *cci,ARGS...args) { - return render_framework?render_framework->CreateComponent(args...):nullptr; //创建组件 + return render_framework?render_framework->CreateComponent(cci,args...):nullptr; //创建组件 } };//class WorkObject diff --git a/inc/hgl/graph/RenderFramework.h b/inc/hgl/graph/RenderFramework.h index 27b8ff12..d0cc80e2 100644 --- a/inc/hgl/graph/RenderFramework.h +++ b/inc/hgl/graph/RenderFramework.h @@ -28,6 +28,44 @@ class Renderer; class CameraComponentManager{/*现阶段测试使用*/}; class LightComponentManager{/*现阶段测试使用*/}; +struct CreateComponentInfo +{ + graph::SceneNode *parent_node; ///<父节点 + graph::Matrix4f mat; ///<矩阵 + +public: + + CreateComponentInfo() + { + parent_node=nullptr; + mat=graph::Identity4f; + } + + CreateComponentInfo(const CreateComponentInfo &cci) + { + parent_node=cci.parent_node; + mat=cci.mat; + } + + CreateComponentInfo(graph::SceneNode *pn,const graph::Matrix4f &m) + { + parent_node=pn; + mat=m; + } + + CreateComponentInfo(graph::SceneNode *pn) + { + parent_node=pn; + mat=graph::Identity4f; + } + + CreateComponentInfo(const graph::Matrix4f &m) + { + parent_node=nullptr; + mat=m; + } +};//struct CreateComponentInfo + class RenderFramework:public io::WindowEvent { OSString app_name; @@ -204,7 +242,7 @@ public: // ComponentManager public: //Component 相关 template - inline C *CreateComponent(ARGS...args) + inline C *CreateComponent(const CreateComponentInfo *cci,ARGS...args) { auto manager=C::GetDefaultManager(); //取得默认管理器 @@ -214,19 +252,7 @@ public: //Component 相关 return(nullptr); } - return (C *)(manager->CreateComponent(args...)); //创建组件 - } - - template - 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(args...); //创建组件 + C *c=(C *)(manager->CreateComponent(args...)); //创建组件 if(!c) { @@ -237,35 +263,14 @@ public: //Component 相关 /** * 如果此处出现转换错误,请检查是否包含了对应的Component头文件。 */ - parent_node->AttachComponent(c); //将组件附加到父节点 - - return c; - } - - template - inline C *CreateComponent(const graph::Matrix4f &mat,graph::SceneNode *parent_node,ARGS...args) - { - if(!parent_node) + if(cci) { - // LOG_ERROR(OS_TEXT("CreateComponent failed, parent node is null!")); - return(nullptr); + if(cci->parent_node) + cci->parent_node->AttachComponent(c); //将组件附加到父节点 + + c->graph::SceneOrient::SetLocalMatrix(cci->mat); } - C *c=this->CreateComponent(args...); //创建组件 - - if(!c) - { - // LOG_ERROR(OS_TEXT("CreateComponent failed, create component failed!")); - return(nullptr); - } - - /** - * 如果此处出现转换错误,请检查是否包含了对应的Component头文件。 - */ - parent_node->AttachComponent(c); //将组件附加到父节点 - - c->graph::SceneOrient::SetLocalMatrix(mat); - return c; } };//class RenderFramework