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:
gibbed
2020-03-02 09:37:11 -06:00
committed by Rick Gibbed
parent 114cea6fb7
commit 5bf0b34445
220 changed files with 4944 additions and 4294 deletions

View File

@@ -31,8 +31,7 @@
#include "xenia/ui/window.h"
#include "xenia/xbox.h"
DEFINE_string(target_trace_file, "", "Specifies the trace file to load.",
"GPU");
DEFINE_path(target_trace_file, "", "Specifies the trace file to load.", "GPU");
namespace xe {
namespace gpu {
@@ -50,17 +49,17 @@ TraceViewer::TraceViewer() = default;
TraceViewer::~TraceViewer() = default;
int TraceViewer::Main(const std::vector<std::wstring>& args) {
int TraceViewer::Main(const std::vector<std::string>& args) {
// Grab path from the flag or unnamed argument.
std::wstring path;
std::filesystem::path path;
if (!cvars::target_trace_file.empty()) {
// Passed as a named argument.
// TODO(benvanik): find something better than gflags that supports
// unicode.
path = xe::to_wstring(cvars::target_trace_file);
path = cvars::target_trace_file;
} else if (args.size() >= 2) {
// Passed as an unnamed argument.
path = args[1];
path = xe::to_path(args[1]);
}
// If no path passed, ask the user.
@@ -69,10 +68,10 @@ int TraceViewer::Main(const std::vector<std::wstring>& args) {
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 Trace File");
file_picker->set_title("Select Trace File");
file_picker->set_extensions({
{L"Supported Files", L"*.xtr"},
{L"All Files (*.*)", L"*.*"},
{"Supported Files", "*.xtr"},
{"All Files (*.*)", "*.*"},
});
if (file_picker->Show()) {
auto selected_files = file_picker->selected_files();
@@ -88,7 +87,7 @@ int TraceViewer::Main(const std::vector<std::wstring>& args) {
}
// Normalize the path and make absolute.
auto abs_path = xe::to_absolute_path(path);
auto abs_path = std::filesystem::absolute(path);
if (!Setup()) {
xe::FatalError("Unable to setup trace viewer");
@@ -105,7 +104,7 @@ int TraceViewer::Main(const std::vector<std::wstring>& args) {
bool TraceViewer::Setup() {
// Main display window.
loop_ = ui::Loop::Create();
window_ = xe::ui::Window::Create(loop_.get(), L"xenia-gpu-trace-viewer");
window_ = xe::ui::Window::Create(loop_.get(), "xenia-gpu-trace-viewer");
loop_->PostSynchronous([&]() {
xe::threading::set_name("Win32 Loop");
if (!window_->Initialize()) {
@@ -122,7 +121,7 @@ bool TraceViewer::Setup() {
window_->Resize(1920, 1200);
// Create the emulator but don't initialize so we can setup the window.
emulator_ = std::make_unique<Emulator>(L"", L"", L"");
emulator_ = std::make_unique<Emulator>("", "", "");
X_STATUS result = emulator_->Setup(
window_.get(), nullptr, [this]() { return CreateGraphicsSystem(); },
nullptr);
@@ -155,9 +154,9 @@ bool TraceViewer::Setup() {
return true;
}
bool TraceViewer::Load(std::wstring trace_file_path) {
auto file_name = xe::find_name_from_path(trace_file_path);
window_->set_title(std::wstring(L"Xenia GPU Trace Viewer: ") + file_name);
bool TraceViewer::Load(const std::filesystem::path& trace_file_path) {
auto file_name = trace_file_path.filename();
window_->set_title("Xenia GPU Trace Viewer: " + xe::path_to_utf8(file_name));
if (!player_->Open(trace_file_path)) {
XELOGE("Could not load trace file");
@@ -177,7 +176,7 @@ void TraceViewer::Run() {
loop_.reset();
}
void TraceViewer::DrawMultilineString(const std::string& str) {
void TraceViewer::DrawMultilineString(const std::string_view str) {
size_t i = 0;
bool done = false;
while (!done && i < str.size()) {
@@ -187,7 +186,7 @@ void TraceViewer::DrawMultilineString(const std::string& str) {
next_i = str.size() - 1;
}
auto line = str.substr(i, next_i - i);
ImGui::Text("%s", line.c_str());
ImGui::Text("%s", std::string(line).c_str());
i = next_i + 1;
}
}