mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 08:51:24 +00:00
type safe CVAR declaration.
This commit is contained in:
parent
db5fcde0db
commit
1111251887
9 changed files with 43 additions and 35 deletions
|
@ -75,12 +75,12 @@ CUSTOM_CVAR(Int, adl_emulator_id, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIR
|
|||
FORWARD_CVAR(adl_emulator_id);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, adl_run_at_pcm_rate, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Bool, adl_run_at_pcm_rate, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_BOOL_CVAR(adl_run_at_pcm_rate);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, adl_fullpan, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Bool, adl_fullpan, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_BOOL_CVAR(adl_fullpan);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ CUSTOM_CVAR(Int, adl_bank, 14, CVAR_ARCHIVE | CVAR_VIRTUAL)
|
|||
FORWARD_CVAR(adl_bank);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, adl_use_custom_bank, 0, CVAR_ARCHIVE | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Bool, adl_use_custom_bank, false, CVAR_ARCHIVE | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_BOOL_CVAR(adl_use_custom_bank);
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ CUSTOM_CVAR(Float, fluid_chorus_speed, 0.3f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG |
|
|||
}
|
||||
|
||||
// depth is in ms and actual maximum depends on the sample rate
|
||||
CUSTOM_CVAR(Float, fluid_chorus_depth, 8, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Float, fluid_chorus_depth, 8.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_CVAR(fluid_chorus_depth);
|
||||
}
|
||||
|
@ -251,17 +251,17 @@ CUSTOM_CVAR(Int, opn_emulator_id, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIR
|
|||
FORWARD_CVAR(opn_emulator_id);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, opn_run_at_pcm_rate, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Bool, opn_run_at_pcm_rate, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_BOOL_CVAR(opn_run_at_pcm_rate);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, opn_fullpan, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Bool, opn_fullpan, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_BOOL_CVAR(opn_fullpan);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, opn_use_custom_bank, 0, CVAR_ARCHIVE | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Bool, opn_use_custom_bank, false, CVAR_ARCHIVE | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_BOOL_CVAR(opn_use_custom_bank);
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ CUSTOM_CVAR(Bool, timidity_channel_pressure, false, CVAR_ARCHIVE | CVAR_GLOBALCO
|
|||
FORWARD_BOOL_CVAR(timidity_channel_pressure);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Int, timidity_lpf_def, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Int, timidity_lpf_def, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_CVAR(timidity_lpf_def);
|
||||
}
|
||||
|
@ -384,12 +384,12 @@ CUSTOM_CVAR(Int, timidity_key_adjust, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR
|
|||
FORWARD_CVAR(timidity_key_adjust);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Float, timidity_tempo_adjust, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Float, timidity_tempo_adjust, 1.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_CVAR(timidity_tempo_adjust);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Float, timidity_min_sustain_time, 5000, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
CUSTOM_CVAR(Float, timidity_min_sustain_time, 5000.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
|
||||
{
|
||||
FORWARD_CVAR(timidity_min_sustain_time);
|
||||
}
|
||||
|
|
|
@ -74,6 +74,19 @@ enum
|
|||
CVAR_CONFIG_ONLY = 1 << 18, // do not save var to savegame and do not send it across network.
|
||||
};
|
||||
|
||||
enum ECVarType
|
||||
{
|
||||
CVAR_Bool,
|
||||
CVAR_Int,
|
||||
CVAR_Float,
|
||||
CVAR_String,
|
||||
CVAR_Color, // stored as CVAR_Int
|
||||
CVAR_Flag, // just redirects to another cvar
|
||||
CVAR_Mask, // just redirects to another cvar
|
||||
CVAR_Dummy, // Unknown
|
||||
};
|
||||
|
||||
|
||||
class FIntCVarRef;
|
||||
union UCVarValue
|
||||
{
|
||||
|
@ -92,17 +105,12 @@ union UCVarValue
|
|||
constexpr UCVarValue(FIntCVarRef& v);
|
||||
};
|
||||
|
||||
enum ECVarType
|
||||
{
|
||||
CVAR_Bool,
|
||||
CVAR_Int,
|
||||
CVAR_Float,
|
||||
CVAR_String,
|
||||
CVAR_Color, // stored as CVAR_Int
|
||||
CVAR_Flag, // just redirects to another cvar
|
||||
CVAR_Mask, // just redirects to another cvar
|
||||
CVAR_Dummy, // Unknown
|
||||
};
|
||||
template <ECVarType t> constexpr UCVarValue CVarValue(bool v) { static_assert(t == CVAR_Bool); return v; }
|
||||
template <ECVarType t> constexpr UCVarValue CVarValue(int v) { static_assert(t == CVAR_Int || t == CVAR_Color); return v; }
|
||||
template <ECVarType t> constexpr UCVarValue CVarValue(float v) { static_assert(t == CVAR_Float); return v; }
|
||||
template <ECVarType t> constexpr UCVarValue CVarValue(double v) { static_assert(t == CVAR_Float); return v; }
|
||||
template <ECVarType t> constexpr UCVarValue CVarValue(const char* v) { static_assert(t == CVAR_String); return v; }
|
||||
template <ECVarType t> constexpr UCVarValue CVarValue(FIntCVarRef& v) { static_assert(t == CVAR_Flag || t == CVAR_Mask); return v; }
|
||||
|
||||
class FConfigFile;
|
||||
|
||||
|
@ -598,7 +606,7 @@ void C_ForgetCVars (void);
|
|||
#define CUSTOM_CVAR(type,name,def,flags) \
|
||||
static void cvarfunc_##name(F##type##CVar &); \
|
||||
F##type##CVarRef name; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #name, def, nullptr, reinterpret_cast<void*>(cvarfunc_##name) }; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #name, CVarValue<CVAR_##type>(def), nullptr, reinterpret_cast<void*>(cvarfunc_##name) }; \
|
||||
extern FCVarDecl const *const cvardeclref_##name; \
|
||||
MSVC_VSEG FCVarDecl const *const cvardeclref_##name GCC_VSEG = &cvardecl_##name; \
|
||||
static void cvarfunc_##name(F##type##CVar &self)
|
||||
|
@ -607,14 +615,14 @@ void C_ForgetCVars (void);
|
|||
#define CUSTOM_CVAR_NAMED(type,name,cname,def,flags) \
|
||||
static void cvarfunc_##name(F##type##CVar &); \
|
||||
F##type##CVarRef name; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #cname, def, nullptr, reinterpret_cast<void*>(cvarfunc_##name) }; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #cname, CVarValue<CVAR_##type>(def), nullptr, reinterpret_cast<void*>(cvarfunc_##name) }; \
|
||||
extern FCVarDecl const *const cvardeclref_##name; \
|
||||
MSVC_VSEG FCVarDecl const *const cvardeclref_##name GCC_VSEG = &cvardecl_##name; \
|
||||
static void cvarfunc_##name(F##type##CVar &self)
|
||||
|
||||
#define CVAR(type,name,def,flags) \
|
||||
F##type##CVarRef name; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #name, def, nullptr, nullptr}; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #name, CVarValue<CVAR_##type>(def), nullptr, nullptr}; \
|
||||
extern FCVarDecl const *const cvardeclref_##name; \
|
||||
MSVC_VSEG FCVarDecl const *const cvardeclref_##name GCC_VSEG = &cvardecl_##name;
|
||||
|
||||
|
@ -623,20 +631,20 @@ void C_ForgetCVars (void);
|
|||
#define CUSTOM_CVARD(type,name,def,flags,descr) \
|
||||
static void cvarfunc_##name(F##type##CVar &); \
|
||||
F##type##CVarRef name; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #name, def, descr, reinterpret_cast<void*>(cvarfunc_##name) }; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #name, CVarValue<CVAR_##type>(def), descr, reinterpret_cast<void*>(cvarfunc_##name) }; \
|
||||
extern FCVarDecl const *const cvardeclref_##name; \
|
||||
MSVC_VSEG FCVarDecl const *const cvardeclref_##name GCC_VSEG = &cvardecl_##name; \
|
||||
static void cvarfunc_##name(F##type##CVar &self)
|
||||
|
||||
#define CVARD(type,name,def,flags, descr) \
|
||||
F##type##CVarRef name; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #name, def, descr, nullptr}; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #name, CVarValue<CVAR_##type>(def), descr, nullptr}; \
|
||||
extern FCVarDecl const *const cvardeclref_##name; \
|
||||
MSVC_VSEG FCVarDecl const *const cvardeclref_##name GCC_VSEG = &cvardecl_##name;
|
||||
|
||||
#define CVARD_NAMED(type,name,varname,def,flags, descr) \
|
||||
F##type##CVarRef name; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #varname, def, descr, nullptr}; \
|
||||
static FCVarDecl cvardecl_##name = { &name, CVAR_##type, (flags), #varname, CVarValue<CVAR_##type>(def), descr, nullptr}; \
|
||||
extern FCVarDecl const *const cvardeclref_##name; \
|
||||
MSVC_VSEG FCVarDecl const *const cvardeclref_##name GCC_VSEG = &cvardecl_##name;
|
||||
|
||||
|
|
|
@ -50,8 +50,8 @@ int eventhead;
|
|||
int eventtail;
|
||||
event_t events[MAXEVENTS];
|
||||
|
||||
CVAR(Float, m_sensitivity_x, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVAR(Float, m_sensitivity_y, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVAR(Float, m_sensitivity_x, 4.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVAR(Float, m_sensitivity_y, 2.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -115,7 +115,7 @@ CVAR(Int, gl_satformula, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
|||
// Texture CVARs
|
||||
//
|
||||
//==========================================================================
|
||||
CUSTOM_CVARD(Float, gl_texture_filter_anisotropic, 8, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL, "changes the OpenGL texture anisotropy setting")
|
||||
CUSTOM_CVARD(Float, gl_texture_filter_anisotropic, 8.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL, "changes the OpenGL texture anisotropy setting")
|
||||
{
|
||||
screen->SetTextureFilterMode();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
// also shamelessly lifted from ZDoomGL! ;)
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CVAR(Float, skyoffset, 0, 0) // for testing
|
||||
CVAR(Float, skyoffset, 0.f, 0) // for testing
|
||||
|
||||
|
||||
struct SkyColor
|
||||
|
|
|
@ -61,7 +61,7 @@ CVAR(Int, crosshairhealth, 2, CVAR_ARCHIVE);
|
|||
CVARD(Float, crosshairscale, 0.5, CVAR_ARCHIVE, "changes the size of the crosshair");
|
||||
CVAR(Bool, crosshairgrow, false, CVAR_ARCHIVE);
|
||||
|
||||
CUSTOM_CVARD(Float, hud_scalefactor, 1, CVAR_ARCHIVE, "changes the hud scale")
|
||||
CUSTOM_CVARD(Float, hud_scalefactor, 1.f, CVAR_ARCHIVE, "changes the hud scale")
|
||||
{
|
||||
if (self < 0.36f) self = 0.36f;
|
||||
else if (self > 1) self = 1;
|
||||
|
|
|
@ -72,7 +72,7 @@ CUSTOM_CVAR(Int, con_notifylines, 4, CVAR_GLOBALCONFIG | CVAR_ARCHIVE)
|
|||
NotifyStrings.Shift(self);
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Float, con_notifyscale, 1, CVAR_ARCHIVE)
|
||||
CUSTOM_CVAR(Float, con_notifyscale, 1.f, CVAR_ARCHIVE)
|
||||
{
|
||||
if (self < 0.36f) self = 0.36f;
|
||||
if (self > 1) self = 1;
|
||||
|
|
|
@ -186,7 +186,7 @@ CUSTOM_CVARD(Int, hud_stats, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enable/disabl
|
|||
CVARD(Bool, hud_showmapname, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "enable/disable map name display on load")
|
||||
CVARD(Bool, hud_position, false, CVAR_ARCHIVE, "aligns the status bar to the bottom/top")
|
||||
CVARD(Bool, hud_bgstretch, false, CVAR_ARCHIVE, "enable/disable background image stretching in wide resolutions")
|
||||
CVARD(Bool, hud_messages, 1, CVAR_ARCHIVE, "enable/disable showing messages")
|
||||
CVARD(Bool, hud_messages, true, CVAR_ARCHIVE, "enable/disable showing messages")
|
||||
|
||||
// This cannot be done with the 'toggle' CCMD because it needs to control itself when to output the message
|
||||
CCMD (togglemessages)
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "hw_renderstate.h"
|
||||
#include "skyboxtexture.h"
|
||||
|
||||
CVAR(Float, skyoffsettest, 0, 0)
|
||||
CVAR(Float, skyoffsettest, 0.f, 0)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue