Changed the default layer indices and renamed them

Note that this doesn't compile yet
This commit is contained in:
Leonard2 2016-05-27 18:08:56 +02:00
parent c82620129c
commit 2f5ae3b51e
7 changed files with 52 additions and 44 deletions

View file

@ -532,7 +532,7 @@ public:
void TickPSprites(); void TickPSprites();
void DestroyPSprites(); void DestroyPSprites();
DPSprite *FindPSprite(int layer); 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. // Bookkeeping on players - state.

View file

@ -142,10 +142,10 @@ DPSprite::DPSprite(player_t *owner, AInventory *caller, int id)
if (Next && Next->ID == ID && ID != 0) if (Next && Next->ID == ID && ID != 0)
Next->Destroy(); // Replace it. 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; Flags |= PSPF_ADDBOB;
if (ID != ps_weapon) if (ID != PSP_WEAPON)
Flags |= PSPF_ADDWEAPON; 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); DPSprite *pspr = FindPSprite(layer);
if (pspr == nullptr) if (pspr == nullptr)
pspr = new DPSprite(this, ReadyWeapon, layer); pspr = new DPSprite(this, ReadyWeapon, layer);
@ -226,14 +224,14 @@ void DPSprite::NewTick()
void DPSprite::SetState(FState *newstate, bool pending) void DPSprite::SetState(FState *newstate, bool pending)
{ {
if (ID == ps_weapon) if (ID == PSP_WEAPON)
{ // A_WeaponReady will re-set these as needed { // A_WeaponReady will re-set these as needed
Owner->WeaponState &= ~(WF_WEAPONREADY | WF_WEAPONREADYALT | WF_WEAPONBOBBING | WF_WEAPONSWITCHOK | WF_WEAPONRELOADOK | WF_WEAPONZOOMOK | Owner->WeaponState &= ~(WF_WEAPONREADY | WF_WEAPONREADYALT | WF_WEAPONBOBBING | WF_WEAPONSWITCHOK | WF_WEAPONRELOADOK | WF_WEAPONZOOMOK |
WF_USER1OK | WF_USER2OK | WF_USER3OK | WF_USER4OK); WF_USER1OK | WF_USER2OK | WF_USER3OK | WF_USER4OK);
} }
// Special handling for the old hardcoded layers. // 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; Caller = Owner->ReadyWeapon;
processPending = pending; processPending = pending;
@ -261,9 +259,9 @@ void DPSprite::SetState(FState *newstate, bool pending)
Tics = newstate->GetTics(); // could be 0 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. { // 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; Tics = newstate->ActionFunc == nullptr ? 0 : 1;
else if (sv_fastweapons == 3) else if (sv_fastweapons == 3)
Tics = (newstate->GetTics() != 0); Tics = (newstate->GetTics() != 0);
@ -271,7 +269,7 @@ void DPSprite::SetState(FState *newstate, bool pending)
Tics = 1; // great for producing decals :) 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. { // It's still possible to set the flash layer's offsets with the action function.
if (newstate->GetMisc1()) if (newstate->GetMisc1())
{ // Set coordinates. { // Set coordinates.
@ -313,7 +311,7 @@ void DPSprite::SetState(FState *newstate, bool pending)
return; 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; if (player == nullptr) return;
player->GetPSprite(id)->SetState(state, pending); 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) DEFINE_ACTION_FUNCTION(AInventory, A_OverlayOffset)
{ {
PARAM_ACTION_PROLOGUE; 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(wx) { wx = 0.; }
PARAM_FLOAT_OPT(wy) { wy = 32.; } PARAM_FLOAT_OPT(wy) { wy = 32.; }
PARAM_INT_OPT(flags) { flags = 0; } 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(wx) { wx = 0.; }
PARAM_FLOAT_OPT(wy) { wy = 32.; } PARAM_FLOAT_OPT(wy) { wy = 32.; }
PARAM_INT_OPT(flags) { flags = 0; } PARAM_INT_OPT(flags) { flags = 0; }
A_OverlayOffset(self, ps_weapon, wx, wy, flags); A_OverlayOffset(self, PSP_WEAPON, wx, wy, flags);
return 0; return 0;
} }
@ -1290,8 +1288,6 @@ void P_SetupPsprites(player_t *player, bool startweaponup)
void player_t::TickPSprites() void player_t::TickPSprites()
{ {
DPSprite *weapon = nullptr;
DPSprite *flash = nullptr;
bool noweapon = (ReadyWeapon == nullptr && (health > 0 || mo->DamageType != NAME_Fire)); bool noweapon = (ReadyWeapon == nullptr && (health > 0 || mo->DamageType != NAME_Fire));
DPSprite *pspr = psprites; 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 // 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. // or if it's from an inventory item that the player no longer owns.
// (except for the old hardcoded layers) // Exclude the old hardcoded layers from this check.
if (!(pspr->ID > 0 && pspr->ID < NUMPSPRITES) && if (!(pspr->ID == PSP_WEAPON || pspr->ID == PSP_FLASH || pspr->ID >= PSP_TARGETCENTER) &&
(pspr->Caller == nullptr || (pspr->Caller == nullptr ||
(pspr->Caller->IsKindOf(RUNTIME_CLASS(AWeapon)) && pspr->Caller != pspr->Owner->ReadyWeapon) || (pspr->Caller->IsKindOf(RUNTIME_CLASS(AWeapon)) && pspr->Caller != pspr->Owner->ReadyWeapon) ||
(pspr->Caller->Owner != pspr->Owner->mo))) (pspr->Caller->Owner != pspr->Owner->mo)))
{ {
pspr->Destroy(); 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(); pspr->Tick();
} }
if (pspr->ID == ps_weapon) if (noweapon && (pspr->ID == PSP_WEAPON || pspr->ID == PSP_FLASH))
weapon = pspr; { // Special treatment to destroy both the flash and weapon layers.
else if (pspr->ID == ps_flash) pspr->Destroy();
flash = pspr; }
pspr = pspr->Next; pspr = pspr->Next;
} }
if (noweapon) if (noweapon)
{ {
if (weapon) weapon->SetState(nullptr);
if (flash) flash->SetState(nullptr);
if (PendingWeapon != WP_NOCHANGE) if (PendingWeapon != WP_NOCHANGE)
P_BringUpWeapon(this); P_BringUpWeapon(this);
} }
@ -1356,7 +1350,7 @@ void DPSprite::Tick()
// [BC] Apply double firing speed. // [BC] Apply double firing speed.
// This is applied to the targeter layers too. // 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 && Owner->cheats & CF_DOUBLEFIRINGSPEED))
Tics--; Tics--;

View file

@ -42,14 +42,13 @@ class FArchive;
// drawn directly on the view screen, // drawn directly on the view screen,
// coordinates are given for a 320*200 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, PSP_WEAPON = 1,
ps_flash, PSP_FLASH = 1000,
ps_targetcenter, PSP_TARGETCENTER = INT_MAX - 2,
ps_targetleft, PSP_TARGETLEFT,
ps_targetright, PSP_TARGETRIGHT,
NUMPSPRITES
}; };
enum PSPFlags enum PSPFlags
@ -103,7 +102,7 @@ private:
void P_NewPspriteTick(); void P_NewPspriteTick();
void P_CalcSwing (player_t *player); 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_BringUpWeapon (player_t *player);
void P_FireWeapon (player_t *player); void P_FireWeapon (player_t *player);
void P_DropWeapon (player_t *player); void P_DropWeapon (player_t *player);

