summaryrefslogtreecommitdiffhomepage
path: root/src/con_.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2021-12-29 18:14:01 +0000
committerMichael Smith <mikesmiffy128@gmail.com>2021-12-29 18:18:42 +0000
commitd40d588f6d7cf866f7de41db9efffdd6c1a05135 (patch)
treecc1ff1eaecf3680815d7b30776f8b6264b0242e3 /src/con_.c
parent8eecc029568bbe8e2f3c0d9af218ad3f957251c9 (diff)
Make convar init macro type-generic
This removes the need to call atof() on each cvar on plugin load; now all that's required is the memory allocations for the string values. The syntax is also a bit nicer since numbers can just be numbers rather than quoted strings. Minor issue: specifying a string value that also happens to be numeric will break this since the numeric representation will be zero, but I can't see a reason this would ever happen. Also, add a DEF_CVAR_MAX just for completeness.
Diffstat (limited to 'src/con_.c')
-rw-r--r--src/con_.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/con_.c b/src/con_.c
index 54a8e9a..1c9d4a7 100644
--- a/src/con_.c
+++ b/src/con_.c
@@ -78,13 +78,11 @@ DECL_VFUNC_CDECL(void, ConsoleColorPrintf_l4d, 21, const struct con_colour *,
DECL_VFUNC_CDECL(void, ConsoleColorPrintf_p2, 24, const struct con_colour *,
const char *, ...)
-static void initval(struct con_var *v) {
+static inline void initval(struct con_var *v) {
// v->strlen is set to defaultval len in _DEF_CVAR so we don't need to call
// strlen() on each string :)
v->strval = extmalloc(v->strlen);
memcpy(v->strval, v->defaultval, v->strlen);
- // FIXME: technically this can be compile time too, using _Generic. Do that!
- v->fval = atof(v->strval); v->ival = v->fval;
}
// generated by build/codegen.c, defines regcmds() and freevars()