Add int variant of CVar_ Get/Set/Register

This commit is contained in:
Baoulettes 2022-04-23 04:47:38 +02:00 committed by GitHub
parent 2108606c09
commit 12a676a858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,6 +47,17 @@ extern "C" char* CVar_GetString(const char* name, char* defaultValue) {
return defaultValue;
}
extern "C" int CVar_GetInt(const char* name, int defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar != nullptr) {
if (cvar->type == CVAR_TYPE_INT)
return cvar->value.valueInt;
}
return defaultValue;
}
extern "C" void CVar_SetS32(const char* name, s32 value) {
CVar* cvar = CVar_Get(name);
if (!cvar) {
@ -77,6 +88,15 @@ void CVar_SetString(const char* name, char* value) {
cvar->value.valueStr = value;
}
void CVar_SetInt(const char* name, int value) {
CVar* cvar = CVar_Get(name);
if (!cvar) {
cvar = new CVar;
cvars[std::string(name)] = cvar;
}
cvar->type = CVAR_TYPE_INT;
cvar->value.valueInt = value;
}
extern "C" void CVar_RegisterS32(const char* name, s32 defaultValue) {
CVar* cvar = CVar_Get(name);
@ -98,3 +118,10 @@ extern "C" void CVar_RegisterString(const char* name, char* defaultValue) {
if (cvar == nullptr)
CVar_SetString(name, defaultValue);
}
extern "C" void CVar_RegisterInt(const char* name, int defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar == nullptr)
CVar_SetInt(name, defaultValue);
}