From: TimePath Date: Sun, 30 Aug 2015 05:18:33 +0000 (+1000) Subject: AUTOCVAR macro; translatable descriptions and initialization in one place X-Git-Tag: xonotic-v0.8.2~1986 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a00de23c6c014d3684036b2afc4ee63db8fc9807;p=xonotic%2Fxonotic-data.pk3dir.git AUTOCVAR macro; translatable descriptions and initialization in one place --- diff --git a/qcsrc/common/mutators/mutator/damagetext.qc b/qcsrc/common/mutators/mutator/damagetext.qc index 44648ab80..23301fe94 100644 --- a/qcsrc/common/mutators/mutator/damagetext.qc +++ b/qcsrc/common/mutators/mutator/damagetext.qc @@ -1,27 +1,15 @@ REGISTER_MUTATOR(damagetext, true); #if defined(CSQC) || defined(MENUQC) -bool autocvar_cl_damagetext = false; -string autocvar_cl_damagetext_format = "-%3$d"; -vector autocvar_cl_damagetext_color = '1 1 0'; -float autocvar_cl_damagetext_size = 8; -float autocvar_cl_damagetext_alpha_start = 1; -float autocvar_cl_damagetext_alpha_lifetime = 3; -vector autocvar_cl_damagetext_velocity = '0 0 20'; -vector autocvar_cl_damagetext_offset = '0 -40 0'; -float autocvar_cl_damagetext_accumulate_range = 30; - -STATIC_INIT(cl_damagetext) { - CVAR_DESCRIBE(cl_damagetext, _("Draw damage dealt. 0: disabled, 1: enabled")); - CVAR_DESCRIBESTR(cl_damagetext_format, _("How to format the damage text. 1$ is health, 2$ is armor, 3$ is both")); - CVAR_DESCRIBEVEC(cl_damagetext_color, _("Default damage text color")); - CVAR_DESCRIBE(cl_damagetext_size, _("Damage text font size")); - CVAR_DESCRIBE(cl_damagetext_alpha_start, _("Damage text initial alpha")); - CVAR_DESCRIBE(cl_damagetext_alpha_lifetime, _("Damage text lifetime in seconds")); - CVAR_DESCRIBEVEC(cl_damagetext_velocity, _("Damage text move direction")); - CVAR_DESCRIBEVEC(cl_damagetext_offset, _("Damage text offset")); - CVAR_DESCRIBE(cl_damagetext_accumulate_range, _("Damage text spawned within this range is accumulated")); -} +AUTOCVAR(cl_damagetext, bool, false, _("Draw damage dealt. 0: disabled, 1: enabled")); +AUTOCVAR(cl_damagetext_format, string, "-%3$d", _("How to format the damage text. 1$ is health, 2$ is armor, 3$ is both")); +AUTOCVAR(cl_damagetext_color, vector, '1 1 0', _("Default damage text color")); +AUTOCVAR(cl_damagetext_size, float, 8, _("Damage text font size")); +AUTOCVAR(cl_damagetext_alpha_start, float, 1, _("Damage text initial alpha")); +AUTOCVAR(cl_damagetext_alpha_lifetime, float, 3, _("Damage text lifetime in seconds")); +AUTOCVAR(cl_damagetext_velocity, vector, '0 0 20', _("Damage text move direction")); +AUTOCVAR(cl_damagetext_offset, vector, '0 -40 0', _("Damage text offset")); +AUTOCVAR(cl_damagetext_accumulate_range, float, 30, _("Damage text spawned within this range is accumulated")); #endif #ifdef CSQC diff --git a/qcsrc/lib/Cvar.qh b/qcsrc/lib/Cvar.qh index 98d5b041c..210a84c0c 100644 --- a/qcsrc/lib/Cvar.qh +++ b/qcsrc/lib/Cvar.qh @@ -1,8 +1,13 @@ #ifndef CVAR_H #define CVAR_H -#define CVAR_DESCRIBE(var, desc) localcmd(sprintf("\nseta %s \"%s\" \"%s\"\n", #var, ftos(autocvar_##var), desc)) -#define CVAR_DESCRIBESTR(var, desc) localcmd(sprintf("\nseta %s \"%s\" \"%s\"\n", #var, autocvar_##var, desc)) -#define CVAR_DESCRIBEVEC(var, desc) localcmd(sprintf("\nseta %s \"%v\" \"%s\"\n", #var, autocvar_##var, desc)) +#define CVAR_DESCRIBE(var, desc) localcmd(sprintf("\nseta %1$s \"$%1$s\" \"%2$s\"\n", #var, desc)) + +#define AUTOCVAR_3(var, type, desc) \ + STATIC_INIT(autocvar_##var) { CVAR_DESCRIBE(var, desc); } \ + type autocvar_##var +#define AUTOCVAR_4(var, type, default, desc) \ + AUTOCVAR_3(var, type, desc) = default +#define AUTOCVAR(...) OVERLOAD(AUTOCVAR, __VA_ARGS__) #endif