diff --git a/src/xenia/debug/ui/application.cc b/src/xenia/debug/ui/application.cc new file mode 100644 index 000000000..838c8764a --- /dev/null +++ b/src/xenia/debug/ui/application.cc @@ -0,0 +1,66 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include "xenia/debug/ui/application.h" + +#include "xenia/base/logging.h" +#include "xenia/base/platform.h" +#include "xenia/base/threading.h" +#include "xenia/debug/ui/main_window.h" +#include "xenia/profiling.h" + +namespace xe { +namespace debug { +namespace ui { + +Application::Application() {} + +Application::~Application() = default; + +std::unique_ptr Application::Create() { + std::unique_ptr app(new Application()); + + xe::threading::Fence fence; + app->loop()->Post([&app, &fence]() { + xe::threading::set_name("Win32 Loop"); + xe::Profiler::ThreadEnter("Win32 Loop"); + + if (!app->Initialize()) { + XEFATAL("Failed to initialize application"); + exit(1); + } + + fence.Signal(); + }); + fence.Wait(); + + return app; +} + +bool Application::Initialize() { + main_window_ = std::make_unique(this); + if (!main_window_->Initialize()) { + XELOGE("Unable to initialize main window"); + return false; + } + + return true; +} + +void Application::Quit() { + loop_.Quit(); + + // TODO(benvanik): proper exit. + XELOGI("User-initiated death!"); + exit(1); +} + +} // namespace ui +} // namespace debug +} // namespace xe diff --git a/src/xenia/debug/ui/application.h b/src/xenia/debug/ui/application.h new file mode 100644 index 000000000..c3e54ddcd --- /dev/null +++ b/src/xenia/debug/ui/application.h @@ -0,0 +1,47 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_DEBUG_UI_APPLICATION_H_ +#define XENIA_DEBUG_UI_APPLICATION_H_ + +#include + +#include "xenia/ui/platform.h" + +namespace xe { +namespace debug { +namespace ui { + +class MainWindow; + +class Application { + public: + ~Application(); + + static std::unique_ptr Create(); + + xe::ui::Loop* loop() { return &loop_; } + MainWindow* main_window() const { return main_window_.get(); } + + void Quit(); + + private: + Application(); + + bool Initialize(); + + xe::ui::PlatformLoop loop_; + std::unique_ptr main_window_; +}; + +} // namespace ui +} // namespace debug +} // namespace xe + +#endif // XENIA_DEBUG_UI_APPLICATION_H_ diff --git a/src/xenia/debug/ui/main_window.cc b/src/xenia/debug/ui/main_window.cc index 4fc981294..fa932a43f 100644 --- a/src/xenia/debug/ui/main_window.cc +++ b/src/xenia/debug/ui/main_window.cc @@ -13,7 +13,6 @@ #include "xenia/base/logging.h" #include "xenia/base/platform.h" #include "xenia/base/threading.h" -#include "xenia/profiling.h" namespace xe { namespace debug { @@ -32,33 +31,13 @@ enum Commands { const std::wstring kBaseTitle = L"xenia debugger"; -MainWindow::MainWindow() - : PlatformWindow(&loop_, kBaseTitle), main_menu_(MenuItem::Type::kNormal) {} +MainWindow::MainWindow(Application* app) + : PlatformWindow(app->loop(), kBaseTitle), + app_(app), + main_menu_(MenuItem::Type::kNormal) {} MainWindow::~MainWindow() = default; -std::unique_ptr MainWindow::Create() { - std::unique_ptr main_window(new MainWindow()); - - xe::threading::Fence fence; - - main_window->loop()->Post([&main_window, &fence]() { - xe::threading::set_name("Win32 Loop"); - xe::Profiler::ThreadEnter("Win32 Loop"); - - if (!main_window->Initialize()) { - XEFATAL("Failed to initialize main window"); - exit(1); - } - - fence.Signal(); - }); - - fence.Wait(); - - return main_window; -} - bool MainWindow::Initialize() { if (!PlatformWindow::Initialize()) { return false; @@ -117,13 +96,7 @@ bool MainWindow::Initialize() { return true; } -void MainWindow::OnClose() { - loop_.Quit(); - - // TODO(benvanik): proper exit. - XELOGI("User-initiated death!"); - exit(1); -} +void MainWindow::OnClose() { app_->Quit(); } void MainWindow::OnCommand(int id) { switch (id) { diff --git a/src/xenia/debug/ui/main_window.h b/src/xenia/debug/ui/main_window.h index 9e5cdaa76..a7de99a25 100644 --- a/src/xenia/debug/ui/main_window.h +++ b/src/xenia/debug/ui/main_window.h @@ -12,6 +12,7 @@ #include +#include "xenia/debug/ui/application.h" #include "xenia/ui/gl/wgl_control.h" #include "xenia/ui/platform.h" #include "xenia/ui/window.h" @@ -22,19 +23,18 @@ namespace ui { class MainWindow : public xe::ui::PlatformWindow { public: + MainWindow(Application* app); ~MainWindow() override; - static std::unique_ptr Create(); - - private: - explicit MainWindow(); + Application* app() const { return app_; } bool Initialize(); + private: void OnClose() override; void OnCommand(int id) override; - xe::ui::PlatformLoop loop_; + Application* app_ = nullptr; xe::ui::PlatformMenu main_menu_; std::unique_ptr control_; }; diff --git a/src/xenia/debug/ui/xe-debug-ui.cc b/src/xenia/debug/ui/xe-debug-ui.cc index e021cbc7d..de4e24266 100644 --- a/src/xenia/debug/ui/xe-debug-ui.cc +++ b/src/xenia/debug/ui/xe-debug-ui.cc @@ -12,15 +12,15 @@ #include #include "xenia/base/main.h" -#include "xenia/debug/ui/main_window.h" +#include "xenia/debug/ui/application.h" namespace xe { namespace debug { namespace ui { int main(std::vector& args) { - auto main_window = MainWindow::Create(); - main_window->loop()->AwaitQuit(); + auto app = Application::Create(); + app->loop()->AwaitQuit(); return 0; } diff --git a/src/xenia/debug/ui/xe-debug-ui.vcxproj b/src/xenia/debug/ui/xe-debug-ui.vcxproj index cf409527c..ebac6c8f5 100644 --- a/src/xenia/debug/ui/xe-debug-ui.vcxproj +++ b/src/xenia/debug/ui/xe-debug-ui.vcxproj @@ -75,10 +75,12 @@ + + diff --git a/src/xenia/debug/ui/xe-debug-ui.vcxproj.filters b/src/xenia/debug/ui/xe-debug-ui.vcxproj.filters index affbf009b..b9a219804 100644 --- a/src/xenia/debug/ui/xe-debug-ui.vcxproj.filters +++ b/src/xenia/debug/ui/xe-debug-ui.vcxproj.filters @@ -24,6 +24,9 @@ src\xenia\debug\ui + + src\xenia\debug\ui + @@ -35,5 +38,8 @@ src\xenia\debug\ui + + src\xenia\debug\ui + \ No newline at end of file