From 1697e6ff3a26d386defbf19767b192225a2dacaa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 21 Jun 2019 19:42:19 +0200 Subject: [PATCH] - 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 # Conflicts: # src/p_acs.cpp --- src/c_cvars.cpp | 10 +++------- src/c_cvars.h | 3 +-- src/g_statusbar/sbarinfo_commands.cpp | 4 ++-- src/p_acs.cpp | 4 ++-- src/p_actionfunctions.cpp | 4 ++-- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/c_cvars.cpp b/src/c_cvars.cpp index b4c3cd394..aef6d6ab9 100644 --- a/src/c_cvars.cpp +++ b/src/c_cvars.cpp @@ -1606,7 +1606,7 @@ DEFINE_ACTION_FUNCTION(_CVar, GetCVar) PARAM_PROLOGUE; PARAM_NAME(name); 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) @@ -1631,7 +1631,7 @@ FBaseCVar *FindCVarSub (const char *var_name, int namelen) return var; } -FBaseCVar *GetCVar(AActor *activator, const char *cvarname) +FBaseCVar *GetCVar(int playernum, const char *cvarname) { FBaseCVar *cvar = FindCVar(cvarname, nullptr); // Either the cvar doesn't exist, or it's for a mod that isn't loaded, so return nullptr. @@ -1644,11 +1644,7 @@ FBaseCVar *GetCVar(AActor *activator, const char *cvarname) // For userinfo cvars, redirect to GetUserCVar if (cvar->GetFlags() & CVAR_USERINFO) { - if (activator == nullptr || activator->player == nullptr) - { - return nullptr; - } - return GetUserCVar(int(activator->player - players), cvarname); + return GetUserCVar(playernum, cvarname); } return cvar; } diff --git a/src/c_cvars.h b/src/c_cvars.h index 11166098b..a74a4c0e4 100644 --- a/src/c_cvars.h +++ b/src/c_cvars.h @@ -90,7 +90,6 @@ enum ECVarType }; class FConfigFile; -class AActor; class FxCVar; @@ -194,7 +193,7 @@ FBaseCVar *FindCVar (const char *var_name, FBaseCVar **prev); FBaseCVar *FindCVarSub (const char *var_name, int namelen); // 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); // Create a new cvar with the specified name and type diff --git a/src/g_statusbar/sbarinfo_commands.cpp b/src/g_statusbar/sbarinfo_commands.cpp index d0c60cf68..313c29648 100644 --- a/src/g_statusbar/sbarinfo_commands.cpp +++ b/src/g_statusbar/sbarinfo_commands.cpp @@ -1484,7 +1484,7 @@ class CommandDrawNumber : public CommandDrawString break; case INTCVAR: { - FBaseCVar *CVar = GetCVar(statusBar->CPlayer->mo, cvarName); + FBaseCVar *CVar = GetCVar(int(statusBar->CPlayer - players), cvarName); if (CVar != nullptr) { ECVarType cvartype = CVar->GetRealType(); @@ -3534,7 +3534,7 @@ class CommandIfCVarInt : public SBarInfoNegatableFlowControl SBarInfoNegatableFlowControl::Tick(block, statusBar, hudChanged); bool result = false; - cvar = GetCVar(statusBar->CPlayer->mo, cvarname); + cvar = GetCVar(int(statusBar->CPlayer - players), cvarname); if (cvar != nullptr) { diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 4100327eb..8f7bc46a7 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -5919,7 +5919,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args) case ACSF_GetCVarString: if (argCount == 1) { - return DoGetCVar(GetCVar(activator, FBehavior::StaticLookupString(args[0])), true); + return DoGetCVar(GetCVar(activator && activator->player ? int(activator->player - players) : -1, FBehavior::StaticLookupString(args[0])), true); } break; @@ -9869,7 +9869,7 @@ scriptwait: break; case PCD_GETCVAR: - STACK(1) = DoGetCVar(GetCVar(activator, FBehavior::StaticLookupString(STACK(1))), false); + STACK(1) = DoGetCVar(GetCVar(activator && activator->player? int(activator->player - players) : -1, FBehavior::StaticLookupString(STACK(1))), false); break; case PCD_SETHUDSIZE: diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 923795383..492394c2c 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -401,7 +401,7 @@ DEFINE_ACTION_FUNCTION(AActor, GetCVar) PARAM_SELF_PROLOGUE(AActor); PARAM_STRING(cvarname); - FBaseCVar *cvar = GetCVar(self, cvarname); + FBaseCVar *cvar = GetCVar(self->player ? int(self->player - players) : -1, cvarname); if (cvar == nullptr) { ret->SetFloat(0); @@ -431,7 +431,7 @@ DEFINE_ACTION_FUNCTION(AActor, GetCVarString) PARAM_SELF_PROLOGUE(AActor); PARAM_STRING(cvarname); - FBaseCVar *cvar = GetCVar(self, cvarname); + FBaseCVar *cvar = GetCVar(self->player? int(self->player - players) : -1, cvarname); if (cvar == nullptr) { ret->SetString("");