- eliminated dependency of CVar code on AActor.

As a low level feature, the CVAR management should not access game structures like actors, just to retrieve a player index. The index should be calculated by the calling code instead and passed into the function.

# Conflicts:
#	src/win32/i_specialpaths.cpp
This commit is contained in:
Christoph Oelckers 2019-06-21 19:42:19 +02:00
parent 8f00eb54d8
commit e93de62f98
6 changed files with 11 additions and 19 deletions

View file

@ -1599,7 +1599,7 @@ DEFINE_ACTION_FUNCTION(_CVar, GetCVar)
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_NAME(name); PARAM_NAME(name);
PARAM_POINTER(plyr, player_t); PARAM_POINTER(plyr, player_t);
ACTION_RETURN_POINTER(GetCVar(plyr ? plyr->mo : nullptr, name)); ACTION_RETURN_POINTER(GetCVar(plyr ? int(plyr - players) : -1, name));
} }
FBaseCVar *FindCVarSub (const char *var_name, int namelen) FBaseCVar *FindCVarSub (const char *var_name, int namelen)
@ -1624,7 +1624,7 @@ FBaseCVar *FindCVarSub (const char *var_name, int namelen)
return var; return var;
} }
FBaseCVar *GetCVar(AActor *activator, const char *cvarname) FBaseCVar *GetCVar(int playernum, const char *cvarname)
{ {
FBaseCVar *cvar = FindCVar(cvarname, nullptr); FBaseCVar *cvar = FindCVar(cvarname, nullptr);
// Either the cvar doesn't exist, or it's for a mod that isn't loaded, so return nullptr. // Either the cvar doesn't exist, or it's for a mod that isn't loaded, so return nullptr.
@ -1637,11 +1637,7 @@ FBaseCVar *GetCVar(AActor *activator, const char *cvarname)
// For userinfo cvars, redirect to GetUserCVar // For userinfo cvars, redirect to GetUserCVar
if (cvar->GetFlags() & CVAR_USERINFO) if (cvar->GetFlags() & CVAR_USERINFO)
{ {
if (activator == nullptr || activator->player == nullptr) return GetUserCVar(playernum, cvarname);
{
return nullptr;
}
return GetUserCVar(int(activator->player - players), cvarname);
} }
return cvar; return cvar;
} }

View file

@ -90,7 +90,6 @@ enum ECVarType
}; };
class FConfigFile; class FConfigFile;
class AActor;
class FxCVar; class FxCVar;
@ -194,7 +193,7 @@ FBaseCVar *FindCVar (const char *var_name, FBaseCVar **prev);
FBaseCVar *FindCVarSub (const char *var_name, int namelen); FBaseCVar *FindCVarSub (const char *var_name, int namelen);
// Used for ACS and DECORATE. // Used for ACS and DECORATE.
FBaseCVar *GetCVar(AActor *activator, const char *cvarname); FBaseCVar *GetCVar(int playernum, const char *cvarname);
FBaseCVar *GetUserCVar(int playernum, const char *cvarname); FBaseCVar *GetUserCVar(int playernum, const char *cvarname);
// Create a new cvar with the specified name and type // Create a new cvar with the specified name and type

View file

@ -1484,7 +1484,7 @@ class CommandDrawNumber : public CommandDrawString
break; break;
case INTCVAR: case INTCVAR:
{ {
FBaseCVar *CVar = GetCVar(statusBar->CPlayer->mo, cvarName); FBaseCVar *CVar = GetCVar(int(statusBar->CPlayer - players), cvarName);
if (CVar != nullptr) if (CVar != nullptr)
{ {
ECVarType cvartype = CVar->GetRealType(); ECVarType cvartype = CVar->GetRealType();
@ -3534,7 +3534,7 @@ class CommandIfCVarInt : public SBarInfoNegatableFlowControl
SBarInfoNegatableFlowControl::Tick(block, statusBar, hudChanged); SBarInfoNegatableFlowControl::Tick(block, statusBar, hudChanged);
bool result = false; bool result = false;
cvar = GetCVar(statusBar->CPlayer->mo, cvarname); cvar = GetCVar(int(statusBar->CPlayer - players), cvarname);
if (cvar != nullptr) if (cvar != nullptr)
{ {

View file

@ -5788,7 +5788,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args)
case ACSF_GetCVarString: case ACSF_GetCVarString:
if (argCount == 1) if (argCount == 1)
{ {
return DoGetCVar(GetCVar(activator, Level->Behaviors.LookupString(args[0])), true); return DoGetCVar(GetCVar(activator && activator->player ? int(activator->player - players) : -1, Level->Behaviors.LookupString(args[0])), true);
} }
break; break;
@ -9733,7 +9733,8 @@ scriptwait:
break; break;
case PCD_GETCVAR: case PCD_GETCVAR:
STACK(1) = DoGetCVar(GetCVar(activator, Level->Behaviors.LookupString(STACK(1))), false); // This should not use Level->PlayerNum!
STACK(1) = DoGetCVar(GetCVar(activator && activator->player? int(activator->player - players) : -1, Level->Behaviors.LookupString(STACK(1))), false);
break; break;
case PCD_SETHUDSIZE: case PCD_SETHUDSIZE:

View file

@ -383,7 +383,7 @@ DEFINE_ACTION_FUNCTION(AActor, GetCVar)
PARAM_SELF_PROLOGUE(AActor); PARAM_SELF_PROLOGUE(AActor);
PARAM_STRING(cvarname); PARAM_STRING(cvarname);
FBaseCVar *cvar = GetCVar(self, cvarname); FBaseCVar *cvar = GetCVar(self->player ? int(self->player - players) : -1, cvarname);
if (cvar == nullptr) if (cvar == nullptr)
{ {
ret->SetFloat(0); ret->SetFloat(0);
@ -413,7 +413,7 @@ DEFINE_ACTION_FUNCTION(AActor, GetCVarString)
PARAM_SELF_PROLOGUE(AActor); PARAM_SELF_PROLOGUE(AActor);
PARAM_STRING(cvarname); PARAM_STRING(cvarname);
FBaseCVar *cvar = GetCVar(self, cvarname); FBaseCVar *cvar = GetCVar(self->player? int(self->player - players) : -1, cvarname);
if (cvar == nullptr) if (cvar == nullptr)
{ {
ret->SetString(""); ret->SetString("");

View file

@ -101,10 +101,6 @@ bool UseKnownFolders()
bool GetKnownFolder(int shell_folder, REFKNOWNFOLDERID known_folder, bool create, FString &path) bool GetKnownFolder(int shell_folder, REFKNOWNFOLDERID known_folder, bool create, FString &path)
{ {
using OptWin32::SHGetKnownFolderPath;
WCHAR pathstr[MAX_PATH];
// SHGetKnownFolderPath knows about more folders than SHGetFolderPath, but is // SHGetKnownFolderPath knows about more folders than SHGetFolderPath, but is
// new to Vista, hence the reason we support both. // new to Vista, hence the reason we support both.
if (!SHGetKnownFolderPath) if (!SHGetKnownFolderPath)