- made CVar declarations type safe again.

This commit is contained in:
Christoph Oelckers 2022-10-22 09:29:38 +02:00
parent 453688ccc6
commit 671b8696bb
17 changed files with 87 additions and 64 deletions

View file

@ -196,7 +196,7 @@ CUSTOM_CVAR(Int, am_emptyspacemargin, 0, CVAR_ARCHIVE)
CVAR(Bool, am_followplayer, true, CVAR_ARCHIVE)
CVAR(Bool, am_portaloverlay, true, CVAR_ARCHIVE)
CVAR(Bool, am_showgrid, false, CVAR_ARCHIVE)
CVAR(Float, am_zoomdir, 0, CVAR_ARCHIVE)
CVAR(Float, am_zoomdir, 0.f, CVAR_ARCHIVE)
static const char *const DEFAULT_FONT_NAME = "AMMNUMx";
CVAR(String, am_markfont, DEFAULT_FONT_NAME, CVAR_ARCHIVE)

View file

@ -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);
}

View file

@ -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;

View file

@ -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)
//==========================================================================
@ -67,7 +67,7 @@ CVAR(Float, m_sensitivity_y, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
void D_ProcessEvents (void)
{
FixedBitArray<NUM_KEYS> keywasdown;
TArray<event_t> delayedevents;
TArray<event_t*> delayedevents;
keywasdown.Zero();
while (eventtail != eventhead)
@ -77,7 +77,7 @@ void D_ProcessEvents (void)
if (ev->type == EV_KeyUp && keywasdown[ev->data1])
{
delayedevents.Push(*ev);
delayedevents.Push(ev);
continue;
}
@ -97,9 +97,9 @@ void D_ProcessEvents (void)
if (sysCallbacks.G_Responder(ev) && ev->type == EV_KeyDown) keywasdown.Set(ev->data1);
}
for (auto& ev: delayedevents)
for (auto ev: delayedevents)
{
D_PostEvent(&ev);
D_PostEvent(ev);
}
}

View file

