|
Odamex
Setting the Standard in Multiplayer Doom
|
00001 // Emacs style mode select -*- C++ -*- 00002 //----------------------------------------------------------------------------- 00003 // 00004 // $Id: c_cvars.h 1788 2010-08-24 04:42:57Z russellrice $ 00005 // 00006 // Copyright (C) 1998-2006 by Randy Heit (ZDoom). 00007 // Copyright (C) 2006-2010 by The Odamex Team. 00008 // 00009 // This program is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 2 00012 // of the License, or (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // DESCRIPTION: 00020 // Command-line variables 00021 // 00022 //----------------------------------------------------------------------------- 00023 00024 00025 #ifndef __C_CVARS_H__ 00026 #define __C_CVARS_H__ 00027 00028 #include "doomtype.h" 00029 #include "tarray.h" 00030 00031 #include <string> 00032 00033 /* 00034 ========================================================== 00035 00036 CVARS (console variables) 00037 00038 ========================================================== 00039 */ 00040 00041 #define CVAR_NULL 0 // [deathz0r] no special properties 00042 #define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc 00043 #define CVAR_USERINFO 2 // added to userinfo when changed 00044 #define CVAR_SERVERINFO 4 // [Toke - todo] Changed the meaning of this flag 00045 // it now describes cvars that clients will be 00046 // informed if changed 00047 #define CVAR_NOSET 8 // don't allow change from console at all, 00048 // but can be set from the command line 00049 #define CVAR_LATCH 16 // save changes until server restart 00050 #define CVAR_UNSETTABLE 32 // can unset this var from console 00051 #define CVAR_DEMOSAVE 64 // save the value of this cvar_t in a demo 00052 #define CVAR_MODIFIED 128 // set each time the cvar_t is changed 00053 #define CVAR_ISDEFAULT 256 // is cvar unchanged since creation? 00054 #define CVAR_AUTO 512 // allocated, needs to be freed when destroyed 00055 #define CVAR_NOENABLEDISABLE 1024 // [Nes] No substitution (0=disable, 1=enable) 00056 #define CVAR_CLIENTINFO 2048 // [Russell] client version of CVAR_SERVERINFO 00057 #define CVAR_SERVERARCHIVE 4096 // [Nes] Server version of CVAR_ARCHIVE 00058 #define CVAR_CLIENTARCHIVE 8192 // [Nes] Client version of CVAR_ARCHIVE 00059 00060 00061 class cvar_t 00062 { 00063 public: 00064 cvar_t (const char *name, const char *def, DWORD flags); 00065 cvar_t (const char *name, const char *def, DWORD flags, void (*callback)(cvar_t &)); 00066 virtual ~cvar_t (); 00067 00068 const char *cstring() const {return m_String.c_str(); } 00069 const char *name() const { return m_Name.c_str(); } 00070 const char *latched() const { return m_LatchedString.c_str(); } 00071 float value() const { return m_Value; } 00072 operator float () const { return m_Value; } 00073 unsigned int flags() const { return m_Flags; } 00074 00075 inline void Callback () { if (m_Callback) m_Callback (*this); } 00076 00077 void SetDefault (const char *value); 00078 void Set (const char *value); 00079 void Set (float value); 00080 void ForceSet (const char *value); 00081 void ForceSet (float value); 00082 00083 static void EnableNoSet (); // enable the honoring of CVAR_NOSET 00084 static void EnableCallbacks (); 00085 00086 unsigned int m_Flags; 00087 00088 // Writes all cvars that could effect demo sync to *demo_p. These are 00089 // cvars that have either CVAR_SERVERINFO or CVAR_DEMOSAVE set. 00090 static void C_WriteCVars (byte **demo_p, DWORD filter, bool compact=false); 00091 00092 // Read all cvars from *demo_p and set them appropriately. 00093 static void C_ReadCVars (byte **demo_p); 00094 00095 // Backup demo cvars. Called before a demo starts playing to save all 00096 // cvars the demo might change. 00097 static void C_BackupCVars (void); 00098 00099 // Restore demo cvars. Called after demo playback to restore all cvars 00100 // that might possibly have been changed during the course of demo playback. 00101 static void C_RestoreCVars (void); 00102 00103 // Finds a named cvar 00104 static cvar_t *FindCVar (const char *var_name, cvar_t **prev); 00105 00106 // Called from G_InitNew() 00107 static void UnlatchCVars (void); 00108 00109 // archive cvars to FILE f 00110 static void C_ArchiveCVars (void *f); 00111 00112 // initialize cvars to default values after they are created 00113 static void C_SetCVarsToDefaults (void); 00114 00115 static bool SetServerVar (const char *name, const char *value); 00116 00117 static void FilterCompactCVars (TArray<cvar_t *> &cvars, DWORD filter); 00118 00119 // console variable interaction 00120 static cvar_t *cvar_set (const char *var_name, const char *value); 00121 static cvar_t *cvar_forceset (const char *var_name, const char *value); 00122 00123 static void cvarlist(); 00124 00125 cvar_t &operator = (float other) { ForceSet(other); return *this; } 00126 cvar_t &operator = (const char *other) { ForceSet(other); return *this; } 00127 00128 cvar_t *GetNext() { return m_Next; } 00129 00130 private: 00131 00132 cvar_t (const cvar_t &var) {} 00133 00134 void InitSelf (const char *name, const char *def, DWORD flags, void (*callback)(cvar_t &)); 00135 void (*m_Callback)(cvar_t &); 00136 cvar_t *m_Next; 00137 00138 std::string m_Name, m_String; 00139 float m_Value; 00140 00141 std::string m_LatchedString, m_Default; 00142 00143 static bool m_UseCallback; 00144 static bool m_DoNoSet; 00145 00146 protected: 00147 00148 cvar_t () : m_Flags(0), m_Name(0), m_String(0), m_Value(0.f) {} 00149 }; 00150 00151 cvar_t* GetFirstCvar(void); 00152 00153 // Maximum number of cvars that can be saved across a demo. If you need 00154 // to save more, bump this up. 00155 #define MAX_DEMOCVARS 32 00156 00157 #define BEGIN_CUSTOM_CVAR(name,def,flags) \ 00158 static void cvarfunc_##name(cvar_t &); \ 00159 cvar_t name (#name, def, flags, cvarfunc_##name); \ 00160 static void cvarfunc_##name(cvar_t &var) 00161 00162 #define END_CUSTOM_CVAR(name) 00163 00164 #define CUSTOM_CVAR(type,name,def,flags) \ 00165 static void cvarfunc_##name(F##type##CVar &); \ 00166 F##type##CVar name (#name, def, flags, cvarfunc_##name); \ 00167 static void cvarfunc_##name(F##type##CVar &self) 00168 00169 #define CVAR(name,def,flags) \ 00170 cvar_t name (#name, def, flags); 00171 00172 #define EXTERN_CVAR(name) extern cvar_t name; 00173 00174 #define CVAR_FUNC_DECL(name,def,flags) \ 00175 extern void cvarfunc_##name(cvar_t &); \ 00176 cvar_t name (#name, def, flags, cvarfunc_##name); 00177 00178 #define CVAR_FUNC_IMPL(name) \ 00179 EXTERN_CVAR(name) \ 00180 void cvarfunc_##name(cvar_t &var) 00181 00182 #endif //__C_CVARS_H__