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