- Added ACS functions SetCVarString and SetUserCVarString. These work just like their non-string

counterparts except that their value argument is an ACS string. (Note that they work with any
  type of cvar, not just string cvars.)
- Make UCVarValue::String point to a constant string.

SVN r4292 (trunk)
This commit is contained in:
Randy Heit 2013-05-27 02:20:32 +00:00
parent 4a8037d66e
commit 587f1e83ba
3 changed files with 34 additions and 13 deletions

View file

@ -266,7 +266,7 @@ static GUID cGUID;
static char truestr[] = "true"; static char truestr[] = "true";
static char falsestr[] = "false"; static char falsestr[] = "false";
char *FBaseCVar::ToString (UCVarValue value, ECVarType type) const char *FBaseCVar::ToString (UCVarValue value, ECVarType type)
{ {
switch (type) switch (type)
{ {

View file

@ -70,7 +70,7 @@ union UCVarValue
bool Bool; bool Bool;
int Int; int Int;
float Float; float Float;
char *String; const char *String;
const GUID *pGUID; const GUID *pGUID;
}; };
@ -132,7 +132,7 @@ protected:
static bool ToBool (UCVarValue value, ECVarType type); static bool ToBool (UCVarValue value, ECVarType type);
static int ToInt (UCVarValue value, ECVarType type); static int ToInt (UCVarValue value, ECVarType type);
static float ToFloat (UCVarValue value, ECVarType type); static float ToFloat (UCVarValue value, ECVarType type);
static char *ToString (UCVarValue value, ECVarType type); static const char *ToString (UCVarValue value, ECVarType type);
static const GUID *ToGUID (UCVarValue value, ECVarType type); static const GUID *ToGUID (UCVarValue value, ECVarType type);
static UCVarValue FromBool (bool value, ECVarType type); static UCVarValue FromBool (bool value, ECVarType type);
static UCVarValue FromInt (int value, ECVarType type); static UCVarValue FromInt (int value, ECVarType type);

View file

@ -3477,6 +3477,8 @@ enum EACSFunctions
ACSF_SetCVar, ACSF_SetCVar,
ACSF_GetUserCVar, ACSF_GetUserCVar,
ACSF_SetUserCVar, ACSF_SetUserCVar,
ACSF_SetCVarString,
ACSF_SetUserCVarString,
// ZDaemon // ZDaemon
ACSF_GetTeamScore = 19620, // (int team) ACSF_GetTeamScore = 19620, // (int team)
@ -3577,7 +3579,7 @@ static int GetUserVariable(AActor *self, FName varname, int index)
} }
// Converts fixed- to floating-point as required. // Converts fixed- to floating-point as required.
static void DoSetCVar(FBaseCVar *cvar, int value, bool force=false) static void DoSetCVar(FBaseCVar *cvar, int value, bool is_string, bool force=false)
{ {
UCVarValue val; UCVarValue val;
ECVarType type; ECVarType type;
@ -3589,7 +3591,12 @@ static void DoSetCVar(FBaseCVar *cvar, int value, bool force=false)
{ {
return; return;
} }
if (cvar->GetRealType() == CVAR_Float) if (is_string)
{
val.String = FBehavior::StaticLookupString(value);
type = CVAR_String;
}
else if (cvar->GetRealType() == CVAR_Float)
{ {
val.Float = FIXED2FLOAT(value); val.Float = FIXED2FLOAT(value);
type = CVAR_Float; type = CVAR_Float;
@ -3664,7 +3671,7 @@ static int GetCVar(AActor *activator, const char *cvarname)
} }
} }
static int SetUserCVar(int playernum, const char *cvarname, int value) static int SetUserCVar(int playernum, const char *cvarname, int value, bool is_string)
{ {
if ((unsigned)playernum >= MAXPLAYERS || !playeringame[playernum]) if ((unsigned)playernum >= MAXPLAYERS || !playeringame[playernum])
{ {
@ -3677,7 +3684,7 @@ static int SetUserCVar(int playernum, const char *cvarname, int value)
{ {
return 0; return 0;
} }
DoSetCVar(cvar, value); DoSetCVar(cvar, value, is_string);
// If we are this player, then also reflect this change in the local version of this cvar. // If we are this player, then also reflect this change in the local version of this cvar.
if (playernum == consoleplayer) if (playernum == consoleplayer)
@ -3687,14 +3694,14 @@ static int SetUserCVar(int playernum, const char *cvarname, int value)
// but check just to be safe. // but check just to be safe.
if (cvar != NULL) if (cvar != NULL)
{ {
DoSetCVar(cvar, value, true); DoSetCVar(cvar, value, is_string, true);
} }
} }
return 1; return 1;
} }
static int SetCVar(AActor *activator, const char *cvarname, int value) static int SetCVar(AActor *activator, const char *cvarname, int value, bool is_string)
{ {
FBaseCVar *cvar = FindCVar(cvarname, NULL); FBaseCVar *cvar = FindCVar(cvarname, NULL);
// Only mod-created cvars may be set. // Only mod-created cvars may be set.
@ -3709,9 +3716,9 @@ static int SetCVar(AActor *activator, const char *cvarname, int value)
{ {
return 0; return 0;
} }
return SetUserCVar(int(activator->player - players), cvarname, value); return SetUserCVar(int(activator->player - players), cvarname, value, is_string);
} }
DoSetCVar(cvar, value); DoSetCVar(cvar, value, is_string);
return 1; return 1;
} }
@ -4169,14 +4176,28 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args)
case ACSF_SetUserCVar: case ACSF_SetUserCVar:
if (argCount == 3) if (argCount == 3)
{ {
return SetUserCVar(args[0], FBehavior::StaticLookupString(args[1]), args[2]); return SetUserCVar(args[0], FBehavior::StaticLookupString(args[1]), args[2], false);
}
break;
case ACSF_SetUserCVarString:
if (argCount == 3)
{
return SetUserCVar(args[0], FBehavior::StaticLookupString(args[1]), args[2], true);
} }
break; break;
case ACSF_SetCVar: case ACSF_SetCVar:
if (argCount == 2) if (argCount == 2)
{ {
return SetCVar(activator, FBehavior::StaticLookupString(args[0]), args[1]); return SetCVar(activator, FBehavior::StaticLookupString(args[0]), args[1], false);
}
break;
case ACSF_SetCVarString:
if (argCount == 2)
{
return SetCVar(activator, FBehavior::StaticLookupString(args[0]), args[1], true);
} }
break; break;