Extract the ConfigSetting implementation into its own file.

This commit is contained in:
Henrik Rydgård 2023-04-05 11:44:11 +02:00
parent 5a1e9ed8f1
commit 6ac45ddba1
7 changed files with 391 additions and 364 deletions

View file

@ -48,6 +48,7 @@
#include "Common/GPU/Vulkan/VulkanLoader.h"
#include "Common/VR/PPSSPPVR.h"
#include "Core/Config.h"
#include "Core/ConfigSettings.h"
#include "Core/ConfigValues.h"
#include "Core/Loaders.h"
#include "Core/KeyMap.h"
@ -79,354 +80,6 @@ static const char *logSectionName = "LogDebug";
static const char *logSectionName = "Log";
#endif
struct ConfigSetting {
enum Type {
TYPE_TERMINATOR,
TYPE_BOOL,
TYPE_INT,
TYPE_UINT32,
TYPE_UINT64,
TYPE_FLOAT,
TYPE_STRING,
TYPE_TOUCH_POS,
TYPE_PATH,
TYPE_CUSTOM_BUTTON
};
union DefaultValue {
bool b;
int i;
uint32_t u;
uint64_t lu;
float f;
const char *s;
const char *p; // not sure how much point..
ConfigTouchPos touchPos;
ConfigCustomButton customButton;
};
union SettingPtr {
bool *b;
int *i;
uint32_t *u;
uint64_t *lu;
float *f;
std::string *s;
Path *p;
ConfigTouchPos *touchPos;
ConfigCustomButton *customButton;
};
typedef bool (*BoolDefaultCallback)();
typedef int (*IntDefaultCallback)();
typedef uint32_t (*Uint32DefaultCallback)();
typedef uint64_t (*Uint64DefaultCallback)();
typedef float (*FloatDefaultCallback)();
typedef const char *(*StringDefaultCallback)();
typedef ConfigTouchPos (*TouchPosDefaultCallback)();
typedef const char *(*PathDefaultCallback)();
typedef ConfigCustomButton (*CustomButtonDefaultCallback)();
union DefaultCallback {
BoolDefaultCallback b;
IntDefaultCallback i;
Uint32DefaultCallback u;
Uint64DefaultCallback lu;
FloatDefaultCallback f;
StringDefaultCallback s;
PathDefaultCallback p;
TouchPosDefaultCallback touchPos;
CustomButtonDefaultCallback customButton;
};
ConfigSetting(const char *ini, bool *v, bool def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_BOOL), report_(false), save_(save), perGame_(perGame) {
ptr_.b = v;
cb_.b = nullptr;
default_.b = def;
}
ConfigSetting(const char *ini, int *v, int def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame) {
ptr_.i = v;
cb_.i = nullptr;
default_.i = def;
}
ConfigSetting(const char *ini, int *v, int def, std::string (*transTo)(int), int (*transFrom)(const std::string &), bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame), translateTo_(transTo), translateFrom_(transFrom) {
ptr_.i = v;
cb_.i = nullptr;
default_.i = def;
}
ConfigSetting(const char *ini, uint32_t *v, uint32_t def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_UINT32), report_(false), save_(save), perGame_(perGame) {
ptr_.u = v;
cb_.u = nullptr;
default_.u = def;
}
ConfigSetting(const char *ini, uint64_t *v, uint64_t def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_UINT64), report_(false), save_(save), perGame_(perGame) {
ptr_.lu = v;
cb_.lu = nullptr;
default_.lu = def;
}
ConfigSetting(const char *ini, float *v, float def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_FLOAT), report_(false), save_(save), perGame_(perGame) {
ptr_.f = v;
cb_.f = nullptr;
default_.f = def;
}
ConfigSetting(const char *ini, std::string *v, const char *def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_STRING), report_(false), save_(save), perGame_(perGame) {
ptr_.s = v;
cb_.s = nullptr;
default_.s = def;
}
ConfigSetting(const char *ini, Path *p, const char *def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_PATH), report_(false), save_(save), perGame_(perGame) {
ptr_.p = p;
cb_.p = nullptr;
default_.p = def;
}
ConfigSetting(const char *iniX, const char *iniY, const char *iniScale, const char *iniShow, ConfigTouchPos *v, ConfigTouchPos def, bool save = true, bool perGame = false)
: iniKey_(iniX), ini2_(iniY), ini3_(iniScale), ini4_(iniShow), type_(TYPE_TOUCH_POS), report_(false), save_(save), perGame_(perGame) {
ptr_.touchPos = v;
cb_.touchPos = nullptr;
default_.touchPos = def;
}
ConfigSetting(const char *iniKey, const char *iniImage, const char *iniShape, const char *iniToggle, const char *iniRepeat, ConfigCustomButton *v, ConfigCustomButton def, bool save = true, bool perGame = false)
: iniKey_(iniKey), ini2_(iniImage), ini3_(iniShape), ini4_(iniToggle), ini5_(iniRepeat), type_(TYPE_CUSTOM_BUTTON), report_(false), save_(save), perGame_(perGame) {
ptr_.customButton = v;
cb_.customButton = nullptr;
default_.customButton = def;
}
ConfigSetting(const char *ini, bool *v, BoolDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_BOOL), report_(false), save_(save), perGame_(perGame) {
ptr_.b = v;
cb_.b = def;
}
ConfigSetting(const char *ini, int *v, IntDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame) {
ptr_ .i = v;
cb_.i = def;
}
ConfigSetting(const char *ini, int *v, IntDefaultCallback def, std::string(*transTo)(int), int(*transFrom)(const std::string &), bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame), translateTo_(transTo), translateFrom_(transFrom) {
ptr_.i = v;
cb_.i = def;
}
ConfigSetting(const char *ini, uint32_t *v, Uint32DefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_UINT32), report_(false), save_(save), perGame_(perGame) {
ptr_ .u = v;
cb_.u = def;
}
ConfigSetting(const char *ini, float *v, FloatDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_FLOAT), report_(false), save_(save), perGame_(perGame) {
ptr_.f = v;
cb_.f = def;
}
ConfigSetting(const char *ini, std::string *v, StringDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_STRING), report_(false), save_(save), perGame_(perGame) {
ptr_.s = v;
cb_.s = def;
}
ConfigSetting(const char *iniX, const char *iniY, const char *iniScale, const char *iniShow, ConfigTouchPos *v, TouchPosDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(iniX), ini2_(iniY), ini3_(iniScale), ini4_(iniShow), type_(TYPE_TOUCH_POS), report_(false), save_(save), perGame_(perGame) {
ptr_.touchPos = v;
cb_.touchPos = def;
}
// Should actually be called ReadFromIni or something.
bool Get(const Section *section) const {
switch (type_) {
case TYPE_BOOL:
return section->Get(iniKey_, ptr_.b, cb_.b ? cb_.b() : default_.b);
case TYPE_INT:
if (translateFrom_) {
std::string value;
if (section->Get(iniKey_, &value, nullptr)) {
*ptr_.i = translateFrom_(value);
return true;
}
}
return section->Get(iniKey_, ptr_.i, cb_.i ? cb_.i() : default_.i);
case TYPE_UINT32:
return section->Get(iniKey_, ptr_.u, cb_.u ? cb_.u() : default_.u);
case TYPE_UINT64:
return section->Get(iniKey_, ptr_.lu, cb_.lu ? cb_.lu() : default_.lu);
case TYPE_FLOAT:
return section->Get(iniKey_, ptr_.f, cb_.f ? cb_.f() : default_.f);
case TYPE_STRING:
return section->Get(iniKey_, ptr_.s, cb_.s ? cb_.s() : default_.s);
case TYPE_TOUCH_POS:
{
ConfigTouchPos defaultTouchPos = cb_.touchPos ? cb_.touchPos() : default_.touchPos;
section->Get(iniKey_, &ptr_.touchPos->x, defaultTouchPos.x);
section->Get(ini2_, &ptr_.touchPos->y, defaultTouchPos.y);
section->Get(ini3_, &ptr_.touchPos->scale, defaultTouchPos.scale);
if (ini4_) {
section->Get(ini4_, &ptr_.touchPos->show, defaultTouchPos.show);
} else {
ptr_.touchPos->show = defaultTouchPos.show;
}
return true;
}
case TYPE_PATH:
{
std::string tmp;
bool result = section->Get(iniKey_, &tmp, cb_.p ? cb_.p() : default_.p);
if (result) {
*ptr_.p = Path(tmp);
}
return result;
}
case TYPE_CUSTOM_BUTTON:
{
ConfigCustomButton defaultCustomButton = cb_.customButton ? cb_.customButton() : default_.customButton;
section->Get(iniKey_, &ptr_.customButton->key, defaultCustomButton.key);
section->Get(ini2_, &ptr_.customButton->image, defaultCustomButton.image);
section->Get(ini3_, &ptr_.customButton->shape, defaultCustomButton.shape);
section->Get(ini4_, &ptr_.customButton->toggle, defaultCustomButton.toggle);
section->Get(ini5_, &ptr_.customButton->repeat, defaultCustomButton.repeat);
return true;
}
default:
_dbg_assert_msg_(false, "Get(%s): Unexpected ini setting type: %d", iniKey_, (int)type_);
return false;
}
}
// Yes, this can be const because what's modified is not the ConfigSetting struct, but the value which is stored elsewhere.
// Should actually be called WriteToIni or something.
void Set(Section *section) const {
if (!save_) {
return;
}
switch (type_) {
case TYPE_BOOL:
return section->Set(iniKey_, *ptr_.b);
case TYPE_INT:
if (translateTo_) {
std::string value = translateTo_(*ptr_.i);
return section->Set(iniKey_, value);
}
return section->Set(iniKey_, *ptr_.i);
case TYPE_UINT32:
return section->Set(iniKey_, *ptr_.u);
case TYPE_UINT64:
return section->Set(iniKey_, *ptr_.lu);
case TYPE_FLOAT:
return section->Set(iniKey_, *ptr_.f);
case TYPE_STRING:
return section->Set(iniKey_, *ptr_.s);
case TYPE_PATH:
return section->Set(iniKey_, ptr_.p->ToString());
case TYPE_TOUCH_POS:
section->Set(iniKey_, ptr_.touchPos->x);
section->Set(ini2_, ptr_.touchPos->y);
section->Set(ini3_, ptr_.touchPos->scale);
if (ini4_) {
section->Set(ini4_, ptr_.touchPos->show);
}
return;
case TYPE_CUSTOM_BUTTON:
section->Set(iniKey_, ptr_.customButton->key);
section->Set(ini2_, ptr_.customButton->image);
section->Set(ini3_, ptr_.customButton->shape);
section->Set(ini4_, ptr_.customButton->toggle);
section->Set(ini5_, ptr_.customButton->repeat);
return;
default:
_dbg_assert_msg_(false, "Set(%s): Unexpected ini setting type: %d", iniKey_, (int)type_);
return;
}
}
void RestoreToDefault() const {
switch (type_) {
case TYPE_BOOL: *ptr_.b = cb_.b ? cb_.b() : default_.b; break;
case TYPE_INT: *ptr_.i = cb_.i ? cb_.i() : default_.i; break;
case TYPE_UINT32: *ptr_.u = cb_.u ? cb_.u() : default_.u; break;
case TYPE_UINT64: *ptr_.lu = cb_.lu ? cb_.lu() : default_.lu; break;
case TYPE_FLOAT: *ptr_.f = cb_.f ? cb_.f() : default_.f; break;
case TYPE_STRING: *ptr_.s = cb_.s ? cb_.s() : default_.s; break;
case TYPE_TOUCH_POS: *ptr_.touchPos = cb_.touchPos ? cb_.touchPos() : default_.touchPos; break;
case TYPE_PATH: *ptr_.p = Path(cb_.p ? cb_.p() : default_.p); break;
case TYPE_CUSTOM_BUTTON: *ptr_.customButton = cb_.customButton ? cb_.customButton() : default_.customButton; break;
default:
_dbg_assert_msg_(false, "RestoreToDefault(%s): Unexpected ini setting type: %d", iniKey_, (int)type_);
}
}
void Report(UrlEncoder &data, const std::string &prefix) const {
if (!report_)
return;
switch (type_) {
case TYPE_BOOL: return data.Add(prefix + iniKey_, *ptr_.b);
case TYPE_INT: return data.Add(prefix + iniKey_, *ptr_.i);
case TYPE_UINT32: return data.Add(prefix + iniKey_, *ptr_.u);
case TYPE_UINT64: return data.Add(prefix + iniKey_, *ptr_.lu);
case TYPE_FLOAT: return data.Add(prefix + iniKey_, *ptr_.f);
case TYPE_STRING: return data.Add(prefix + iniKey_, *ptr_.s);
case TYPE_PATH: return data.Add(prefix + iniKey_, ptr_.p->ToString());
case TYPE_TOUCH_POS: return; // Doesn't report.
case TYPE_CUSTOM_BUTTON: return; // Doesn't report.
default:
_dbg_assert_msg_(false, "Report(%s): Unexpected ini setting type: %d", iniKey_, (int)type_);
return;
}
}
const char *iniKey_ = nullptr;
const char *ini2_ = nullptr;
const char *ini3_ = nullptr;
const char *ini4_ = nullptr;
const char *ini5_ = nullptr;
const Type type_;
bool report_;
const bool save_;
const bool perGame_;
SettingPtr ptr_;
DefaultValue default_{};
DefaultCallback cb_;
// We only support transform for ints.
std::string (*translateTo_)(int) = nullptr;
int(*translateFrom_)(const std::string &) = nullptr;
};
struct ReportedConfigSetting : public ConfigSetting {
template <typename T1, typename T2>
ReportedConfigSetting(const char *ini, T1 *v, T2 def, bool save = true, bool perGame = false)
: ConfigSetting(ini, v, def, save, perGame) {
report_ = true;
}
template <typename T1, typename T2>
ReportedConfigSetting(const char *ini, T1 *v, T2 def, std::string(*transTo)(int), int(*transFrom)(const std::string &), bool save = true, bool perGame = false)
: ConfigSetting(ini, v, def, transTo, transFrom, save, perGame) {
report_ = true;
}
};
const char *DefaultLangRegion() {
// Unfortunate default. There's no need to use bFirstRun, since this is only a default.
static std::string defaultLangRegion = "en_US";

View file

@ -48,22 +48,6 @@ namespace http {
struct UrlEncoder;
struct ConfigPrivate;
struct ConfigTouchPos {
float x;
float y;
float scale;
// Note: Show is not used for all settings.
bool show;
};
struct ConfigCustomButton {
uint64_t key;
int image;
int shape;
bool toggle;
bool repeat;
};
struct Config {
public:
Config();

View file

@ -1,3 +1,147 @@
#include "Common/Data/Format/IniFile.h"
#include "Common/Net/URL.h"
#include "Common/Log.h"
#include "Core/ConfigSettings.h"
#include "Core/ConfigValues.h"
bool ConfigSetting::Get(const Section *section) const {
switch (type_) {
case TYPE_BOOL:
return section->Get(iniKey_, ptr_.b, cb_.b ? cb_.b() : default_.b);
case TYPE_INT:
if (translateFrom_) {
std::string value;
if (section->Get(iniKey_, &value, nullptr)) {
*ptr_.i = translateFrom_(value);
return true;
}
}
return section->Get(iniKey_, ptr_.i, cb_.i ? cb_.i() : default_.i);
case TYPE_UINT32:
return section->Get(iniKey_, ptr_.u, cb_.u ? cb_.u() : default_.u);
case TYPE_UINT64:
return section->Get(iniKey_, ptr_.lu, cb_.lu ? cb_.lu() : default_.lu);
case TYPE_FLOAT:
return section->Get(iniKey_, ptr_.f, cb_.f ? cb_.f() : default_.f);
case TYPE_STRING:
return section->Get(iniKey_, ptr_.s, cb_.s ? cb_.s() : default_.s);
case TYPE_TOUCH_POS:
{
ConfigTouchPos defaultTouchPos = cb_.touchPos ? cb_.touchPos() : default_.touchPos;
section->Get(iniKey_, &ptr_.touchPos->x, defaultTouchPos.x);
section->Get(ini2_, &ptr_.touchPos->y, defaultTouchPos.y);
section->Get(ini3_, &ptr_.touchPos->scale, defaultTouchPos.scale);
if (ini4_) {
section->Get(ini4_, &ptr_.touchPos->show, defaultTouchPos.show);
} else {
ptr_.touchPos->show = defaultTouchPos.show;
}
return true;
}
case TYPE_PATH:
{
std::string tmp;
bool result = section->Get(iniKey_, &tmp, cb_.p ? cb_.p() : default_.p);
if (result) {
*ptr_.p = Path(tmp);
}
return result;
}
case TYPE_CUSTOM_BUTTON:
{
ConfigCustomButton defaultCustomButton = cb_.customButton ? cb_.customButton() : default_.customButton;
section->Get(iniKey_, &ptr_.customButton->key, defaultCustomButton.key);
section->Get(ini2_, &ptr_.customButton->image, defaultCustomButton.image);
section->Get(ini3_, &ptr_.customButton->shape, defaultCustomButton.shape);
section->Get(ini4_, &ptr_.customButton->toggle, defaultCustomButton.toggle);
section->Get(ini5_, &ptr_.customButton->repeat, defaultCustomButton.repeat);
return true;
}
default:
_dbg_assert_msg_(false, "Get(%s): Unexpected ini setting type: %d", iniKey_, (int)type_);
return false;
}
}
void ConfigSetting::Set(Section *section) const {
if (!save_) {
return;
}
switch (type_) {
case TYPE_BOOL:
return section->Set(iniKey_, *ptr_.b);
case TYPE_INT:
if (translateTo_) {
std::string value = translateTo_(*ptr_.i);
return section->Set(iniKey_, value);
}
return section->Set(iniKey_, *ptr_.i);
case TYPE_UINT32:
return section->Set(iniKey_, *ptr_.u);
case TYPE_UINT64:
return section->Set(iniKey_, *ptr_.lu);
case TYPE_FLOAT:
return section->Set(iniKey_, *ptr_.f);
case TYPE_STRING:
return section->Set(iniKey_, *ptr_.s);
case TYPE_PATH:
return section->Set(iniKey_, ptr_.p->ToString());
case TYPE_TOUCH_POS:
section->Set(iniKey_, ptr_.touchPos->x);
section->Set(ini2_, ptr_.touchPos->y);
section->Set(ini3_, ptr_.touchPos->scale);
if (ini4_) {
section->Set(ini4_, ptr_.touchPos->show);
}
return;
case TYPE_CUSTOM_BUTTON:
section->Set(iniKey_, ptr_.customButton->key);
section->Set(ini2_, ptr_.customButton->image);
section->Set(ini3_, ptr_.customButton->shape);
section->Set(ini4_, ptr_.customButton->toggle);
section->Set(ini5_, ptr_.customButton->repeat);
return;
default:
_dbg_assert_msg_(false, "Set(%s): Unexpected ini setting type: %d", iniKey_, (int)type_);
return;
}
}
void ConfigSetting::RestoreToDefault() const {
switch (type_) {
case TYPE_BOOL: *ptr_.b = cb_.b ? cb_.b() : default_.b; break;
case TYPE_INT: *ptr_.i = cb_.i ? cb_.i() : default_.i; break;
case TYPE_UINT32: *ptr_.u = cb_.u ? cb_.u() : default_.u; break;
case TYPE_UINT64: *ptr_.lu = cb_.lu ? cb_.lu() : default_.lu; break;
case TYPE_FLOAT: *ptr_.f = cb_.f ? cb_.f() : default_.f; break;
case TYPE_STRING: *ptr_.s = cb_.s ? cb_.s() : default_.s; break;
case TYPE_TOUCH_POS: *ptr_.touchPos = cb_.touchPos ? cb_.touchPos() : default_.touchPos; break;
case TYPE_PATH: *ptr_.p = Path(cb_.p ? cb_.p() : default_.p); break;
case TYPE_CUSTOM_BUTTON: *ptr_.customButton = cb_.customButton ? cb_.customButton() : default_.customButton; break;
default:
_dbg_assert_msg_(false, "RestoreToDefault(%s): Unexpected ini setting type: %d", iniKey_, (int)type_);
}
}
void ConfigSetting::Report(UrlEncoder &data, const std::string &prefix) const {
if (!report_)
return;
switch (type_) {
case TYPE_BOOL: return data.Add(prefix + iniKey_, *ptr_.b);
case TYPE_INT: return data.Add(prefix + iniKey_, *ptr_.i);
case TYPE_UINT32: return data.Add(prefix + iniKey_, *ptr_.u);
case TYPE_UINT64: return data.Add(prefix + iniKey_, *ptr_.lu);
case TYPE_FLOAT: return data.Add(prefix + iniKey_, *ptr_.f);
case TYPE_STRING: return data.Add(prefix + iniKey_, *ptr_.s);
case TYPE_PATH: return data.Add(prefix + iniKey_, ptr_.p->ToString());
case TYPE_TOUCH_POS: return; // Doesn't report.
case TYPE_CUSTOM_BUTTON: return; // Doesn't report.
default:
_dbg_assert_msg_(false, "Report(%s): Unexpected ini setting type: %d", iniKey_, (int)type_);
return;
}
}

View file

@ -1,2 +1,224 @@
#pragma once
#include <cstdint>
#include "Core/ConfigValues.h"
class Path;
class Section; // ini file section
struct UrlEncoder;
struct ConfigSetting {
enum Type {
TYPE_TERMINATOR,
TYPE_BOOL,
TYPE_INT,
TYPE_UINT32,
TYPE_UINT64,
TYPE_FLOAT,
TYPE_STRING,
TYPE_TOUCH_POS,
TYPE_PATH,
TYPE_CUSTOM_BUTTON
};
union DefaultValue {
bool b;
int i;
uint32_t u;
uint64_t lu;
float f;
const char *s;
const char *p; // not sure how much point..
ConfigTouchPos touchPos;
ConfigCustomButton customButton;
};
union SettingPtr {
bool *b;
int *i;
uint32_t *u;
uint64_t *lu;
float *f;
std::string *s;
Path *p;
ConfigTouchPos *touchPos;
ConfigCustomButton *customButton;
};
typedef bool (*BoolDefaultCallback)();
typedef int (*IntDefaultCallback)();
typedef uint32_t(*Uint32DefaultCallback)();
typedef uint64_t(*Uint64DefaultCallback)();
typedef float (*FloatDefaultCallback)();
typedef const char *(*StringDefaultCallback)();
typedef ConfigTouchPos(*TouchPosDefaultCallback)();
typedef const char *(*PathDefaultCallback)();
typedef ConfigCustomButton(*CustomButtonDefaultCallback)();
union DefaultCallback {
BoolDefaultCallback b;
IntDefaultCallback i;
Uint32DefaultCallback u;
Uint64DefaultCallback lu;
FloatDefaultCallback f;
StringDefaultCallback s;
PathDefaultCallback p;
TouchPosDefaultCallback touchPos;
CustomButtonDefaultCallback customButton;
};
ConfigSetting(const char *ini, bool *v, bool def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_BOOL), report_(false), save_(save), perGame_(perGame) {
ptr_.b = v;
cb_.b = nullptr;
default_.b = def;
}
ConfigSetting(const char *ini, int *v, int def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame) {
ptr_.i = v;
cb_.i = nullptr;
default_.i = def;
}
ConfigSetting(const char *ini, int *v, int def, std::string(*transTo)(int), int (*transFrom)(const std::string &), bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame), translateTo_(transTo), translateFrom_(transFrom) {
ptr_.i = v;
cb_.i = nullptr;
default_.i = def;
}
ConfigSetting(const char *ini, uint32_t *v, uint32_t def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_UINT32), report_(false), save_(save), perGame_(perGame) {
ptr_.u = v;
cb_.u = nullptr;
default_.u = def;
}
ConfigSetting(const char *ini, uint64_t *v, uint64_t def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_UINT64), report_(false), save_(save), perGame_(perGame) {
ptr_.lu = v;
cb_.lu = nullptr;
default_.lu = def;
}
ConfigSetting(const char *ini, float *v, float def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_FLOAT), report_(false), save_(save), perGame_(perGame) {
ptr_.f = v;
cb_.f = nullptr;
default_.f = def;
}
ConfigSetting(const char *ini, std::string *v, const char *def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_STRING), report_(false), save_(save), perGame_(perGame) {
ptr_.s = v;
cb_.s = nullptr;
default_.s = def;
}
ConfigSetting(const char *ini, Path *p, const char *def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_PATH), report_(false), save_(save), perGame_(perGame) {
ptr_.p = p;
cb_.p = nullptr;
default_.p = def;
}
ConfigSetting(const char *iniX, const char *iniY, const char *iniScale, const char *iniShow, ConfigTouchPos *v, ConfigTouchPos def, bool save = true, bool perGame = false)
: iniKey_(iniX), ini2_(iniY), ini3_(iniScale), ini4_(iniShow), type_(TYPE_TOUCH_POS), report_(false), save_(save), perGame_(perGame) {
ptr_.touchPos = v;
cb_.touchPos = nullptr;
default_.touchPos = def;
}
ConfigSetting(const char *iniKey, const char *iniImage, const char *iniShape, const char *iniToggle, const char *iniRepeat, ConfigCustomButton *v, ConfigCustomButton def, bool save = true, bool perGame = false)
: iniKey_(iniKey), ini2_(iniImage), ini3_(iniShape), ini4_(iniToggle), ini5_(iniRepeat), type_(TYPE_CUSTOM_BUTTON), report_(false), save_(save), perGame_(perGame) {
ptr_.customButton = v;
cb_.customButton = nullptr;
default_.customButton = def;
}
ConfigSetting(const char *ini, bool *v, BoolDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_BOOL), report_(false), save_(save), perGame_(perGame) {
ptr_.b = v;
cb_.b = def;
}
ConfigSetting(const char *ini, int *v, IntDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame) {
ptr_.i = v;
cb_.i = def;
}
ConfigSetting(const char *ini, int *v, IntDefaultCallback def, std::string(*transTo)(int), int(*transFrom)(const std::string &), bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame), translateTo_(transTo), translateFrom_(transFrom) {
ptr_.i = v;
cb_.i = def;
}
ConfigSetting(const char *ini, uint32_t *v, Uint32DefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_UINT32), report_(false), save_(save), perGame_(perGame) {
ptr_.u = v;
cb_.u = def;
}
ConfigSetting(const char *ini, float *v, FloatDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_FLOAT), report_(false), save_(save), perGame_(perGame) {
ptr_.f = v;
cb_.f = def;
}
ConfigSetting(const char *ini, std::string *v, StringDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(ini), type_(TYPE_STRING), report_(false), save_(save), perGame_(perGame) {
ptr_.s = v;
cb_.s = def;
}
ConfigSetting(const char *iniX, const char *iniY, const char *iniScale, const char *iniShow, ConfigTouchPos *v, TouchPosDefaultCallback def, bool save = true, bool perGame = false)
: iniKey_(iniX), ini2_(iniY), ini3_(iniScale), ini4_(iniShow), type_(TYPE_TOUCH_POS), report_(false), save_(save), perGame_(perGame) {
ptr_.touchPos = v;
cb_.touchPos = def;
}
// Should actually be called ReadFromIni or something.
bool Get(const Section *section) const;
// Yes, this can be const because what's modified is not the ConfigSetting struct, but the value which is stored elsewhere.
// Should actually be called WriteToIni or something.
void Set(Section *section) const;
void RestoreToDefault() const;
void Report(UrlEncoder &data, const std::string &prefix) const;
const char *iniKey_ = nullptr;
const char *ini2_ = nullptr;
const char *ini3_ = nullptr;
const char *ini4_ = nullptr;
const char *ini5_ = nullptr;
const Type type_;
bool report_;
const bool save_;
const bool perGame_;
SettingPtr ptr_;
DefaultValue default_{};
DefaultCallback cb_;
// We only support transform for ints.
std::string(*translateTo_)(int) = nullptr;
int(*translateFrom_)(const std::string &) = nullptr;
};
struct ReportedConfigSetting : public ConfigSetting {
template <typename T1, typename T2>
ReportedConfigSetting(const char *ini, T1 *v, T2 def, bool save = true, bool perGame = false)
: ConfigSetting(ini, v, def, save, perGame) {
report_ = true;
}
template <typename T1, typename T2>
ReportedConfigSetting(const char *ini, T1 *v, T2 def, std::string(*transTo)(int), int(*transFrom)(const std::string &), bool save = true, bool perGame = false)
: ConfigSetting(ini, v, def, transTo, transFrom, save, perGame) {
report_ = true;
}
};

View file

@ -31,6 +31,22 @@ const int PSP_DEFAULT_FIRMWARE = 660;
static const int8_t VOLUME_OFF = 0;
static const int8_t VOLUME_FULL = 10;
struct ConfigTouchPos {
float x;
float y;
float scale;
// Note: Show is not used for all settings.
bool show;
};
struct ConfigCustomButton {
uint64_t key;
int image;
int shape;
bool toggle;
bool repeat;
};
enum class CPUCore {
INTERPRETER = 0,
JIT = 1,

View file

@ -540,6 +540,7 @@
<ClCompile Include="..\ext\udis86\syn-intel.c" />
<ClCompile Include="..\ext\udis86\syn.c" />
<ClCompile Include="..\ext\udis86\udis86.c" />
<ClCompile Include="ConfigSettings.cpp" />
<ClCompile Include="ControlMapper.cpp" />
<ClCompile Include="AVIDump.cpp" />
<ClCompile Include="Debugger\MemBlockInfo.cpp" />
@ -1110,6 +1111,7 @@
<ClInclude Include="..\ext\udis86\types.h" />
<ClInclude Include="..\ext\udis86\udint.h" />
<ClInclude Include="..\ext\udis86\udis86.h" />
<ClInclude Include="ConfigSettings.h" />
<ClInclude Include="ControlMapper.h" />
<ClInclude Include="AVIDump.h" />
<ClInclude Include="ConfigValues.h" />

View file

@ -1195,6 +1195,9 @@
<ClCompile Include="MIPS\MIPSVFPUFallbacks.cpp">
<Filter>MIPS</Filter>
</ClCompile>
<ClCompile Include="ConfigSettings.cpp">
<Filter>Core</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ELF\ElfReader.h">
@ -1932,6 +1935,9 @@
<ClInclude Include="MIPS\MIPSVFPUFallbacks.h">
<Filter>MIPS</Filter>
</ClInclude>
<ClInclude Include="ConfigSettings.h">
<Filter>Core</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE.TXT" />