From 76103a869bc8f21c34087e7235a6282d5db8fa37 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 8 Jan 2025 13:26:27 +0800 Subject: [PATCH] [wip] --- CMAssetsManage | 2 +- CMCore | 2 +- CMUtil | 2 +- inc/hgl/graph/module/GraphModule.h | 19 +++++----- inc/hgl/graph/module/GraphModuleFactory.h | 11 +----- inc/hgl/graph/module/SwapchainModule.h | 2 - res | 2 +- src/SceneGraph/module/GraphModule.cpp | 39 +++++++++++++++++++- src/SceneGraph/module/GraphModuleManager.cpp | 21 ++--------- src/SceneGraph/module/SwapchainModule.cpp | 10 +---- 10 files changed, 58 insertions(+), 52 deletions(-) diff --git a/CMAssetsManage b/CMAssetsManage index 878335ba..0fae4623 160000 --- a/CMAssetsManage +++ b/CMAssetsManage @@ -1 +1 @@ -Subproject commit 878335ba9c4159d558f41c47783447092e0602c9 +Subproject commit 0fae462338cd01c5a26d0a8f0175fe3729a65c94 diff --git a/CMCore b/CMCore index 77a3a9d2..8c86a153 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 77a3a9d26e0f3b38c8d8b46b24aff22b1738d10e +Subproject commit 8c86a153ebe97bb03a6abf4bb7c0ac7bebb8eb4f diff --git a/CMUtil b/CMUtil index f330a667..57ff3a70 160000 --- a/CMUtil +++ b/CMUtil @@ -1 +1 @@ -Subproject commit f330a6672e9b3124e83ce527d2db747b6ee3226b +Subproject commit 57ff3a70c99265ed7bb97b3b6840709e84bac0c1 diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index ab44d841..df0e4ef9 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -19,6 +19,8 @@ struct GraphModulesMap Map gm_map_by_name; Map gm_map_by_hash; + List gm_list; //按创建顺序记录,用于倒序释放 + public: bool Add(GraphModule *gm); @@ -50,6 +52,10 @@ public: template const bool IsLoaded()const{return gm_map_by_hash.ContainsKey(T::GetTypeHash());} + + bool Release(GraphModule *gm); + + void Destory(); }; class GraphModuleManager @@ -99,17 +105,16 @@ class GraphModule:public Comparator AnsiIDName module_name; - bool module_inited_dependent; bool module_inited; bool module_enabled; bool module_ready; protected: - //GraphModule *GetModule(const AnsiIDName &name){return module_manager->GetModule(name,true);} ///<获取指定名称的模块 + GraphModule *GetModule(const AnsiIDName &name){return module_manager->GetModule(name,false);} ///<获取指定名称的模块 - //template - //T *GetModule(){return (T *)GetModule(T::GetModuleName());} ///<获取指定类型的模块 + template + T *GetModule(){return module_manager->GetModule();} ///<获取指定类型的模块 protected: @@ -132,7 +137,6 @@ 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;} ///<当前模块是否准备好 @@ -146,11 +150,6 @@ public: virtual const size_t GetTypeHash()const=0; - /** - * 依赖的模块是在模板new之前就获取的,当前函数仅用于传递这些数据 - */ - virtual bool InitDependentModules(GraphModulesMap &){module_inited_dependent=true;return true;} ///<初始化依赖的模块 - virtual bool Init()=0; ///<初始化当前模块 static const char **GetDependentModules(){return nullptr;} ///<取得依赖的模块列表 diff --git a/inc/hgl/graph/module/GraphModuleFactory.h b/inc/hgl/graph/module/GraphModuleFactory.h index 38da46ea..5a3c1344 100644 --- a/inc/hgl/graph/module/GraphModuleFactory.h +++ b/inc/hgl/graph/module/GraphModuleFactory.h @@ -1,12 +1,11 @@ #pragma once #include +#include +#include VK_NAMESPACE_BEGIN -class GraphModule; -class GraphModuleManager; - class GraphModuleFactory { public: @@ -50,12 +49,6 @@ public: GraphModule *gm=new T(gmm); - if(!gm->InitDependentModules(dgm)) - { - delete gm; - return(nullptr); - } - if(!gm->Init()) { delete gm; diff --git a/inc/hgl/graph/module/SwapchainModule.h b/inc/hgl/graph/module/SwapchainModule.h index ea8f4160..d4f064e9 100644 --- a/inc/hgl/graph/module/SwapchainModule.h +++ b/inc/hgl/graph/module/SwapchainModule.h @@ -32,8 +32,6 @@ public: GRAPH_MODULE_CONSTRUCT(SwapchainModule) virtual ~SwapchainModule(); - bool InitDependentModules(GraphModulesMap &) override; - bool Init() override; bool BeginFrame(); diff --git a/res b/res index e1a36d78..475d8ad4 160000 --- a/res +++ b/res @@ -1 +1 @@ -Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d +Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd diff --git a/src/SceneGraph/module/GraphModule.cpp b/src/SceneGraph/module/GraphModule.cpp index 1ee7f167..63d9ce60 100644 --- a/src/SceneGraph/module/GraphModule.cpp +++ b/src/SceneGraph/module/GraphModule.cpp @@ -12,9 +12,46 @@ bool GraphModulesMap::Add(GraphModule *gm) if(gm_set.Contains(gm)) return(false); - + gm_list.Add(gm); gm_set.Add(gm); gm_map_by_name.Add(gm->GetName(),gm); + gm_map_by_hash.Add(gm->GetTypeHash(),gm); +} + +void GraphModulesMap::Destory() +{ +//按顺序加入module_list的,要倒着释放 + + auto *m=gm_list.last(); + auto *begin=gm_list.begin(); + + while(m>=begin) + { + delete m; + --m; + } + + gm_list.Clear(); + gm_set.Clear(); + gm_map_by_name.Clear(); + gm_map_by_hash.Clear(); +} + +bool GraphModulesMap::Release(GraphModule *gm) +{ + if(!gm) + return(false); + if(!gm_set.Contains(gm)) + return(false); + + //因为总计就没几个数据,所以无序关心效能 + + gm_set.Delete(gm); + gm_list.DeleteByValue(gm); + gm_map_by_name.DeleteByValue(gm); + gm_map_by_hash.DeleteByValue(gm); + + return(true); } GraphModule::GraphModule(GraphModuleManager *gmm,const AnsiIDName &name) diff --git a/src/SceneGraph/module/GraphModuleManager.cpp b/src/SceneGraph/module/GraphModuleManager.cpp index d5c94786..7865e0cc 100644 --- a/src/SceneGraph/module/GraphModuleManager.cpp +++ b/src/SceneGraph/module/GraphModuleManager.cpp @@ -109,19 +109,7 @@ GraphModuleManager::GraphModuleManager(RenderFramework *rf) GraphModuleManager::~GraphModuleManager() { - //按顺序加入module_list的,要倒着释放 - - GraphModule **gm=module_list.end(); - - while(gm>module_list.begin()) - { - --gm; - delete *gm; - } - - //其实下面释不释放都无所谓了 - module_list.Clear(); - graph_module_map.Clear(); + graph_module_map.Destory(); } void GraphModuleManager::ReleaseModule(GraphModule *gm) @@ -129,8 +117,7 @@ void GraphModuleManager::ReleaseModule(GraphModule *gm) if(!gm) return; - graph_module_map.DeleteByValue(gm); - delete gm; + graph_module_map.Release(gm); } void GraphModuleManager::OnResize(const VkExtent2D &extent) @@ -138,9 +125,9 @@ void GraphModuleManager::OnResize(const VkExtent2D &extent) if(graph_module_map.IsEmpty()) return; - for(auto *gm:graph_module_map) + for(auto *gm:graph_module_map.gm_list) { - gm->value->OnResize(extent); + gm->OnResize(extent); } } diff --git a/src/SceneGraph/module/SwapchainModule.cpp b/src/SceneGraph/module/SwapchainModule.cpp index b6a8ef3c..bd295b3c 100644 --- a/src/SceneGraph/module/SwapchainModule.cpp +++ b/src/SceneGraph/module/SwapchainModule.cpp @@ -230,7 +230,7 @@ SwapchainModule::~SwapchainModule() delete swapchain; } -bool SwapchainModule::InitDependentModules(GraphModulesMap &dep_gmm) +bool SwapchainModule::Init() { RenderPassManager *rp_manager=dep_gmm.Get(); @@ -240,18 +240,10 @@ bool SwapchainModule::InitDependentModules(GraphModulesMap &dep_gmm) SwapchainRenderbufferInfo rbi(swapchain->surface_format.format,swapchain->depth_format); swapchain_rp=rp_manager->AcquireRenderPass(&rbi); -} -bool SwapchainModule::Init() -{ if(!CreateSwapchain()) return(false); - RenderPassManager *rpm=GetModule(); - - if(!rpm) - return(false); - //#ifdef _DEBUG // if(dev_attr->debug_utils) // dev_attr->debug_utils->SetRenderPass(swapchain_rp->GetVkRenderPass(),"SwapchainRenderPass");