[wip]
This commit is contained in:
Submodule CMAssetsManage updated: 878335ba9c...0fae462338
2
CMCore
2
CMCore
Submodule CMCore updated: 77a3a9d26e...8c86a153eb
2
CMUtil
2
CMUtil
Submodule CMUtil updated: f330a6672e...57ff3a70c9
@@ -19,6 +19,8 @@ struct GraphModulesMap
|
||||
Map<AnsiIDName,GraphModule *> gm_map_by_name;
|
||||
Map<size_t,GraphModule *> gm_map_by_hash;
|
||||
|
||||
List<GraphModule *> gm_list; //按创建顺序记录,用于倒序释放
|
||||
|
||||
public:
|
||||
|
||||
bool Add(GraphModule *gm);
|
||||
@@ -50,6 +52,10 @@ public:
|
||||
|
||||
template<typename T>
|
||||
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<GraphModule>
|
||||
|
||||
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<typename T>
|
||||
//T *GetModule(){return (T *)GetModule(T::GetModuleName());} ///<获取指定类型的模块
|
||||
template<typename T>
|
||||
T *GetModule(){return module_manager->GetModule<T>();} ///<获取指定类型的模块
|
||||
|
||||
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;} ///<取得依赖的模块列表
|
||||
|
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKNamespace.h>
|
||||
#include<hgl/type/IDName.h>
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
|
||||
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;
|
||||
|
@@ -32,8 +32,6 @@ public:
|
||||
GRAPH_MODULE_CONSTRUCT(SwapchainModule)
|
||||
virtual ~SwapchainModule();
|
||||
|
||||
bool InitDependentModules(GraphModulesMap &) override;
|
||||
|
||||
bool Init() override;
|
||||
|
||||
bool BeginFrame();
|
||||
|
2
res
2
res
Submodule res updated: e1a36d78f0...475d8ad43c
@@ -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)
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -230,7 +230,7 @@ SwapchainModule::~SwapchainModule()
|
||||
delete swapchain;
|
||||
}
|
||||
|
||||
bool SwapchainModule::InitDependentModules(GraphModulesMap &dep_gmm)
|
||||
bool SwapchainModule::Init()
|
||||
{
|
||||
RenderPassManager *rp_manager=dep_gmm.Get<RenderPassManager>();
|
||||
|
||||
@@ -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<RenderPassManager>();
|
||||
|
||||
if(!rpm)
|
||||
return(false);
|
||||
|
||||
//#ifdef _DEBUG
|
||||
// if(dev_attr->debug_utils)
|
||||
// dev_attr->debug_utils->SetRenderPass(swapchain_rp->GetVkRenderPass(),"SwapchainRenderPass");
|
||||
|
Reference in New Issue
Block a user