Browse Source

engine: cvar: move common checks if cvar can be updated into generic function

pull/4/head
Alibek Omarov 12 months ago
parent
commit
6c3fee7f27
  1. 51
      engine/common/cvar.c

51
engine/common/cvar.c

@ -563,6 +563,27 @@ void Cvar_RegisterVariable( convar_t *var )
#endif #endif
} }
static qboolean Cvar_CanSet( const convar_t *cv )
{
if( FBitSet( cv->flags, FCVAR_READ_ONLY ))
{
Con_Printf( "%s is read-only.\n", cv->name );
return false;
}
if( FBitSet( cv->flags, FCVAR_CHEAT ) && !host.allow_cheats )
{
Con_Printf( "%s is cheat protected.\n", cv->name );
return false;
}
// just tell user about deferred changes
if( FBitSet( cv->flags, FCVAR_LATCH ) && ( SV_Active() || CL_Active( )))
Con_Printf( "%s will be changed upon restarting.\n", cv->name );
return true;
}
/* /*
============ ============
Cvar_Set2 Cvar_Set2
@ -633,23 +654,10 @@ static convar_t *Cvar_Set2( const char *var_name, const char *value )
if( !force ) if( !force )
{ {
if( FBitSet( var->flags, FCVAR_READ_ONLY )) if( !Cvar_CanSet( var ))
{
Con_Printf( "%s is read-only.\n", var->name );
return var; return var;
} }
if( FBitSet( var->flags, FCVAR_CHEAT ) && !host.allow_cheats )
{
Con_Printf( "%s is cheat protected.\n", var->name );
return var;
}
// just tell user about deferred changes
if( FBitSet( var->flags, FCVAR_LATCH ) && ( SV_Active() || CL_Active( )))
Con_Printf( "%s will be changed upon restarting.\n", var->name );
}
pszValue = Cvar_ValidateString( var, value ); pszValue = Cvar_ValidateString( var, value );
// nothing to change // nothing to change
@ -694,21 +702,8 @@ void Cvar_DirectSet( convar_t *var, const char *value )
return; // how this possible? return; // how this possible?
} }
if( FBitSet( var->flags, FCVAR_READ_ONLY )) if( !Cvar_CanSet( var ))
{
Con_Printf( "%s is read-only.\n", var->name );
return; return;
}
if( FBitSet( var->flags, FCVAR_CHEAT ) && !host.allow_cheats )
{
Con_Printf( "%s is cheat protected.\n", var->name );
return;
}
// just tell user about deferred changes
if( FBitSet( var->flags, FCVAR_LATCH ) && ( SV_Active() || CL_Active( )))
Con_Printf( "%s will be changed upon restarting.\n", var->name );
// check value // check value
if( !value ) if( !value )

Loading…
Cancel
Save