@ -15,6 +15,8 @@
#include <signal.h>
#endif
int I_FileAvailable(const char* filename);
static const char crash_switch[] = "--cc-handle-crash";
@ -363,12 +365,11 @@ static void crash_handler(const char *logfile)
if(logfile)
{
const char *str;
char buf[512];
if((str=getenv("KDE_FULL_SESSION")) && strcmp(str, "true") == 0)
if(I_FileAvailable("kdialog"))
snprintf(buf, sizeof(buf), "kdialog --title \"Very Fatal Error\" --textbox \"%s\" 800 600", logfile);
else if((str=getenv("GNOME_DESKTOP_SESSION_ID")) && str[0] != '\0')
else if(I_FileAvailable("gxmessage"))
snprintf(buf, sizeof(buf), "gxmessage -buttons \"Okay:0\" -geometry 800x600 -title \"Very Fatal Error\" -center -file \"%s\"", logfile);
else
snprintf(buf, sizeof(buf), "xmessage -buttons \"Okay:0\" -center -file \"%s\"", logfile);

View file

@ -85,22 +85,18 @@ void I_SetIWADInfo()
{
}
static bool I_KDialogAvailable()
extern "C" int I_FileAvailable(const char* filename)
{
// Is KDE running?
const char* str = getenv("KDE_FULL_SESSION");
if (str && strcmp(str, "true") == 0)
FString cmd = "which {0} >/dev/null 2>&1";
cmd.Substitute("{0}", filename);
if (FILE* f = popen(cmd.GetChars(), "r"))
{
// Is kdialog available?
FILE* f = popen("which kdialog >/dev/null 2>&1", "r");
if (f != NULL)
{
int status = pclose(f);
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
}
int status = pclose(f);
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
}
return false;
return 0;
}
//
@ -117,7 +113,7 @@ void Unix_I_FatalError(const char* errortext)
// Close window or exit fullscreen and release mouse capture
SDL_QuitSubSystem(SDL_INIT_VIDEO);
if(I_KDialogAvailable())
if(I_FileAvailable("kdialog"))
{
FString cmd;
cmd << "kdialog --title \"" GAMENAME " " << GetVersionString()
@ -311,7 +307,7 @@ int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad, int&
}
#ifndef __APPLE__
if(I_KDialogAvailable())
if(I_FileAvailable("kdialog"))
{
FString cmd("kdialog --title \"" GAMENAME " ");
cmd << GetVersionString() << ": Select an IWAD to use\""

View file

@ -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();
}

View file

@ -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

View file

@ -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;

View file

@ -237,6 +237,12 @@ struct TVector2
{
return X*X + Y*Y;
}
double Sum() const
{
return abs(X) + abs(Y);
}
// Return a unit vector facing the same direction as this one
TVector2 Unit() const
@ -601,6 +607,12 @@ struct TVector3
{
return X*X + Y*Y + Z*Z;
}
double Sum() const
{
return abs(X) + abs(Y) + abs(Z);
}
// Return a unit vector facing the same direction as this one
TVector3 Unit() const
@ -900,6 +912,12 @@ struct TVector4
{
return X*X + Y*Y + Z*Z + W*W;
}
double Sum() const
{
return abs(X) + abs(Y) + abs(Z) + abs(W);
}
// Return a unit vector facing the same direction as this one
TVector4 Unit() const
@ -1693,6 +1711,7 @@ constexpr DAngle nullAngle = DAngle::fromDeg(0.);
constexpr DAngle minAngle = DAngle::fromDeg(1. / 65536.);
constexpr FAngle nullFAngle = FAngle::fromDeg(0.);
constexpr DAngle DAngle1 = DAngle::fromDeg(1);
constexpr DAngle DAngle22_5 = DAngle::fromDeg(22.5);
constexpr DAngle DAngle45 = DAngle::fromDeg(45);
constexpr DAngle DAngle60 = DAngle::fromDeg(60);

View file

@ -1918,7 +1918,6 @@ static void LoadGameError(const char *label, const char *append = "")
void C_SerializeCVars(FSerializer& arc, const char* label, uint32_t filter)
{
FBaseCVar* cvar;
FString dump;
if (arc.BeginObject(label))

View file

@ -51,7 +51,7 @@
#include "g_game.h"
CVAR (Int, cl_rockettrails, 1, CVAR_ARCHIVE);
CVAR (Bool, r_rail_smartspiral, 0, CVAR_ARCHIVE);
CVAR (Bool, r_rail_smartspiral, false, CVAR_ARCHIVE);
CVAR (Int, r_rail_spiralsparsity, 1, CVAR_ARCHIVE);
CVAR (Int, r_rail_trailsparsity, 1, CVAR_ARCHIVE);
CVAR (Bool, r_particles, true, 0);

View file

@ -90,7 +90,7 @@ enum EWRF_Options
// [SO] 1=Weapons states are all 1 tick
// 2=states with a function 1 tick, others 0 ticks.
CVAR(Int, sv_fastweapons, false, CVAR_SERVERINFO);
CVAR(Int, sv_fastweapons, 0, CVAR_SERVERINFO);
// PRIVATE DATA DEFINITIONS ------------------------------------------------

View file

@ -78,7 +78,7 @@
//
//==========================================================================
CUSTOM_CVAR(Int, r_fakecontrast, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CUSTOM_CVAR(Int, r_fakecontrast, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (self < 0) self = 1;
else if (self > 2) self = 2;

View file

@ -54,8 +54,8 @@
#include "swrenderer/scene/r_light.h"
#include "playsim/a_dynlight.h"
CVAR(Bool, r_dynlights, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Bool, r_fuzzscale, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Bool, r_dynlights, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Bool, r_fuzzscale, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
namespace swrenderer
{

View file

@ -43,7 +43,7 @@
#include "swrenderer/r_renderthread.h"
#include "r_memory.h"
CVAR(Int, r_3dfloors, true, 0);
CVAR(Int, r_3dfloors, 1, 0);
namespace swrenderer
{

View file

@ -86,7 +86,7 @@ namespace
double line_distance_cull = 1e16;
}
CUSTOM_CVAR(Float, r_sprite_distance_cull, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CUSTOM_CVAR(Float, r_sprite_distance_cull, 0.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (r_sprite_distance_cull > 0.0)
{
@ -98,7 +98,7 @@ CUSTOM_CVAR(Float, r_sprite_distance_cull, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
}
}
CUSTOM_CVAR(Float, r_line_distance_cull, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CUSTOM_CVAR(Float, r_line_distance_cull, 0.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (r_line_distance_cull > 0.0)
{
@ -110,7 +110,7 @@ CUSTOM_CVAR(Float, r_line_distance_cull, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
}
}
CUSTOM_CVAR(Float, r_model_distance_cull, 1024, 0/*CVAR_ARCHIVE | CVAR_GLOBALCONFIG*/) // Experimental for the moment until a good default is chosen
CUSTOM_CVAR(Float, r_model_distance_cull, 1024.f, 0/*CVAR_ARCHIVE | CVAR_GLOBALCONFIG*/) // Experimental for the moment until a good default is chosen
{
if (r_model_distance_cull > 0.0)
{