Skip to content

Commit

Permalink
Replace all gflag implementations with cvar implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoyvaerts committed Aug 3, 2019
1 parent a01908a commit c1af632
Show file tree
Hide file tree
Showing 74 changed files with 346 additions and 376 deletions.
14 changes: 7 additions & 7 deletions src/xenia/app/emulator_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
******************************************************************************
*/

#include <gflags/gflags.h>

#include "xenia/app/emulator_window.h"

// Autogenerated by `xb premake`.
Expand All @@ -17,6 +15,7 @@
#include "third_party/imgui/imgui.h"
#include "xenia/app/discord/discord_presence.h"
#include "xenia/base/clock.h"
#include "xenia/base/cvar.h"
#include "xenia/base/debugging.h"
#include "xenia/base/logging.h"
#include "xenia/base/platform.h"
Expand All @@ -29,7 +28,8 @@
#include "xenia/ui/imgui_dialog.h"
#include "xenia/ui/imgui_drawer.h"

DEFINE_bool(discord, false, "Enable Discord rich presence");
DECLARE_bool(debug);
DEFINE_bool(discord, false, "Enable Discord rich presence", "General");

namespace xe {
namespace app {
Expand Down Expand Up @@ -85,7 +85,7 @@ bool EmulatorWindow::Initialize() {
return false;
}

if (FLAGS_discord) {
if (cvars::discord) {
discord::DiscordPresence::InitializeDiscord();
discord::DiscordPresence::NotPlaying();
}
Expand Down Expand Up @@ -344,7 +344,7 @@ void EmulatorWindow::FileOpen() {
void EmulatorWindow::FileClose() {
if (emulator_->is_title_open()) {
emulator_->TerminateTitle();
if (FLAGS_discord) {
if (cvars::discord) {
discord::DiscordPresence::NotPlaying();
}
}
Expand Down Expand Up @@ -398,7 +398,7 @@ void EmulatorWindow::CpuTimeScalarSetDouble() {
}

void EmulatorWindow::CpuBreakIntoDebugger() {
if (!FLAGS_debug) {
if (!cvars::debug) {
xe::ui::ImGuiDialog::ShowMessageBox(window_.get(), "Xenia Debugger",
"Xenia must be launched with the "
"--debug flag in order to enable "
Expand Down Expand Up @@ -444,7 +444,7 @@ void EmulatorWindow::UpdateTitle() {
auto game_title = emulator()->game_title();
title += xe::format_string(L" | [%.8X] %s", emulator()->title_id(),
game_title.c_str());
if (FLAGS_discord) {
if (cvars::discord) {
discord::DiscordPresence::PlayingTitle(game_title);
}
}
Expand Down
67 changes: 32 additions & 35 deletions src/xenia/app/xenia_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
******************************************************************************
*/

#include <gflags/gflags.h>

#include "xenia/app/emulator_window.h"
#include "xenia/base/cvar.h"
#include "xenia/base/debugging.h"
#include "xenia/base/logging.h"
#include "xenia/base/main.h"
Expand Down Expand Up @@ -37,26 +36,33 @@
#include "xenia/hid/xinput/xinput_hid.h"
#endif // XE_PLATFORM_WIN32

DEFINE_string(apu, "any", "Audio system. Use: [any, nop, xaudio2]");
DEFINE_string(gpu, "any", "Graphics system. Use: [any, vulkan, null]");
DEFINE_string(hid, "any", "Input system. Use: [any, nop, winkey, xinput]");
#include "third_party/xbyak/xbyak/xbyak_util.h"

DEFINE_string(apu, "any", "Audio system. Use: [any, nop, xaudio2]", "General");
DEFINE_string(gpu, "any", "Graphics system. Use: [any, vulkan, null]",
"General");
DEFINE_string(hid, "any", "Input system. Use: [any, nop, winkey, xinput]",
"General");

DEFINE_string(target, "", "Specifies the target .xex or .iso to execute.");
DEFINE_bool(fullscreen, false, "Toggles fullscreen");
DEFINE_bool(fullscreen, false, "Toggles fullscreen", "General");

DEFINE_string(content_root, "", "Root path for content (save/etc) storage.");
DEFINE_string(content_root, "", "Root path for content (save/etc) storage.",
"General");

DEFINE_bool(mount_scratch, false, "Enable scratch mount");
DEFINE_bool(mount_cache, false, "Enable cache mount");
DEFINE_bool(mount_scratch, false, "Enable scratch mount", "General");
DEFINE_bool(mount_cache, false, "Enable cache mount", "General");

CmdVar(target, "", "Specifies the target .xex or .iso to execute.");
DECLARE_bool(debug);

namespace xe {
namespace app {

std::unique_ptr<apu::AudioSystem> CreateAudioSystem(cpu::Processor* processor) {
if (FLAGS_apu.compare("nop") == 0) {
if (cvars::apu.compare("nop") == 0) {
return apu::nop::NopAudioSystem::Create(processor);
#if XE_PLATFORM_WIN32
} else if (FLAGS_apu.compare("xaudio2") == 0) {
} else if (cvars::apu.compare("xaudio2") == 0) {
return apu::xaudio2::XAudio2AudioSystem::Create(processor);
#endif // XE_PLATFORM_WIN32
} else {
Expand All @@ -76,10 +82,10 @@ std::unique_ptr<apu::AudioSystem> CreateAudioSystem(cpu::Processor* processor) {
}

std::unique_ptr<gpu::GraphicsSystem> CreateGraphicsSystem() {
if (FLAGS_gpu.compare("vulkan") == 0) {
if (cvars::gpu.compare("vulkan") == 0) {
return std::unique_ptr<gpu::GraphicsSystem>(
new xe::gpu::vulkan::VulkanGraphicsSystem());
} else if (FLAGS_gpu.compare("null") == 0) {
} else if (cvars::gpu.compare("null") == 0) {
return std::unique_ptr<gpu::GraphicsSystem>(
new xe::gpu::null::NullGraphicsSystem());
} else {
Expand All @@ -100,12 +106,12 @@ std::unique_ptr<gpu::GraphicsSystem> CreateGraphicsSystem() {
std::vector<std::unique_ptr<hid::InputDriver>> CreateInputDrivers(
ui::Window* window) {
std::vector<std::unique_ptr<hid::InputDriver>> drivers;
if (FLAGS_hid.compare("nop") == 0) {
if (cvars::hid.compare("nop") == 0) {
drivers.emplace_back(xe::hid::nop::Create(window));
#if XE_PLATFORM_WIN32
} else if (FLAGS_hid.compare("winkey") == 0) {
} else if (cvars::hid.compare("winkey") == 0) {
drivers.emplace_back(xe::hid::winkey::Create(window));
} else if (FLAGS_hid.compare("xinput") == 0) {
} else if (cvars::hid.compare("xinput") == 0) {
drivers.emplace_back(xe::hid::xinput::Create(window));
#endif // XE_PLATFORM_WIN32
} else {
Expand Down Expand Up @@ -139,10 +145,9 @@ int xenia_main(const std::vector<std::wstring>& args) {
Profiler::ThreadEnter("main");

// Figure out where content should go.
std::wstring content_root;
if (!FLAGS_content_root.empty()) {
content_root = xe::to_wstring(FLAGS_content_root);
} else {
std::wstring content_root = xe::to_wstring(cvars::content_root);

if (content_root.empty()) {
auto base_path = xe::filesystem::GetExecutableFolder();
base_path = xe::to_absolute_path(base_path);

Expand Down Expand Up @@ -181,7 +186,7 @@ int xenia_main(const std::vector<std::wstring>& args) {
return 1;
}

if (FLAGS_mount_scratch) {
if (cvars::mount_scratch) {
auto scratch_device = std::make_unique<xe::vfs::HostPathDevice>(
"\\SCRATCH", L"scratch", false);
if (!scratch_device->Initialize()) {
Expand All @@ -195,7 +200,7 @@ int xenia_main(const std::vector<std::wstring>& args) {
}
}

if (FLAGS_mount_cache) {
if (cvars::mount_cache) {
auto cache0_device =
std::make_unique<xe::vfs::HostPathDevice>("\\CACHE0", L"cache0", false);
if (!cache0_device->Initialize()) {
Expand Down Expand Up @@ -224,7 +229,7 @@ int xenia_main(const std::vector<std::wstring>& args) {
// Set a debug handler.
// This will respond to debugging requests so we can open the debug UI.
std::unique_ptr<xe::debug::ui::DebugWindow> debug_window;
if (FLAGS_debug) {
if (cvars::debug) {
emulator->processor()->set_debug_listener_request_handler(
[&](xe::cpu::Processor* processor) {
if (debug_window) {
Expand Down Expand Up @@ -270,20 +275,12 @@ int xenia_main(const std::vector<std::wstring>& args) {

// Grab path from the flag or unnamed argument.
std::wstring path;
if (!FLAGS_target.empty() || args.size() >= 2) {
if (!FLAGS_target.empty()) {
// Passed as a named argument.
// TODO(benvanik): find something better than gflags that supports
// unicode.
path = xe::to_wstring(FLAGS_target);
} else {
// Passed as an unnamed argument.
path = args[1];
}
if (!cvars::target.empty()) {
path = xe::to_wstring(cvars::target);
}

// Toggles fullscreen
if (FLAGS_fullscreen) emulator_window->ToggleFullscreen();
if (cvars::fullscreen) emulator_window->ToggleFullscreen();

if (!path.empty()) {
// Normalize the path and make absolute.
Expand Down
2 changes: 1 addition & 1 deletion src/xenia/apu/apu_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

#include "xenia/apu/apu_flags.h"

DEFINE_bool(mute, false, "Mutes all audio output.");
DEFINE_bool(mute, false, "Mutes all audio output.", "Audio")
5 changes: 2 additions & 3 deletions src/xenia/apu/apu_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#ifndef XENIA_APU_APU_FLAGS_H_
#define XENIA_APU_APU_FLAGS_H_

#include <gflags/gflags.h>

DECLARE_bool(mute);
#include "xenia/base/cvar.h"
DECLARE_bool(mute)

#endif // XENIA_APU_APU_FLAGS_H_
2 changes: 0 additions & 2 deletions src/xenia/apu/nop/nop_apu_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
#ifndef XENIA_APU_NOP_NOP_APU_FLAGS_H_
#define XENIA_APU_NOP_NOP_APU_FLAGS_H_

#include <gflags/gflags.h>

#endif // XENIA_APU_NOP_NOP_APU_FLAGS_H_
2 changes: 0 additions & 2 deletions src/xenia/apu/xaudio2/xaudio2_apu_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
#ifndef XENIA_APU_XAUDIO2_XAUDIO2_APU_FLAGS_H_
#define XENIA_APU_XAUDIO2_XAUDIO2_APU_FLAGS_H_

#include <gflags/gflags.h>

#endif // XENIA_APU_XAUDIO2_XAUDIO2_APU_FLAGS_H_
2 changes: 1 addition & 1 deletion src/xenia/apu/xaudio2/xaudio2_audio_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool XAudio2AudioDriver::Initialize() {
return false;
}

if (FLAGS_mute) {
if (cvars::mute) {
pcm_voice_->SetVolume(0.0f);
}

Expand Down
8 changes: 4 additions & 4 deletions src/xenia/apu/xma_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

#include "xenia/apu/xma_decoder.h"

#include <gflags/gflags.h>

#include "xenia/apu/xma_context.h"
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/profiling.h"
Expand Down Expand Up @@ -49,7 +48,8 @@ extern "C" {
// do this, it's likely they are either passing the context to XAudio or
// using the XMA* functions.

DEFINE_bool(libav_verbose, false, "Verbose libav output (debug and above)");
DEFINE_bool(libav_verbose, false, "Verbose libav output (debug and above)",
"Audio");

namespace xe {
namespace apu {
Expand All @@ -60,7 +60,7 @@ XmaDecoder::XmaDecoder(cpu::Processor* processor)
XmaDecoder::~XmaDecoder() = default;

void av_log_callback(void* avcl, int level, const char* fmt, va_list va) {
if (!FLAGS_libav_verbose && level > AV_LOG_WARNING) {
if (!cvars::libav_verbose && level > AV_LOG_WARNING) {
return;
}

Expand Down
27 changes: 15 additions & 12 deletions src/xenia/base/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include "xenia/base/logging.h"

#include <gflags/gflags.h>

#include <atomic>
#include <cinttypes>
#include <cstdarg>
Expand All @@ -19,13 +17,15 @@
#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"
#include "xenia/base/math.h"
#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?
Expand All @@ -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 {

Expand All @@ -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");
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -148,7 +151,7 @@ class Logger {
fwrite(buf, 1, size, file_);
}

if (FLAGS_log_debugprint) {
if (cvars::log_debugprint) {
debugging::DebugPrint("%.*s", size, buf);
}
}
Expand Down Expand Up @@ -214,7 +217,7 @@ class Logger {
read_head_ = rb.read_offset();
}
if (did_write) {
if (FLAGS_flush_log) {
if (cvars::flush_log) {
fflush(file_);
}

Expand Down
Loading

0 comments on commit c1af632

Please sign in to comment.