From 9b6518376c26b20889aa5a63fe7b7d7c89848567 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 13 Jan 2024 05:18:30 +0300 Subject: [PATCH] engine: cvar: add Cvar_DirectSetValue function --- engine/common/cvar.c | 18 ++++++++++++++++++ engine/common/cvar.h | 1 + 2 files changed, 19 insertions(+) diff --git a/engine/common/cvar.c b/engine/common/cvar.c index 78f34bb9..24d71ecb 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -736,6 +736,24 @@ void Cvar_DirectSet( convar_t *var, const char *value ) Cvar_Changed( var ); } +/* +============ +Cvar_DirectSetValue + +functionally is the same as Cvar_SetValue but for direct cvar access +============ +*/ +void Cvar_DirectSetValue( convar_t *var, float value ) +{ + char val[32]; + + if( fabs( value - (int)value ) < 0.000001 ) + Q_snprintf( val, sizeof( val ), "%d", (int)value ); + else Q_snprintf( val, sizeof( val ), "%f", value ); + + Cvar_DirectSet( var, val ); +} + /* ============ Cvar_FullSet diff --git a/engine/common/cvar.h b/engine/common/cvar.h index 7a162138..36040fe4 100644 --- a/engine/common/cvar.h +++ b/engine/common/cvar.h @@ -66,6 +66,7 @@ convar_t *Cvar_Getf( const char *var_name, int flags, const char *description, c void Cvar_LookupVars( int checkbit, void *buffer, void *ptr, setpair_t callback ); void Cvar_FullSet( const char *var_name, const char *value, int flags ); void Cvar_DirectSet( convar_t *var, const char *value ); +void Cvar_DirectSetValue( convar_t *var, float value ); void Cvar_Set( const char *var_name, const char *value ); void Cvar_SetValue( const char *var_name, float value ); const char *Cvar_BuildAutoDescription( const char *szName, int flags );