From 2516e9cfc109ee767520444a84f5a0f4eb830240 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 21 Dec 2024 17:25:30 +0800 Subject: [PATCH] splited InitDependentModules --- inc/hgl/graph/manager/TextureManager.h | 4 ++- inc/hgl/graph/module/GraphModule.h | 6 ++++- inc/hgl/graph/module/GraphModuleFactory.h | 6 +++++ src/SceneGraph/manager/TextureManager.cpp | 20 +++++++++++++-- src/SceneGraph/module/GraphModule.cpp | 30 ++++++++++------------- 5 files changed, 45 insertions(+), 21 deletions(-) diff --git a/inc/hgl/graph/manager/TextureManager.h b/inc/hgl/graph/manager/TextureManager.h index dc618fa2..ba774cfe 100644 --- a/inc/hgl/graph/manager/TextureManager.h +++ b/inc/hgl/graph/manager/TextureManager.h @@ -42,7 +42,9 @@ public: GRAPH_MODULE_CONSTRUCT(TextureManager) virtual ~TextureManager(); - bool Init(GraphModulesMap *) override; + static const char **GetDependentModules(); + + bool Init() override; const VkFormatProperties GetFormatProperties(const VkFormat)const; diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index 3fb4c647..2d205d77 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -96,6 +96,7 @@ class GraphModule:public Comparator AnsiIDName module_name; + bool module_inited_dependent; bool module_inited; bool module_enabled; bool module_ready; @@ -130,6 +131,7 @@ public: virtual const bool IsPerFrame () {return false;} ///<是否每帧运行 virtual const bool IsRender () {return false;} ///<是否为渲染模块 + const bool IsInitedDependent ()const {return module_inited_dependent;} ///<是否已经初始化依赖的模块 const bool IsInited ()const {return module_inited;} ///<是否已经初始化 const bool IsEnabled ()const noexcept{return module_enabled;} ///<当前模块是否启用 const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好 @@ -143,7 +145,9 @@ public: virtual const size_t GetTypeHash()const=0; - virtual bool Init(GraphModulesMap *); ///<初始化当前模块 + virtual bool InitDependentModules(GraphModulesMap *); ///<初始化依赖的模块 + + virtual bool Init()=0; ///<初始化当前模块 static const AnsiIDNameSet &GetDependentModules() ///<取得依赖的模块列表 { diff --git a/inc/hgl/graph/module/GraphModuleFactory.h b/inc/hgl/graph/module/GraphModuleFactory.h index d7ea6ed5..53d35dba 100644 --- a/inc/hgl/graph/module/GraphModuleFactory.h +++ b/inc/hgl/graph/module/GraphModuleFactory.h @@ -50,6 +50,12 @@ public: GraphModule *gm=new T(gmm,dgm_map); + if(!gm->InitDependentModules(gmm)) + { + delete gm; + return(nullptr); + } + if(!gm->Init()) { delete gm; diff --git a/src/SceneGraph/manager/TextureManager.cpp b/src/SceneGraph/manager/TextureManager.cpp index 8a616168..94847055 100644 --- a/src/SceneGraph/manager/TextureManager.cpp +++ b/src/SceneGraph/manager/TextureManager.cpp @@ -1,6 +1,7 @@ -#include +#include #include #include +#include VK_NAMESPACE_BEGIN const VkFormatProperties TextureManager::GetFormatProperties(const VkFormat format) const @@ -8,8 +9,23 @@ const VkFormatProperties TextureManager::GetFormatProperties(const VkFormat form return GetPhysicalDevice()->GetFormatProperties(format); } -bool TextureManager::Init() +namespace { + const char *tex_manager_dep[] + { + "RenderPassManager" + }; +} + +const char **TextureManager::GetDependentModules() ///<取得依赖的模块列表 +{ + return tex_manager_dep; +} + +bool TextureManager::Init(GraphModulesMap *gmm) +{ + + GPUDevice *dev=GetDevice(); if(!dev) diff --git a/src/SceneGraph/module/GraphModule.cpp b/src/SceneGraph/module/GraphModule.cpp index c0a1b2c6..c2c61418 100644 --- a/src/SceneGraph/module/GraphModule.cpp +++ b/src/SceneGraph/module/GraphModule.cpp @@ -31,7 +31,7 @@ GraphModule::~GraphModule() LOG_INFO("GraphModule::~GraphModule: "+AnsiString(module_name.GetName())) } -bool GraphModule::Init(GraphModulesMap *gmm) +bool GraphModule::InitDependentModules(GraphModulesMap *) { auto dm_list=GetDependentModules(); @@ -40,27 +40,23 @@ bool GraphModule::Init(GraphModulesMap *gmm) if(!gmm) return(false); - if(!gmm->IsEmpty()) - { - for(auto dm_name:dm_list) - { - GraphModule *dm; - - if(gmm->Get(dm_name,dm)) - { - if(dm->IsInited()) - { - dependent_modules.Add(dm); - continue; - } - } + if(gmm->IsEmpty()) + return(false); - return(false); + for(auto dm_name:dm_list) + { + GraphModule *dm=gmm->Get(dm_name); + + if(dm&&dm->IsInited()) + { + dependent_modules.Add(dm); + continue; } + + return(false); } } - module_inited=true; return(true); }