diff --git a/src/namedef_custom.h b/src/namedef_custom.h index 0343e307d4..85c93b6cb3 100644 --- a/src/namedef_custom.h +++ b/src/namedef_custom.h @@ -279,6 +279,8 @@ xx(Crosshair) xx(WeaponFlags) xx(DropTime) xx(PickupSound) +xx(WeaponScaleX) +xx(WeaponScaleY) // PlayerPawn member fields xx(ColorRangeStart) diff --git a/src/playsim/p_pspr.cpp b/src/playsim/p_pspr.cpp index 97e58bd680..cc921b86b8 100644 --- a/src/playsim/p_pspr.cpp +++ b/src/playsim/p_pspr.cpp @@ -132,6 +132,7 @@ DEFINE_FIELD(DPSprite, x) DEFINE_FIELD(DPSprite, y) DEFINE_FIELD(DPSprite, oldx) DEFINE_FIELD(DPSprite, oldy) +DEFINE_FIELD(DPSprite, baseScale) DEFINE_FIELD(DPSprite, pivot) DEFINE_FIELD(DPSprite, scale) DEFINE_FIELD(DPSprite, rotation) @@ -180,6 +181,7 @@ DPSprite::DPSprite(player_t *owner, AActor *caller, int id) ID(id), processPending(true) { + baseScale = {1.0, 1.2}; rotation = 0.; scale = {1.0, 1.0}; pivot = {0.0, 0.0}; @@ -250,6 +252,26 @@ DEFINE_ACTION_FUNCTION(_PlayerInfo, FindPSprite) // the underscore is needed to } +//------------------------------------------------------------------------ +// +// +// +//------------------------------------------------------------------------ + +static DPSprite *P_CreatePsprite(player_t *player, AActor *caller, int layer) +{ + DPSprite *pspr = Create(player, caller, layer); + + // [XA] apply WeaponScaleX/WeaponScaleY properties for weapon psprites + if (caller != nullptr && caller->IsKindOf(NAME_Weapon)) + { + pspr->baseScale.X = caller->FloatVar(NAME_WeaponScaleX); + pspr->baseScale.Y = caller->FloatVar(NAME_WeaponScaleY); + } + + return pspr; +} + //------------------------------------------------------------------------ // // @@ -299,7 +321,7 @@ DPSprite *player_t::GetPSprite(PSPLayers layer) DPSprite *pspr = FindPSprite(layer); if (pspr == nullptr) { - pspr = Create(this, newcaller, layer); + pspr = P_CreatePsprite(this, newcaller, layer); } else { @@ -1110,7 +1132,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Overlay) } DPSprite *pspr; - pspr = Create(player, stateowner, layer); + pspr = P_CreatePsprite(player, stateowner, layer); pspr->SetState(state); ACTION_RETURN_BOOL(true); } @@ -1251,7 +1273,8 @@ void DPSprite::Serialize(FSerializer &arc) ("rotation", rotation) ("halign", HAlign) ("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); } //------------------------------------------------------------------------ diff --git a/src/playsim/p_pspr.h b/src/playsim/p_pspr.h index df5b45f540..31d3ec0bbe 100644 --- a/src/playsim/p_pspr.h +++ b/src/playsim/p_pspr.h @@ -114,9 +114,10 @@ public: float GetYAdjust(bool fullscreen); 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. DVector2 pivot; // pivot points - DVector2 scale; // Scale + DVector2 scale; // Dynamic scale (set by A_Overlay functions) double x, y, alpha; double oldx, oldy; bool InterpolateTic; // One tic interpolation (WOF_INTERPOLATE) diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index 1ba5dafe6e..5125b41b9b 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -411,6 +411,7 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy, float tx; float scale; float scalex; + float ftextureadj; float ftexturemid; // decide which patch to use @@ -428,7 +429,7 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy, FloatRect r = spi.GetSpriteRect(); // 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; @@ -445,9 +446,13 @@ 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 - psp->GetYAdjust(screenblocks >= 11); + ftextureadj = (120.0f / psp->baseScale.Y) - 100.0f; // [XA] scale relative to weapon baseline + ftexturemid = 100.f - sy - r.top - psp->GetYAdjust(screenblocks >= 11) - ftextureadj; - 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); y2 = y1 + (r.height * scale) + 1; diff --git a/src/rendering/swrenderer/things/r_playersprite.cpp b/src/rendering/swrenderer/things/r_playersprite.cpp index 45d3d5fa26..a9873d52dc 100644 --- a/src/rendering/swrenderer/things/r_playersprite.cpp +++ b/src/rendering/swrenderer/things/r_playersprite.cpp @@ -265,7 +265,8 @@ namespace swrenderer auto viewport = Thread->Viewport.get(); 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; int tleft = tex->GetDisplayLeftOffset(0); @@ -292,7 +293,8 @@ namespace swrenderer vis.renderflags = owner->renderflags; FSoftwareTexture* stex = GetSoftwareTexture(tex); - vis.texturemid = (BASEYCENTER - sy) * stex->GetScale().Y + stex->GetTopOffset(0); + double textureadj = (120.0f / pspr->baseScale.Y) - BASEYCENTER; // [XA] scale relative to weapon baseline + vis.texturemid = (BASEYCENTER - sy - textureadj) * stex->GetScale().Y + stex->GetTopOffset(0); // Force it to use software rendering when drawing to a canvas texture. bool renderToCanvas = viewport->RenderingToCanvas; diff --git a/wadsrc/static/zscript/actors/inventory/weapons.zs b/wadsrc/static/zscript/actors/inventory/weapons.zs index 8e1801600a..eca9122912 100644 --- a/wadsrc/static/zscript/actors/inventory/weapons.zs +++ b/wadsrc/static/zscript/actors/inventory/weapons.zs @@ -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) 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. + double 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 Weapon SisterWeapon; double FOVScale; @@ -57,6 +58,8 @@ class Weapon : StateProvider property BobSpeed: BobSpeed; property BobRangeX: BobRangeX; property BobRangeY: BobRangeY; + property WeaponScaleX: WeaponScaleX; + property WeaponScaleY: WeaponScaleY; property SlotNumber: SlotNumber; property SlotPriority: SlotPriority; property LookScale: LookScale; @@ -95,6 +98,8 @@ class Weapon : StateProvider Weapon.BobSpeed 1.0; Weapon.BobRangeX 1.0; Weapon.BobRangeY 1.0; + Weapon.WeaponScaleX 1.0; + Weapon.WeaponScaleY 1.2; Weapon.SlotNumber -1; Weapon.SlotPriority 32767; +WEAPONSPAWN @@ -218,6 +223,8 @@ class Weapon : StateProvider { if (!psp) return; psp.rotation = 0; + psp.baseScale.x = invoker.WeaponScaleX; + psp.baseScale.y = invoker.WeaponScaleY; psp.scale.x = 1; psp.scale.y = 1; psp.pivot.x = 0; diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index e3f4cc354f..e72bef8385 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -2605,6 +2605,7 @@ class PSprite : Object native play native double y; native double oldx; native double oldy; + native Vector2 baseScale; native Vector2 pivot; native Vector2 scale; native double rotation;