From 75cb8c00a67dc97720903c11e3bd7db037fef83b Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Sat, 18 Jun 2016 11:29:02 +0200 Subject: [PATCH 1/9] Fixed: the flags weren't properly reset if a mod used the old layers before the code used them --- src/p_pspr.cpp | 10 +++++++--- src/p_pspr.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index e634901108..87afc64fca 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -216,14 +216,18 @@ DPSprite *player_t::GetPSprite(PSPLayers layer) } // Always update the caller here in case we switched weapon - // or if the layer was being used by an inventory item before. + // or if the layer was being used by something else before. pspr->Caller = newcaller; if (newcaller != oldcaller) - { // Only change the flags if this layer was created now or if we updated the caller. + { // Only reset flags if this layer was created now or if it was being used before. if (layer >= PSP_TARGETCENTER) { // The targeter layers were affected by those. - pspr->Flags |= (PSPF_CVARFAST|PSPF_POWDOUBLE); + pspr->Flags = (PSPF_CVARFAST|PSPF_POWDOUBLE); + } + else + { + pspr->Flags = (PSPF_ADDWEAPON|PSPF_ADDBOB|PSPF_CVARFAST|PSPF_POWDOUBLE); } } diff --git a/src/p_pspr.h b/src/p_pspr.h index 2c7a36518d..a7cf49f8c9 100644 --- a/src/p_pspr.h +++ b/src/p_pspr.h @@ -42,7 +42,7 @@ class FArchive; // drawn directly on the view screen, // coordinates are given for a 320*200 view screen. // -enum PSPLayers // These are all called by the owner's ReadyWeapon. +enum PSPLayers { PSP_STRIFEHANDS = -1, PSP_WEAPON = 1, From da6e12d5bc736ed5a8a0097e396c4fd462e2875b Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Fri, 8 Jul 2016 11:13:58 +0200 Subject: [PATCH 2/9] Fixed: the weapon layer offsets were interpolated even after the player switched his weapon --- src/p_pspr.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 87afc64fca..148c788fa7 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -220,7 +220,7 @@ DPSprite *player_t::GetPSprite(PSPLayers layer) pspr->Caller = newcaller; if (newcaller != oldcaller) - { // Only reset flags if this layer was created now or if it was being used before. + { // Only reset stuff if this layer was created now or if it was being used before. if (layer >= PSP_TARGETCENTER) { // The targeter layers were affected by those. pspr->Flags = (PSPF_CVARFAST|PSPF_POWDOUBLE); @@ -229,6 +229,9 @@ DPSprite *player_t::GetPSprite(PSPLayers layer) { pspr->Flags = (PSPF_ADDWEAPON|PSPF_ADDBOB|PSPF_CVARFAST|PSPF_POWDOUBLE); } + + pspr->oldx = pspr->x; + pspr->oldy = pspr->y; } return pspr; From b8e1bead0a9d36f389041deba15f03ef0b2a10e4 Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Sat, 18 Jun 2016 09:38:22 +0200 Subject: [PATCH 3/9] Removed unneeded checks GetPSprite cannot return a null pointer and calling setstate with a null pointer destroys it --- src/g_strife/a_strifestuff.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/g_strife/a_strifestuff.cpp b/src/g_strife/a_strifestuff.cpp index 4e49121fac..8f571328b6 100644 --- a/src/g_strife/a_strifestuff.cpp +++ b/src/g_strife/a_strifestuff.cpp @@ -352,22 +352,15 @@ DEFINE_ACTION_FUNCTION(AActor, A_ItBurnsItBurns) if (self->player != nullptr && self->player->mo == self) { - FState *firehands = self->FindState("FireHands"); - if (firehands != NULL) - { - DPSprite *psp = self->player->GetPSprite(PSP_STRIFEHANDS); - if (psp != nullptr) - { - psp->SetState(firehands); - psp->Flags &= PSPF_ADDWEAPON | PSPF_ADDBOB; - psp->y = WEAPONTOP; - } + DPSprite *psp = self->player->GetPSprite(PSP_STRIFEHANDS); + psp->Flags &= PSPF_ADDWEAPON | PSPF_ADDBOB; + psp->y = WEAPONTOP; + psp->SetState(self->FindState("FireHands")); - self->player->ReadyWeapon = nullptr; - self->player->PendingWeapon = WP_NOCHANGE; - self->player->playerstate = PST_LIVE; - self->player->extralight = 3; - } + self->player->ReadyWeapon = nullptr; + self->player->PendingWeapon = WP_NOCHANGE; + self->player->playerstate = PST_LIVE; + self->player->extralight = 3; } return 0; } From 3ea70980f97a25bbcdb8dc213e7564f2a215841b Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Sat, 18 Jun 2016 09:46:55 +0200 Subject: [PATCH 4/9] Fixed: the strife firehands were interpolated if a mod used the layer before them The flags were also already reset, no need to do it twice --- src/g_strife/a_strifestuff.cpp | 5 +---- src/p_pspr.cpp | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/g_strife/a_strifestuff.cpp b/src/g_strife/a_strifestuff.cpp index 8f571328b6..c0e2807628 100644 --- a/src/g_strife/a_strifestuff.cpp +++ b/src/g_strife/a_strifestuff.cpp @@ -352,10 +352,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_ItBurnsItBurns) if (self->player != nullptr && self->player->mo == self) { - DPSprite *psp = self->player->GetPSprite(PSP_STRIFEHANDS); - psp->Flags &= PSPF_ADDWEAPON | PSPF_ADDBOB; - psp->y = WEAPONTOP; - psp->SetState(self->FindState("FireHands")); + P_SetPsprite(self->player, PSP_STRIFEHANDS, self->FindState("FireHands")); self->player->ReadyWeapon = nullptr; self->player->PendingWeapon = WP_NOCHANGE; diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 148c788fa7..94a0084dd2 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -229,6 +229,10 @@ DPSprite *player_t::GetPSprite(PSPLayers layer) { pspr->Flags = (PSPF_ADDWEAPON|PSPF_ADDBOB|PSPF_CVARFAST|PSPF_POWDOUBLE); } + if (layer == PSP_STRIFEHANDS) + { + pspr->y = WEAPONTOP; + } pspr->oldx = pspr->x; pspr->oldy = pspr->y; From 05d1df3571c5a0023529d1bf878facd2f96ca517 Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Sat, 18 Jun 2016 10:48:13 +0200 Subject: [PATCH 5/9] Fixed crashes with the A_CrispyPlayer and A_HandLower action functions Simply using FindPSprite in those functions wouldn't be enough because if a mod is using the firehands layer when they are called this would go very wrong --- src/g_strife/a_strifestuff.cpp | 25 ++++++++++++++++++++----- src/p_pspr.cpp | 3 +++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/g_strife/a_strifestuff.cpp b/src/g_strife/a_strifestuff.cpp index c0e2807628..4533016ec1 100644 --- a/src/g_strife/a_strifestuff.cpp +++ b/src/g_strife/a_strifestuff.cpp @@ -378,14 +378,22 @@ DEFINE_ACTION_FUNCTION(AActor, A_CrispyPlayer) if (self->player != nullptr && self->player->mo == self) { - self->player->playerstate = PST_DEAD; - DPSprite *psp; psp = self->player->GetPSprite(PSP_STRIFEHANDS); + FState *firehandslower = self->FindState("FireHandsLower"); FState *firehands = self->FindState("FireHands"); - if (firehandslower != NULL && firehands != NULL && firehands < firehandslower) - psp->SetState(psp->GetState() + (firehandslower - firehands)); + FState *state = psp->GetState(); + + if (state != nullptr && firehandslower != nullptr && firehands != nullptr && firehands < firehandslower) + { + self->player->playerstate = PST_DEAD; + psp->SetState(state + (firehandslower - firehands)); + } + else if (state == nullptr) + { + psp->SetState(nullptr); + } } return 0; } @@ -397,13 +405,20 @@ DEFINE_ACTION_FUNCTION(AActor, A_HandLower) if (self->player != nullptr) { DPSprite *psp = self->player->GetPSprite(PSP_STRIFEHANDS); + + if (psp->GetState() == nullptr) + { + psp->SetState(nullptr); + return 0; + } + psp->y += 9; if (psp->y > WEAPONBOTTOM*2) { psp->SetState(nullptr); } + if (self->player->extralight > 0) self->player->extralight--; } return 0; } - diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 94a0084dd2..2e285b34a7 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -231,6 +231,9 @@ DPSprite *player_t::GetPSprite(PSPLayers layer) } if (layer == PSP_STRIFEHANDS) { + // Some of the old hacks rely on this layer coming from the FireHands state. + // This is the ONLY time a psprite's state is actually null. + pspr->State = nullptr; pspr->y = WEAPONTOP; } From 5c182c7fd795e9f525dbdf8409b1cc87bbf38f93 Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Fri, 8 Jul 2016 11:55:04 +0200 Subject: [PATCH 6/9] Fixed a crash with heretic's ChickenPlayer class --- src/d_player.h | 5 ++++- src/g_heretic/a_chicken.cpp | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 48649de7ad..e932223aaa 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -532,7 +532,10 @@ public: void TickPSprites(); void DestroyPSprites(); DPSprite *FindPSprite(int layer); - DPSprite *GetPSprite(PSPLayers layer); // Used ONLY for compatibility with the old hardcoded layers. + // Used ONLY for compatibility with the old hardcoded layers. + // Make sure that a state is properly set after calling this unless + // you are 100% sure the context already implies the layer exists. + DPSprite *GetPSprite(PSPLayers layer); }; // Bookkeeping on players - state. diff --git a/src/g_heretic/a_chicken.cpp b/src/g_heretic/a_chicken.cpp index b70e4ff080..7f62d5f0e1 100644 --- a/src/g_heretic/a_chicken.cpp +++ b/src/g_heretic/a_chicken.cpp @@ -123,9 +123,10 @@ DEFINE_ACTION_FUNCTION(AActor, A_Feathers) void P_UpdateBeak (AActor *self) { - if (self->player != nullptr) + DPSprite *pspr; + if (self->player != nullptr && (pspr = self->player->FindPSprite(PSP_WEAPON)) != nullptr) { - self->player->GetPSprite(PSP_WEAPON)->y = WEAPONTOP + self->player->chickenPeck / 2; + pspr->y = WEAPONTOP + self->player->chickenPeck / 2; } } From 59593e57c6f04f5454481fe9756f491804738288 Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Thu, 14 Jul 2016 09:27:29 -0500 Subject: [PATCH 7/9] - Fixed: RGF_ITEMS wasn't considered a part of the RGF_MASK flag. --- src/thingdef/thingdef_codeptr.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 4f4d887794..25d68fc8fe 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -5669,7 +5669,9 @@ enum RadiusGiveFlags RGF_MONSTERS | RGF_OBJECTS | RGF_VOODOO | - RGF_CORPSES | RGF_MISSILES, + RGF_CORPSES | + RGF_MISSILES | + RGF_ITEMS, }; static bool DoRadiusGive(AActor *self, AActor *thing, PClassActor *item, int amount, double distance, int flags, PClassActor *filter, FName species, double mindist) @@ -5681,7 +5683,7 @@ static bool DoRadiusGive(AActor *self, AActor *thing, PClassActor *item, int amo if (!(flags & RGF_GIVESELF)) return false; } - else if (thing->flags & MF_MISSILE) + if (thing->flags & MF_MISSILE) { if (!missilePass) return false; From 09175a6a7a9607e63f5513a01262777e35b8fe50 Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Thu, 14 Jul 2016 09:55:13 -0500 Subject: [PATCH 8/9] This wasn't supposed to be committed... --- src/thingdef/thingdef_codeptr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 25d68fc8fe..441ba48995 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -5683,7 +5683,7 @@ static bool DoRadiusGive(AActor *self, AActor *thing, PClassActor *item, int amo if (!(flags & RGF_GIVESELF)) return false; } - if (thing->flags & MF_MISSILE) + else if (thing->flags & MF_MISSILE) { if (!missilePass) return false; From b121284fc023b6a211cfaa23d822d088cab40aaa Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Fri, 24 Jun 2016 13:19:49 -0500 Subject: [PATCH 9/9] Added GAF_SWITCH to GetAngle, inverting the function to get the caller's angle on the pointer instead. --- src/thingdef/thingdef_codeptr.cpp | 13 ++++++++++--- wadsrc/static/actors/actor.txt | 2 +- wadsrc/static/actors/constants.txt | 6 ++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 441ba48995..1b1c7b2cf6 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -329,13 +329,19 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetDistance) // NON-ACTION function to get the angle in degrees (normalized to -180..180) // //========================================================================== +enum GAFlags +{ + GAF_RELATIVE = 1, + GAF_SWITCH = 1 << 1, +}; + DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetAngle) { if (numret > 0) { assert(ret != NULL); PARAM_SELF_PROLOGUE(AActor); - PARAM_BOOL(relative); + PARAM_INT(flags); PARAM_INT_OPT(ptr) { ptr = AAPTR_TARGET; } AActor *target = COPY_AAPTR(self, ptr); @@ -346,9 +352,10 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetAngle) } else { - DVector3 diff = self->Vec3To(target); + DVector3 diff = (flags & GAF_SWITCH) ? target->Vec3To(self) : self->Vec3To(target); DAngle angto = diff.Angle(); - if (relative) angto = deltaangle(self->Angles.Yaw, angto); + DAngle yaw = (flags & GAF_SWITCH) ? target->Angles.Yaw : self->Angles.Yaw; + if (flags & GAF_RELATIVE) angto = deltaangle(yaw, angto); ret->SetFloat(angto.Degrees); } return 1; diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 901d7a553d..cb6ff4d934 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -41,7 +41,7 @@ ACTOR Actor native //: Thinker native bool IsPointerEqual(int ptr_select1, int ptr_select2); native int CountInv(class itemtype, int ptr_select = AAPTR_DEFAULT); native float GetDistance(bool checkz, int ptr = AAPTR_DEFAULT); - native float GetAngle(bool relative, int ptr = AAPTR_DEFAULT); + native float GetAngle(int flags, int ptr = AAPTR_DEFAULT); native float GetZAt(float px = 0, float py = 0, float angle = 0, int flags = 0, int pick_pointer = AAPTR_DEFAULT); native int GetSpawnHealth(); native int GetGibHealth(); diff --git a/wadsrc/static/actors/constants.txt b/wadsrc/static/actors/constants.txt index 7b75b481d1..46e810a7f7 100644 --- a/wadsrc/static/actors/constants.txt +++ b/wadsrc/static/actors/constants.txt @@ -652,3 +652,9 @@ enum BT_USER3 = 1<<23, BT_USER4 = 1<<24, }; +// Flags for GetAngle +enum +{ + GAF_RELATIVE = 1, + GAF_SWITCH = 1 << 1, +}; \ No newline at end of file