add Module::BeforeRender & Module::AfterRender
This commit is contained in:
parent
1c8c92862a
commit
0b9aaf799d
|
|
@ -88,10 +88,8 @@ void ImGuiModule::OnUpdate(UpdateModuleContext& ctx)
|
|||
ctx.Next();
|
||||
}
|
||||
|
||||
void ImGuiModule::OnRender(RenderModuleContext& ctx)
|
||||
void ImGuiModule::BeforeRender(RenderModuleContext& ctx)
|
||||
{
|
||||
// Before render
|
||||
{
|
||||
ImGui_Impl_NewFrame();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
|
@ -102,16 +100,13 @@ void ImGuiModule::OnRender(RenderModuleContext& ctx)
|
|||
io.DisplaySize = ImVec2(display_size.x, display_size.y);
|
||||
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Next();
|
||||
|
||||
// After render
|
||||
{
|
||||
void ImGuiModule::AfterRender(RenderModuleContext& ctx)
|
||||
{
|
||||
ImGui::Render();
|
||||
|
||||
ImGui_Impl_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
}
|
||||
|
||||
void ImGuiModule::HandleEvent(EventModuleContext& ctx)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ public:
|
|||
|
||||
void OnUpdate(UpdateModuleContext& ctx) override;
|
||||
|
||||
void OnRender(RenderModuleContext& ctx) override;
|
||||
void BeforeRender(RenderModuleContext& ctx) override;
|
||||
|
||||
void AfterRender(RenderModuleContext& ctx) override;
|
||||
|
||||
void HandleEvent(EventModuleContext& ctx) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ ModuleContext::ModuleContext(ModuleList& modules)
|
|||
|
||||
ModuleContext::~ModuleContext() {}
|
||||
|
||||
void ModuleContext::ResetIndex()
|
||||
{
|
||||
index_ = -1;
|
||||
}
|
||||
|
||||
void ModuleContext::Next()
|
||||
{
|
||||
index_++;
|
||||
|
|
@ -43,19 +48,41 @@ void ModuleContext::Next()
|
|||
|
||||
RenderModuleContext::RenderModuleContext(ModuleList& modules, RenderContext& ctx)
|
||||
: ModuleContext(modules)
|
||||
, step_(Step::Before)
|
||||
, render_ctx(ctx)
|
||||
{
|
||||
this->Next();
|
||||
this->ResetIndex();
|
||||
|
||||
render_ctx.BeginDraw();
|
||||
step_ = Step::Rendering;
|
||||
}
|
||||
|
||||
RenderModuleContext::~RenderModuleContext()
|
||||
{
|
||||
render_ctx.EndDraw();
|
||||
step_ = Step::After;
|
||||
|
||||
this->ResetIndex();
|
||||
this->Next();
|
||||
}
|
||||
|
||||
void RenderModuleContext::Handle(Module* m)
|
||||
{
|
||||
switch (step_)
|
||||
{
|
||||
case RenderModuleContext::Step::Before:
|
||||
m->BeforeRender(*this);
|
||||
break;
|
||||
case RenderModuleContext::Step::Rendering:
|
||||
m->OnRender(*this);
|
||||
break;
|
||||
case RenderModuleContext::Step::After:
|
||||
m->AfterRender(*this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateModuleContext::UpdateModuleContext(ModuleList& modules, Duration dt)
|
||||
|
|
@ -88,17 +115,22 @@ void Module::DestroyModule() {}
|
|||
|
||||
void Module::OnRender(RenderModuleContext& ctx)
|
||||
{
|
||||
ctx.Next();
|
||||
}
|
||||
|
||||
void Module::OnUpdate(UpdateModuleContext& ctx)
|
||||
{
|
||||
ctx.Next();
|
||||
}
|
||||
|
||||
void Module::HandleEvent(EventModuleContext& ctx)
|
||||
{
|
||||
ctx.Next();
|
||||
}
|
||||
|
||||
void Module::BeforeRender(RenderModuleContext& ctx)
|
||||
{
|
||||
}
|
||||
|
||||
void Module::AfterRender(RenderModuleContext& ctx)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ protected:
|
|||
|
||||
virtual void Handle(Module* m) = 0;
|
||||
|
||||
void ResetIndex();
|
||||
|
||||
private:
|
||||
int index_;
|
||||
ModuleList& modules_;
|
||||
|
|
@ -63,6 +65,16 @@ public:
|
|||
|
||||
protected:
|
||||
void Handle(Module* m) override;
|
||||
|
||||
private:
|
||||
enum class Step
|
||||
{
|
||||
Before,
|
||||
Rendering,
|
||||
After,
|
||||
};
|
||||
|
||||
Step step_;
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
|
|
@ -106,11 +118,6 @@ public:
|
|||
/// @brief 销毁模块
|
||||
virtual void DestroyModule();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染时
|
||||
/// @param ctx 渲染上下文
|
||||
virtual void OnRender(RenderModuleContext& ctx);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新时
|
||||
/// @param ctx 更新上下文
|
||||
|
|
@ -121,6 +128,21 @@ public:
|
|||
/// @param ctx 事件上下文
|
||||
virtual void HandleEvent(EventModuleContext& ctx);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染前
|
||||
/// @param ctx 渲染上下文
|
||||
virtual void BeforeRender(RenderModuleContext& ctx);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染时
|
||||
/// @param ctx 渲染上下文
|
||||
virtual void OnRender(RenderModuleContext& ctx);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染后
|
||||
/// @param ctx 渲染上下文
|
||||
virtual void AfterRender(RenderModuleContext& ctx);
|
||||
|
||||
protected:
|
||||
Module();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace
|
|||
bool tracing_leaks = false;
|
||||
Vector<ObjectBase*> tracing_objects;
|
||||
std::atomic<uint64_t> last_object_id = 0;
|
||||
ObjectPolicyFunc object_policy_ = ObjectPolicy::Exception();
|
||||
ObjectPolicyFunc object_policy_ = ObjectPolicy::ErrorLog();
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
|
|||
|
|
@ -115,13 +115,13 @@ struct ObjectPolicy
|
|||
static ObjectPolicyFunc WarnLog(int threshold = ObjectStatus::fail);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 在对象状态变为失败时打印错误日志
|
||||
/// @brief 在对象状态变为失败时打印错误日志(默认策略)
|
||||
/// @param threshold 触发阈值
|
||||
/// @return 对象处理策略方法
|
||||
static ObjectPolicyFunc ErrorLog(int threshold = ObjectStatus::fail);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 在对象状态变为失败时抛出 ObjectFailException(默认策略)
|
||||
/// @brief 在对象状态变为失败时抛出 ObjectFailException
|
||||
/// @param threshold 触发阈值
|
||||
/// @return 对象处理策略方法
|
||||
static ObjectPolicyFunc Exception(int threshold = ObjectStatus::fail);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/render/DirectX/D2DDeviceResources.h>
|
||||
#include <kiwano/utils/Logger.h>
|
||||
|
||||
#pragma comment(lib, "d2d1.lib")
|
||||
#pragma comment(lib, "dwrite.lib")
|
||||
|
|
|
|||
Loading…
Reference in New Issue