| 1 | /* |
| 2 | * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
| 3 | * It is copyright by its individual contributors, as recorded in the |
| 4 | * project's Git history. See COPYING.txt at the top level for license |
| 5 | * terms and a link to the Git history. |
| 6 | * |
| 7 | */ |
| 8 | /* |
| 9 | * |
| 10 | * Console variables |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #pragma once |
| 15 | |
| 16 | #include <cstdint> |
| 17 | #include <string> |
| 18 | #include <physfs.h> |
| 19 | #include "maths.h" |
| 20 | #include "dxxsconf.h" |
| 21 | |
| 22 | // cvar flags |
| 23 | #define CVAR_NONE 0 |
| 24 | #define CVAR_ARCHIVE 1 // save to descent.cfg |
| 25 | #define CVAR_CHEAT 512 // can not be changed if cheats are disabled |
| 26 | |
| 27 | // Other examples we could implement (from quake 3, see also iconvar.h from the Source sdk.) |
| 28 | //#define CVAR_USERINFO 2 // sent to server on connect or change |
| 29 | //#define CVAR_SERVERINFO 4 // sent in response to front end requests |
| 30 | //#define CVAR_SYSTEMINFO 8 // these cvars will be duplicated on all clients |
| 31 | //#define CVAR_INIT 16 // don't allow change from console at all, but can be set from the command line |
| 32 | //#define CVAR_LATCH 32 // will only change when C code next does a Cvar_Get(), so it can't be changed |
| 33 | // // without proper initialization. modified will be set, even though the value hasn't changed yet |
| 34 | //#define CVAR_ROM 64 // display only, cannot be set by user at all |
| 35 | //#define CVAR_USER_CREATED 128 // created by a set command |
| 36 | //#define CVAR_TEMP 256 // can be set even when cheats are disabled, but is not archived |
| 37 | //#define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued |
| 38 | |
| 39 | struct cvar_t |
| 40 | { |
| 41 | const char *name; |
| 42 | std::string string; |
| 43 | uint16_t flags; |
| 44 | fix value; |
| 45 | int intval; |
| 46 | |
| 47 | operator int() const { return intval; } |
| 48 | const char *operator=(const char *s); |
| 49 | int operator=(int i); |
| 50 | unsigned int operator=(unsigned int i) { return *this = static_cast<int>(i); } |
| 51 | }; |
| 52 | |
| 53 | void cvar_init(void); |
| 54 | void cvar_cmd_set(unsigned long, const char *const *const); |
| 55 | |
| 56 | /* Register a CVar with the name and string and optionally archive elements set */ |
| 57 | void cvar_registervariable (cvar_t &cvar); |
| 58 | |
| 59 | /* Set a CVar's value */ |
| 60 | void cvar_set_cvar(cvar_t *cvar, const char *value); |
| 61 | dxx_compiler_attribute_format_printf(2, 3) |
| 62 | void cvar_set_cvarf(cvar_t *cvar, const char *fmt, ...); |
| 63 | |
| 64 | /* Equivalent to typing <var_name> <value> at the console */ |
| 65 | void cvar_set(const char *cvar_name, char *value); |
| 66 | |
| 67 | /* Get the pointer to a cvar by name */ |
| 68 | cvar_t *cvar_find(const char *cvar_name); |
| 69 | |
| 70 | /* Try to autocomplete a cvar name */ |
| 71 | const char *cvar_complete(const char *text); |
| 72 | |
| 73 | /* Write archive cvars to file */ |
| 74 | void cvar_write(PHYSFS_File *file); |