ULRE/inc/hgl/WorkManager.h

95 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include<hgl/WorkObject.h>
namespace hgl
{
/**
* 工作管理器管理一个序列的WorkObject<br>
*/
class WorkManager:public io::WindowEvent
{
protected:
graph::RenderFramework *render_framework;
uint fps=60;
double frame_time=1.0f/double(fps);
double last_update_time=0;
double last_render_time=0;
double cur_time=0;
WorkObject *cur_work_object=nullptr;
public:
WorkManager(graph::RenderFramework *rf)
{
render_framework=rf;
}
virtual ~WorkManager()
{
SAFE_CLEAR(cur_work_object);
}
void SetFPS(uint f)
{
fps=f;
frame_time=1.0f/double(fps);
}
void Tick(WorkObject *wo);
virtual void Render(WorkObject *wo);
virtual void OnResize(uint w,uint h) override
{
if(!cur_work_object)return;
VkExtent2D ext={w,h};
cur_work_object->OnResize(ext);
}
void Run(WorkObject *wo);
};//class WorkManager
class SwapchainWorkManager:public WorkManager
{
graph::SwapchainModule *swpachain_module;
public:
SwapchainWorkManager(graph::RenderFramework *rf):WorkManager(rf)
{
swpachain_module=rf->GetSwapchainModule();
rf->GetWindow()->Join(this);
}
~SwapchainWorkManager()
{
render_framework->GetWindow()->Unjoin(this);
}
void Render(WorkObject *wo) override;
void OnResize(uint w,uint h) override;
};
template<typename WO> int RunFramework(const OSString &title,uint width=1280,uint height=720)
{
graph::RenderFramework rf(title);
if(!rf.Init(width,height))
return(-1);
SwapchainWorkManager wm(&rf);
wm.Run(new WO(&rf));
return 0;
}
}//namespcae hgl