- consolidated the 3 nearly identical code fragments handling the weapon's YAdjust for the different renderers into a utility function in DPSprite.

This commit is contained in:
Christoph Oelckers 2018-11-24 22:40:14 +01:00
parent 4392b4e96d
commit ead28db007
5 changed files with 31 additions and 39 deletions

View file

@ -433,21 +433,7 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy,
x2 += viewwindowx;
// killough 12/98: fix psprite positioning problem
ftexturemid = 100.f - sy - r.top;
AWeapon * wi = player->ReadyWeapon;
if (wi && wi->YAdjust != 0)
{
float fYAd = wi->YAdjust;
if (screenblocks >= 11)
{
ftexturemid -= fYAd;
}
else
{
ftexturemid -= float(StatusBar->GetDisplacement()) * fYAd;
}
}
ftexturemid = 100.f - sy - r.top - psp->GetYAdjust(screenblocks >= 11);
scale = (SCREENHEIGHT*vw) / (SCREENWIDTH * 200.0f);
y1 = viewwindowy + vh / 2 - (ftexturemid * scale);

View file

@ -44,6 +44,7 @@
#include "cmdlib.h"
#include "g_levellocals.h"
#include "vm.h"
#include "sbar.h"
// MACROS ------------------------------------------------------------------
@ -1348,6 +1349,32 @@ void DPSprite::OnDestroy()
//
//------------------------------------------------------------------------
float DPSprite::GetYAdjust(bool fullscreen)
{
AWeapon *weapon = dyn_cast<AWeapon>(GetCaller());
if (weapon != nullptr)
{
float fYAd = weapon->YAdjust;
if (fYAd != 0)
{
if (fullscreen)
{
return fYAd;
}
else
{
return StatusBar->GetDisplacement() * fYAd;
}
}
}
}
//------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------
ADD_STAT(psprites)
{
FString out;

View file

@ -92,6 +92,7 @@ public:
void ResetInterpolation() { oldx = x; oldy = y; }
void OnDestroy() override;
std::pair<FRenderStyle, float> GetRenderStyle(FRenderStyle ownerstyle, double owneralpha);
float GetYAdjust(bool fullscreen);
double x, y, alpha;
double oldx, oldy;

View file

@ -296,18 +296,7 @@ void RenderPolyPlayerSprites::RenderSprite(PolyRenderThread *thread, DPSprite *p
viewheight == renderTarget->GetHeight() ||
(renderTarget->GetWidth() > (BASEXCENTER * 2))))
{ // Adjust PSprite for fullscreen views
AWeapon *weapon = dyn_cast<AWeapon>(pspr->GetCaller());
if (weapon != nullptr && weapon->YAdjust != 0)
{
if (renderToCanvas || viewheight == renderTarget->GetHeight())
{
vis.texturemid -= weapon->YAdjust;
}
else
{
vis.texturemid -= StatusBar->GetDisplacement() * weapon->YAdjust;
}
}
vis.texturemid -= pspr->GetYAdjust(renderToCanvas || viewheight == renderTarget->GetHeight());
}
if (pspr->GetID() < PSP_TARGETCENTER)
{ // Move the weapon down for 1280x1024.

View file

@ -295,18 +295,7 @@ namespace swrenderer
viewheight == viewport->RenderTarget->GetHeight() ||
(viewport->RenderTarget->GetWidth() > (BASEXCENTER * 2))))
{ // Adjust PSprite for fullscreen views
AWeapon *weapon = dyn_cast<AWeapon>(pspr->GetCaller());
if (weapon != nullptr && weapon->YAdjust != 0)
{
if (renderToCanvas || viewheight == viewport->RenderTarget->GetHeight())
{
vis.texturemid -= weapon->YAdjust;
}
else
{
vis.texturemid -= StatusBar->GetDisplacement() * weapon->YAdjust;
}
}
vis.texturemid -= pspr->GetYAdjust(renderToCanvas || viewheight == viewport->RenderTarget->GetHeight());
}
if (pspr->GetID() < PSP_TARGETCENTER)
{ // Move the weapon down for 1280x1024.