From 81314a6cd6381238ad3f33a1eaafd220aa784b42 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 20 Feb 2016 21:27:42 -0600 Subject: [PATCH 1/6] Revert "- fixed a few occurences where ACTION_RETURN_* eliminated the side effect of its argument when no return value was requested." This reverts commit 7ede77c1d274cb207b36926bcbf6013408988907. --- src/thingdef/thingdef_codeptr.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index e0d0fa541..7b5f33875 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -2008,15 +2008,13 @@ static bool DoGiveInventory(AActor *receiver, bool orresult, VM_ARGS) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveInventory) { PARAM_ACTION_PROLOGUE; - bool result = DoGiveInventory(self, false, VM_ARGS_NAMES); - ACTION_RETURN_BOOL(result); + ACTION_RETURN_BOOL(DoGiveInventory(self, false, VM_ARGS_NAMES)); } DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveToTarget) { PARAM_ACTION_PROLOGUE; - bool result = DoGiveInventory(self->target, false, VM_ARGS_NAMES); - ACTION_RETURN_BOOL(result); + ACTION_RETURN_BOOL(DoGiveInventory(self->target, false, VM_ARGS_NAMES)); } DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveToChildren) @@ -2096,15 +2094,13 @@ bool DoTakeInventory(AActor *receiver, bool orresult, VM_ARGS) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_TakeInventory) { PARAM_ACTION_PROLOGUE; - bool result = DoTakeInventory(self, false, VM_ARGS_NAMES); - ACTION_RETURN_BOOL(result); + ACTION_RETURN_BOOL(DoTakeInventory(self, false, VM_ARGS_NAMES)); } DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_TakeFromTarget) { PARAM_ACTION_PROLOGUE; - bool result = DoTakeInventory(self->target, false, VM_ARGS_NAMES); - ACTION_RETURN_BOOL(result); + ACTION_RETURN_BOOL(DoTakeInventory(self->target, false, VM_ARGS_NAMES)); } DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_TakeFromChildren) @@ -2405,8 +2401,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SpawnItem) AActor *mo = Spawn( missile, self->Vec3Angle(distance, self->angle, -self->floorclip + self->GetBobOffset() + zheight), ALLOW_REPLACE); int flags = (transfer_translation ? SIXF_TRANSFERTRANSLATION : 0) + (useammo ? SIXF_SETMASTER : 0); - bool result = InitSpawnedItem(self, mo, flags); - ACTION_RETURN_BOOL(result); // for an inventory item's use state + ACTION_RETURN_BOOL(InitSpawnedItem(self, mo, flags)); // for an inventory item's use state } //=========================================================================== @@ -3255,8 +3250,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIf) PARAM_BOOL (condition); PARAM_STATE (jump); - if (!condition) jump = NULL; - ACTION_RETURN_STATE(jump); + ACTION_RETURN_STATE(condition ? jump : NULL); } //=========================================================================== From 5e298173f7c7367d7acbf426a8908b1e36d78146 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 20 Feb 2016 21:34:58 -0600 Subject: [PATCH 2/6] Redo ACTION_RETURN macros so they can be treated like return statements --- src/thingdef/thingdef.h | 4 ++-- src/thingdef/thingdef_codeptr.cpp | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/thingdef/thingdef.h b/src/thingdef/thingdef.h index a9703ffa6..f5f2d156c 100644 --- a/src/thingdef/thingdef.h +++ b/src/thingdef/thingdef.h @@ -357,8 +357,8 @@ int MatchString (const char *in, const char **strings); } -#define ACTION_RETURN_STATE(state) if (numret > 0) { assert(ret != NULL); ret->SetPointer(state, ATAG_STATE); return 1; } return 0 -#define ACTION_RETURN_INT(v) if (numret > 0) { assert(ret != NULL); ret->SetInt(v); return 1; } return 0 +#define ACTION_RETURN_STATE(v) do { FState *state = v; if (numret > 0) { assert(ret != NULL); ret->SetPointer(state, ATAG_STATE); return 1; } return 0; } while(0) +#define ACTION_RETURN_INT(v) do { int u = v; if (numret > 0) { assert(ret != NULL); ret->SetInt(u); return 1; } return 0; } while(0) #define ACTION_RETURN_BOOL(v) ACTION_RETURN_INT(v) // Checks to see what called the current action function diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 7b5f33875..ad6a8b903 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -1969,8 +1969,6 @@ static bool DoGiveInventory(AActor *receiver, bool orresult, VM_ARGS) return false; } - bool res = true; - if (amount <= 0) { amount = 1; From cab39973df3534521644f827f8e16d7fbdb0f7bf Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 20 Feb 2016 21:52:29 -0600 Subject: [PATCH 3/6] Add PARAM_STATE_NOT_NULL for the A_Jump* functions - Now that state jumps are handled by returning a state, we still need a way for them to jump to a NULL state. If the parameter processed by this macro turns out to be NULL, Actor's 'Null' state will be substituted instead, since that's something that can be jumped to. --- src/thingdef/thingdef_codeptr.cpp | 129 ++++++++++++++++-------------- src/zscript/vm.h | 5 ++ 2 files changed, 72 insertions(+), 62 deletions(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index ad6a8b903..554ab0d64 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -825,6 +825,11 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Jump) { int jumpnum = (count == 1 ? 0 : (pr_cajump() % count)); PARAM_STATE_AT(paramnum + jumpnum, jumpto); + if (jumpto == NULL) + { // Remap NULL state to the 'Null' state found in Actor, since + // returning NULL would not jump. + jumpto = RUNTIME_CLASS(AActor)->FindState(NAME_Null); + } ACTION_RETURN_STATE(jumpto); } ACTION_RETURN_STATE(NULL); @@ -838,9 +843,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Jump) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfHealthLower) { PARAM_ACTION_PROLOGUE; - PARAM_INT (health); - PARAM_STATE (jump); - PARAM_INT_OPT (ptr_selector) { ptr_selector = AAPTR_DEFAULT; } + PARAM_INT (health); + PARAM_STATE_NOT_NULL(jump); + PARAM_INT_OPT (ptr_selector) { ptr_selector = AAPTR_DEFAULT; } AActor *measured; @@ -861,7 +866,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfHealthLower) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetOutsideMeleeRange) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(jump); + PARAM_STATE_NOT_NULL(jump); if (!self->CheckMeleeRange()) { @@ -878,7 +883,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetOutsideMeleeRange) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetInsideMeleeRange) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(jump); + PARAM_STATE_NOT_NULL(jump); if (self->CheckMeleeRange()) { @@ -895,9 +900,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetInsideMeleeRange) static int DoJumpIfCloser(AActor *target, VM_ARGS) { PARAM_ACTION_PROLOGUE; - PARAM_FIXED (dist); - PARAM_STATE (jump); - PARAM_BOOL_OPT(noz) { noz = false; } + PARAM_FIXED (dist); + PARAM_STATE_NOT_NULL(jump); + PARAM_BOOL_OPT (noz) { noz = false; } if (!target) { // No target - no jump @@ -951,10 +956,10 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfMasterCloser) int DoJumpIfInventory(AActor *owner, AActor *self, AActor *stateowner, FState *callingstate, VMValue *param, int numparam, VMReturn *ret, int numret) { int paramnum = NAP-1; - PARAM_CLASS (itemtype, AInventory); - PARAM_INT (itemamount); - PARAM_STATE (label); - PARAM_INT_OPT (setowner) { setowner = AAPTR_DEFAULT; } + PARAM_CLASS (itemtype, AInventory); + PARAM_INT (itemamount); + PARAM_STATE_NOT_NULL(label); + PARAM_INT_OPT (setowner) { setowner = AAPTR_DEFAULT; } if (itemtype == NULL) { @@ -1005,9 +1010,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfInTargetInventory) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfArmorType) { PARAM_ACTION_PROLOGUE; - PARAM_NAME (type); - PARAM_STATE (label); - PARAM_INT_OPT(amount) { amount = 1; } + PARAM_NAME (type); + PARAM_STATE_NOT_NULL(label); + PARAM_INT_OPT (amount) { amount = 1; } ABasicArmor *armor = (ABasicArmor *)self->FindInventory(NAME_BasicArmor); @@ -1462,7 +1467,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomComboAttack) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfNoAmmo) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(jump); + PARAM_STATE_NOT_NULL(jump); if (!ACTION_CALL_FROM_WEAPON()) { @@ -3029,7 +3034,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SpawnParticle) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckSight) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(jump); + PARAM_STATE_NOT_NULL(jump); for (int i = 0; i < MAXPLAYERS; i++) { @@ -3097,9 +3102,9 @@ static bool DoCheckSightOrRange(AActor *self, AActor *camera, double range, bool DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckSightOrRange) { PARAM_ACTION_PROLOGUE; - PARAM_FLOAT(range); - PARAM_STATE(jump); - PARAM_BOOL_OPT(twodi) { twodi = false; } + PARAM_FLOAT (range); + PARAM_STATE_NOT_NULL(jump); + PARAM_BOOL_OPT (twodi) { twodi = false; } range = range * range * (double(FRACUNIT) * FRACUNIT); // no need for square roots for (int i = 0; i < MAXPLAYERS; ++i) @@ -3162,9 +3167,9 @@ static bool DoCheckRange(AActor *self, AActor *camera, double range, bool twodi) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckRange) { PARAM_ACTION_PROLOGUE; - PARAM_FLOAT(range); - PARAM_STATE(jump); - PARAM_BOOL_OPT(twodi) { twodi = false; } + PARAM_FLOAT (range); + PARAM_STATE_NOT_NULL(jump); + PARAM_BOOL_OPT (twodi) { twodi = false; } range = range * range * (double(FRACUNIT) * FRACUNIT); // no need for square roots for (int i = 0; i < MAXPLAYERS; ++i) @@ -3245,8 +3250,8 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetBlend) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIf) { PARAM_ACTION_PROLOGUE; - PARAM_BOOL (condition); - PARAM_STATE (jump); + PARAM_BOOL (condition); + PARAM_STATE_NOT_NULL(jump); ACTION_RETURN_STATE(condition ? jump : NULL); } @@ -3349,7 +3354,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Burst) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckFloor) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(jump); + PARAM_STATE_NOT_NULL(jump); if (self->Z() <= self->floorz) { @@ -3368,7 +3373,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckFloor) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckCeiling) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(jump); + PARAM_STATE_NOT_NULL(jump); if (self->Top() >= self->ceilingz) // Height needs to be counted { @@ -3504,7 +3509,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Respawn) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_PlayerSkinCheck) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(jump); + PARAM_STATE_NOT_NULL(jump); if (self->player != NULL && skins[self->player->userinfo.GetSkin()].othergame) @@ -3687,10 +3692,10 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckLOF) fixed_t vx, vy, vz; PARAM_ACTION_PROLOGUE; - PARAM_STATE (jump); - PARAM_INT_OPT (flags) { flags = 0; } - PARAM_FIXED_OPT (range) { range = 0; } - PARAM_FIXED_OPT (minrange) { minrange = 0; } + PARAM_STATE_NOT_NULL(jump); + PARAM_INT_OPT (flags) { flags = 0; } + PARAM_FIXED_OPT (range) { range = 0; } + PARAM_FIXED_OPT (minrange) { minrange = 0; } { PARAM_ANGLE_OPT (angle) { angle = 0; } PARAM_ANGLE_OPT (pitch) { pitch = 0; } @@ -3887,11 +3892,11 @@ enum JLOS_flags DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetInLOS) { PARAM_ACTION_PROLOGUE; - PARAM_STATE (jump); - PARAM_ANGLE_OPT (fov) { fov = 0; } - PARAM_INT_OPT (flags) { flags = 0; } - PARAM_FIXED_OPT (dist_max) { dist_max = 0; } - PARAM_FIXED_OPT (dist_close) { dist_close = 0; } + PARAM_STATE_NOT_NULL(jump); + PARAM_ANGLE_OPT (fov) { fov = 0; } + PARAM_INT_OPT (flags) { flags = 0; } + PARAM_FIXED_OPT (dist_max) { dist_max = 0; } + PARAM_FIXED_OPT (dist_close) { dist_close = 0; } angle_t an; AActor *target, *viewport; @@ -4022,11 +4027,11 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetInLOS) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfInTargetLOS) { PARAM_ACTION_PROLOGUE; - PARAM_STATE (jump); - PARAM_ANGLE_OPT (fov) { fov = 0; } - PARAM_INT_OPT (flags) { flags = 0; } - PARAM_FIXED_OPT (dist_max) { dist_max = 0; } - PARAM_FIXED_OPT (dist_close) { dist_close = 0; } + PARAM_STATE_NOT_NULL(jump); + PARAM_ANGLE_OPT (fov) { fov = 0; } + PARAM_INT_OPT (flags) { flags = 0; } + PARAM_FIXED_OPT (dist_max) { dist_max = 0; } + PARAM_FIXED_OPT (dist_close) { dist_close = 0; } angle_t an; AActor *target; @@ -4109,9 +4114,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckForReload) { ACTION_RETURN_STATE(NULL); } - PARAM_INT (count); - PARAM_STATE (jump); - PARAM_BOOL_OPT (dontincrement) { dontincrement = false; } + PARAM_INT (count); + PARAM_STATE_NOT_NULL(jump); + PARAM_BOOL_OPT (dontincrement) { dontincrement = false; } if (numret > 0) { @@ -4273,9 +4278,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_ChangeFlag) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckFlag) { PARAM_ACTION_PROLOGUE; - PARAM_STRING (flagname); - PARAM_STATE (jumpto); - PARAM_INT_OPT (checkpointer) { checkpointer = AAPTR_DEFAULT; } + PARAM_STRING (flagname); + PARAM_STATE_NOT_NULL(jumpto); + PARAM_INT_OPT (checkpointer) { checkpointer = AAPTR_DEFAULT; } AActor *owner = COPY_AAPTR(self, checkpointer); if (owner == NULL) @@ -4380,8 +4385,8 @@ DEFINE_ACTION_FUNCTION_PARAMS (AActor, A_FaceConsolePlayer) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_MonsterRefire) { PARAM_ACTION_PROLOGUE; - PARAM_INT (prob); - PARAM_STATE (jump); + PARAM_INT (prob); + PARAM_STATE_NOT_NULL(jump); A_FaceTarget(self); @@ -5210,7 +5215,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Warp) if (P_Thing_Warp(self, reference, xofs, yofs, zofs, angle, flags, heightoffset, radiusoffset, pitch)) { - if (success_state) + if (success_state != NULL) { // Jumps should never set the result for inventory state chains! // in this case, you have the statejump to help you handle all the success anyway. @@ -5554,9 +5559,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_RadiusGive) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckSpecies) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(jump); - PARAM_NAME_OPT(species) { species = NAME_None; } - PARAM_INT_OPT(ptr) { ptr = AAPTR_DEFAULT; } + PARAM_STATE_NOT_NULL(jump); + PARAM_NAME_OPT (species) { species = NAME_None; } + PARAM_INT_OPT (ptr) { ptr = AAPTR_DEFAULT; } AActor *mobj = COPY_AAPTR(self, ptr); @@ -6354,12 +6359,12 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_ResetHealth) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfHigherOrLower) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(high); - PARAM_STATE(low); - PARAM_FIXED_OPT(offsethigh) { offsethigh = 0; } - PARAM_FIXED_OPT(offsetlow) { offsetlow = 0; } - PARAM_BOOL_OPT(includeHeight) { includeHeight = true; } - PARAM_INT_OPT(ptr) { ptr = AAPTR_TARGET; } + PARAM_STATE_NOT_NULL(high); + PARAM_STATE_NOT_NULL(low); + PARAM_FIXED_OPT (offsethigh) { offsethigh = 0; } + PARAM_FIXED_OPT (offsetlow) { offsetlow = 0; } + PARAM_BOOL_OPT (includeHeight) { includeHeight = true; } + PARAM_INT_OPT (ptr) { ptr = AAPTR_TARGET; } AActor *mobj = COPY_AAPTR(self, ptr); @@ -6495,7 +6500,7 @@ enum CPXFflags DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckProximity) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(jump); + PARAM_STATE_NOT_NULL(jump); PARAM_CLASS(classname, AActor); PARAM_FIXED(distance); PARAM_INT_OPT(count) { count = 1; } @@ -6650,7 +6655,7 @@ enum CBF DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckBlock) { PARAM_ACTION_PROLOGUE; - PARAM_STATE(block) + PARAM_STATE_NOT_NULL(block); PARAM_INT_OPT(flags) { flags = 0; } PARAM_INT_OPT(ptr) { ptr = AAPTR_DEFAULT; } diff --git a/src/zscript/vm.h b/src/zscript/vm.h index f92906fd2..9a5e82b75 100644 --- a/src/zscript/vm.h +++ b/src/zscript/vm.h @@ -951,4 +951,9 @@ void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction #define PARAM_OBJECT_OPT(x,type) ++paramnum; PARAM_OBJECT_OPT_AT(paramnum,x,type) #define PARAM_CLASS_OPT(x,base) ++paramnum; PARAM_CLASS_OPT_AT(paramnum,x,base) +// For use in the A_Jump* family of functions. If the function is passed a NULL state, +// it still needs to be able to jump (and destroy the actor), so map it to Actor's +// 'Null' state. +#define PARAM_STATE_NOT_NULL(x) PARAM_STATE(x); do { if (x == NULL) { x = RUNTIME_CLASS(AActor)->FindState(NAME_Null); } } while(0) + #endif From e7b9e7e95509832f32dae330eb53e250d5a7eea3 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 20 Feb 2016 22:05:17 -0600 Subject: [PATCH 4/6] Rename A_Int/A_Bool/A_State to int/bool/state - This is an effort to emphasize that these are just type casts. Now they look like function-style casts with no action function styling. They do no magic joojoo at all. The only reason they exist is because the DECORATE parser can only parse return statements that call a function, so these satisfy that requirement. i.e. *return int(666);* is identical to *return 666;* (if the parser could handle the latter). --- src/namedef.h | 4 ++++ src/thingdef/thingdef.h | 1 + src/thingdef/thingdef_codeptr.cpp | 12 ++++++------ src/thingdef/thingdef_states.cpp | 25 ++++++++++++++++++++++++- wadsrc/static/actors/actor.txt | 9 +++++---- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/namedef.h b/src/namedef.h index e7af23025..323d6f29c 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -673,3 +673,7 @@ xx(Max_Exp) xx(Mant_Dig) xx(Min_10_Exp) xx(Max_10_Exp) + +xx(__decorate_internal_int__) +xx(__decorate_internal_bool__) +xx(__decorate_internal_state__) \ No newline at end of file diff --git a/src/thingdef/thingdef.h b/src/thingdef/thingdef.h index f5f2d156c..e2d8eb1f4 100644 --- a/src/thingdef/thingdef.h +++ b/src/thingdef/thingdef.h @@ -192,6 +192,7 @@ void ParseFunctionParameters(FScanner &sc, PClassActor *cls, TArray *args, TArray *argflags, PClassActor *cls, DWORD funcflags); diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 554ab0d64..60e57f9a3 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -325,13 +325,13 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetDistance) //=========================================================================== // -// A_State +// __decorate_internal_state__ // // Returns the state passed in. // //=========================================================================== -DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_State) +DEFINE_ACTION_FUNCTION_PARAMS(AActor, __decorate_internal_state__) { PARAM_PROLOGUE; PARAM_OBJECT(self, AActor); @@ -341,13 +341,13 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_State) //=========================================================================== // -// A_Int +// __decorate_internal_int__ // // Returns the int passed in. // //=========================================================================== -DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Int) +DEFINE_ACTION_FUNCTION_PARAMS(AActor, __decorate_internal_int__) { PARAM_PROLOGUE; PARAM_OBJECT(self, AActor); @@ -357,13 +357,13 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Int) //=========================================================================== // -// A_Bool +// __decorate_internal_bool__ // // Returns the bool passed in. // //=========================================================================== -DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Bool) +DEFINE_ACTION_FUNCTION_PARAMS(AActor, __decorate_internal_bool__) { PARAM_PROLOGUE; PARAM_OBJECT(self, AActor); diff --git a/src/thingdef/thingdef_states.cpp b/src/thingdef/thingdef_states.cpp index f90b34c47..32a6b0913 100644 --- a/src/thingdef/thingdef_states.cpp +++ b/src/thingdef/thingdef_states.cpp @@ -555,7 +555,9 @@ FxVMFunctionCall *ParseAction(FScanner &sc, FState state, FString statestring, B return call; } - PFunction *afd = dyn_cast(bag.Info->Symbols.FindSymbol(FName(sc.String, true), true)); + FName symname = FName(sc.String, true); + symname = CheckCastKludges(symname); + PFunction *afd = dyn_cast(bag.Info->Symbols.FindSymbol(symname, true)); if (afd != NULL) { FArgumentList *args = new FArgumentList; @@ -678,3 +680,24 @@ void ParseFunctionParameters(FScanner &sc, PClassActor *cls, TArray itemtype, int ptr_select = AAPTR_DEFAULT); native float GetDistance(bool checkz, int ptr = AAPTR_DEFAULT); - native state A_State(state returnme); - native int A_Int(int returnme); - native bool A_Bool(bool returnme); - // Action functions // Meh, MBF redundant functions. Only for DeHackEd support. action native A_Turn(float angle = 0); @@ -353,4 +349,9 @@ ACTOR Actor native //: Thinker POL5 A -1 Stop } + + // Internal functions + native state __decorate_internal_state__(state); + native int __decorate_internal_int__(int); + native bool __decorate_internal_bool__(bool); } From 19af8a3a8243af25510dffa76f1c4f6625e39f44 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 20 Feb 2016 23:13:44 -0600 Subject: [PATCH 5/6] Change error message for missing return --- src/thingdef/thingdef_states.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thingdef/thingdef_states.cpp b/src/thingdef/thingdef_states.cpp index 32a6b0913..50b03eb27 100644 --- a/src/thingdef/thingdef_states.cpp +++ b/src/thingdef/thingdef_states.cpp @@ -372,7 +372,7 @@ void AddImplicitReturn(FxSequence *code, const PPrototype *proto, FScanner &sc) else { // Something was returned earlier in the sequence. Make it an error // instead of adding an implicit one. - sc.ScriptError("Action list must return a value"); + sc.ScriptError("Not all paths return a value"); } } From 70c663b253b6ed7c09d0aff287b46ec14962316e Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 21 Feb 2016 19:21:39 -0600 Subject: [PATCH 6/6] Revert "Add PARAM_STATE_NOT_NULL for the A_Jump* functions" - This reverts commit cab39973df3534521644f827f8e16d7fbdb0f7bf. I was wrong. DoJump never allowed jumping to NULL states. --- src/thingdef/thingdef_codeptr.cpp | 129 ++++++++++++++---------------- src/zscript/vm.h | 5 -- 2 files changed, 62 insertions(+), 72 deletions(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 60e57f9a3..7119b577d 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -825,11 +825,6 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Jump) { int jumpnum = (count == 1 ? 0 : (pr_cajump() % count)); PARAM_STATE_AT(paramnum + jumpnum, jumpto); - if (jumpto == NULL) - { // Remap NULL state to the 'Null' state found in Actor, since - // returning NULL would not jump. - jumpto = RUNTIME_CLASS(AActor)->FindState(NAME_Null); - } ACTION_RETURN_STATE(jumpto); } ACTION_RETURN_STATE(NULL); @@ -843,9 +838,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Jump) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfHealthLower) { PARAM_ACTION_PROLOGUE; - PARAM_INT (health); - PARAM_STATE_NOT_NULL(jump); - PARAM_INT_OPT (ptr_selector) { ptr_selector = AAPTR_DEFAULT; } + PARAM_INT (health); + PARAM_STATE (jump); + PARAM_INT_OPT (ptr_selector) { ptr_selector = AAPTR_DEFAULT; } AActor *measured; @@ -866,7 +861,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfHealthLower) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetOutsideMeleeRange) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); + PARAM_STATE(jump); if (!self->CheckMeleeRange()) { @@ -883,7 +878,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetOutsideMeleeRange) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetInsideMeleeRange) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); + PARAM_STATE(jump); if (self->CheckMeleeRange()) { @@ -900,9 +895,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetInsideMeleeRange) static int DoJumpIfCloser(AActor *target, VM_ARGS) { PARAM_ACTION_PROLOGUE; - PARAM_FIXED (dist); - PARAM_STATE_NOT_NULL(jump); - PARAM_BOOL_OPT (noz) { noz = false; } + PARAM_FIXED (dist); + PARAM_STATE (jump); + PARAM_BOOL_OPT(noz) { noz = false; } if (!target) { // No target - no jump @@ -956,10 +951,10 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfMasterCloser) int DoJumpIfInventory(AActor *owner, AActor *self, AActor *stateowner, FState *callingstate, VMValue *param, int numparam, VMReturn *ret, int numret) { int paramnum = NAP-1; - PARAM_CLASS (itemtype, AInventory); - PARAM_INT (itemamount); - PARAM_STATE_NOT_NULL(label); - PARAM_INT_OPT (setowner) { setowner = AAPTR_DEFAULT; } + PARAM_CLASS (itemtype, AInventory); + PARAM_INT (itemamount); + PARAM_STATE (label); + PARAM_INT_OPT (setowner) { setowner = AAPTR_DEFAULT; } if (itemtype == NULL) { @@ -1010,9 +1005,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfInTargetInventory) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfArmorType) { PARAM_ACTION_PROLOGUE; - PARAM_NAME (type); - PARAM_STATE_NOT_NULL(label); - PARAM_INT_OPT (amount) { amount = 1; } + PARAM_NAME (type); + PARAM_STATE (label); + PARAM_INT_OPT(amount) { amount = 1; } ABasicArmor *armor = (ABasicArmor *)self->FindInventory(NAME_BasicArmor); @@ -1467,7 +1462,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomComboAttack) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfNoAmmo) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); + PARAM_STATE(jump); if (!ACTION_CALL_FROM_WEAPON()) { @@ -3034,7 +3029,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SpawnParticle) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckSight) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); + PARAM_STATE(jump); for (int i = 0; i < MAXPLAYERS; i++) { @@ -3102,9 +3097,9 @@ static bool DoCheckSightOrRange(AActor *self, AActor *camera, double range, bool DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckSightOrRange) { PARAM_ACTION_PROLOGUE; - PARAM_FLOAT (range); - PARAM_STATE_NOT_NULL(jump); - PARAM_BOOL_OPT (twodi) { twodi = false; } + PARAM_FLOAT(range); + PARAM_STATE(jump); + PARAM_BOOL_OPT(twodi) { twodi = false; } range = range * range * (double(FRACUNIT) * FRACUNIT); // no need for square roots for (int i = 0; i < MAXPLAYERS; ++i) @@ -3167,9 +3162,9 @@ static bool DoCheckRange(AActor *self, AActor *camera, double range, bool twodi) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckRange) { PARAM_ACTION_PROLOGUE; - PARAM_FLOAT (range); - PARAM_STATE_NOT_NULL(jump); - PARAM_BOOL_OPT (twodi) { twodi = false; } + PARAM_FLOAT(range); + PARAM_STATE(jump); + PARAM_BOOL_OPT(twodi) { twodi = false; } range = range * range * (double(FRACUNIT) * FRACUNIT); // no need for square roots for (int i = 0; i < MAXPLAYERS; ++i) @@ -3250,8 +3245,8 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetBlend) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIf) { PARAM_ACTION_PROLOGUE; - PARAM_BOOL (condition); - PARAM_STATE_NOT_NULL(jump); + PARAM_BOOL (condition); + PARAM_STATE (jump); ACTION_RETURN_STATE(condition ? jump : NULL); } @@ -3354,7 +3349,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Burst) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckFloor) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); + PARAM_STATE(jump); if (self->Z() <= self->floorz) { @@ -3373,7 +3368,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckFloor) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckCeiling) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); + PARAM_STATE(jump); if (self->Top() >= self->ceilingz) // Height needs to be counted { @@ -3509,7 +3504,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Respawn) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_PlayerSkinCheck) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); + PARAM_STATE(jump); if (self->player != NULL && skins[self->player->userinfo.GetSkin()].othergame) @@ -3692,10 +3687,10 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckLOF) fixed_t vx, vy, vz; PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); - PARAM_INT_OPT (flags) { flags = 0; } - PARAM_FIXED_OPT (range) { range = 0; } - PARAM_FIXED_OPT (minrange) { minrange = 0; } + PARAM_STATE (jump); + PARAM_INT_OPT (flags) { flags = 0; } + PARAM_FIXED_OPT (range) { range = 0; } + PARAM_FIXED_OPT (minrange) { minrange = 0; } { PARAM_ANGLE_OPT (angle) { angle = 0; } PARAM_ANGLE_OPT (pitch) { pitch = 0; } @@ -3892,11 +3887,11 @@ enum JLOS_flags DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetInLOS) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); - PARAM_ANGLE_OPT (fov) { fov = 0; } - PARAM_INT_OPT (flags) { flags = 0; } - PARAM_FIXED_OPT (dist_max) { dist_max = 0; } - PARAM_FIXED_OPT (dist_close) { dist_close = 0; } + PARAM_STATE (jump); + PARAM_ANGLE_OPT (fov) { fov = 0; } + PARAM_INT_OPT (flags) { flags = 0; } + PARAM_FIXED_OPT (dist_max) { dist_max = 0; } + PARAM_FIXED_OPT (dist_close) { dist_close = 0; } angle_t an; AActor *target, *viewport; @@ -4027,11 +4022,11 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetInLOS) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfInTargetLOS) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); - PARAM_ANGLE_OPT (fov) { fov = 0; } - PARAM_INT_OPT (flags) { flags = 0; } - PARAM_FIXED_OPT (dist_max) { dist_max = 0; } - PARAM_FIXED_OPT (dist_close) { dist_close = 0; } + PARAM_STATE (jump); + PARAM_ANGLE_OPT (fov) { fov = 0; } + PARAM_INT_OPT (flags) { flags = 0; } + PARAM_FIXED_OPT (dist_max) { dist_max = 0; } + PARAM_FIXED_OPT (dist_close) { dist_close = 0; } angle_t an; AActor *target; @@ -4114,9 +4109,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckForReload) { ACTION_RETURN_STATE(NULL); } - PARAM_INT (count); - PARAM_STATE_NOT_NULL(jump); - PARAM_BOOL_OPT (dontincrement) { dontincrement = false; } + PARAM_INT (count); + PARAM_STATE (jump); + PARAM_BOOL_OPT (dontincrement) { dontincrement = false; } if (numret > 0) { @@ -4278,9 +4273,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_ChangeFlag) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckFlag) { PARAM_ACTION_PROLOGUE; - PARAM_STRING (flagname); - PARAM_STATE_NOT_NULL(jumpto); - PARAM_INT_OPT (checkpointer) { checkpointer = AAPTR_DEFAULT; } + PARAM_STRING (flagname); + PARAM_STATE (jumpto); + PARAM_INT_OPT (checkpointer) { checkpointer = AAPTR_DEFAULT; } AActor *owner = COPY_AAPTR(self, checkpointer); if (owner == NULL) @@ -4385,8 +4380,8 @@ DEFINE_ACTION_FUNCTION_PARAMS (AActor, A_FaceConsolePlayer) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_MonsterRefire) { PARAM_ACTION_PROLOGUE; - PARAM_INT (prob); - PARAM_STATE_NOT_NULL(jump); + PARAM_INT (prob); + PARAM_STATE (jump); A_FaceTarget(self); @@ -5215,7 +5210,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Warp) if (P_Thing_Warp(self, reference, xofs, yofs, zofs, angle, flags, heightoffset, radiusoffset, pitch)) { - if (success_state != NULL) + if (success_state) { // Jumps should never set the result for inventory state chains! // in this case, you have the statejump to help you handle all the success anyway. @@ -5559,9 +5554,9 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_RadiusGive) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckSpecies) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); - PARAM_NAME_OPT (species) { species = NAME_None; } - PARAM_INT_OPT (ptr) { ptr = AAPTR_DEFAULT; } + PARAM_STATE(jump); + PARAM_NAME_OPT(species) { species = NAME_None; } + PARAM_INT_OPT(ptr) { ptr = AAPTR_DEFAULT; } AActor *mobj = COPY_AAPTR(self, ptr); @@ -6359,12 +6354,12 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_ResetHealth) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfHigherOrLower) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(high); - PARAM_STATE_NOT_NULL(low); - PARAM_FIXED_OPT (offsethigh) { offsethigh = 0; } - PARAM_FIXED_OPT (offsetlow) { offsetlow = 0; } - PARAM_BOOL_OPT (includeHeight) { includeHeight = true; } - PARAM_INT_OPT (ptr) { ptr = AAPTR_TARGET; } + PARAM_STATE(high); + PARAM_STATE(low); + PARAM_FIXED_OPT(offsethigh) { offsethigh = 0; } + PARAM_FIXED_OPT(offsetlow) { offsetlow = 0; } + PARAM_BOOL_OPT(includeHeight) { includeHeight = true; } + PARAM_INT_OPT(ptr) { ptr = AAPTR_TARGET; } AActor *mobj = COPY_AAPTR(self, ptr); @@ -6500,7 +6495,7 @@ enum CPXFflags DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckProximity) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(jump); + PARAM_STATE(jump); PARAM_CLASS(classname, AActor); PARAM_FIXED(distance); PARAM_INT_OPT(count) { count = 1; } @@ -6655,7 +6650,7 @@ enum CBF DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckBlock) { PARAM_ACTION_PROLOGUE; - PARAM_STATE_NOT_NULL(block); + PARAM_STATE(block) PARAM_INT_OPT(flags) { flags = 0; } PARAM_INT_OPT(ptr) { ptr = AAPTR_DEFAULT; } diff --git a/src/zscript/vm.h b/src/zscript/vm.h index 9a5e82b75..f92906fd2 100644 --- a/src/zscript/vm.h +++ b/src/zscript/vm.h @@ -951,9 +951,4 @@ void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction #define PARAM_OBJECT_OPT(x,type) ++paramnum; PARAM_OBJECT_OPT_AT(paramnum,x,type) #define PARAM_CLASS_OPT(x,base) ++paramnum; PARAM_CLASS_OPT_AT(paramnum,x,base) -// For use in the A_Jump* family of functions. If the function is passed a NULL state, -// it still needs to be able to jump (and destroy the actor), so map it to Actor's -// 'Null' state. -#define PARAM_STATE_NOT_NULL(x) PARAM_STATE(x); do { if (x == NULL) { x = RUNTIME_CLASS(AActor)->FindState(NAME_Null); } } while(0) - #endif