settings: Add PerGameValues class to encapsulate game-specific settings

Provides various operators and methods to facilitate easy management and use of settings.
This commit is contained in:
Zach Hilman
2018-10-17 21:15:22 -04:00
parent c94db0e071
commit 7452a10688
2 changed files with 133 additions and 21 deletions

View File

@@ -12,6 +12,76 @@ namespace Settings {
Values values = {};
Values::Values() : current_game(default_game) {}
void Values::SetUpdateCurrentGameFunction(std::function<bool(u64, PerGameValues&)> new_function) {
update_current_game = std::move(new_function);
}
u64 Values::CurrentTitleID() {
return current_title_id;
}
void Values::SetCurrentTitleID(u64 title_id) {
// Ignore Updates
title_id &= ~0x800;
if (current_title_id == title_id)
return;
update_current_game(title_id, current_game);
}
PerGameValues& Values::operator[](u64 title_id) {
// Ignore Updates
title_id &= ~0x800;
if (current_title_id == title_id)
return current_game;
if (!update_current_game(title_id, current_game))
return default_game;
current_title_id = title_id;
return current_game;
}
const PerGameValues& Values::operator[](u64 title_id) const {
// Ignore Updates
title_id &= ~0x800;
if (current_title_id == title_id)
return current_game;
return default_game;
}
PerGameValues* Values::operator->() {
if (current_title_id == 0)
return &default_game;
return &current_game;
}
const PerGameValues* Values::operator->() const {
if (current_title_id == 0)
return &default_game;
return &current_game;
}
PerGameValues& Values::operator*() {
if (current_title_id == 0)
return default_game;
return current_game;
}
const PerGameValues& Values::operator*() const {
if (current_title_id == 0)
return default_game;
return current_game;
}
void Apply() {
GDBStub::SetServerPort(values.gdbstub_port);
GDBStub::ToggleServer(values.use_gdbstub);

View File

@@ -6,11 +6,16 @@
#include <array>
#include <atomic>
#include <functional>
#include <string>
#include <vector>
#include "common/common_types.h"
#include "input_common/motion_emu.h"
namespace Settings {
constexpr u64 DEFAULT_PER_GAME = 0;
namespace NativeButton {
enum Values {
A,
@@ -110,28 +115,15 @@ static const std::array<const char*, NumAnalogs> mapping = {{
}};
} // namespace NativeAnalog
struct Values {
// System
bool use_docked_mode;
bool enable_nfc;
int current_user;
int language_index;
struct PerGameValues {
// Controls
std::array<std::string, NativeButton::NumButtons> buttons;
std::array<std::string, NativeAnalog::NumAnalogs> analogs;
std::string motion_device;
std::string touch_device;
std::atomic_bool is_device_reload_pending{true};
// Core
bool use_cpu_jit;
bool use_multi_core;
// Data Storage
bool use_virtual_sd;
std::string nand_dir;
std::string sdmc_dir;
// System
bool use_docked_mode;
// Renderer
float resolution_factor;
@@ -143,10 +135,6 @@ struct Values {
float bg_green;
float bg_blue;
std::string log_filter;
bool use_dev_keys;
// Audio
std::string sink_id;
bool enable_audio_stretching;
@@ -154,15 +142,69 @@ struct Values {
float volume;
// Debugging
std::string program_args;
// Add-Ons
std::vector<std::string> disabled_patches;
};
struct Values {
Values();
// Per-Game
PerGameValues default_game;
void SetUpdateCurrentGameFunction(std::function<bool(u64, PerGameValues&)> new_function);
u64 CurrentTitleID();
void SetCurrentTitleID(u64 title_id);
PerGameValues& operator[](u64 title_id);
const PerGameValues& operator[](u64 title_id) const;
PerGameValues* operator->();
const PerGameValues* operator->() const;
PerGameValues& operator*();
const PerGameValues& operator*() const;
// Core
bool use_cpu_jit;
bool use_multi_core;
// System
std::string username;
bool enable_nfc;
int current_user;
int language_index;
// Renderer
bool use_accurate_framebuffers;
// Input
std::atomic_bool is_device_reload_pending{true};
// Data Storage
bool use_virtual_sd;
std::string nand_dir;
std::string sdmc_dir;
// Debugging
std::string log_filter;
bool use_dev_keys;
bool use_gdbstub;
u16 gdbstub_port;
std::string program_args;
// WebService
bool enable_telemetry;
std::string web_api_url;
std::string yuzu_username;
std::string yuzu_token;
private:
u64 current_title_id = 0;
PerGameValues current_game;
std::function<bool(u64, PerGameValues&)> update_current_game = [](u64 in, PerGameValues& val) {
return false;
};
} extern values;
void Apply();