cvar.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // cvar.h
  16. /*
  17. cvar_t variables are used to hold scalar or string variables that can be changed or displayed at the console or prog code as well as accessed directly
  18. in C code.
  19. it is sufficient to initialize a cvar_t with just the first two fields, or
  20. you can add a ,true flag for variables that you want saved to the configuration
  21. file when the game is quit:
  22. cvar_t r_draworder = {"r_draworder","1"};
  23. cvar_t scr_screensize = {"screensize","1",true};
  24. Cvars must be registered before use, or they will have a 0 value instead of the float interpretation of the string. Generally, all cvar_t declarations should be registered in the apropriate init function before any console commands are executed:
  25. Cvar_RegisterVariable (&host_framerate);
  26. C code usually just references a cvar in place:
  27. if ( r_draworder.value )
  28. It could optionally ask for the value to be looked up for a string name:
  29. if (Cvar_VariableValue ("r_draworder"))
  30. Interpreted prog code can access cvars with the cvar(name) or
  31. cvar_set (name, value) internal functions:
  32. teamplay = cvar("teamplay");
  33. cvar_set ("registered", "1");
  34. The user can access cvars from the console in two ways:
  35. r_draworder prints the current value
  36. r_draworder 0 sets the current value to 0
  37. Cvars are restricted from having the same names as commands to keep this
  38. interface from being ambiguous.
  39. */
  40. typedef struct cvar_s
  41. {
  42. char *name;
  43. char *string;
  44. qboolean archive; // set to true to cause it to be saved to vars.rc
  45. qboolean info; // added to serverinfo or userinfo when changed
  46. float value;
  47. struct cvar_s *next;
  48. } cvar_t;
  49. void Cvar_RegisterVariable (cvar_t *variable);
  50. // registers a cvar that allready has the name, string, and optionally the
  51. // archive elements set.
  52. void Cvar_Set (char *var_name, char *value);
  53. // equivelant to "<name> <variable>" typed at the console
  54. void Cvar_SetValue (char *var_name, float value);
  55. // expands value to a string and calls Cvar_Set
  56. float Cvar_VariableValue (char *var_name);
  57. // returns 0 if not defined or non numeric
  58. char *Cvar_VariableString (char *var_name);
  59. // returns an empty string if not defined
  60. char *Cvar_CompleteVariable (char *partial);
  61. // attempts to match a partial variable name for command line completion
  62. // returns NULL if nothing fits
  63. qboolean Cvar_Command (void);
  64. // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
  65. // command. Returns true if the command was a variable reference that
  66. // was handled. (print or change)
  67. void Cvar_WriteVariables (FILE *f);
  68. // Writes lines containing "set variable value" for all variables
  69. // with the archive flag set to true.
  70. cvar_t *Cvar_FindVar (char *var_name);
  71. extern cvar_t *cvar_vars;