View file

@ -3075,7 +3075,8 @@ void player_t::Serialize (FArchive &arc)
if (SaveVersion < 4547) if (SaveVersion < 4547)
{ {
for (i = ps_weapon; i < NUMPSPRITES; i++) int layer = PSP_WEAPON;
for (i = 0; i < 5; i++)
{ {
FState *state; FState *state;
int tics; int tics;
@ -3090,14 +3091,14 @@ void player_t::Serialize (FArchive &arc)
if (state != nullptr) if (state != nullptr)
{ {
DPSprite *pspr; DPSprite *pspr;
pspr = GetPSprite(psprnum_t(i)); pspr = GetPSprite(PSPLayers(layer));
pspr->State = state; pspr->State = state;
pspr->Tics = tics; pspr->Tics = tics;
pspr->Sprite = sprite; pspr->Sprite = sprite;
pspr->Frame = frame; pspr->Frame = frame;
pspr->Owner = this; pspr->Owner = this;
if (i == ps_flash) if (layer == PSP_FLASH)
{ {
pspr->x = 0; pspr->x = 0;
pspr->y = 0; pspr->y = 0;
@ -3109,13 +3110,20 @@ void player_t::Serialize (FArchive &arc)
} }
pspr->Flags = 0; pspr->Flags = 0;
if (i < ps_targetcenter) if (layer < PSP_TARGETCENTER)
{ {
pspr->Flags |= PSPF_ADDBOB; pspr->Flags |= PSPF_ADDBOB;
if (i == ps_flash) if (layer == PSP_FLASH)
pspr->Flags |= PSPF_ADDWEAPON; pspr->Flags |= PSPF_ADDWEAPON;
} }
} }
if (layer == PSP_WEAPON)
layer = PSP_FLASH;
else if (layer == PSP_FLASH)
layer = PSP_TARGETCENTER;
else
layer++;
} }
} }
else else

