From 8c205ebac3bb1e20d29e8f9a4fa891b2c8c4d218 Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Wed, 18 May 2016 14:20:36 +0200 Subject: [PATCH] Added A_OverlayOffset Like A_WeaponOffset except it can access any psprites --- src/d_player.h | 1 + src/p_pspr.cpp | 61 +++++++++++++++++++---- wadsrc/static/actors/shared/inventory.txt | 1 + 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index ee9e64f0c..e743a7b4f 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -532,6 +532,7 @@ public: void TickPSprites(); void DestroyPSprites(); DPSprite *GetPSprite(psprnum_t layer); // Used ONLY for compatibility with the old hardcoded layers. + DPSprite *FindPSprite(int layer); }; // Bookkeeping on players - state. diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index c271e4795..11433b6f8 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -158,6 +158,29 @@ DPSprite *player_t::GetPSprite(psprnum_t layer) return pspr; } +//------------------------------------------------------------------------ +// +// +// +//------------------------------------------------------------------------ + +DPSprite *player_t::FindPSprite(int layer) +{ + if (layer == 0) + return nullptr; + + DPSprite *pspr = psprites; + while (pspr) + { + if (pspr->ID == layer) + break; + + pspr = pspr->Next; + } + + return pspr; +} + //--------------------------------------------------------------------------- // // PROC P_NewPspriteTick @@ -863,7 +886,7 @@ DEFINE_ACTION_FUNCTION(AInventory, A_CheckReload) //--------------------------------------------------------------------------- // -// PROC A_WeaponOffset +// PROC A_OverlayOffset // //--------------------------------------------------------------------------- enum WOFFlags @@ -873,16 +896,11 @@ enum WOFFlags WOF_ADD = 1 << 2, }; -DEFINE_ACTION_FUNCTION(AInventory, A_WeaponOffset) +void A_OverlayOffset(AActor *self, int layer, double wx, double wy, int flags) { - PARAM_ACTION_PROLOGUE; - PARAM_FLOAT_OPT(wx) { wx = 0.; } - PARAM_FLOAT_OPT(wy) { wy = 32.; } - PARAM_INT_OPT(flags) { flags = 0; } - if ((flags & WOF_KEEPX) && (flags & WOF_KEEPY)) { - return 0; + return; } player_t *player = self->player; @@ -890,7 +908,11 @@ DEFINE_ACTION_FUNCTION(AInventory, A_WeaponOffset) if (player && (player->playerstate != PST_DEAD)) { - psp = player->GetPSprite(ps_weapon); + psp = player->FindPSprite(layer); + + if (psp == nullptr) + return; + if (!(flags & WOF_KEEPX)) { if (flags & WOF_ADD) @@ -914,7 +936,26 @@ DEFINE_ACTION_FUNCTION(AInventory, A_WeaponOffset) } } } - +} + +DEFINE_ACTION_FUNCTION(AInventory, A_OverlayOffset) +{ + PARAM_ACTION_PROLOGUE; + PARAM_INT_OPT(layer) { layer = ps_weapon; } + PARAM_FLOAT_OPT(wx) { wx = 0.; } + PARAM_FLOAT_OPT(wy) { wy = 32.; } + PARAM_INT_OPT(flags) { flags = 0; } + A_OverlayOffset(self, layer, wx, wy, flags); + return 0; +} + +DEFINE_ACTION_FUNCTION(AInventory, A_WeaponOffset) +{ + PARAM_ACTION_PROLOGUE; + PARAM_FLOAT_OPT(wx) { wx = 0.; } + PARAM_FLOAT_OPT(wy) { wy = 32.; } + PARAM_INT_OPT(flags) { flags = 0; } + A_OverlayOffset(self, ps_weapon, wx, wy, flags); return 0; } diff --git a/wadsrc/static/actors/shared/inventory.txt b/wadsrc/static/actors/shared/inventory.txt index 990205869..396274332 100644 --- a/wadsrc/static/actors/shared/inventory.txt +++ b/wadsrc/static/actors/shared/inventory.txt @@ -50,6 +50,7 @@ ACTOR Inventory native action native A_RestoreSpecialThing1(); action native A_RestoreSpecialThing2(); action native A_WeaponOffset(float wx = 0, float wy = 32, int flags = 0); + action native A_OverlayOffset(int layer = 1, float wx = 0, float wy = 32, int flags = 0); States {