[DON'T WORK] added dependent modules ....
This commit is contained in:
@@ -26,7 +26,7 @@ private:
|
||||
GRAPH_MODULE_CONSTRUCT(RenderPassManager)
|
||||
~RenderPassManager();
|
||||
|
||||
bool Init() override;
|
||||
bool Init(GraphModulesMap *) override;
|
||||
|
||||
private:
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
@@ -12,6 +12,8 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
class TextureManager:public GraphModule
|
||||
{
|
||||
RenderPassManager *rp_manager=nullptr;
|
||||
|
||||
DeviceQueue *texture_queue=nullptr;
|
||||
TextureCmdBuffer *texture_cmd_buf=nullptr;
|
||||
|
||||
@@ -40,7 +42,7 @@ public:
|
||||
GRAPH_MODULE_CONSTRUCT(TextureManager)
|
||||
virtual ~TextureManager();
|
||||
|
||||
bool Init() override;
|
||||
bool Init(GraphModulesMap *) override;
|
||||
|
||||
const VkFormatProperties GetFormatProperties(const VkFormat)const;
|
||||
|
||||
|
@@ -11,14 +11,40 @@ class GraphModule;
|
||||
|
||||
class RenderFramework;
|
||||
|
||||
struct GraphModulesMap
|
||||
{
|
||||
List<GraphModule *> gm_list;
|
||||
|
||||
Map<AnsiIDName,GraphModule *> gm_map_by_name;
|
||||
Map<size_t,GraphModule *> gm_map_by_hash;
|
||||
|
||||
public:
|
||||
|
||||
bool Add(GraphModule *gm);
|
||||
|
||||
GraphModule *Get(const AnsiIDName &name)const
|
||||
{
|
||||
GraphModule *gm;
|
||||
|
||||
if(gm_map_by_name.Get(name,gm))
|
||||
return gm;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const bool Get(T *&gm)const
|
||||
{
|
||||
return gm_map_by_hash.Get(GetTypeHash<T>(),gm);
|
||||
}
|
||||
};
|
||||
|
||||
class GraphModuleManager
|
||||
{
|
||||
GPUDevice *device;
|
||||
RenderFramework *framework;
|
||||
|
||||
List<GraphModule *> module_list; ///<模块列表
|
||||
|
||||
Map<AnsiIDName,GraphModule *> graph_module_map; ///<模块映射表
|
||||
GraphModulesMap graph_module_map; ///<模块映射表
|
||||
|
||||
public:
|
||||
|
||||
@@ -65,12 +91,19 @@ class GraphModule:public Comparator<GraphModule>
|
||||
|
||||
AnsiIDName module_name;
|
||||
|
||||
SortedSet<AnsiIDName> dependent_module; ///<依赖的模块
|
||||
|
||||
bool module_inited;
|
||||
bool module_enabled;
|
||||
bool module_ready;
|
||||
|
||||
GraphModulesMap dependent_modules;
|
||||
|
||||
protected:
|
||||
|
||||
//GraphModule *GetModule(const AnsiIDName &name){return module_manager->GetModule(name,true);} ///<获取指定名称的模块
|
||||
|
||||
//template<typename T>
|
||||
//T *GetModule(){return (T *)GetModule(T::GetModuleName());} ///<获取指定类型的模块
|
||||
|
||||
protected:
|
||||
|
||||
virtual void SetModuleEnabled(bool e){module_enabled=e;}
|
||||
@@ -103,19 +136,28 @@ public:
|
||||
GraphModule(GraphModuleManager *gmm,const AnsiIDName &name);
|
||||
virtual ~GraphModule();
|
||||
|
||||
virtual bool Init(){module_inited=true;return true;} ///<初始化当前模块
|
||||
virtual bool Init(GraphModulesMap *); ///<初始化当前模块
|
||||
|
||||
static const AnsiIDNameSet &GetDependentModules() ///<取得依赖的模块列表
|
||||
{
|
||||
static const AnsiIDNameSet empty;
|
||||
|
||||
return empty;
|
||||
}
|
||||
|
||||
const int compare(const GraphModule &gm)const override
|
||||
{
|
||||
return(dependent_module.Contains(gm.module_name)?1:-1); //如果我依赖于他,那么我比他大
|
||||
auto &dependent_modules_name=GetDependentModules();
|
||||
|
||||
return(dependent_modules_name.Contains(gm.module_name)?1:-1); //如果我依赖于他,那么我比他大
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
GraphModule * GetModule(const AnsiIDName &name,bool create=false){return module_manager->GetModule(name,create);} ///<获取指定名称的模块
|
||||
GraphModule * GetDependentModule(const AnsiIDName &name); ///<获取指定名称的模块
|
||||
|
||||
template<typename T>
|
||||
T * GetModule(bool create=false){return module_manager->GetModule<T>(create);} ///<获取指定类型的模块
|
||||
T * GetDependentModule(){return GetDependentModule(T::GetName());} ///<获取指定类型的模块
|
||||
|
||||
public: //回调事件
|
||||
|
||||
@@ -128,6 +170,7 @@ public: //回调事件
|
||||
|
||||
#define GRAPH_MODULE_CONSTRUCT(name) public:\
|
||||
NO_COPY_NO_MOVE(name) \
|
||||
static const size_t GetTypeHash(){return typeid(name).hash_code();} \
|
||||
static const AnsiIDName &GetModuleName() \
|
||||
{ \
|
||||
static const AnsiIDName id_name(#name); \
|
||||
@@ -137,6 +180,7 @@ public: //回调事件
|
||||
name(GraphModuleManager *gmm):GraphModule(gmm,GetModuleName()){}
|
||||
|
||||
#define RENDER_MODULE_CONSTRUCT(name) public:\
|
||||
static const size_t GetTypeHash(){return typeid(name).hash_code();} \
|
||||
NO_COPY_NO_MOVE(name) \
|
||||
static const AnsiIDName &GetModuleName() \
|
||||
{ \
|
||||
|
@@ -28,7 +28,27 @@ public:
|
||||
if(!gmm)
|
||||
return(nullptr);
|
||||
|
||||
GraphModule *gm=new T(gmm);
|
||||
Map<AnsiIDName,GraphModule *> dgm_map;
|
||||
|
||||
//检查依赖模块
|
||||
{
|
||||
const auto &dependent_modules=T::GetDependentModules();
|
||||
|
||||
if(!dependent_modules.IsEmpty())
|
||||
{
|
||||
for(const AnsiIDName &name:dependent_modules)
|
||||
{
|
||||
GraphModule *dgm=gmm->GetModule(name,true);
|
||||
|
||||
if(!dgm)
|
||||
return(nullptr);
|
||||
|
||||
dgm_map.Add(name,dgm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GraphModule *gm=new T(gmm,dgm_map);
|
||||
|
||||
if(!gm->Init())
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/module/RenderModule.h>
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
GRAPH_MODULE_CONSTRUCT(SwapchainModule)
|
||||
virtual ~SwapchainModule();
|
||||
|
||||
bool Init() override;
|
||||
bool Init(GraphModulesMap *) override;
|
||||
|
||||
bool BeginFrame();
|
||||
void EndFrame();
|
||||
|
Reference in New Issue
Block a user