From 5700d251205ec97f8e05119886e7a61bcb2bb1a2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 7 Oct 2022 18:29:20 +0200 Subject: [PATCH] - minor cleanup on scaling code --- source/build/src/clip.cpp | 2 +- source/core/maptypes.h | 34 +++++++++++++++++------------- source/games/blood/src/nnexts.cpp | 4 ++-- source/games/blood/src/seq.cpp | 2 +- source/games/duke/src/gameexec.cpp | 6 +++++- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index 01a814d7b..e7a5222b1 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -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) diff --git a/source/core/maptypes.h b/source/core/maptypes.h index 162dc366f..13f929912 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -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; } }; diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 1cc78cedc..8a4f9b250 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -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); } } diff --git a/source/games/blood/src/seq.cpp b/source/games/blood/src/seq.cpp index 8535c7f7e..358b9f21e 100644 --- a/source/games/blood/src/seq.cpp +++ b/source/games/blood/src/seq.cpp @@ -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); diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 87d0012b7..8622737c9 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -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;