1 /* 2 Copyright (C) 1996-1997 Id Software, Inc. 3 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 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. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 20 */ 21 22 // cvar.h 23 #ifndef __CVAR_H__ 24 #define __CVAR_H__ 25 26 /* 27 28 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 29 in C code. 30 31 it is sufficient to initialize a cvar_t with just the first two fields, or 32 you can add a ,true flag for variables that you want saved to the configuration 33 file when the game is quit: 34 35 cvar_t r_draworder = {"r_draworder","1"}; 36 cvar_t scr_screensize = {"screensize","1",CVAR_ARCHIVE}; 37 38 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: 39 Cvar_Register (&host_framerate); 40 41 42 C code usually just references a cvar in place: 43 if ( r_draworder.value ) 44 45 It could optionally ask for the value to be looked up for a string name: 46 if (Cvar_Value ("r_draworder")) 47 48 Interpreted prog code can access cvars with the cvar(name) or 49 cvar_set (name, value) internal functions: 50 teamplay = cvar("teamplay"); 51 cvar_set ("registered", "1"); 52 53 The user can access cvars from the console in two ways: 54 r_draworder prints the current value 55 r_draworder 0 sets the current value to 0 56 Cvars are restricted from having the same names as commands to keep this 57 interface from being ambiguous. 58 */ 59 60 // cvar flags 61 #define CVAR_NONE (0) 62 #define CVAR_SERVERINFO (1<<0) // mirrored to serverinfo 63 #define CVAR_ROM (1<<1) // read only 64 #define CVAR_USER_CREATED (1<<2) // created by a set command 65 66 typedef struct cvar_s 67 { 68 char *name; 69 char *string; 70 int flags; 71 void (*OnChange) (struct cvar_s *var, char *value, qbool *cancel); 72 float value; 73 struct cvar_s *hash_next; 74 struct cvar_s *next; 75 } cvar_t; 76 77 #define Cvar_SetCurrentGroup(...) // ezquake compatibility 78 #define Cvar_ResetCurrentGroup(...) // ezquake compatibility 79 80 void Cvar_Register (cvar_t *variable); 81 // registers a cvar that already has the name, string, and optionally the 82 // archive elements set. 83 84 void Cvar_Set (cvar_t *var, char *value); 85 // equivalent to "<name> <variable>" typed at the console 86 87 void Cvar_SetROM (cvar_t *var, char *value); 88 // force a set even if the cvar is read only 89 90 void Cvar_SetByName (const char *var_name, char *value); 91 // equivalent to "<name> <variable>" typed at the console 92 93 void Cvar_SetValue (cvar_t *var, const float value); 94 // expands value to a string and calls Cvar_Set 95 96 void Cvar_SetValueByName (const char *var_name, const float value); 97 // expands value to a string and calls Cvar_Set 98 99 float Cvar_Value (const char *var_name); 100 // returns 0 if not defined or non numeric 101 102 char *Cvar_String (const char *var_name); 103 // returns an empty string if not defined 104 105 qbool Cvar_Command (void); 106 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known 107 // command. Returns true if the command was a variable reference that 108 // was handled. (print or change) 109 110 // Use this to walk through all vars 111 cvar_t *Cvar_Next (cvar_t *var); 112 113 int Cvar_GetFlags (cvar_t *var); 114 115 cvar_t *Cvar_Find (const char *var_name); 116 qbool Cvar_Delete (const char *name); 117 118 cvar_t *Cvar_Create (const char *name, char *string, int cvarflags); 119 120 void Cvar_Init (void); 121 122 char* Cvar_ServerInfoValue(char* key, char* value); 123 124 #endif /* !__CVAR_H__ */ 125