From d40d588f6d7cf866f7de41db9efffdd6c1a05135 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Wed, 29 Dec 2021 18:14:01 +0000 Subject: 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. --- src/con_.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/con_.c') 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() -- cgit v1.2.3