- minor cleanup on scaling code

This commit is contained in:
Christoph Oelckers 2022-10-07 18:29:20 +02:00
parent befa5a933c
commit 5700d25120
5 changed files with 28 additions and 20 deletions

View file

@ -516,7 +516,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
const int32_t cosang = bcos(actor->int_ang());
const int32_t sinang = bsin(actor->int_ang());
vec2_t const span = { tileWidth(tilenum), tileHeight(tilenum) };
vec2_t const repeat = { actor->spr.xrepeat, actor->spr.yrepeat };
vec2_t const repeat = { int(actor->spr.ScaleX() * scaletoint), int(actor->spr.ScaleY() * scaletoint) };
vec2_t adjofs = { tileLeftOffset(tilenum), tileTopOffset(tilenum) };
if (actor->spr.cstat & CSTAT_SPRITE_XFLIP)

View file

@ -35,15 +35,19 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
void MarkVerticesForSector(int sector);
static constexpr double maptoworld = (1 / 16.); // this for necessary conversions to convert map data to floating point representation.
static constexpr double inttoworld = (1 / 16.); // this is for conversions needed to make floats coexist with existing code.
static constexpr double worldtoint = 16.;
// Build conversion factors
static constexpr double zmaptoworld = (1 / 256.); // this for necessary conversions to convert map data to floating point representation.
static constexpr double zinttoworld = (1 / 256.); // this is for conversions needed to make floats coexist with existing code.
static constexpr double zworldtoint = 256.;
static constexpr double maptoworld = (1 / 16.); // this for necessary conversions to convert map data to floating point representation.
static constexpr double REPEAT_SCALE = (1 / 64.); // map's 'repeat' values use 2.6 fixed point.
static constexpr double INV_REPEAT_SCALE = 64;
// These are refactoring markers that should be eliminated.
static constexpr double zinttoworld = (1 / 256.); // this is for conversions needed to make floats coexist with existing code.
static constexpr double inttoworld = (1 / 16.); // this is for conversions needed to make floats coexist with existing code.
static constexpr double zworldtoint = 256.;
static constexpr double worldtoint = 16.;
static constexpr double scaletoint = 64; // refactoring marker of the stuff above
static constexpr double inttoscale = (1/64.); // map's 'repeat' values use 2.6 fixed point.
//=============================================================================
//
@ -476,28 +480,28 @@ struct spritetypebase
void SetScale(double x, double y)
{
xrepeat = uint8_t(x * (1 / REPEAT_SCALE));
yrepeat = uint8_t(y * (1 / REPEAT_SCALE));
xrepeat = uint8_t(x * scaletoint);
yrepeat = uint8_t(y * scaletoint);
}
void SetScaleX(double x)
{
xrepeat = uint8_t(x * (1 / REPEAT_SCALE));
xrepeat = uint8_t(x * scaletoint);
}
void SetScaleY(double y)
{
yrepeat = uint8_t(y * (1 / REPEAT_SCALE));
yrepeat = uint8_t(y * scaletoint);
}
void AddScaleX(double x)
{
xrepeat += uint8_t(x * (1 / REPEAT_SCALE));
xrepeat += uint8_t(x * scaletoint);
}
void AddScaleY(double y)
{
yrepeat += uint8_t(y * (1 / REPEAT_SCALE));
yrepeat += uint8_t(y * scaletoint);
}
void MultScaleX(double x)
@ -518,12 +522,12 @@ struct spritetypebase
double ScaleX() const
{
return xrepeat * REPEAT_SCALE;
return xrepeat * inttoscale;
}
double ScaleY() const
{
return yrepeat * REPEAT_SCALE;
return yrepeat * inttoscale;
}
};

View file

@ -3984,9 +3984,9 @@ bool condCheckMixed(DBloodActor* aCond, const EVENT& event, int cmpOp, bool PUSH
case 27: return condCmp(actor->spr.shade, arg1, arg2, cmpOp);
case 28: return (arg3) ? condCmp((actor->spr.cstat & ESpriteFlags::FromInt(arg3)), arg1, arg2, cmpOp) : (actor->spr.cstat & ESpriteFlags::FromInt(arg1));
case 29: return (arg3) ? condCmp((actor->spr.hitag & arg3), arg1, arg2, cmpOp) : (actor->spr.hitag & arg1);
case 30: return condCmp(int(actor->spr.ScaleX() / REPEAT_SCALE), arg1, arg2, cmpOp);
case 30: return condCmp(int(actor->spr.ScaleX() * INV_REPEAT_SCALE), arg1, arg2, cmpOp);
case 31: return condCmp(actor->spr.xoffset, arg1, arg2, cmpOp);
case 32: return condCmp(int(actor->spr.ScaleY() / REPEAT_SCALE), arg1, arg2, cmpOp);
case 32: return condCmp(int(actor->spr.ScaleY() * INV_REPEAT_SCALE), arg1, arg2, cmpOp);
case 33: return condCmp(actor->spr.yoffset, arg1, arg2, cmpOp);
}
}

View file

@ -245,7 +245,7 @@ void UpdateSprite(DBloodActor* actor, SEQFRAME* pFrame)
if (actor->spr.flags & 2)
{
if (tileHeight(actor->spr.picnum) != tileHeight(seqGetTile(pFrame)) || tileTopOffset(actor->spr.picnum) != tileTopOffset(seqGetTile(pFrame))
|| (pFrame->scaley && pFrame->scaley != int(actor->spr.ScaleY() / REPEAT_SCALE)))
|| (pFrame->scaley && pFrame->scaley != int(actor->spr.ScaleY() * INV_REPEAT_SCALE)))
actor->spr.flags |= 4;
}
actor->spr.picnum = seqGetTile(pFrame);

View file

@ -1721,6 +1721,7 @@ int ParseState::parse(void)
ps[g_p].quick_kick = 14;
break;
case concmd_sizeto:
{
insptr++;
// JBF 20030805: As I understand it, if xrepeat becomes 0 it basically kills the
@ -1733,7 +1734,8 @@ int ParseState::parse(void)
insptr++;
if ((g_ac->isPlayer() && g_ac->spr.yrepeat < 36) || *insptr < g_ac->spr.yrepeat || (g_ac->spr.yrepeat * (tileHeight(g_ac->spr.picnum) + 8) * REPEAT_SCALE) < g_ac->floorz - g_ac->ceilingz)
auto scale = g_ac->spr.ScaleY();
if ((g_ac->isPlayer() && scale < 0.5626) || *insptr * REPEAT_SCALE < scale || (scale * (tileHeight(g_ac->spr.picnum) + 8)) < g_ac->floorz - g_ac->ceilingz)
{
j = ((*insptr) - g_ac->spr.yrepeat) << 1;
if (abs(j)) g_ac->spr.yrepeat += Sgn(j);
@ -1742,6 +1744,8 @@ int ParseState::parse(void)
insptr++;
break;
}
case concmd_sizeat:
insptr++;
g_ac->spr.xrepeat = (uint8_t)*insptr;