C++17ification.
C++17ification! - Filesystem interaction now uses std::filesystem::path. - Usage of const char*, std::string have been changed to std::string_view where appropriate. - Usage of printf-style functions changed to use fmt.
This commit is contained in:
@@ -9,9 +9,7 @@
|
||||
|
||||
#include "xenia/app/emulator_window.h"
|
||||
|
||||
// Autogenerated by `xb premake`.
|
||||
#include "build/version.h"
|
||||
|
||||
#include "third_party/fmt/include/fmt/format.h"
|
||||
#include "third_party/imgui/imgui.h"
|
||||
#include "xenia/base/clock.h"
|
||||
#include "xenia/base/cvar.h"
|
||||
@@ -19,14 +17,17 @@
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/platform.h"
|
||||
#include "xenia/base/profiling.h"
|
||||
#include "xenia/base/system.h"
|
||||
#include "xenia/base/threading.h"
|
||||
#include "xenia/emulator.h"
|
||||
#include "xenia/gpu/graphics_system.h"
|
||||
|
||||
#include "xenia/ui/file_picker.h"
|
||||
#include "xenia/ui/imgui_dialog.h"
|
||||
#include "xenia/ui/imgui_drawer.h"
|
||||
|
||||
// Autogenerated by `xb premake`.
|
||||
#include "build/version.h"
|
||||
|
||||
DECLARE_bool(debug);
|
||||
|
||||
namespace xe {
|
||||
@@ -38,7 +39,7 @@ using xe::ui::MenuItem;
|
||||
using xe::ui::MouseEvent;
|
||||
using xe::ui::UIEvent;
|
||||
|
||||
const std::wstring kBaseTitle = L"xenia";
|
||||
const std::string kBaseTitle = "xenia";
|
||||
|
||||
EmulatorWindow::EmulatorWindow(Emulator* emulator)
|
||||
: emulator_(emulator),
|
||||
@@ -47,14 +48,13 @@ EmulatorWindow::EmulatorWindow(Emulator* emulator)
|
||||
base_title_ = kBaseTitle +
|
||||
#ifdef DEBUG
|
||||
#if _NO_DEBUG_HEAP == 1
|
||||
L" DEBUG" +
|
||||
" DEBUG"
|
||||
#else
|
||||
L" CHECKED" +
|
||||
" CHECKED"
|
||||
#endif
|
||||
#endif
|
||||
L" (" + xe::to_wstring(XE_BUILD_BRANCH) + L"/" +
|
||||
xe::to_wstring(XE_BUILD_COMMIT_SHORT) + L"/" +
|
||||
xe::to_wstring(XE_BUILD_DATE) + L")";
|
||||
" (" XE_BUILD_BRANCH "/" XE_BUILD_COMMIT_SHORT "/" XE_BUILD_DATE
|
||||
")";
|
||||
}
|
||||
|
||||
EmulatorWindow::~EmulatorWindow() {
|
||||
@@ -123,13 +123,13 @@ bool EmulatorWindow::Initialize() {
|
||||
// Save to file
|
||||
// TODO: Choose path based on user input, or from options
|
||||
// TODO: Spawn a new thread to do this.
|
||||
emulator()->SaveToFile(L"test.sav");
|
||||
emulator()->SaveToFile("test.sav");
|
||||
} break;
|
||||
case 0x77: { // VK_F8
|
||||
// Restore from file
|
||||
// TODO: Choose path from user
|
||||
// TODO: Spawn a new thread to do this.
|
||||
emulator()->RestoreFromFile(L"test.sav");
|
||||
emulator()->RestoreFromFile("test.sav");
|
||||
} break;
|
||||
case 0x7A: { // VK_F11
|
||||
ToggleFullscreen();
|
||||
@@ -182,105 +182,102 @@ bool EmulatorWindow::Initialize() {
|
||||
// Main menu.
|
||||
// FIXME: This code is really messy.
|
||||
auto main_menu = MenuItem::Create(MenuItem::Type::kNormal);
|
||||
auto file_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&File");
|
||||
auto file_menu = MenuItem::Create(MenuItem::Type::kPopup, "&File");
|
||||
{
|
||||
file_menu->AddChild(
|
||||
MenuItem::Create(MenuItem::Type::kString, L"&Open...", L"Ctrl+O",
|
||||
MenuItem::Create(MenuItem::Type::kString, "&Open...", "Ctrl+O",
|
||||
std::bind(&EmulatorWindow::FileOpen, this)));
|
||||
file_menu->AddChild(
|
||||
MenuItem::Create(MenuItem::Type::kString, L"Close",
|
||||
MenuItem::Create(MenuItem::Type::kString, "Close",
|
||||
std::bind(&EmulatorWindow::FileClose, this)));
|
||||
file_menu->AddChild(MenuItem::Create(MenuItem::Type::kSeparator));
|
||||
file_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"Show content directory...",
|
||||
MenuItem::Type::kString, "Show content directory...",
|
||||
std::bind(&EmulatorWindow::ShowContentDirectory, this)));
|
||||
file_menu->AddChild(MenuItem::Create(MenuItem::Type::kSeparator));
|
||||
file_menu->AddChild(MenuItem::Create(MenuItem::Type::kString, L"E&xit",
|
||||
L"Alt+F4",
|
||||
file_menu->AddChild(MenuItem::Create(MenuItem::Type::kString, "E&xit",
|
||||
"Alt+F4",
|
||||
[this]() { window_->Close(); }));
|
||||
}
|
||||
main_menu->AddChild(std::move(file_menu));
|
||||
|
||||
// CPU menu.
|
||||
auto cpu_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&CPU");
|
||||
auto cpu_menu = MenuItem::Create(MenuItem::Type::kPopup, "&CPU");
|
||||
{
|
||||
cpu_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"&Reset Time Scalar", L"Numpad *",
|
||||
MenuItem::Type::kString, "&Reset Time Scalar", "Numpad *",
|
||||
std::bind(&EmulatorWindow::CpuTimeScalarReset, this)));
|
||||
cpu_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"Time Scalar /= 2", L"Numpad -",
|
||||
MenuItem::Type::kString, "Time Scalar /= 2", "Numpad -",
|
||||
std::bind(&EmulatorWindow::CpuTimeScalarSetHalf, this)));
|
||||
cpu_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"Time Scalar *= 2", L"Numpad +",
|
||||
MenuItem::Type::kString, "Time Scalar *= 2", "Numpad +",
|
||||
std::bind(&EmulatorWindow::CpuTimeScalarSetDouble, this)));
|
||||
}
|
||||
cpu_menu->AddChild(MenuItem::Create(MenuItem::Type::kSeparator));
|
||||
{
|
||||
cpu_menu->AddChild(MenuItem::Create(MenuItem::Type::kString,
|
||||
L"Toggle Profiler &Display", L"F3",
|
||||
"Toggle Profiler &Display", "F3",
|
||||
[]() { Profiler::ToggleDisplay(); }));
|
||||
cpu_menu->AddChild(MenuItem::Create(MenuItem::Type::kString,
|
||||
L"&Pause/Resume Profiler", L"`",
|
||||
"&Pause/Resume Profiler", "`",
|
||||
[]() { Profiler::TogglePause(); }));
|
||||
}
|
||||
cpu_menu->AddChild(MenuItem::Create(MenuItem::Type::kSeparator));
|
||||
{
|
||||
cpu_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"&Break and Show Guest Debugger",
|
||||
L"Pause/Break",
|
||||
std::bind(&EmulatorWindow::CpuBreakIntoDebugger, this)));
|
||||
MenuItem::Type::kString, "&Break and Show Guest Debugger",
|
||||
"Pause/Break", std::bind(&EmulatorWindow::CpuBreakIntoDebugger, this)));
|
||||
cpu_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"&Break into Host Debugger",
|
||||
L"Ctrl+Pause/Break",
|
||||
MenuItem::Type::kString, "&Break into Host Debugger",
|
||||
"Ctrl+Pause/Break",
|
||||
std::bind(&EmulatorWindow::CpuBreakIntoHostDebugger, this)));
|
||||
}
|
||||
main_menu->AddChild(std::move(cpu_menu));
|
||||
|
||||
// GPU menu.
|
||||
auto gpu_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&GPU");
|
||||
auto gpu_menu = MenuItem::Create(MenuItem::Type::kPopup, "&GPU");
|
||||
{
|
||||
gpu_menu->AddChild(
|
||||
MenuItem::Create(MenuItem::Type::kString, L"&Trace Frame", L"F4",
|
||||
MenuItem::Create(MenuItem::Type::kString, "&Trace Frame", "F4",
|
||||
std::bind(&EmulatorWindow::GpuTraceFrame, this)));
|
||||
}
|
||||
gpu_menu->AddChild(MenuItem::Create(MenuItem::Type::kSeparator));
|
||||
{
|
||||
gpu_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"&Clear Runtime Caches", L"F5",
|
||||
std::bind(&EmulatorWindow::GpuClearCaches, this)));
|
||||
gpu_menu->AddChild(
|
||||
MenuItem::Create(MenuItem::Type::kString, "&Clear Runtime Caches", "F5",
|
||||
std::bind(&EmulatorWindow::GpuClearCaches, this)));
|
||||
}
|
||||
main_menu->AddChild(std::move(gpu_menu));
|
||||
|
||||
// Window menu.
|
||||
auto window_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&Window");
|
||||
auto window_menu = MenuItem::Create(MenuItem::Type::kPopup, "&Window");
|
||||
{
|
||||
window_menu->AddChild(
|
||||
MenuItem::Create(MenuItem::Type::kString, L"&Fullscreen", L"F11",
|
||||
MenuItem::Create(MenuItem::Type::kString, "&Fullscreen", "F11",
|
||||
std::bind(&EmulatorWindow::ToggleFullscreen, this)));
|
||||
}
|
||||
main_menu->AddChild(std::move(window_menu));
|
||||
|
||||
// Help menu.
|
||||
auto help_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&Help");
|
||||
auto help_menu = MenuItem::Create(MenuItem::Type::kPopup, "&Help");
|
||||
{
|
||||
help_menu->AddChild(
|
||||
MenuItem::Create(MenuItem::Type::kString, "Build commit on GitHub...",
|
||||
"F2", std::bind(&EmulatorWindow::ShowCommitID, this)));
|
||||
help_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"Build commit on GitHub...", L"F2",
|
||||
std::bind(&EmulatorWindow::ShowCommitID, this)));
|
||||
help_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"Recent changes on GitHub...", [this]() {
|
||||
std::wstring url =
|
||||
std::wstring(L"https://github.com/xenia-project/xenia/compare/") +
|
||||
xe::to_wstring(XE_BUILD_COMMIT) + L"..." +
|
||||
xe::to_wstring(XE_BUILD_BRANCH);
|
||||
LaunchBrowser(url.c_str());
|
||||
MenuItem::Type::kString, "Recent changes on GitHub...", [this]() {
|
||||
LaunchWebBrowser(
|
||||
"https://github.com/xenia-project/xenia/compare/" XE_BUILD_COMMIT
|
||||
"..." XE_BUILD_BRANCH);
|
||||
}));
|
||||
help_menu->AddChild(MenuItem::Create(MenuItem::Type::kSeparator));
|
||||
help_menu->AddChild(
|
||||
MenuItem::Create(MenuItem::Type::kString, L"&Website...", L"F1",
|
||||
MenuItem::Create(MenuItem::Type::kString, "&Website...", "F1",
|
||||
std::bind(&EmulatorWindow::ShowHelpWebsite, this)));
|
||||
help_menu->AddChild(MenuItem::Create(
|
||||
MenuItem::Type::kString, L"&About...",
|
||||
[this]() { LaunchBrowser(L"https://xenia.jp/about/"); }));
|
||||
MenuItem::Type::kString, "&About...",
|
||||
[this]() { LaunchWebBrowser("https://xenia.jp/about/"); }));
|
||||
}
|
||||
main_menu->AddChild(std::move(help_menu));
|
||||
|
||||
@@ -293,7 +290,7 @@ bool EmulatorWindow::Initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void EmulatorWindow::FileDrop(const wchar_t* filename) {
|
||||
void EmulatorWindow::FileDrop(const std::filesystem::path& filename) {
|
||||
auto result = emulator_->LaunchPath(filename);
|
||||
if (XFAILED(result)) {
|
||||
// TODO: Display a message box.
|
||||
@@ -302,19 +299,19 @@ void EmulatorWindow::FileDrop(const wchar_t* filename) {
|
||||
}
|
||||
|
||||
void EmulatorWindow::FileOpen() {
|
||||
std::wstring path;
|
||||
std::filesystem::path path;
|
||||
|
||||
auto file_picker = xe::ui::FilePicker::Create();
|
||||
file_picker->set_mode(ui::FilePicker::Mode::kOpen);
|
||||
file_picker->set_type(ui::FilePicker::Type::kFile);
|
||||
file_picker->set_multi_selection(false);
|
||||
file_picker->set_title(L"Select Content Package");
|
||||
file_picker->set_title("Select Content Package");
|
||||
file_picker->set_extensions({
|
||||
{L"Supported Files", L"*.iso;*.xex;*.xcp;*.*"},
|
||||
{L"Disc Image (*.iso)", L"*.iso"},
|
||||
{L"Xbox Executable (*.xex)", L"*.xex"},
|
||||
//{ L"Content Package (*.xcp)", L"*.xcp" },
|
||||
{L"All Files (*.*)", L"*.*"},
|
||||
{"Supported Files", "*.iso;*.xex;*.xcp;*.*"},
|
||||
{"Disc Image (*.iso)", "*.iso"},
|
||||
{"Xbox Executable (*.xex)", "*.xex"},
|
||||
//{"Content Package (*.xcp)", "*.xcp" },
|
||||
{"All Files (*.*)", "*.*"},
|
||||
});
|
||||
if (file_picker->Show(window_->native_handle())) {
|
||||
auto selected_files = file_picker->selected_files();
|
||||
@@ -325,8 +322,7 @@ void EmulatorWindow::FileOpen() {
|
||||
|
||||
if (!path.empty()) {
|
||||
// Normalize the path and make absolute.
|
||||
std::wstring abs_path = xe::to_absolute_path(path);
|
||||
|
||||
auto abs_path = std::filesystem::absolute(path);
|
||||
auto result = emulator_->LaunchPath(abs_path);
|
||||
if (XFAILED(result)) {
|
||||
// TODO: Display a message box.
|
||||
@@ -342,16 +338,16 @@ void EmulatorWindow::FileClose() {
|
||||
}
|
||||
|
||||
void EmulatorWindow::ShowContentDirectory() {
|
||||
std::wstring target_path;
|
||||
std::filesystem::path target_path;
|
||||
|
||||
auto content_root = emulator_->content_root();
|
||||
if (!emulator_->is_title_open() || !emulator_->kernel_state()) {
|
||||
target_path = content_root;
|
||||
} else {
|
||||
// TODO(gibbed): expose this via ContentManager?
|
||||
wchar_t title_id[9] = L"00000000";
|
||||
std::swprintf(title_id, 9, L"%.8X", emulator_->kernel_state()->title_id());
|
||||
auto package_root = xe::join_paths(content_root, title_id);
|
||||
auto title_id =
|
||||
fmt::format("{:08X}", emulator_->kernel_state()->title_id());
|
||||
auto package_root = content_root / title_id;
|
||||
target_path = package_root;
|
||||
}
|
||||
|
||||
@@ -359,7 +355,7 @@ void EmulatorWindow::ShowContentDirectory() {
|
||||
xe::filesystem::CreateFolder(target_path);
|
||||
}
|
||||
|
||||
LaunchBrowser(target_path.c_str());
|
||||
LaunchFileExplorer(target_path);
|
||||
}
|
||||
|
||||
void EmulatorWindow::CheckHideCursor() {
|
||||
@@ -426,36 +422,36 @@ void EmulatorWindow::ToggleFullscreen() {
|
||||
}
|
||||
}
|
||||
|
||||
void EmulatorWindow::ShowHelpWebsite() { LaunchBrowser(L"https://xenia.jp"); }
|
||||
void EmulatorWindow::ShowHelpWebsite() { LaunchWebBrowser("https://xenia.jp"); }
|
||||
|
||||
void EmulatorWindow::ShowCommitID() {
|
||||
std::wstring url =
|
||||
std::wstring(L"https://github.com/xenia-project/xenia/commit/") +
|
||||
xe::to_wstring(XE_BUILD_COMMIT) + L"/";
|
||||
LaunchBrowser(url.c_str());
|
||||
LaunchWebBrowser(
|
||||
"https://github.com/xenia-project/xenia/commit/" XE_BUILD_COMMIT "/");
|
||||
}
|
||||
|
||||
void EmulatorWindow::UpdateTitle() {
|
||||
std::wstring title(base_title_);
|
||||
std::string title(base_title_);
|
||||
|
||||
if (emulator()->is_title_open()) {
|
||||
auto game_title = emulator()->game_title();
|
||||
title += xe::format_string(L" | [%.8X] %s", emulator()->title_id(),
|
||||
game_title.c_str());
|
||||
title += fmt::format(" | [{:08X}] {}", emulator()->title_id(), game_title);
|
||||
}
|
||||
|
||||
auto graphics_system = emulator()->graphics_system();
|
||||
if (graphics_system) {
|
||||
auto graphics_name = graphics_system->name();
|
||||
title += L" <" + graphics_name + L">";
|
||||
title += fmt::format(" <{}>", graphics_name);
|
||||
}
|
||||
|
||||
if (Clock::guest_time_scalar() != 1.0) {
|
||||
title += xe::format_string(L" (@%.2fx)", Clock::guest_time_scalar());
|
||||
title += fmt::format(" (@{:.2f}x)", Clock::guest_time_scalar());
|
||||
}
|
||||
|
||||
if (initializing_shader_storage_) {
|
||||
title += L" (Preloading shaders\u2026)";
|
||||
title +=
|
||||
" (Preloading shaders"
|
||||
u8"\u2026"
|
||||
")";
|
||||
}
|
||||
|
||||
window_->set_title(title);
|
||||
|
||||
Reference in New Issue
Block a user