View file

@ -1319,8 +1319,8 @@ void R_DrawPSprite(DPSprite *pspr, AActor *owner, float bobx, float boby, double
if (tex->UseType == FTexture::TEX_Null) if (tex->UseType == FTexture::TEX_Null)
return; return;
isweapon = ((pspr->GetID() > 0 && pspr->GetID() < ps_targetcenter) || isweapon = ((pspr->GetID() == PSP_WEAPON || pspr->GetID() == PSP_FLASH) ||
(pspr->GetID() >= NUMPSPRITES && pspr->GetCaller() && pspr->GetCaller()->IsKindOf(RUNTIME_CLASS(AWeapon)))); (pspr->GetID() < PSP_TARGETCENTER && pspr->GetCaller()->IsKindOf(RUNTIME_CLASS(AWeapon))));
if (pspr->firstTic) if (pspr->firstTic)
{ // Can't interpolate the first tic. { // Can't interpolate the first tic.
@ -1627,7 +1627,7 @@ void R_DrawPlayerSprites ()
P_BobWeapon (camera->player, &bobx, &boby, r_TicFracF); 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. // 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) if (weapon->firstTic)
{ {
@ -1651,7 +1651,7 @@ void R_DrawPlayerSprites ()
while (psp) while (psp)
{ {
// [RH] Don't draw the targeter's crosshair if the player already has a crosshair set. // [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); R_DrawPSprite(psp, camera, bobx, boby, wx, wy, r_TicFracF);
} }

View file

@ -576,3 +576,10 @@ enum
PSPF_ADDWEAPON = 1 << 0, PSPF_ADDWEAPON = 1 << 0,
PSPF_ADDBOB = 1 << 1, PSPF_ADDBOB = 1 << 1,
}; };
// Default psprite layers
enum
{
PSP_WEAPON = 1,
PSP_FLASH = 1000,
};

View file

@ -50,7 +50,7 @@ ACTOR Inventory native
action native A_RestoreSpecialThing1(); action native A_RestoreSpecialThing1();
action native A_RestoreSpecialThing2(); action native A_RestoreSpecialThing2();
action native A_WeaponOffset(float wx = 0, float wy = 32, int flags = 0); 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); action native A_OverlayFlags(int layer, int flags, bool set);
States States