From 8aeb048f0aa11e573d910d42f9117d936751919d Mon Sep 17 00:00:00 2001 From: Lactozilla <jp6781615@gmail.com> Date: Thu, 30 Jan 2025 14:49:07 -0300 Subject: [PATCH] Refactor spriteframepivot_t into spriteinfoframe_t --- src/deh_soc.c | 4 ++-- src/lua_infolib.c | 12 ++++++------ src/r_patchrotation.c | 8 ++++---- src/r_picformats.c | 10 +++++----- src/r_picformats.h | 7 ++++++- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index b9cb3adb9b..001c6d2896 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -925,9 +925,9 @@ static void readspriteframe(MYFILE *f, spriteinfo_t *sprinfo, UINT8 frame) value = atoi(word2); // used for numerical settings if (fastcmp(word, "XPIVOT")) - sprinfo->pivot[frame].x = value; + sprinfo->frames[frame].pivot.x = value; else if (fastcmp(word, "YPIVOT")) - sprinfo->pivot[frame].y = value; + sprinfo->frames[frame].pivot.y = value; // TODO: 2.3: Delete else if (fastcmp(word, "ROTAXIS")) deh_warning("SpriteInfo: ROTAXIS is deprecated and will be removed."); diff --git a/src/lua_infolib.c b/src/lua_infolib.c index c714a6382f..44ced92e94 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -333,9 +333,9 @@ static int PopPivotSubTable(spriteinfo_t *info, lua_State *L, int stk, int idx) } // Set it if (ikey == 1 || (key && fastcmp(key, "x"))) - info->pivot[idx].x = (INT32)value; + info->frames[idx].pivot.x = (INT32)value; else if (ikey == 2 || (key && fastcmp(key, "y"))) - info->pivot[idx].y = (INT32)value; + info->frames[idx].pivot.y = (INT32)value; // TODO: 2.3: Delete else if (ikey == 3 || (key && fastcmp(key, "rotaxis"))) LUA_UsageWarning(L, "\"rotaxis\" is deprecated and will be removed.") @@ -552,8 +552,8 @@ static int pivotlist_set(lua_State *L) else if (lua_isuserdata(L, 3)) { struct PivotFrame *container = luaL_checkudata(L, 3, META_FRAMEPIVOT); - memcpy(&sprinfo->pivot[frame], - &container->sprinfo->pivot[container->frame], + memcpy(&sprinfo->frames[frame].pivot, + &container->sprinfo->frames[container->frame].pivot, sizeof(spriteframepivot_t)); okcool = 1; } @@ -573,7 +573,7 @@ static int pivotlist_num(lua_State *L) static int framepivot_get(lua_State *L) { struct PivotFrame *container = luaL_checkudata(L, 1, META_FRAMEPIVOT); - spriteframepivot_t *framepivot = &container->sprinfo->pivot[container->frame]; + spriteframepivot_t *framepivot = &container->sprinfo->frames[container->frame].pivot; const char *field = luaL_checkstring(L, 2); I_Assert(framepivot != NULL); @@ -597,7 +597,7 @@ static int framepivot_get(lua_State *L) static int framepivot_set(lua_State *L) { struct PivotFrame *container = luaL_checkudata(L, 1, META_FRAMEPIVOT); - spriteframepivot_t *framepivot = &container->sprinfo->pivot[container->frame]; + spriteframepivot_t *framepivot = &container->sprinfo->frames[container->frame].pivot; UINT8 *available = container->sprinfo->available; const char *field = luaL_checkstring(L, 2); diff --git a/src/r_patchrotation.c b/src/r_patchrotation.c index 61129d608c..a84f0ad4a4 100644 --- a/src/r_patchrotation.c +++ b/src/r_patchrotation.c @@ -98,13 +98,13 @@ patch_t *Patch_GetRotatedSprite( if (R_IsSpriteInfoAvailable(sprinfo, frame)) { - xpivot = sprinfo->pivot[frame].x; - ypivot = sprinfo->pivot[frame].y; + xpivot = sprinfo->frames[frame].pivot.x; + ypivot = sprinfo->frames[frame].pivot.y; } else if (R_IsSpriteInfoAvailable(sprinfo, SPRINFO_DEFAULT_FRAME)) { - xpivot = sprinfo->pivot[SPRINFO_DEFAULT_FRAME].x; - ypivot = sprinfo->pivot[SPRINFO_DEFAULT_FRAME].y; + xpivot = sprinfo->frames[SPRINFO_DEFAULT_FRAME].pivot.x; + ypivot = sprinfo->frames[SPRINFO_DEFAULT_FRAME].pivot.y; } else { diff --git a/src/r_picformats.c b/src/r_picformats.c index 8aa3eab516..84fc980a3a 100644 --- a/src/r_picformats.c +++ b/src/r_picformats.c @@ -1556,18 +1556,18 @@ struct ParsedSpriteInfoFrame { INT32 pivotY; }; -static boolean define_spriteinfo_frame(struct ParsedSpriteInfoFrame *frame, spriteinfo_t *dest, UINT16 index) +static boolean define_spriteinfo_frame(struct ParsedSpriteInfoFrame *frame, spriteinfoframe_t *dest) { boolean defined = false; if (frame->pivotX != INT32_MAX) { - dest->pivot[index].x = frame->pivotX; + dest->pivot.x = frame->pivotX; defined = true; } if (frame->pivotY != INT32_MAX) { - dest->pivot[index].y = frame->pivotY; + dest->pivot.y = frame->pivotY; defined = true; } @@ -1704,7 +1704,7 @@ static void R_ParseSpriteInfoFrame(struct ParseSpriteInfoState *parser, boolean { for (UINT16 frameIter = frameID; frameIter <= frameEndID; frameIter++) { - if (define_spriteinfo_frame(&frame, parser->info, frameIter)) + if (define_spriteinfo_frame(&frame, &parser->info->frames[frameIter])) { set_bit_array(parser->info->available, frameIter); } @@ -1712,7 +1712,7 @@ static void R_ParseSpriteInfoFrame(struct ParseSpriteInfoState *parser, boolean } else { - if (define_spriteinfo_frame(&frame, parser->info, frameID)) + if (define_spriteinfo_frame(&frame, &parser->info->frames[frameID])) { set_bit_array(parser->info->available, frameID); } diff --git a/src/r_picformats.h b/src/r_picformats.h index 1388be0134..b07b6a9485 100644 --- a/src/r_picformats.h +++ b/src/r_picformats.h @@ -98,12 +98,17 @@ typedef struct INT32 x, y; } spriteframepivot_t; +typedef struct +{ + spriteframepivot_t pivot; +} spriteinfoframe_t; + #define SPRINFO_DEFAULT_FRAME (MAXFRAMENUM) typedef struct { UINT8 available[BIT_ARRAY_SIZE(MAXFRAMENUM + 1)]; // 1 extra for default_frame - spriteframepivot_t pivot[MAXFRAMENUM + 1]; + spriteinfoframe_t frames[MAXFRAMENUM + 1]; } spriteinfo_t; // PNG support -- GitLab