cvar.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. Copyright (C) 2004 Michael Liebscher
  3. Copyright (C) 1997-2001 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * cvar.h: Dynamic variable tracking.
  18. *
  19. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  20. * Date: 2004
  21. *
  22. * Acknowledgement:
  23. * This code was derived from Quake II, and was originally
  24. * written by Id Software, Inc.
  25. *
  26. */
  27. /*
  28. Notes:
  29. Dynamic variable tracking.
  30. cvar_t variables are used to hold scalar or string variables
  31. that can be changed or displayed at the console or prog code
  32. as well as accessed directly in C code.
  33. The user can access cvars from the console in three ways:
  34. r_draworder -prints the current value
  35. r_draworder 0 -sets the current value to 0
  36. set r_draworder 0 -as above, but creates the cvar if not present
  37. Cvars are restricted from having the same names as commands to keep this
  38. module from being ambiguous.
  39. This module is implemented by cvar.c
  40. */
  41. #ifndef __CVAR_H__
  42. #define __CVAR_H__
  43. #include "arch.h"
  44. #if 0
  45. typedef enum _CVARType
  46. {
  47. CVAR_DEFAULT = BIT( 0 ), // Just create it with no flag value.
  48. CVAR_BOOL = BIT( 0 ), // Set to cause it to be saved to vars.rc
  49. CVAR_INT = BIT( 0 ), // Added to userinfo when changed.
  50. CVAR_FLOAT = BIT( 0 ), // Added to serverinfo when changed.
  51. CVAR_STRING = BIT( 0 ), // Don't allow change from console at all,
  52. // but can be set from the command line.
  53. CVAR_LATCH = BIT( 0 ), // Save changes until server restart.
  54. } CVARType;
  55. #endif
  56. typedef enum _CVARFlags
  57. {
  58. CVAR_INIT = 0x0, // Just create it with no flag value.
  59. CVAR_ARCHIVE = 0x1, // Set to cause it to be saved to vars.rc
  60. CVAR_USERINFO = 0x2, // Added to userinfo when changed.
  61. CVAR_SERVERINFO = 0x4, // Added to serverinfo when changed.
  62. CVAR_NOSET = 0x8, // Don't allow change from console at all,
  63. // but can be set from the command line.
  64. CVAR_LATCH = 0x10, // Save changes until server restart.
  65. } CVARFlags;
  66. // nothing outside the Cvar_*() functions should modify these fields!
  67. typedef struct cvar_s
  68. {
  69. char *name;
  70. char *string;
  71. W32 id;
  72. char *latched_string; // for CVAR_LATCH vars
  73. int flags;
  74. _boolean modified; // set each time the cvar is changed
  75. float value;
  76. struct cvar_s *next;
  77. } cvar_t;
  78. extern cvar_t *cvar_vars;
  79. extern cvar_t *Cvar_Get( const char *var_name, const char *value, CVARFlags flags );
  80. // creates the variable if it doesn't exist, or returns the existing one
  81. // if it exists, the value will not be changed, but flags will be ORed in
  82. // that allows variables to be unarchived without needing bitflags
  83. extern cvar_t *Cvar_Set( const char *var_name, const char *value );
  84. // will create the variable if it doesn't exist
  85. extern cvar_t *Cvar_ForceSet( const char *var_name, const char *value );
  86. // will set the variable even if NOSET or LATCH
  87. extern cvar_t *Cvar_FullSet( const char *var_name, const char *value, CVARFlags flags );
  88. extern void Cvar_SetValue( const char *var_name, float value );
  89. // expands value to a string and calls Cvar_Set
  90. extern float Cvar_VariableValue( const char *var_name );
  91. // returns 0 if not defined or non numeric
  92. extern char *Cvar_VariableString( const char *var_name );
  93. // returns an empty string if not defined
  94. extern char *Cvar_CompleteVariable( const char *partial );
  95. // attempts to match a partial variable name for command line completion
  96. // returns NULL if nothing fits
  97. extern void Cvar_GetLatchedVars( void );
  98. // any CVAR_LATCHED variables that have been set will now take effect
  99. extern _boolean Cvar_Command( void );
  100. // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
  101. // command. Returns true if the command was a variable reference that
  102. // was handled. (print or change)
  103. extern void Cvar_WriteVariables( const char *path );
  104. // appends lines containing "set variable value" for all variables
  105. // with the archive flag set to true.
  106. extern void Cvar_Init( void );
  107. extern char *Cvar_Userinfo( void );
  108. // returns an info string containing all the CVAR_USERINFO cvars
  109. extern char *Cvar_Serverinfo( void );
  110. // returns an info string containing all the CVAR_SERVERINFO cvars
  111. extern _boolean userinfo_modified;
  112. // this is set each time a CVAR_USERINFO variable is changed
  113. // so that the client knows to send it to the server
  114. #endif /* __CVAR_H__ */