- reworked CVARs to not use a linked list and to be initialized manually.

This solves two problems:

* The linked list is too slow, a map is better. A map cannot be used with statically allocated CVARs because order of initialization is undefined.
* The current CVAR system is an unordered mishmash of static variables and dynamically allocated ones and the means of identification are unsafe. With this everything is allocated on the heap so it can all be handled the same by the cleanup code.
This commit is contained in:
Christoph Oelckers 2022-10-21 18:28:28 +02:00
commit 453688ccc6
28 changed files with 369 additions and 203 deletions

View file

@ -396,8 +396,11 @@ void D_SetupUserInfo ()
// Initialize the console player's user info
coninfo = &players[consoleplayer].userinfo;
for (FBaseCVar *cvar = CVars; cvar != NULL; cvar = cvar->GetNext())
decltype(cvarMap)::Iterator it(cvarMap);
decltype(cvarMap)::Pair *pair;
while (it.NextPair(pair))
{
auto cvar = pair->Value;
if ((cvar->GetFlags() & (CVAR_USERINFO|CVAR_IGNORE)) == CVAR_USERINFO)
{
FBaseCVar **newcvar;
@ -434,8 +437,11 @@ void userinfo_t::Reset()
Clear();
// Create userinfo vars for this player, initialized to their defaults.
for (FBaseCVar *cvar = CVars; cvar != NULL; cvar = cvar->GetNext())
decltype(cvarMap)::Iterator it2(cvarMap);
decltype(cvarMap)::Pair *pair2;
while (it2.NextPair(pair2))
{
auto cvar = pair2->Value;
if ((cvar->GetFlags() & (CVAR_USERINFO|CVAR_IGNORE)) == CVAR_USERINFO)
{
ECVarType type;
@ -528,7 +534,8 @@ void D_UserInfoChanged (FBaseCVar *cvar)
FString escaped_val;
char foo[256];
if (cvar == &autoaim)
#if 0
if (cvar == autoaim->get())
{
if (autoaim < 0.0f)
{
@ -541,6 +548,7 @@ void D_UserInfoChanged (FBaseCVar *cvar)
return;
}
}
#endif
val = cvar->GetGenericRep (CVAR_String);
escaped_val = D_EscapeUserInfo(val.String);
@ -604,7 +612,8 @@ static const char *SetServerVar (char *name, ECVarType type, uint8_t **stream, b
delete[] value.String;
}
if (var == &teamplay)
#if 0
if (var == teamplay->get())
{
// Put players on teams if teamplay turned on
for (int i = 0; i < MAXPLAYERS; ++i)
@ -615,6 +624,7 @@ static const char *SetServerVar (char *name, ECVarType type, uint8_t **stream, b
}
}
}
#endif
if (var)
{