From b6e3358b1cf62e39bd4f6c7d54ffacf546bd3cec Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 29 Mar 2016 22:14:31 -0500 Subject: [PATCH] Add A_SetUserVarFloat and A_SetUserArrayFloat --- src/thingdef/thingdef_codeptr.cpp | 86 ++++++++++++++++++++++++------- wadsrc/static/actors/actor.txt | 2 + 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 6efbeb1671..9fa547f461 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -4681,22 +4681,46 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetSpecial) // //=========================================================================== -DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserVar) +static PField *GetVar(AActor *self, FName varname) { - PARAM_ACTION_PROLOGUE; - PARAM_NAME (varname); - PARAM_INT (value); - PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); if (var == NULL || (var->Flags & VARF_Native) || !var->Type->IsKindOf(RUNTIME_CLASS(PBasicType))) { Printf("%s is not a user variable in class %s\n", varname.GetChars(), self->GetClass()->TypeName.GetChars()); - return 0; + return nullptr; } + return var; +} + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserVar) +{ + PARAM_ACTION_PROLOGUE; + PARAM_NAME (varname); + PARAM_INT (value); + // Set the value of the specified user variable. - var->Type->SetValue(reinterpret_cast(self) + var->Offset, value); + PField *var = GetVar(self, varname); + if (var != nullptr) + { + var->Type->SetValue(reinterpret_cast(self) + var->Offset, value); + } + return 0; +} + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserVarFloat) +{ + PARAM_ACTION_PROLOGUE; + PARAM_NAME (varname); + PARAM_FLOAT (value); + + // Set the value of the specified user variable. + PField *var = GetVar(self, varname); + if (var != nullptr) + { + var->Type->SetValue(reinterpret_cast(self) + var->Offset, value); + } return 0; } @@ -4706,13 +4730,8 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserVar) // //=========================================================================== -DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserArray) +static PField *GetArrayVar(AActor *self, FName varname, int pos) { - PARAM_ACTION_PROLOGUE; - PARAM_NAME (varname); - PARAM_INT (pos); - PARAM_INT (value); - PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); if (var == NULL || (var->Flags & VARF_Native) || @@ -4721,17 +4740,48 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserArray) { Printf("%s is not a user array in class %s\n", varname.GetChars(), self->GetClass()->TypeName.GetChars()); - return 0; + return nullptr; } - PArray *arraytype = static_cast(var->Type); - if ((unsigned)pos >= arraytype->ElementCount) + if ((unsigned)pos >= static_cast(var->Type)->ElementCount) { Printf("%d is out of bounds in array %s in class %s\n", pos, varname.GetChars(), self->GetClass()->TypeName.GetChars()); - return 0; + return nullptr; } + return var; +} + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserArray) +{ + PARAM_ACTION_PROLOGUE; + PARAM_NAME (varname); + PARAM_INT (pos); + PARAM_INT (value); + // Set the value of the specified user array at index pos. - arraytype->ElementType->SetValue(reinterpret_cast(self) + var->Offset + arraytype->ElementSize * pos, value); + PField *var = GetArrayVar(self, varname, pos); + if (var != nullptr) + { + PArray *arraytype = static_cast(var->Type); + arraytype->ElementType->SetValue(reinterpret_cast(self) + var->Offset + arraytype->ElementSize * pos, value); + } + return 0; +} + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetUserArrayFloat) +{ + PARAM_ACTION_PROLOGUE; + PARAM_NAME (varname); + PARAM_INT (pos); + PARAM_FLOAT (value); + + // Set the value of the specified user array at index pos. + PField *var = GetArrayVar(self, varname, pos); + if (var != nullptr) + { + PArray *arraytype = static_cast(var->Type); + arraytype->ElementType->SetValue(reinterpret_cast(self) + var->Offset + arraytype->ElementSize * pos, value); + } return 0; } diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index e3bb06fe74..7548cd6c91 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -275,6 +275,8 @@ ACTOR Actor native //: Thinker action native A_SetArg(int pos, int value); action native A_SetUserVar(name varname, int value); action native A_SetUserArray(name varname, int index, int value); + action native A_SetUserVarFloat(name varname, float value); + action native A_SetUserArrayFloat(name varname, int index, float value); action native A_SetSpecial(int spec, int arg0 = 0, int arg1 = 0, int arg2 = 0, int arg3 = 0, int arg4 = 0); action native A_Quake(int intensity, int duration, int damrad, int tremrad, sound sfx = "world/quake"); action native A_QuakeEx(int intensityX, int intensityY, int intensityZ, int duration, int damrad, int tremrad, sound sfx = "world/quake", int flags = 0, float mulWaveX = 1, float mulWaveY = 1, float mulWaveZ = 1, int falloff = 0, int highpoint = 0);