Replace all gflag implementations with cvar implementations

This commit is contained in:
Jonathan Goyvaerts
2019-04-17 21:49:29 +02:00
parent a01908aa15
commit c1af632562
74 changed files with 345 additions and 375 deletions

View File

@@ -9,8 +9,6 @@
#include "xenia/base/logging.h"
#include <gflags/gflags.h>
#include <atomic>
#include <cinttypes>
#include <cstdarg>
@@ -19,6 +17,7 @@
#include <vector>
#include "xenia/base/atomic.h"
#include "xenia/base/cvar.h"
#include "xenia/base/debugging.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/main.h"
@@ -26,6 +25,7 @@
#include "xenia/base/memory.h"
#include "xenia/base/ring_buffer.h"
#include "xenia/base/threading.h"
//#include "xenia/base/cvar.h"
// For MessageBox:
// TODO(benvanik): generic API? logging_win.cc?
@@ -35,12 +35,15 @@
DEFINE_string(
log_file, "",
"Logs are written to the given file (specify stdout for command line)");
DEFINE_bool(log_debugprint, false, "Dump the log to DebugPrint.");
DEFINE_bool(flush_log, true, "Flush log file after each log line batch.");
"Logs are written to the given file (specify stdout for command line)",
"Logging");
DEFINE_bool(log_debugprint, false, "Dump the log to DebugPrint.", "Logging");
DEFINE_bool(flush_log, true, "Flush log file after each log line batch.",
"Logging");
DEFINE_int32(
log_level, 2,
"Maximum level to be logged. (0=error, 1=warning, 2=info, 3=debug)");
"Maximum level to be logged. (0=error, 1=warning, 2=info, 3=debug)",
"Logging");
namespace xe {
@@ -52,16 +55,16 @@ thread_local std::vector<char> log_format_buffer_(64 * 1024);
class Logger {
public:
explicit Logger(const std::wstring& app_name) : running_(true) {
if (FLAGS_log_file.empty()) {
if (cvars::log_file.empty()) {
// Default to app name.
auto file_path = app_name + L".log";
xe::filesystem::CreateParentFolder(file_path);
file_ = xe::filesystem::OpenFile(file_path, "wt");
} else {
if (FLAGS_log_file == "stdout") {
if (cvars::log_file == "stdout") {
file_ = stdout;
} else {
auto file_path = xe::to_wstring(FLAGS_log_file.c_str());
auto file_path = xe::to_wstring(cvars::log_file);
xe::filesystem::CreateParentFolder(file_path);
file_ = xe::filesystem::OpenFile(file_path, "wt");
}
@@ -81,7 +84,7 @@ class Logger {
void AppendLine(uint32_t thread_id, LogLevel level, const char prefix_char,
const char* buffer, size_t buffer_length) {
if (static_cast<int32_t>(level) > FLAGS_log_level) {
if (static_cast<int32_t>(level) > cvars::log_level) {
// Discard this line.
return;
}
@@ -148,7 +151,7 @@ class Logger {
fwrite(buf, 1, size, file_);
}
if (FLAGS_log_debugprint) {
if (cvars::log_debugprint) {
debugging::DebugPrint("%.*s", size, buf);
}
}
@@ -214,7 +217,7 @@ class Logger {
read_head_ = rb.read_offset();
}
if (did_write) {
if (FLAGS_flush_log) {
if (cvars::flush_log) {
fflush(file_);
}

View File

@@ -7,10 +7,9 @@
******************************************************************************
*/
#include "xenia/base/cvar.h"
#include "xenia/base/main.h"
#include <gflags/gflags.h>
#include "xenia/base/logging.h"
#include "xenia/base/string.h"
@@ -23,10 +22,7 @@ bool has_console_attached() { return true; }
extern "C" int main(int argc, char** argv) {
auto entry_info = xe::GetEntryInfo();
google::SetUsageMessage(std::string("usage: ") +
xe::to_string(entry_info.usage));
google::SetVersionString("1.0");
google::ParseCommandLineFlags(&argc, &argv, true);
cvar::ParseLaunchArguments(argc, argv);
std::vector<std::wstring> args;
for (int n = 0; n < argc; n++) {
@@ -39,6 +35,5 @@ extern "C" int main(int argc, char** argv) {
// Call app-provided entry point.
int result = entry_info.entry_point(args);
google::ShutDownCommandLineFlags();
return result;
}

View File

@@ -10,7 +10,6 @@
#include "xenia/base/main.h"
#include <fcntl.h>
#include <gflags/gflags.h>
#include <io.h>
#include <cstdlib>
@@ -18,6 +17,7 @@
// Autogenerated by `xb premake`.
#include "build/version.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/logging.h"
#include "xenia/base/platform_win.h"
#include "xenia/base/string.h"
@@ -25,9 +25,10 @@
#include "third_party/xbyak/xbyak/xbyak_util.h"
#include <bcrypt.h>
#include "xenia/base/cvar.h"
DEFINE_bool(win32_high_freq, true,
"Requests high performance from the NT kernel");
"Requests high performance from the NT kernel", "Kernel");
namespace xe {
@@ -96,10 +97,6 @@ int Main() {
return 1;
}
google::SetUsageMessage(std::string("usage: ") +
xe::to_string(entry_info.usage));
google::SetVersionString("1.0");
// Convert all args to narrow, as gflags doesn't support wchar.
int argca = argc;
char** argva = reinterpret_cast<char**>(alloca(sizeof(char*) * argca));
@@ -109,8 +106,7 @@ int Main() {
std::wcstombs(argva[n], argv[n], len + 1);
}
// Parse flags; this may delete some of them.
google::ParseCommandLineFlags(&argc, &argva, true);
cvar::ParseLaunchArguments(argca, argva);
// Widen all remaining flags and convert to usable strings.
std::vector<std::wstring> args;
@@ -143,7 +139,7 @@ int Main() {
XE_BUILD_DATE);
// Request high performance timing.
if (FLAGS_win32_high_freq) {
if (cvars::win32_high_freq) {
RequestHighPerformance();
}
@@ -151,7 +147,6 @@ int Main() {
int result = entry_info.entry_point(args);
xe::ShutdownLogging();
google::ShutDownCommandLineFlags();
LocalFree(argv);
return result;
}

View File

@@ -7,8 +7,6 @@
******************************************************************************
*/
#include <gflags/gflags.h>
#include <string>
// NOTE: this must be included before microprofile as macro expansion needs
@@ -30,6 +28,7 @@
#include "third_party/microprofile/microprofile.h"
#include "xenia/base/assert.h"
#include "xenia/base/cvar.h"
#include "xenia/base/profiling.h"
#include "xenia/ui/window.h"
@@ -42,7 +41,7 @@
#include "xenia/ui/microprofile_drawer.h"
#endif // XE_OPTION_PROFILING_UI
DEFINE_bool(show_profiler, false, "Show profiling UI by default.");
DEFINE_bool(show_profiler, false, "Show profiling UI by default.", "Other");
namespace xe {
@@ -77,7 +76,7 @@ void Profiler::Initialize() {
g_MicroProfileUI.bShowSpikes = true;
g_MicroProfileUI.nOpacityBackground = 0x40u << 24;
g_MicroProfileUI.nOpacityForeground = 0xc0u << 24;
if (FLAGS_show_profiler) {
if (cvars::show_profiler) {
MicroProfileSetDisplayMode(1);
}
#else