From 9d9398e764e4f1fce9ffbe8403784760fdee5131 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Fri, 21 Jul 2023 13:43:23 +0200 Subject: [PATCH] Add cvars.h header With macros for declaring cvar_t ptrs in source and header, registering new cvars and checking if the value is positive. Also cvars_init function and cv_bhop declaration --- src/include/cvars.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/include/cvars.h diff --git a/src/include/cvars.h b/src/include/cvars.h new file mode 100644 index 0000000..a22b475 --- /dev/null +++ b/src/include/cvars.h @@ -0,0 +1,38 @@ + +#ifndef _CVARS_H +#define _CVARS_H + +#include "sdk.h" +#include "globals.h" + +#define CVAR_PREFIX "cv_" +#define CVAR_HACK_ID 0x2000 /* (1<<13) */ + +/* + * DECL_CVAR: Declares cvar variable in source file. + * DECL_CVAR_EXTERN: Same but for headers. + * REGISTER_CVAR: Create the cvar, return cvar_t* + * CVAR_ON: Returns true if the cvar is non-zero + * + * prefix | meaning + * -------+------------------------------- + * cv_* | cvar variable + */ +#define DECL_CVAR(name) cvar_t* cv_##name = NULL; + +#define DECL_CVAR_EXTERN(name) extern cvar_t* cv_##name; + +#define REGISTER_CVAR(name, value) \ + i_engine->pfnRegisterVariable(CVAR_PREFIX name, value, CVAR_HACK_ID); + +#define CVAR_ON(name) (cv_##name->value != 0) + +/*----------------------------------------------------------------------------*/ + +DECL_CVAR_EXTERN(bhop); + +/*----------------------------------------------------------------------------*/ + +bool cvars_init(void); + +#endif /* _CVARS_H */