From 2f5ae3b51e514706fe06f1d83ec2240863c49b42 Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Fri, 27 May 2016 18:08:56 +0200 Subject: [PATCH] Changed the default layer indices and renamed them Note that this doesn't compile yet --- src/d_player.h | 2 +- src/p_pspr.cpp | 44 ++++++++++------------- src/p_pspr.h | 15 ++++---- src/p_user.cpp | 18 +++++++--- src/r_things.cpp | 8 ++--- wadsrc/static/actors/constants.txt | 7 ++++ wadsrc/static/actors/shared/inventory.txt | 2 +- 7 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 8a90d9680f..48649de7ad 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -532,7 +532,7 @@ public: void TickPSprites(); void DestroyPSprites(); DPSprite *FindPSprite(int layer); - DPSprite *GetPSprite(psprnum_t layer); // Used ONLY for compatibility with the old hardcoded layers. + DPSprite *GetPSprite(PSPLayers layer); // Used ONLY for compatibility with the old hardcoded layers. }; // Bookkeeping on players - state. diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 52fc483dc8..b37e30a6f3 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -142,10 +142,10 @@ DPSprite::DPSprite(player_t *owner, AInventory *caller, int id) if (Next && Next->ID == ID && ID != 0) Next->Destroy(); // Replace it. - if (ID == ps_weapon || ID == ps_flash || (ID >= NUMPSPRITES && Caller->IsKindOf(RUNTIME_CLASS(AWeapon)))) + if (ID == PSP_WEAPON || ID == PSP_FLASH || (ID < PSP_TARGETCENTER && Caller->IsKindOf(RUNTIME_CLASS(AWeapon)))) { Flags |= PSPF_ADDBOB; - if (ID != ps_weapon) + if (ID != PSP_WEAPON) Flags |= PSPF_ADDWEAPON; } } @@ -179,10 +179,8 @@ DPSprite *player_t::FindPSprite(int layer) // //------------------------------------------------------------------------ -DPSprite *player_t::GetPSprite(psprnum_t layer) +DPSprite *player_t::GetPSprite(PSPLayers layer) { - assert(layer > 0 && layer < NUMPSPRITES); - DPSprite *pspr = FindPSprite(layer); if (pspr == nullptr) pspr = new DPSprite(this, ReadyWeapon, layer); @@ -226,14 +224,14 @@ void DPSprite::NewTick() void DPSprite::SetState(FState *newstate, bool pending) { - if (ID == ps_weapon) + if (ID == PSP_WEAPON) { // A_WeaponReady will re-set these as needed Owner->WeaponState &= ~(WF_WEAPONREADY | WF_WEAPONREADYALT | WF_WEAPONBOBBING | WF_WEAPONSWITCHOK | WF_WEAPONRELOADOK | WF_WEAPONZOOMOK | WF_USER1OK | WF_USER2OK | WF_USER3OK | WF_USER4OK); } // Special handling for the old hardcoded layers. - if (ID > 0 && ID < NUMPSPRITES) + if (ID == PSP_WEAPON || ID == PSP_FLASH || ID >= PSP_TARGETCENTER) Caller = Owner->ReadyWeapon; processPending = pending; @@ -261,9 +259,9 @@ void DPSprite::SetState(FState *newstate, bool pending) Tics = newstate->GetTics(); // could be 0 - if ((ID > 0 && ID < NUMPSPRITES) || Caller->IsKindOf(RUNTIME_CLASS(AWeapon))) + if ((ID == PSP_WEAPON || ID == PSP_FLASH || ID >= PSP_TARGETCENTER) || Caller->IsKindOf(RUNTIME_CLASS(AWeapon))) { // The targeter layers are affected by this too. - if (sv_fastweapons == 2 && ID == ps_weapon) + if (sv_fastweapons == 2 && ID == PSP_WEAPON) Tics = newstate->ActionFunc == nullptr ? 0 : 1; else if (sv_fastweapons == 3) Tics = (newstate->GetTics() != 0); @@ -271,7 +269,7 @@ void DPSprite::SetState(FState *newstate, bool pending) Tics = 1; // great for producing decals :) } - if (ID != ps_flash) + if (ID != PSP_FLASH) { // It's still possible to set the flash layer's offsets with the action function. if (newstate->GetMisc1()) { // Set coordinates. @@ -313,7 +311,7 @@ void DPSprite::SetState(FState *newstate, bool pending) return; } -void P_SetPsprite(player_t *player, psprnum_t id, FState *state, bool pending) +void P_SetPsprite(player_t *player, PSPLayers id, FState *state, bool pending) { if (player == nullptr) return; player->GetPSprite(id)->SetState(state, pending); @@ -961,7 +959,7 @@ void A_OverlayOffset(AActor *self, int layer, double wx, double wy, int flags) DEFINE_ACTION_FUNCTION(AInventory, A_OverlayOffset) { PARAM_ACTION_PROLOGUE; - PARAM_INT_OPT(layer) { layer = ps_weapon; } + PARAM_INT_OPT(layer) { layer = PSP_WEAPON; } PARAM_FLOAT_OPT(wx) { wx = 0.; } PARAM_FLOAT_OPT(wy) { wy = 32.; } PARAM_INT_OPT(flags) { flags = 0; } @@ -975,7 +973,7 @@ DEFINE_ACTION_FUNCTION(AInventory, A_WeaponOffset) 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); + A_OverlayOffset(self, PSP_WEAPON, wx, wy, flags); return 0; } @@ -1290,8 +1288,6 @@ void P_SetupPsprites(player_t *player, bool startweaponup) void player_t::TickPSprites() { - DPSprite *weapon = nullptr; - DPSprite *flash = nullptr; bool noweapon = (ReadyWeapon == nullptr && (health > 0 || mo->DamageType != NAME_Fire)); DPSprite *pspr = psprites; @@ -1299,31 +1295,29 @@ void player_t::TickPSprites() { // Destroy the psprite if it's from a weapon that isn't currently selected by the player // or if it's from an inventory item that the player no longer owns. - // (except for the old hardcoded layers) - if (!(pspr->ID > 0 && pspr->ID < NUMPSPRITES) && + // Exclude the old hardcoded layers from this check. + if (!(pspr->ID == PSP_WEAPON || pspr->ID == PSP_FLASH || pspr->ID >= PSP_TARGETCENTER) && (pspr->Caller == nullptr || (pspr->Caller->IsKindOf(RUNTIME_CLASS(AWeapon)) && pspr->Caller != pspr->Owner->ReadyWeapon) || (pspr->Caller->Owner != pspr->Owner->mo))) { pspr->Destroy(); } - else if (!(pspr->ID > 0 && pspr->ID < NUMPSPRITES && noweapon)) + else if (!((pspr->ID == PSP_WEAPON || pspr->ID == PSP_FLASH || pspr->ID >= PSP_TARGETCENTER) && noweapon)) { pspr->Tick(); } - if (pspr->ID == ps_weapon) - weapon = pspr; - else if (pspr->ID == ps_flash) - flash = pspr; + if (noweapon && (pspr->ID == PSP_WEAPON || pspr->ID == PSP_FLASH)) + { // Special treatment to destroy both the flash and weapon layers. + pspr->Destroy(); + } pspr = pspr->Next; } if (noweapon) { - if (weapon) weapon->SetState(nullptr); - if (flash) flash->SetState(nullptr); if (PendingWeapon != WP_NOCHANGE) P_BringUpWeapon(this); } @@ -1356,7 +1350,7 @@ void DPSprite::Tick() // [BC] Apply double firing speed. // This is applied to the targeter layers too. - if (((ID > 0 && ID < NUMPSPRITES) || (Caller->IsKindOf(RUNTIME_CLASS(AWeapon)))) && + if (((ID == PSP_WEAPON || ID == PSP_FLASH || ID >= PSP_TARGETCENTER) || Caller->IsKindOf(RUNTIME_CLASS(AWeapon))) && (Tics && Owner->cheats & CF_DOUBLEFIRINGSPEED)) Tics--; diff --git a/src/p_pspr.h b/src/p_pspr.h index 65293a79cb..edcad9dd60 100644 --- a/src/p_pspr.h +++ b/src/p_pspr.h @@ -42,14 +42,13 @@ class FArchive; // drawn directly on the view screen, // coordinates are given for a 320*200 view screen. // -enum psprnum_t // These are all called by the owner's ReadyWeapon. +enum PSPLayers // These are all called by the owner's ReadyWeapon. { - ps_weapon = 1, - ps_flash, - ps_targetcenter, - ps_targetleft, - ps_targetright, - NUMPSPRITES + PSP_WEAPON = 1, + PSP_FLASH = 1000, + PSP_TARGETCENTER = INT_MAX - 2, + PSP_TARGETLEFT, + PSP_TARGETRIGHT, }; enum PSPFlags @@ -103,7 +102,7 @@ private: void P_NewPspriteTick(); void P_CalcSwing (player_t *player); -void P_SetPsprite(player_t *player, psprnum_t id, FState *state, bool pending = false); +void P_SetPsprite(player_t *player, PSPLayers id, FState *state, bool pending = false); void P_BringUpWeapon (player_t *player); void P_FireWeapon (player_t *player); void P_DropWeapon (player_t *player); diff --git a/src/p_user.cpp b/src/p_user.cpp index cbdab07309..0f3704b255 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -3075,7 +3075,8 @@ void player_t::Serialize (FArchive &arc) if (SaveVersion < 4547) { - for (i = ps_weapon; i < NUMPSPRITES; i++) + int layer = PSP_WEAPON; + for (i = 0; i < 5; i++) { FState *state; int tics; @@ -3090,14 +3091,14 @@ void player_t::Serialize (FArchive &arc) if (state != nullptr) { DPSprite *pspr; - pspr = GetPSprite(psprnum_t(i)); + pspr = GetPSprite(PSPLayers(layer)); pspr->State = state; pspr->Tics = tics; pspr->Sprite = sprite; pspr->Frame = frame; pspr->Owner = this; - if (i == ps_flash) + if (layer == PSP_FLASH) { pspr->x = 0; pspr->y = 0; @@ -3109,13 +3110,20 @@ void player_t::Serialize (FArchive &arc) } pspr->Flags = 0; - if (i < ps_targetcenter) + if (layer < PSP_TARGETCENTER) { pspr->Flags |= PSPF_ADDBOB; - if (i == ps_flash) + if (layer == PSP_FLASH) pspr->Flags |= PSPF_ADDWEAPON; } } + + if (layer == PSP_WEAPON) + layer = PSP_FLASH; + else if (layer == PSP_FLASH) + layer = PSP_TARGETCENTER; + else + layer++; } } else diff --git a/src/r_things.cpp b/src/r_things.cpp index e194dc6d47..35b9a51fa5 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1319,8 +1319,8 @@ void R_DrawPSprite(DPSprite *pspr, AActor *owner, float bobx, float boby, double if (tex->UseType == FTexture::TEX_Null) return; - isweapon = ((pspr->GetID() > 0 && pspr->GetID() < ps_targetcenter) || - (pspr->GetID() >= NUMPSPRITES && pspr->GetCaller() && pspr->GetCaller()->IsKindOf(RUNTIME_CLASS(AWeapon)))); + isweapon = ((pspr->GetID() == PSP_WEAPON || pspr->GetID() == PSP_FLASH) || + (pspr->GetID() < PSP_TARGETCENTER && pspr->GetCaller()->IsKindOf(RUNTIME_CLASS(AWeapon)))); if (pspr->firstTic) { // Can't interpolate the first tic. @@ -1627,7 +1627,7 @@ void R_DrawPlayerSprites () P_BobWeapon (camera->player, &bobx, &boby, r_TicFracF); // Interpolate the main weapon layer once so as to be able to add it to other layers. - if ((weapon = camera->player->FindPSprite(ps_weapon)) != nullptr) + if ((weapon = camera->player->FindPSprite(PSP_WEAPON)) != nullptr) { if (weapon->firstTic) { @@ -1651,7 +1651,7 @@ void R_DrawPlayerSprites () while (psp) { // [RH] Don't draw the targeter's crosshair if the player already has a crosshair set. - if (psp->GetID() != ps_targetcenter || CrosshairImage == nullptr) + if (psp->GetID() != PSP_TARGETCENTER || CrosshairImage == nullptr) { R_DrawPSprite(psp, camera, bobx, boby, wx, wy, r_TicFracF); } diff --git a/wadsrc/static/actors/constants.txt b/wadsrc/static/actors/constants.txt index 8e082cc72e..d65e9e4638 100644 --- a/wadsrc/static/actors/constants.txt +++ b/wadsrc/static/actors/constants.txt @@ -576,3 +576,10 @@ enum PSPF_ADDWEAPON = 1 << 0, PSPF_ADDBOB = 1 << 1, }; + +// Default psprite layers +enum +{ + PSP_WEAPON = 1, + PSP_FLASH = 1000, +}; diff --git a/wadsrc/static/actors/shared/inventory.txt b/wadsrc/static/actors/shared/inventory.txt index 0dffc106b4..d523afe5cf 100644 --- a/wadsrc/static/actors/shared/inventory.txt +++ b/wadsrc/static/actors/shared/inventory.txt @@ -50,7 +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); + action native A_OverlayOffset(int layer = PSP_WEAPON, float wx = 0, float wy = 32, int flags = 0); action native A_OverlayFlags(int layer, int flags, bool set); States