The targeter layers now use a proper Caller

This will avoid having to check for certain stuff and also allow them to not be destroyed when the ReadyWeapon is null like before
This commit is contained in:
Leonard2 2016-06-01 23:20:18 +02:00
parent 8244d2c844
commit e1f139ddcd
4 changed files with 33 additions and 19 deletions

View file

@ -1364,9 +1364,15 @@ void APowerTargeter::EndEffect ()
Super::EndEffect(); Super::EndEffect();
if (Owner != nullptr && Owner->player != nullptr) if (Owner != nullptr && Owner->player != nullptr)
{ {
Owner->player->GetPSprite(PSP_TARGETCENTER)->SetState(nullptr); // Calling GetPSprite here could crash if we're creating a new game.
Owner->player->GetPSprite(PSP_TARGETLEFT)->SetState(nullptr); // This is because P_SetupLevel nulls the player's mo before destroying
Owner->player->GetPSprite(PSP_TARGETRIGHT)->SetState(nullptr); // every DThinker which in turn ends up calling this.
// However P_SetupLevel is only called after G_NewInit which calls
// every player's dtor which destroys all their psprites.
DPSprite *pspr;
if ((pspr = Owner->player->FindPSprite(PSP_TARGETCENTER)) != nullptr) pspr->SetState(nullptr);
if ((pspr = Owner->player->FindPSprite(PSP_TARGETLEFT)) != nullptr) pspr->SetState(nullptr);
if ((pspr = Owner->player->FindPSprite(PSP_TARGETRIGHT)) != nullptr) pspr->SetState(nullptr);
} }
} }

View file

@ -177,14 +177,27 @@ DPSprite *player_t::FindPSprite(int layer)
DPSprite *player_t::GetPSprite(PSPLayers layer) DPSprite *player_t::GetPSprite(PSPLayers layer)
{ {
assert(ReadyWeapon != nullptr); AInventory *oldcaller = nullptr;
AInventory *newcaller = nullptr;
if (layer >= PSP_TARGETCENTER)
{
if (mo != nullptr)
{
newcaller = mo->FindInventory(RUNTIME_CLASS(APowerTargeter), true);
}
}
else
{
newcaller = ReadyWeapon;
}
assert(newcaller != nullptr);
AInventory *oldcaller;
DPSprite *pspr = FindPSprite(layer); DPSprite *pspr = FindPSprite(layer);
if (pspr == nullptr) if (pspr == nullptr)
{ {
pspr = new DPSprite(this, ReadyWeapon, layer); pspr = new DPSprite(this, newcaller, layer);
oldcaller = nullptr;
} }
else else
{ {
@ -193,18 +206,13 @@ DPSprite *player_t::GetPSprite(PSPLayers layer)
// Always update the caller here in case we switched weapon // 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 an inventory item before.
pspr->Caller = ReadyWeapon; pspr->Caller = newcaller;
if (ReadyWeapon != oldcaller) if (newcaller != oldcaller)
{ // Only change the flags if this layer was created now or if we updated the caller. { // Only change the flags if this layer was created now or if we updated the caller.
if (layer != PSP_FLASH) if (layer != PSP_FLASH)
{ // Only the flash layer should follow the weapon. { // Only the flash layer should follow the weapon.
pspr->Flags &= ~PSPF_ADDWEAPON; pspr->Flags &= ~PSPF_ADDWEAPON;
if (layer != PSP_WEAPON)
{ // [RH] Don't bob the targeter.
pspr->Flags &= ~PSPF_ADDBOB;
}
} }
} }
@ -279,7 +287,7 @@ void DPSprite::SetState(FState *newstate, bool pending)
Tics = newstate->GetTics(); // could be 0 Tics = newstate->GetTics(); // could be 0
if (Caller->IsKindOf(RUNTIME_CLASS(AWeapon))) if (Caller->IsKindOf(RUNTIME_CLASS(AWeapon)))
{ // The targeter layers are affected by this too. {
if (sv_fastweapons == 2 && ID == PSP_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)
@ -1350,7 +1358,6 @@ void DPSprite::Tick()
Tics--; Tics--;
// [BC] Apply double firing speed. // [BC] Apply double firing speed.
// This is applied to the targeter layers too.
if (Caller->IsKindOf(RUNTIME_CLASS(AWeapon)) && Tics && Owner->cheats & CF_DOUBLEFIRINGSPEED) if (Caller->IsKindOf(RUNTIME_CLASS(AWeapon)) && Tics && Owner->cheats & CF_DOUBLEFIRINGSPEED)
Tics--; Tics--;

View file

@ -3090,7 +3090,9 @@ void player_t::Serialize (FArchive &arc)
<< sx << sy << sx << sy
<< sprite << frame; << sprite << frame;
if (state != nullptr && ReadyWeapon != nullptr) if (state != nullptr &&
((layer < PSP_TARGETCENTER && ReadyWeapon != nullptr) ||
(layer >= PSP_TARGETCENTER && mo->FindInventory(RUNTIME_CLASS(APowerTargeter), true))))
{ {
DPSprite *pspr; DPSprite *pspr;
pspr = GetPSprite(PSPLayers(layer)); pspr = GetPSprite(PSPLayers(layer));

View file

@ -1319,8 +1319,7 @@ 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;
// The targeters aren't weapons. isweapon = pspr->GetCaller()->IsKindOf(RUNTIME_CLASS(AWeapon));
isweapon = (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.