Reintroduce setRaw dvar methods

- Makes it possible to set the value of a dvar without using the game's way of first converting it to a string and checking all kinds of dvar flags
This commit is contained in:
Jan 2021-09-10 11:40:30 +02:00
parent e8185a27b9
commit cc39a7bbe5
2 changed files with 34 additions and 0 deletions

View File

@ -134,6 +134,36 @@ namespace Components
}
}
void Dvar::Var::setRaw(int integer)
{
assert(this->dvar->type == Game::DVAR_TYPE_INT);
if (this->dvar)
{
this->dvar->current.integer = integer;
this->dvar->latched.integer = integer;
}
}
void Dvar::Var::setRaw(float value)
{
assert(this->dvar->type == Game::DVAR_TYPE_FLOAT);
if (this->dvar)
{
this->dvar->current.value = value;
this->dvar->latched.value = value;
}
}
void Dvar::Var::setRaw(bool enabled)
{
assert(this->dvar->type == Game::DVAR_TYPE_BOOL);
if (this->dvar)
{
this->dvar->current.enabled = enabled;
this->dvar->latched.enabled = enabled;
}
}
template<> static Dvar::Var Dvar::Register(const char* name, bool value, Dvar::Flag flag, const char* description)
{
return Game::Dvar_RegisterBool(name, value, flag.val, description);

View File

@ -33,6 +33,10 @@ namespace Components
void set(float value);
void set(bool enabled);
void setRaw(int integer);
void setRaw(float value);
void setRaw(bool enabled);
private:
Game::dvar_t* dvar;
};