cvar.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Copyright (C) 2009-2011 id Software LLC, a ZeniMax Media company.
  3. Copyright (C) 2004 Michael Liebscher
  4. Copyright (C) 1997-2001 Id Software, Inc.
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. * cvar.h: Dynamic variable tracking.
  19. *
  20. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  21. * Date: 2004
  22. *
  23. * Acknowledgement:
  24. * This code was derived from Quake II, and was originally
  25. * written by Id Software, Inc.
  26. *
  27. */
  28. /*
  29. Notes:
  30. Dynamic variable tracking.
  31. cvar_t variables are used to hold scalar or string variables
  32. that can be changed or displayed at the console or prog code
  33. as well as accessed directly in C code.
  34. The user can access cvars from the console in three ways:
  35. r_draworder -prints the current value
  36. r_draworder 0 -sets the current value to 0
  37. set r_draworder 0 -as above, but creates the cvar if not present
  38. Cvars are restricted from having the same names as commands to keep this
  39. module from being ambiguous.
  40. This module is implemented by cvar.c
  41. */
  42. #ifndef __CVAR_H__
  43. #define __CVAR_H__
  44. typedef enum _CVARFlags
  45. {
  46. CVAR_INIT = 0x0, // Just create it with no flag value.
  47. CVAR_ARCHIVE = 0x1, // Set to cause it to be saved to the config file
  48. CVAR_NOSET = 0x8, // Don't allow change from console at all,
  49. // but can be set from the command line.
  50. } CVARFlags;
  51. // nothing outside the Cvar_*() functions should modify these fields!
  52. typedef struct cvar_s {
  53. // By putting the value first, cvars can be referenced in other code
  54. // as just extern float *name, without having to include the cvar_t
  55. // declaration. This is probably a bad idea that I will
  56. // regret at some point.
  57. float value;
  58. char *name;
  59. char *string;
  60. char *defaultString;
  61. int hashid;
  62. int flags;
  63. boolean modified; // set each time the cvar is changed
  64. struct cvar_s *next;
  65. } cvar_t;
  66. extern cvar_t *cvar_vars;
  67. void Cvar_List_f();
  68. void Cvar_Reset_f();
  69. extern cvar_t *Cvar_Get( const char *var_name, const char *value, CVARFlags flags );
  70. // creates the variable if it doesn't exist, or returns the existing one
  71. // if it exists, the value will not be changed, but flags will be ORed in
  72. // that allows variables to be unarchived without needing bitflags
  73. extern cvar_t *Cvar_FindVar( const char *var_name );
  74. // returns NULL if it doesn't exist
  75. extern void Cvar_Set( const char *var_name, const char *value );
  76. // prints warning if it doesn't exist
  77. extern void Cvar_SetValue( const char *var_name, float value );
  78. // expands value to a string and calls Cvar_Set
  79. extern float Cvar_VariableValue( const char *var_name );
  80. // returns 0 if not defined or non numeric
  81. extern char *Cvar_VariableString( const char *var_name );
  82. // returns an empty string if not defined
  83. extern char *Cvar_CompleteVariable( const char *partial );
  84. // attempts to match a partial variable name for command line completion
  85. // returns NULL if nothing fits
  86. extern void Cvar_GetLatchedVars( void );
  87. // any CVAR_LATCHED variables that have been set will now take effect
  88. extern void Cvar_WriteVariables( const char *path );
  89. // appends lines containing "set variable value" for all variables
  90. // with the archive flag set to true.
  91. extern void Cvar_Init( void );
  92. extern char *Cvar_Userinfo( void );
  93. // returns an info string containing all the CVAR_USERINFO cvars
  94. extern char *Cvar_Serverinfo( void );
  95. // returns an info string containing all the CVAR_SERVERINFO cvars
  96. #endif /* __CVAR_H__ */