From fbf80849995724d5907da4eea2c732f3d68fe8e8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 2 Dec 2016 18:52:58 +0100 Subject: [PATCH] - corrected the export signatures of several script exports to contain the correct classes, so that the fudging in FindFunction could be removed. - fixed PARAM_ACTION_PROLOGUE to assign correct types to the implicit pointers. It gave the actual class to the wrong one, which until now did not matter because all functions were using 'Actor', regardless of actual class association. - fixed the definition of IceChunk and removed some redundant code here. Since A_FreezeDeathChunks already calls SetState, which in turn calls the state's action function, there is no need to call it again explicitly. --- src/g_shared/a_action.cpp | 32 ----------------------- src/g_shared/a_bridge.cpp | 4 +-- src/g_shared/a_specialspot.cpp | 4 +-- src/p_actionfunctions.cpp | 28 ++++++++++---------- src/p_pspr.cpp | 16 ++++++------ src/scripting/thingdef_data.cpp | 39 ++++++++++------------------ src/scripting/vm/vm.h | 4 +-- wadsrc/static/zscript/shared/ice.txt | 16 ++++++++++-- 8 files changed, 56 insertions(+), 87 deletions(-) diff --git a/src/g_shared/a_action.cpp b/src/g_shared/a_action.cpp index 2e4597617..187b215b8 100644 --- a/src/g_shared/a_action.cpp +++ b/src/g_shared/a_action.cpp @@ -13,7 +13,6 @@ #include "r_data/r_translate.h" static FRandom pr_freezedeath ("FreezeDeath"); -static FRandom pr_icesettics ("IceSetTics"); static FRandom pr_freeze ("FreezeDeathChunks"); @@ -121,36 +120,6 @@ DEFINE_ACTION_FUNCTION(AActor, A_FreezeDeath) return 0; } -//============================================================================ -// -// A_IceSetTics -// -//============================================================================ - -void IceSetTics(AActor *self) -{ - - int floor; - - self->tics = 70 + (pr_icesettics() & 63); - floor = P_GetThingFloorType(self); - if (Terrains[floor].DamageMOD == NAME_Fire) - { - self->tics >>= 2; - } - else if (Terrains[floor].DamageMOD == NAME_Ice) - { - self->tics <<= 1; - } -} - -DEFINE_ACTION_FUNCTION(AActor, A_IceSetTics) -{ - PARAM_SELF_PROLOGUE(AActor); - IceSetTics(self); - return 0; -} - //============================================================================ // // A_FreezeDeathChunks @@ -193,7 +162,6 @@ DEFINE_ACTION_FUNCTION(AActor, A_FreezeDeathChunks) mo->Vel.X = pr_freeze.Random2() / 128.; mo->Vel.Y = pr_freeze.Random2() / 128.; mo->Vel.Z = (mo->Z() - self->Z()) / self->Height * 4; - IceSetTics(mo); // set a random tic wait mo->RenderStyle = self->RenderStyle; mo->Alpha = self->Alpha; } diff --git a/src/g_shared/a_bridge.cpp b/src/g_shared/a_bridge.cpp index 138210061..cb6657796 100644 --- a/src/g_shared/a_bridge.cpp +++ b/src/g_shared/a_bridge.cpp @@ -114,7 +114,7 @@ static void BridgeOrbit(AActor *self) self->ceilingz = self->target->ceilingz; } -DEFINE_ACTION_FUNCTION(AActor, A_BridgeOrbit) +DEFINE_ACTION_FUNCTION(ABridgeBall, A_BridgeOrbit) { PARAM_SELF_PROLOGUE(AActor); BridgeOrbit(self); @@ -122,7 +122,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_BridgeOrbit) } -DEFINE_ACTION_FUNCTION(AActor, A_BridgeInit) +DEFINE_ACTION_FUNCTION(ACustomBridge, A_BridgeInit) { PARAM_SELF_PROLOGUE(AActor); PARAM_CLASS_DEF(balltype, AActor); diff --git a/src/g_shared/a_specialspot.cpp b/src/g_shared/a_specialspot.cpp index b5debf2df..335f10ace 100644 --- a/src/g_shared/a_specialspot.cpp +++ b/src/g_shared/a_specialspot.cpp @@ -402,9 +402,9 @@ void ASpecialSpot::Destroy() // will build a list of all mace spots in the level and spawn a // mace. The rest of the spots will do nothing. -DEFINE_ACTION_FUNCTION(AActor, A_SpawnSingleItem) +DEFINE_ACTION_FUNCTION(ASpecialSpot, A_SpawnSingleItem) { - PARAM_SELF_PROLOGUE(AActor); + PARAM_SELF_PROLOGUE(ASpecialSpot); PARAM_CLASS_NOT_NULL(cls, AActor); PARAM_INT_DEF (fail_sp) PARAM_INT_DEF (fail_co) diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 115bc1f54..83844ffd7 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -1773,9 +1773,9 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomComboAttack) // State jump function // //========================================================================== -DEFINE_ACTION_FUNCTION(AActor, A_JumpIfNoAmmo) +DEFINE_ACTION_FUNCTION(AStateProvider, A_JumpIfNoAmmo) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); PARAM_STATE_ACTION(jump); if (!ACTION_CALL_FROM_PSPRITE() || self->player->ReadyWeapon == nullptr) @@ -1844,9 +1844,9 @@ static void AimBulletMissile(AActor *proj, AActor *puff, int flags, bool temp, b } } -DEFINE_ACTION_FUNCTION(AActor, A_FireBullets) +DEFINE_ACTION_FUNCTION(AStateProvider, A_FireBullets) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); PARAM_ANGLE (spread_xy); PARAM_ANGLE (spread_z); PARAM_INT (numbullets); @@ -1974,9 +1974,9 @@ enum FP_Flags FPF_TRANSFERTRANSLATION = 2, FPF_NOAUTOAIM = 4, }; -DEFINE_ACTION_FUNCTION(AActor, A_FireCustomMissile) +DEFINE_ACTION_FUNCTION(AStateProvider, A_FireCustomMissile) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); PARAM_CLASS (ti, AActor); PARAM_ANGLE_DEF (angle); PARAM_BOOL_DEF (useammo); @@ -2051,9 +2051,9 @@ enum CPF_STEALARMOR = 32, }; -DEFINE_ACTION_FUNCTION(AActor, A_CustomPunch) +DEFINE_ACTION_FUNCTION(AStateProvider, A_CustomPunch) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); PARAM_INT (damage); PARAM_BOOL_DEF (norandom); PARAM_INT_DEF (flags); @@ -2155,9 +2155,9 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomPunch) // customizable railgun attack function // //========================================================================== -DEFINE_ACTION_FUNCTION(AActor, A_RailAttack) +DEFINE_ACTION_FUNCTION(AStateProvider, A_RailAttack) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); PARAM_INT (damage); PARAM_INT_DEF (spawnofs_xy); PARAM_BOOL_DEF (useammo); @@ -4443,9 +4443,9 @@ DEFINE_ACTION_FUNCTION(AActor, CheckIfInTargetLOS) // //=========================================================================== -DEFINE_ACTION_FUNCTION(AActor, A_CheckForReload) +DEFINE_ACTION_FUNCTION(AStateProvider, A_CheckForReload) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); if ( self->player == NULL || self->player->ReadyWeapon == NULL ) { @@ -4496,9 +4496,9 @@ DEFINE_ACTION_FUNCTION(AActor, A_CheckForReload) // //=========================================================================== -DEFINE_ACTION_FUNCTION(AActor, A_ResetReloadCounter) +DEFINE_ACTION_FUNCTION(AStateProvider, A_ResetReloadCounter) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); if (self->player == NULL || self->player->ReadyWeapon == NULL) return 0; diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 733741cb2..2bd3696d4 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -828,7 +828,7 @@ void DoReadyWeapon(AActor *self) DEFINE_ACTION_FUNCTION(AStateProvider, A_WeaponReady) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); PARAM_INT_DEF(flags); DoReadyWeaponToSwitch(self, !(flags & WRF_NoSwitch)); @@ -960,7 +960,7 @@ static void P_CheckWeaponButtons (player_t *player) DEFINE_ACTION_FUNCTION(AStateProvider, A_ReFire) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); PARAM_STATE_ACTION_DEF(state); A_ReFire(self, state); return 0; @@ -998,7 +998,7 @@ void A_ReFire(AActor *self, FState *state) DEFINE_ACTION_FUNCTION(AStateProvider, A_ClearReFire) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); player_t *player = self->player; if (NULL != player) @@ -1020,7 +1020,7 @@ DEFINE_ACTION_FUNCTION(AStateProvider, A_ClearReFire) DEFINE_ACTION_FUNCTION(AStateProvider, A_CheckReload) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); if (self->player != NULL) { @@ -1208,7 +1208,7 @@ DEFINE_ACTION_FUNCTION(AActor, OverlayID) DEFINE_ACTION_FUNCTION(AStateProvider, A_Lower) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); player_t *player = self->player; DPSprite *psp; @@ -1254,9 +1254,9 @@ DEFINE_ACTION_FUNCTION(AStateProvider, A_Lower) // //--------------------------------------------------------------------------- -DEFINE_ACTION_FUNCTION(AActor, A_Raise) +DEFINE_ACTION_FUNCTION(AStateProvider, A_Raise) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); if (self == nullptr) { @@ -1368,7 +1368,7 @@ enum GF_Flags DEFINE_ACTION_FUNCTION(AStateProvider, A_GunFlash) { - PARAM_ACTION_PROLOGUE(AActor); + PARAM_ACTION_PROLOGUE(AStateProvider); PARAM_STATE_ACTION_DEF(flash); PARAM_INT_DEF(flags); diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index b34157b36..18962fbca 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -583,35 +583,24 @@ FPropertyInfo *FindProperty(const char * string) AFuncDesc *FindFunction(PStruct *cls, const char * string) { - for (int i = 0; i < 2; i++) + int min = 0, max = AFTable.Size() - 1; + + while (min <= max) { - // Since many functions have been declared with Actor as owning class, despite being members of something else, let's hack around this until they have been fixed or exported. - // Since most of these are expected to be scriptified anyway, there's no point fixing them all before they get exported. - if (i == 1) + int mid = (min + max) / 2; + int lexval = stricmp(cls->TypeName.GetChars(), AFTable[mid].ClassName + 1); + if (lexval == 0) lexval = stricmp(string, AFTable[mid].FuncName); + if (lexval == 0) { - if (!cls->IsKindOf(RUNTIME_CLASS(PClassActor))) break; - cls = RUNTIME_CLASS(AActor); + return &AFTable[mid]; } - - int min = 0, max = AFTable.Size() - 1; - - while (min <= max) + else if (lexval > 0) { - int mid = (min + max) / 2; - int lexval = stricmp(cls->TypeName.GetChars(), AFTable[mid].ClassName + 1); - if (lexval == 0) lexval = stricmp(string, AFTable[mid].FuncName); - if (lexval == 0) - { - return &AFTable[mid]; - } - else if (lexval > 0) - { - min = mid + 1; - } - else - { - max = mid - 1; - } + min = mid + 1; + } + else + { + max = mid - 1; } } return nullptr; diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index 7285fb48d..aeb52dabb 100644 --- a/src/scripting/vm/vm.h +++ b/src/scripting/vm/vm.h @@ -1140,8 +1140,8 @@ class AActor; // callingstate - State this action was called from #define PARAM_ACTION_PROLOGUE(type) \ PARAM_PROLOGUE; \ - PARAM_OBJECT (self, type); \ - PARAM_OBJECT (stateowner, AActor) \ + PARAM_OBJECT (self, AActor); \ + PARAM_OBJECT (stateowner, type) \ PARAM_POINTER (stateinfo, FStateParamInfo) \ // Number of action paramaters diff --git a/wadsrc/static/zscript/shared/ice.txt b/wadsrc/static/zscript/shared/ice.txt index 534113785..9b72e2455 100644 --- a/wadsrc/static/zscript/shared/ice.txt +++ b/wadsrc/static/zscript/shared/ice.txt @@ -21,12 +21,24 @@ class IceChunk : Actor +NOBLOCKMAP +MOVEWITHSECTOR } - native void A_IceSetTics (); + + void A_IceSetTics () + { + tics = 70 + (random[IceTics]() & 63); + Name dtype = GetFloorTerrain().DamageMOD; + if (dtype == 'Fire') + { + tics >>= 2; + } + else if (dtype == 'Ice') + { + tics <<= 1; + } + } States { Spawn: - ICEC A 1; ICEC ABCD 10 A_IceSetTics; Stop; }