32 #include "../shared/infostring.h"
35 #define CVAR_HASH_SIZE 64
96 return s[strcspn(s,
"\\\";")] ==
'\0';
111 if (
Q_streq(varName, var->name))
143 Com_Printf(
"Could not set check function for cvar '%s'\n", varName);
165 if (shouldBeIntegral) {
173 if (cvar->
value < minVal) {
174 Com_Printf(
"WARNING: cvar '%s' out of range (%f < %f)\n", cvar->
name, cvar->
value, minVal);
177 }
else if (cvar->
value > maxVal) {
178 Com_Printf(
"WARNING: cvar '%s' out of range (%f > %f)\n", cvar->
name, cvar->
value, maxVal);
261 for (
cvar_t const* cvar = cvarVars; cvar; cvar = cvar->
next) {
267 Com_Printf(
"[var] %-20s = \"%s\"\n", cvar->name, cvar->string);
268 if (cvar->description)
282 for (
cvar_t** anchor = &cvarVarsHash[hash]; *anchor; anchor = &(*anchor)->
hash_next) {
283 cvar_t*
const var = *anchor;
285 if (var->
flags != 0) {
286 Com_Printf(
"Can't delete the cvar '%s' - it's a special cvar\n", varName);
294 cvarVars = var->
next;
312 while (changeListener) {
315 changeListener = changeListener2;
322 Com_Printf(
"Cvar '%s' wasn't found\n", varName);
342 cvar_t*
Cvar_Get (
const char* var_name,
const char* var_value,
int flags,
const char* desc)
354 if (!var->defaultString && (flags &
CVAR_CHEAT))
369 Com_Printf(
"invalid info cvar value '%s' of cvar '%s'\n", var_value, var_name);
429 listener = listener->
next;
436 listener->
exec = listenerFunc;
450 Com_Printf(
"Could not register change listener, cvar '%s' wasn't found\n", varName);
461 if (l->
exec == listenerFunc) {
491 Com_Printf(
"Could not unregister change listener, cvar '%s' wasn't found\n", varName);
497 if (l->
exec == listenerFunc) {
524 Com_Printf(
"invalid info cvar value '%s' of cvar '%s'\n", value, varName);
531 Com_Printf(
"%s is write protected.\n", varName);
536 Com_Printf(
"%s is a developer cvar.\n", varName);
554 Com_Printf(
"%s will be changed for next game.\n", varName);
565 Com_Printf(
"Invalid value for cvar %s\n", varName);
592 Com_Printf(
"Invalid value for cvar %s\n", varName);
619 va_start(argptr, value);
648 return Cvar_Get(varName, value, flags);
673 if (value == (
int) value)
674 Cvar_Set(varName,
"%i", (
int)value);
685 for (
cvar_t* var = cvarVars; var; var = var->
next) {
686 if (!var->latchedString)
688 var->oldString = var->string;
689 var->string = var->latchedString;
690 var->latchedString =
nullptr;
691 var->value = atof(var->string);
692 var->integer = atoi(var->string);
764 if (c != 3 && c != 4) {
779 while (arg[0] !=
'\0') {
791 Com_Printf(
"Invalid flags %c given\n", arg[0]);
808 if (c != 2 && c != 3) {
823 while (arg[0] !=
'\0') {
835 Com_Printf(
"Invalid flags %c given\n", arg[0]);
870 for (
const cvar_t* var = cvarVars; var; var = var->
next) {
883 for (
const cvar_t* var = cvarVars; var; var = var->
next) {
884 if ((var->flags & flags) && var->modified)
893 for (
cvar_t* var = cvarVars; var; var = var->
next) {
894 if (var->flags & flags)
895 var->modified =
false;
905 const char* token =
nullptr;
914 for (
cvar_t* var = cvarVars; var; var = var->
next, i++) {
915 if (token && strncmp(var->name, token, l)) {
933 Com_Printf(
" %-20s \"%s\"\n", var->name, var->string);
934 if (var->description)
945 "-: Not changeable\n"
957 for (
cvar_t* var = cvarVars; var; var = var->
next) {
958 if (var->flags & bit)
1047 for (
cvar_t* var = cvarVars; var; var = var->
next) {
1051 if (!var->defaultString) {
1052 Com_Printf(
"Cheat cvars: Cvar %s has no default value\n", var->name);
1056 if (
Q_streq(var->string, var->defaultString))
1061 var->oldString =
nullptr;
1064 var->value = atof(var->string);
1065 var->integer = atoi(var->string);
1067 Com_Printf(
"'%s' is a cheat cvar - activate sv_cheats to use it.\n", var->name);
1072 void Cvar_PrintDebugCvars (
void)
1075 for (
const cvar_t* var = cvarVars; var; var = var->
next) {
1076 if ((var->flags &
CVAR_DEVELOPER) || !strncmp(var->name,
"debug_", 6))
1077 Com_Printf(
" * %s (%s)\n %s\n", var->name, var->string, var->description ? var->description :
"");
void Com_SetRenderModified(bool modified)
const char * Cmd_Argv(int arg)
Returns a given argument.
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
cvarChangeListener_t * Cvar_RegisterChangeListener(const char *varName, cvarChangeListenerFunc_t listenerFunc)
Registers a listener that is executed each time a cvar changed its value.
static bool userinfoModified
This is set each time a CVAR_USERINFO variable is changed so that the client knows to send it to the ...
void Cvar_UnRegisterChangeListener(const char *varName, cvarChangeListenerFunc_t listenerFunc)
Unregisters a cvar change listener.
struct cvar_s * hash_next
#define HASH_Delete(anchor)
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
bool Cvar_AssertValue(cvar_t *cvar, float minVal, float maxVal, bool shouldBeIntegral)
Checks cvar values.
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
static cvarChangeListener_t * Cvar_GetChangeListener(cvarChangeListenerFunc_t listenerFunc)
const char * Cvar_Serverinfo(char *info, size_t infoSize)
Returns an info string containing all the CVAR_SERVERINFO cvars.
static void Cvar_Switch_f(void)
Allows switching boolean cvars between zero and not-zero from console.
void(* cvarChangeListenerFunc_t)(const char *cvarName, const char *oldValue, const char *newValue, void *data)
Callback for the change listener.
static void Cvar_Copy_f(void)
Allows copying variables Available via console command copy.
void Cvar_UnRegisterCvarListener(CvarListenerPtr listener)
Unregisters a cvar listener.
void Cvar_UpdateLatchedVars(void)
Any variables with latched values will now be updated.
void Com_Printf(const char *const fmt,...)
bool Cmd_GenericCompleteFunction(char const *candidate, char const *partial, char const **match)
static void Cvar_Mod_f(void)
Apply a modulo to a cvar.
bool Cvar_PendingCvars(int flags)
Checks whether there are pending cvars for the given flags.
int Cvar_GetInteger(const char *varName)
Returns the int value of a cvar.
static void Cvar_Define_f(void)
static char * Cvar_BitInfo(int bit, char *info, size_t infoSize)
Return a string with all cvars with bitflag given by parameter set.
cvar_t * Cvar_GetFirst(void)
Return the first cvar of the cvar list.
bool Cvar_Command(void)
Handles variable inspection and changing from the console.
cvarChangeListenerFunc_t exec
static void Cvar_ExecuteChangeListener(const cvar_t *cvar)
Executes the change listeners for a cvar.
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
void Cvar_Init(void)
Reads in all archived cvars.
float Cvar_GetValue(const char *varName)
Returns the float value of a cvar.
void Cvar_RegisterCvarListener(CvarListenerPtr listener)
Registers a cvar listener.
static wrapCache_t * hash[MAX_WRAP_HASH]
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
const char * Cvar_VariableStringOld(const char *varName)
Returns the old value of cvar as string before we changed it.
int FS_Printf(qFILE *f, const char *msg,...)
Can print chunks for 1024 chars into a file.
bool Com_IsUserinfoModified(void)
#define Q_strcasecmp(a, b)
memPool_t * com_cvarSysPool
#define HASH_Add(hash, elem, index)
void Cvar_FixCheatVars(void)
Reset cheat cvar values to default.
bool Cvar_Delete(const char *varName)
Function to remove the cvar and free the space.
static void Cvar_Add_f(void)
Add a value to a cvar.
static void Cvar_Set_f(void)
Allows setting and defining of arbitrary cvars from console.
cvar_t * Cvar_FullSet(const char *varName, const char *value, int flags)
Sets a cvar from console with the given flags.
void Info_SetValueForKey(char *s, const size_t size, const char *key, const char *value)
Adds a new entry into string with given value.
void Cvar_Reset(cvar_t *cvar)
Sets the cvar value back to the old value.
cvarChangeListener_t * changeListener
std::vector< CvarListenerPtr > CvarListeners
bool Com_IsRenderModified(void)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
static void Cvar_List_f(void)
List all cvars via console command 'cvarlist'.
unsigned int Com_HashKey(const char *name, int hashsize)
returns hash key for a string
const char * Cvar_Userinfo(char *info, size_t infoSize)
Returns an info string containing all the CVAR_USERINFO cvars.
bool(* check)(struct cvar_s *cvar)
definitions common between client and server, but not game lib
static CvarListeners cvarListeners
static cvar_t * Cvar_Set2(const char *varName, const char *value, bool force)
Sets a cvar values Handles write protection and latched cvars as expected.
cvar_t * Cvar_ForceSet(const char *varName, const char *value)
Will set the variable even if NOSET or LATCH.
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
struct cvarChangeListener_s * next
const char * Cvar_GetString(const char *varName)
Returns the value of cvar as string.
#define Mem_PoolStrDup(in, pool, tagNum)
static void Cvar_Del_f(void)
Delete a cvar - set [cvar] "" isn't working from within the scripts.
static cvar_t * cvarVarsHash[CVAR_HASH_SIZE]
static void Cvar_SetOld_f(void)
Allows resetting cvars to old value from console.
#define Mem_PoolAllocType(type, pool)
void Cvar_ClearVars(int flags)
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
int Cvar_CompleteVariable(const char *partial, const char **match)
Unix like tab completion for console variables.
QGL_EXTERN int GLboolean GLfloat * v
cvar_t * Cvar_FindVar(const char *varName)
Searches for a cvar given by parameter.
int Com_ServerState(void)
Check whether we are the server or have a singleplayer tactical mission.
void Cvar_WriteVariables(qFILE *f)
appends lines containing "set variable value" for all variables with the archive flag set to true...
bool Cvar_SetCheckFunction(const char *varName, bool(*check)(cvar_t *cvar))
Set a checker function for cvar values.
void Com_SetUserinfoModified(bool modified)
static bool renderModified
This is set each time a CVAR_USERINFO variable is changed so that the renderer knows to update stuff ...
static bool Cvar_InfoValidate(const char *s)
Check that the Cvar identifier name doesn't contain a backslash, a double quote or a semi-colon...
static cvar_t * cvarVars
Cvar list.