With the help of GitLab user Lach, I turned my approximated sprite scaling in destroyed-kart.cpp into 100% accurate sprite scaling

This commit is contained in:
Jack 2024-09-09 15:41:26 +01:00
parent 40b231ff62
commit 2bdc014006

View file

@ -326,20 +326,13 @@ struct Kart : Mobj
}
Particle::spew(this);
auto oldScale = scale();
scale(3*scale()/2);
if(hasCustomHusk){
flags |= MF_NOSQUISH; //K_Squish() automates spritexscale/spriteyscale & this flag prevents that at the cost of no squish visual when the kart husk hits the ground
//approximate inverse spritescale() by exaggerating fixed_t values by 100 and then dividing back down instead of doing float maths
//this way there's no decimal points and no potential for desyncs across builds/platforms
//there is potential this could overflow at exceptionally high scale() values
fixed_t z = FixedDiv(FixedMul(scale(),100),oldScale);
auto formula = [&](fixed_t subject){return FixedDiv(FixedMul(subject,100),z);};
spritexscale(formula(spritexscale()));
spriteyscale(formula(spriteyscale()));
fixed_t huskScale = FixedDiv(mapobjectscale, scale());
spritexscale(FixedMul(spritexscale(), huskScale));
spriteyscale(FixedMul(spriteyscale(), huskScale));
}
health = 1;