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:
@@ -2,7 +2,7 @@
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2015 Ben Vanik. All rights reserved. *
|
||||
* Copyright 2020 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -26,9 +26,8 @@
|
||||
#undef _CRT_NONSTDC_NO_DEPRECATE
|
||||
#include "third_party/stb/stb_image_write.h"
|
||||
|
||||
DEFINE_string(target_trace_file, "", "Specifies the trace file to load.",
|
||||
"GPU");
|
||||
DEFINE_string(trace_dump_path, "", "Output path for dumped files.", "GPU");
|
||||
DEFINE_path(target_trace_file, "", "Specifies the trace file to load.", "GPU");
|
||||
DEFINE_path(trace_dump_path, "", "Output path for dumped files.", "GPU");
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
@@ -39,21 +38,21 @@ TraceDump::TraceDump() = default;
|
||||
|
||||
TraceDump::~TraceDump() = default;
|
||||
|
||||
int TraceDump::Main(const std::vector<std::wstring>& args) {
|
||||
int TraceDump::Main(const std::vector<std::string>& args) {
|
||||
// Grab path from the flag or unnamed argument.
|
||||
std::wstring path;
|
||||
std::wstring output_path;
|
||||
std::filesystem::path path;
|
||||
std::filesystem::path output_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 (args.size() >= 3) {
|
||||
output_path = args[2];
|
||||
output_path = xe::to_path(args[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +62,8 @@ int TraceDump::Main(const std::vector<std::wstring>& args) {
|
||||
}
|
||||
|
||||
// Normalize the path and make absolute.
|
||||
auto abs_path = xe::to_absolute_path(path);
|
||||
XELOGI("Loading trace file %ls...", abs_path.c_str());
|
||||
auto abs_path = std::filesystem::absolute(path);
|
||||
XELOGI("Loading trace file %s...", xe::path_to_utf8(abs_path).c_str());
|
||||
|
||||
if (!Setup()) {
|
||||
XELOGE("Unable to setup trace dump tool");
|
||||
@@ -77,21 +76,12 @@ int TraceDump::Main(const std::vector<std::wstring>& args) {
|
||||
|
||||
// Root file name for outputs.
|
||||
if (output_path.empty()) {
|
||||
base_output_path_ =
|
||||
xe::fix_path_separators(xe::to_wstring(cvars::trace_dump_path));
|
||||
base_output_path_ = cvars::trace_dump_path;
|
||||
auto output_name = path.filename().replace_extension();
|
||||
|
||||
std::wstring output_name =
|
||||
xe::find_name_from_path(xe::fix_path_separators(path));
|
||||
|
||||
// Strip the extension from the filename.
|
||||
auto last_dot = output_name.find_last_of(L".");
|
||||
if (last_dot != std::string::npos) {
|
||||
output_name = output_name.substr(0, last_dot);
|
||||
}
|
||||
|
||||
base_output_path_ = xe::join_paths(base_output_path_, output_name);
|
||||
base_output_path_ = base_output_path_ / output_name;
|
||||
} else {
|
||||
base_output_path_ = xe::fix_path_separators(output_path);
|
||||
base_output_path_ = output_path;
|
||||
}
|
||||
|
||||
// Ensure output path exists.
|
||||
@@ -102,7 +92,7 @@ int TraceDump::Main(const std::vector<std::wstring>& args) {
|
||||
|
||||
bool TraceDump::Setup() {
|
||||
// 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(
|
||||
nullptr, nullptr, [this]() { return CreateGraphicsSystem(); }, nullptr);
|
||||
if (XFAILED(result)) {
|
||||
@@ -114,8 +104,8 @@ bool TraceDump::Setup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TraceDump::Load(std::wstring trace_file_path) {
|
||||
trace_file_path_ = std::move(trace_file_path);
|
||||
bool TraceDump::Load(const std::filesystem::path& trace_file_path) {
|
||||
trace_file_path_ = trace_file_path;
|
||||
|
||||
if (!player_->Open(trace_file_path_)) {
|
||||
XELOGE("Could not load trace file");
|
||||
@@ -138,10 +128,16 @@ int TraceDump::Run() {
|
||||
auto raw_image = graphics_system_->Capture();
|
||||
if (raw_image) {
|
||||
// Save framebuffer png.
|
||||
std::string png_path = xe::to_string(base_output_path_ + L".png");
|
||||
stbi_write_png(png_path.c_str(), static_cast<int>(raw_image->width),
|
||||
static_cast<int>(raw_image->height), 4,
|
||||
raw_image->data.data(), static_cast<int>(raw_image->stride));
|
||||
auto png_path = base_output_path_.replace_extension(".png");
|
||||
auto handle = filesystem::OpenFile(png_path, "wb");
|
||||
auto callback = [](void* context, void* data, int size) {
|
||||
fwrite(data, 1, size, (FILE*)context);
|
||||
};
|
||||
stbi_write_png_to_func(callback, handle, static_cast<int>(raw_image->width),
|
||||
static_cast<int>(raw_image->height), 4,
|
||||
raw_image->data.data(),
|
||||
static_cast<int>(raw_image->stride));
|
||||
fclose(handle);
|
||||
} else {
|
||||
result = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user