add WeaponScaleX/WeaponScaleY properties for applying global scaling to a weapon's PSprites

This commit is contained in:
Xaser Acheron 2021-11-14 23:21:07 -06:00
parent 01b825b181
commit 0b93aef776
6 changed files with 21 additions and 5 deletions

View file

@ -132,6 +132,7 @@ DEFINE_FIELD(DPSprite, x)
DEFINE_FIELD(DPSprite, y) DEFINE_FIELD(DPSprite, y)
DEFINE_FIELD(DPSprite, oldx) DEFINE_FIELD(DPSprite, oldx)
DEFINE_FIELD(DPSprite, oldy) DEFINE_FIELD(DPSprite, oldy)
DEFINE_FIELD(DPSprite, baseScale)
DEFINE_FIELD(DPSprite, pivot) DEFINE_FIELD(DPSprite, pivot)
DEFINE_FIELD(DPSprite, scale) DEFINE_FIELD(DPSprite, scale)
DEFINE_FIELD(DPSprite, rotation) DEFINE_FIELD(DPSprite, rotation)
@ -180,6 +181,7 @@ DPSprite::DPSprite(player_t *owner, AActor *caller, int id)
ID(id), ID(id),
processPending(true) processPending(true)
{ {
baseScale = {1.0, 1.2};
rotation = 0.; rotation = 0.;
scale = {1.0, 1.0}; scale = {1.0, 1.0};
pivot = {0.0, 0.0}; pivot = {0.0, 0.0};
@ -1251,7 +1253,8 @@ void DPSprite::Serialize(FSerializer &arc)
("rotation", rotation) ("rotation", rotation)
("halign", HAlign) ("halign", HAlign)
("valign", VAlign) ("valign", VAlign)
("renderstyle_", Renderstyle); // The underscore is intentional to avoid problems with old savegames which had this as an ERenderStyle (which is not future proof.) ("renderstyle_", Renderstyle) // The underscore is intentional to avoid problems with old savegames which had this as an ERenderStyle (which is not future proof.)
("baseScale", baseScale);
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------

View file

@ -114,9 +114,10 @@ public:
float GetYAdjust(bool fullscreen); float GetYAdjust(bool fullscreen);
int HAlign, VAlign; // Horizontal and vertical alignment int HAlign, VAlign; // Horizontal and vertical alignment
DVector2 baseScale; // Base scale (set by weapon); defaults to (1.0, 1.2) since that's Doom's native aspect ratio
DAngle rotation; // How much rotation to apply. DAngle rotation; // How much rotation to apply.
DVector2 pivot; // pivot points DVector2 pivot; // pivot points
DVector2 scale; // Scale DVector2 scale; // Dynamic scale (set by A_Overlay functions)
double x, y, alpha; double x, y, alpha;
double oldx, oldy; double oldx, oldy;
bool InterpolateTic; // One tic interpolation (WOF_INTERPOLATE) bool InterpolateTic; // One tic interpolation (WOF_INTERPOLATE)

View file

@ -428,7 +428,7 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy,
FloatRect r = spi.GetSpriteRect(); FloatRect r = spi.GetSpriteRect();
// calculate edges of the shape // calculate edges of the shape
scalex = (320.0f / (240.0f * r_viewwindow.WidescreenRatio)) * vw / 320; scalex = psp->baseScale.X * (320.0f / (240.0f * r_viewwindow.WidescreenRatio)) * (vw / 320);
float x1, y1, x2, y2, u1, v1, u2, v2; float x1, y1, x2, y2, u1, v1, u2, v2;
@ -447,7 +447,10 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy,
// killough 12/98: fix psprite positioning problem // killough 12/98: fix psprite positioning problem
ftexturemid = 100.f - sy - r.top - psp->GetYAdjust(screenblocks >= 11); ftexturemid = 100.f - sy - r.top - psp->GetYAdjust(screenblocks >= 11);
scale = (SCREENHEIGHT*vw) / (SCREENWIDTH * 200.0f); // [XA] note: Doom's native 1.2x aspect ratio was originally
// handled here by multiplying SCREENWIDTH by 200 instead of
// 240, but now the baseScale var defines this from now on.
scale = psp->baseScale.Y * (SCREENHEIGHT*vw) / (SCREENWIDTH * 240.0f);
y1 = viewwindowy + vh / 2 - (ftexturemid * scale); y1 = viewwindowy + vh / 2 - (ftexturemid * scale);
y2 = y1 + (r.height * scale) + 1; y2 = y1 + (r.height * scale) + 1;

View file

@ -265,7 +265,8 @@ namespace swrenderer
auto viewport = Thread->Viewport.get(); auto viewport = Thread->Viewport.get();
double pspritexscale = viewport->viewwindow.centerxwide / 160.0; double pspritexscale = viewport->viewwindow.centerxwide / 160.0;
double pspriteyscale = pspritexscale * viewport->BaseYaspectMul * ((double)SCREENHEIGHT / SCREENWIDTH) * r_viewwindow.WidescreenRatio; double pspriteyscale = pspritexscale * pspr->baseScale.Y * ((double)SCREENHEIGHT / SCREENWIDTH) * r_viewwindow.WidescreenRatio;
pspritexscale *= pspr->baseScale.X; // [XA] don't accidentally apply this to the Y calculation above; math be weird
double pspritexiscale = 1 / pspritexscale; double pspritexiscale = 1 / pspritexscale;
int tleft = tex->GetDisplayLeftOffset(0); int tleft = tex->GetDisplayLeftOffset(0);

View file

@ -25,6 +25,7 @@ class Weapon : StateProvider
int BobStyle; // [XA] Bobbing style. Defines type of bobbing (e.g. Normal, Alpha) (visual only so no need to be a double) int BobStyle; // [XA] Bobbing style. Defines type of bobbing (e.g. Normal, Alpha) (visual only so no need to be a double)
float BobSpeed; // [XA] Bobbing speed. Defines how quickly a weapon bobs. float BobSpeed; // [XA] Bobbing speed. Defines how quickly a weapon bobs.
float BobRangeX, BobRangeY; // [XA] Bobbing range. Defines how far a weapon bobs in either direction. float BobRangeX, BobRangeY; // [XA] Bobbing range. Defines how far a weapon bobs in either direction.
float WeaponScaleX, WeaponScaleY; // [XA] Weapon scale. Defines the scale for the held weapon sprites (PSprite). Defaults to (1.0, 1.2) since that's what Doom does.
Ammo Ammo1, Ammo2; // In-inventory instance variables Ammo Ammo1, Ammo2; // In-inventory instance variables
Weapon SisterWeapon; Weapon SisterWeapon;
double FOVScale; double FOVScale;
@ -57,6 +58,8 @@ class Weapon : StateProvider
property BobSpeed: BobSpeed; property BobSpeed: BobSpeed;
property BobRangeX: BobRangeX; property BobRangeX: BobRangeX;
property BobRangeY: BobRangeY; property BobRangeY: BobRangeY;
property WeaponScaleX: WeaponScaleX;
property WeaponScaleY: WeaponScaleY;
property SlotNumber: SlotNumber; property SlotNumber: SlotNumber;
property SlotPriority: SlotPriority; property SlotPriority: SlotPriority;
property LookScale: LookScale; property LookScale: LookScale;
@ -95,6 +98,8 @@ class Weapon : StateProvider
Weapon.BobSpeed 1.0; Weapon.BobSpeed 1.0;
Weapon.BobRangeX 1.0; Weapon.BobRangeX 1.0;
Weapon.BobRangeY 1.0; Weapon.BobRangeY 1.0;
Weapon.WeaponScaleX 1.0;
Weapon.WeaponScaleY 1.2;
Weapon.SlotNumber -1; Weapon.SlotNumber -1;
Weapon.SlotPriority 32767; Weapon.SlotPriority 32767;
+WEAPONSPAWN +WEAPONSPAWN
@ -218,6 +223,8 @@ class Weapon : StateProvider
{ {
if (!psp) return; if (!psp) return;
psp.rotation = 0; psp.rotation = 0;
psp.baseScale.x = invoker.WeaponScaleX;
psp.baseScale.y = invoker.WeaponScaleY;
psp.scale.x = 1; psp.scale.x = 1;
psp.scale.y = 1; psp.scale.y = 1;
psp.pivot.x = 0; psp.pivot.x = 0;

View file

@ -2600,6 +2600,7 @@ class PSprite : Object native play
native double y; native double y;
native double oldx; native double oldx;
native double oldy; native double oldy;
native Vector2 baseScale;
native Vector2 pivot; native Vector2 pivot;
native Vector2 scale; native Vector2 scale;
native double rotation; native double rotation;