From 0b93aef776b2704122ae8d8e7985e19ea05b600f Mon Sep 17 00:00:00 2001 From: Xaser Acheron Date: Sun, 14 Nov 2021 23:21:07 -0600 Subject: [PATCH 1/4] add WeaponScaleX/WeaponScaleY properties for applying global scaling to a weapon's PSprites --- src/playsim/p_pspr.cpp | 5 ++++- src/playsim/p_pspr.h | 3 ++- src/rendering/hwrenderer/scene/hw_weapon.cpp | 7 +++++-- src/rendering/swrenderer/things/r_playersprite.cpp | 3 ++- wadsrc/static/zscript/actors/inventory/weapons.zs | 7 +++++++ wadsrc/static/zscript/actors/player/player.zs | 1 + 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/playsim/p_pspr.cpp b/src/playsim/p_pspr.cpp index 97e58bd68..4a810374a 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}; @@ -1251,7 +1253,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 df5b45f54..31d3ec0bb 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 f90ff4fd9..a49f497c3 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -428,7 +428,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; @@ -447,7 +447,10 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy, // killough 12/98: fix psprite positioning problem 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); 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 45d3d5fa2..e892cf7da 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); diff --git a/wadsrc/static/zscript/actors/inventory/weapons.zs b/wadsrc/static/zscript/actors/inventory/weapons.zs index 9c3519b48..f3723b3d9 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. + 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 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 be17e160b..1a381c3a8 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -2600,6 +2600,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; From 441b70022d8c594ae32cce4de745c63fb742db67 Mon Sep 17 00:00:00 2001 From: Xaser Acheron Date: Mon, 15 Nov 2021 01:52:49 -0600 Subject: [PATCH 2/4] apply weaponscale relative to baseline --- src/rendering/hwrenderer/scene/hw_weapon.cpp | 4 +++- src/rendering/swrenderer/things/r_playersprite.cpp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index a49f497c3..579c0e3b2 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 @@ -445,7 +446,8 @@ 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; // [XA] note: Doom's native 1.2x aspect ratio was originally // handled here by multiplying SCREENWIDTH by 200 instead of diff --git a/src/rendering/swrenderer/things/r_playersprite.cpp b/src/rendering/swrenderer/things/r_playersprite.cpp index e892cf7da..a9873d52d 100644 --- a/src/rendering/swrenderer/things/r_playersprite.cpp +++ b/src/rendering/swrenderer/things/r_playersprite.cpp @@ -293,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; From e9c86017e47a0a06c742ee9a193e780db80c66b6 Mon Sep 17 00:00:00 2001 From: Xaser Acheron Date: Sun, 23 Jan 2022 19:59:06 -0600 Subject: [PATCH 3/4] apply WeaponScaleX/Y to all PSprites on a weapon --- src/common/engine/namedef.h | 2 ++ src/playsim/p_pspr.cpp | 24 +++++++++++++++++-- .../zscript/actors/inventory/weapons.zs | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/common/engine/namedef.h b/src/common/engine/namedef.h index 489507061..f2f2ebcc7 100644 --- a/src/common/engine/namedef.h +++ b/src/common/engine/namedef.h @@ -1032,6 +1032,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 4a810374a..cc921b86b 100644 --- a/src/playsim/p_pspr.cpp +++ b/src/playsim/p_pspr.cpp @@ -252,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; +} + //------------------------------------------------------------------------ // // @@ -301,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 { @@ -1112,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); } diff --git a/wadsrc/static/zscript/actors/inventory/weapons.zs b/wadsrc/static/zscript/actors/inventory/weapons.zs index f3723b3d9..3ef7080c8 100644 --- a/wadsrc/static/zscript/actors/inventory/weapons.zs +++ b/wadsrc/static/zscript/actors/inventory/weapons.zs @@ -25,7 +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. - 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. + 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; From a07e16099d0d1bd4007c893d01e7520edfe6163b Mon Sep 17 00:00:00 2001 From: Xaser Acheron Date: Sun, 23 Jan 2022 20:05:32 -0600 Subject: [PATCH 4/4] move WeaponScaleX/Y namedefs to namedef_custom.h; clean unwanted stuff from merge --- src/common/engine/namedef.h | 23 ----------------------- src/namedef_custom.h | 2 ++ 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/common/engine/namedef.h b/src/common/engine/namedef.h index cf1b670be..77eb95bf9 100644 --- a/src/common/engine/namedef.h +++ b/src/common/engine/namedef.h @@ -199,29 +199,6 @@ xx(OptionMenuItemStaticTextSwitchable) xx(Color) -// Weapon member fields that need direct access -xx(Ammo1) -xx(Ammo2) -xx(AmmoType1) -xx(AmmoType2) -xx(AmmoGive1) -xx(AmmoGive2) -xx(AmmoUse1) -xx(SisterWeapon) -xx(BobStyle) -xx(Kickback) -xx(MinSelAmmo1) -xx(bDehAmmo) -xx(FOVScale) -xx(LookScale) -xx(YAdjust) -xx(Crosshair) -xx(WeaponFlags) -xx(DropTime) -xx(PickupSound) -xx(WeaponScaleX) -xx(WeaponScaleY) - xx(Mididevices) xx(Aldevices) xx(Alresamplers) diff --git a/src/namedef_custom.h b/src/namedef_custom.h index 1c188007c..a1157aa38 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)