Skip to content

Add and use an "instant" parameter for P_SetScale

Zwip-Zwap Zapony requested to merge Zwip-Zwap_Zapony/SRB2:instant-setscale into next

Lua users can use mobj.scale to automatically set mobj->scale, mobj->destscale, and mobj->old_scale all at once, but us hardcoders have to do it one by one. This merge request adds an instant parameter to P_SetScale(mobj, newscale, instant) - when true, P_SetScale sets all three of those variables, equivalent to Lua's mobj.scale.
In Lua scripts that use P_SetScale, its new instant parameter is optional and defaults to false, matching the previous behaviour.

I've looked through every occurrence of "P_SetScale" and "->destscale =", checked whether it's intended to be an instant change, and used the instant parameter or manually set mobj->old_scale wherever I think that it's appropriate (except in ghost playback), fixing several scale interpolation issues (often on a mobj's first-spawned tic). Fixes #1120 (closed) and other similar issues.

Additionally, some places that set mobj->scale directly have been changed to use P_SetScale instead. Metal Sonic's underwater bubbles still start at metalsonic->scale/2, but they now grow to metalsonic->scale instead of to FRACUNIT. A_FireShrink with var2 set to 0 is now instant, instead of dividing by 0 and crashing. A_OrbitNights had its comments' radius factor defaults corrected and 19th bit re-documented, and it now scales the actor before instead of after using its scale for positioning (and more aggressively matches the target's scale). P_SpawnGhostMobj now sets old_scale appropriately (instead of not at all), fixing Super Sonic/Sneakers after-images when scaled - and since I was at it anyway, old_spritexscale/old_spriteyscale/old_spritexoffset/old_spriteyoffset now have "2" versions (like other old_ variables) and are set by P_SpawnGhostMobj too (though the offsets are still not actually interpolated when rendering).


Now, you might be thinking, "say, why would you not just make mobj->resetinterp stop scale interpolation?", and that's a really good question.
...
(The good news is, this merge request's approach allows a mobj to interpolate its scale on its first-spawned tic. With mobj = P_SpawnMobj(x,y,z,type); P_SetScale(mobj, 2*FRACUNIT, true); mobj->destscale = 3*FRACUNIT;, that mobj will "think" later in the same tic, increasing its scale by scalespeed before the tic is rendered. That increase will be interpolated, instead of the rendered scale appearing unchanging until the next tic. Plus, you no longer need to use P_SetScale and set mobj->destscale separately.)

-

TL;DR:
- An optional instant boolean was added to P_SetScale(mobj, newscale, [instant?]). When true, a mobj's destscale and old_scale are also set, equivalent to directly setting mobj.scale in Lua.
- Fixed some interpolation artefacts
- Metal Sonic's underwater bubbles now match Metal Sonic's scale
- A_FireShrink with var2 set to 0 no longer causes a crash

Merge request reports