App skeleton.

This commit is contained in:
Ben Vanik 2015-07-01 08:24:44 -07:00
parent 1bae2ef10b
commit 88d01e8375
7 changed files with 134 additions and 40 deletions

View File

@ -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> Application::Create() {
std::unique_ptr<Application> 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<MainWindow>(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

View File

@ -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 <memory>
#include "xenia/ui/platform.h"
namespace xe {
namespace debug {
namespace ui {
class MainWindow;
class Application {
public:
~Application();
static std::unique_ptr<Application> 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<MainWindow> main_window_;
};
} // namespace ui
} // namespace debug
} // namespace xe
#endif // XENIA_DEBUG_UI_APPLICATION_H_

View File

@ -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> MainWindow::Create() {
std::unique_ptr<MainWindow> 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) {

View File

@ -12,6 +12,7 @@
#include <memory>
#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<MainWindow> 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<xe::ui::gl::WGLControl> control_;
};

View File

@ -12,15 +12,15 @@
#include <cstring>
#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<std::wstring>& args) {
auto main_window = MainWindow::Create();
main_window->loop()->AwaitQuit();
auto app = Application::Create();
app->loop()->AwaitQuit();
return 0;
}

View File

@ -75,10 +75,12 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\base\main.h" />
<ClInclude Include="application.h" />
<ClInclude Include="main_window.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\base\main_win.cc" />
<ClCompile Include="application.cc" />
<ClCompile Include="main_window.cc" />
<ClCompile Include="xe-debug-ui.cc" />
</ItemGroup>

View File

@ -24,6 +24,9 @@
<ClInclude Include="main_window.h">
<Filter>src\xenia\debug\ui</Filter>
</ClInclude>
<ClInclude Include="application.h">
<Filter>src\xenia\debug\ui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\base\main_win.cc">
@ -35,5 +38,8 @@
<ClCompile Include="main_window.cc">
<Filter>src\xenia\debug\ui</Filter>
</ClCompile>
<ClCompile Include="application.cc">
<Filter>src\xenia\debug\ui</Filter>
</ClCompile>
</ItemGroup>
</Project>