[deploy] update Runner
This commit is contained in:
parent
a6961c0d20
commit
a1ed803bc1
|
|
@ -63,17 +63,22 @@ void Application::Run(RunnerPtr runner, bool debug)
|
|||
}
|
||||
|
||||
// Everything is ready
|
||||
runner->Ready();
|
||||
runner->OnReady();
|
||||
|
||||
quiting_ = false;
|
||||
quiting_ = false;
|
||||
last_update_time_ = Time::Now();
|
||||
while (!quiting_)
|
||||
{
|
||||
if (!runner->MainLoop())
|
||||
const Time now = Time::Now();
|
||||
const Duration dt = (now - last_update_time_);
|
||||
last_update_time_ = now;
|
||||
|
||||
if (!runner->MainLoop(dt))
|
||||
quiting_ = true;
|
||||
}
|
||||
|
||||
// Destroy all resources
|
||||
runner->Destroy();
|
||||
runner->OnDestroy();
|
||||
this->Destroy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,10 +136,17 @@ public:
|
|||
*/
|
||||
void Destroy();
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 获取上一次更新时间
|
||||
*/
|
||||
Time GetLastUpdateTime() const;
|
||||
|
||||
private:
|
||||
bool quiting_;
|
||||
float time_scale_;
|
||||
RunnerPtr runner_;
|
||||
Time last_update_time_;
|
||||
List<Module*> modules_;
|
||||
std::mutex perform_mutex_;
|
||||
Queue<Function<void()>> functions_to_perform_;
|
||||
|
|
@ -156,4 +163,9 @@ inline WindowPtr Application::GetMainWindow() const
|
|||
return runner_->GetMainWindow();
|
||||
}
|
||||
|
||||
inline Time Application::GetLastUpdateTime() const
|
||||
{
|
||||
return last_update_time_;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ Runner::Runner() {}
|
|||
|
||||
Runner::~Runner() {}
|
||||
|
||||
bool Runner::MainLoop()
|
||||
bool Runner::MainLoop(Duration dt)
|
||||
{
|
||||
if (main_window_->ShouldClose())
|
||||
{
|
||||
|
|
@ -88,30 +88,9 @@ bool Runner::MainLoop()
|
|||
}
|
||||
|
||||
// Update & render
|
||||
const Time now = Time::Now();
|
||||
const Duration dt = (now - last_update_time_);
|
||||
last_update_time_ = now;
|
||||
|
||||
app.Update(dt);
|
||||
app.Render();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Runner::Ready()
|
||||
{
|
||||
OnReady();
|
||||
last_update_time_ = Time::Now();
|
||||
}
|
||||
|
||||
void Runner::Destroy()
|
||||
{
|
||||
OnDestroy();
|
||||
|
||||
if (main_window_)
|
||||
{
|
||||
main_window_->Destroy();
|
||||
main_window_.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -73,9 +73,10 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 应用程序主循环
|
||||
/// @details 重载该函数以
|
||||
/// @param dt 时间间隔
|
||||
/// @details 重载该函数以控制程序主循环
|
||||
/// @return 返回false退出主循环,否则继续运行主循环
|
||||
virtual bool MainLoop();
|
||||
virtual bool MainLoop(Duration dt);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取主窗口
|
||||
|
|
@ -85,18 +86,8 @@ public:
|
|||
/// @brief 设置主窗口
|
||||
void SetMainWindow(WindowPtr window);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取上一次更新时间
|
||||
Time GetLastUpdateTime() const;
|
||||
|
||||
private:
|
||||
void Ready();
|
||||
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
WindowPtr main_window_;
|
||||
Time last_update_time_;
|
||||
};
|
||||
|
||||
inline void Runner::OnReady() {}
|
||||
|
|
@ -118,9 +109,4 @@ inline void Runner::SetMainWindow(WindowPtr window)
|
|||
main_window_ = window;
|
||||
}
|
||||
|
||||
inline Time Runner::GetLastUpdateTime() const
|
||||
{
|
||||
return last_update_time_;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -205,7 +205,10 @@ WindowWin32Impl::WindowWin32Impl()
|
|||
key_map_[VK_F1 + i] = KeyCode(size_t(KeyCode::F1) + i);
|
||||
}
|
||||
|
||||
WindowWin32Impl::~WindowWin32Impl() {}
|
||||
WindowWin32Impl::~WindowWin32Impl()
|
||||
{
|
||||
this->Destroy();
|
||||
}
|
||||
|
||||
void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable,
|
||||
bool fullscreen)
|
||||
|
|
|
|||
Loading…
Reference in New Issue