mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-04-23 02:40:11 +00:00
Change spriteinfo_t.available to bit array
Co-authored-by: James R <justsomejames2@gmail.com>
This commit is contained in:
parent
d9dcb546ee
commit
a464da0af1
5 changed files with 50 additions and 25 deletions
|
@ -955,7 +955,6 @@ void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2)
|
|||
|
||||
// allocate a spriteinfo
|
||||
spriteinfo_t *info = Z_Calloc(sizeof(spriteinfo_t), PU_STATIC, NULL);
|
||||
info->available = true;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -1074,6 +1073,7 @@ void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2)
|
|||
|
||||
// read sprite frame and store it in the spriteinfo_t struct
|
||||
readspriteframe(f, info, frame);
|
||||
set_bit_array(info->available, frame);
|
||||
if (sprite2)
|
||||
{
|
||||
INT32 i;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// SONIC ROBO BLAST 2
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 2012-2016 by John "JTE" Muniz.
|
||||
// Copyright (C) 2012-2024 by Sonic Team Junior.
|
||||
// Copyright (C) 2012-2025 by Sonic Team Junior.
|
||||
//
|
||||
// This program is free software distributed under the
|
||||
// terms of the GNU General Public License, version 2.
|
||||
|
@ -236,6 +236,11 @@ static int lib_spr2namelen(lua_State *L)
|
|||
// SPRITE INFO //
|
||||
/////////////////
|
||||
|
||||
struct PivotFrame {
|
||||
spriteinfo_t *sprinfo;
|
||||
UINT8 frame;
|
||||
};
|
||||
|
||||
// spriteinfo[]
|
||||
static int lib_getSpriteInfo(lua_State *L)
|
||||
{
|
||||
|
@ -299,7 +304,7 @@ static int PopPivotSubTable(spriteframepivot_t *pivot, lua_State *L, int stk, in
|
|||
default:
|
||||
TYPEERROR("pivot value", LUA_TNUMBER, lua_type(L, stk+2))
|
||||
}
|
||||
// finally set omg!!!!!!!!!!!!!!!!!!
|
||||
// Set it
|
||||
if (ikey == 1 || (key && fastcmp(key, "x")))
|
||||
pivot[idx].x = (INT32)value;
|
||||
else if (ikey == 2 || (key && fastcmp(key, "y")))
|
||||
|
@ -351,7 +356,7 @@ static int PopPivotTable(spriteinfo_t *info, lua_State *L, int stk)
|
|||
return luaL_error(L, "pivot frame %d out of range (0 - %d)", idx, MAXFRAMENUM - 1);
|
||||
// the values in pivot[] are also tables
|
||||
if (PopPivotSubTable(info->pivot, L, stk+2, idx))
|
||||
info->available = true;
|
||||
set_bit_array(info->available, idx);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
|
@ -426,7 +431,7 @@ static int spriteinfo_get(lua_State *L)
|
|||
{
|
||||
// bypass LUA_PushUserdata
|
||||
void **userdata = lua_newuserdata(L, sizeof(void *));
|
||||
*userdata = &sprinfo->pivot;
|
||||
*userdata = sprinfo;
|
||||
luaL_getmetatable(L, META_PIVOTLIST);
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
|
@ -465,9 +470,8 @@ static int spriteinfo_set(lua_State *L)
|
|||
// pivot[] is userdata
|
||||
else if (lua_isuserdata(L, 1))
|
||||
{
|
||||
spriteframepivot_t *pivot = *((spriteframepivot_t **)luaL_checkudata(L, 1, META_PIVOTLIST));
|
||||
memcpy(&sprinfo->pivot, pivot, sizeof(spriteframepivot_t));
|
||||
sprinfo->available = true; // Just in case?
|
||||
spriteinfo_t *copyinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_PIVOTLIST));
|
||||
memcpy(sprinfo, copyinfo, sizeof(spriteinfo_t));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -490,8 +494,8 @@ static int spriteinfo_num(lua_State *L)
|
|||
// framepivot_t
|
||||
static int pivotlist_get(lua_State *L)
|
||||
{
|
||||
void **userdata;
|
||||
spriteframepivot_t *framepivot = *((spriteframepivot_t **)luaL_checkudata(L, 1, META_PIVOTLIST));
|
||||
struct PivotFrame *container;
|
||||
spriteinfo_t *sprinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_PIVOTLIST));
|
||||
const char *field = luaL_checkstring(L, 2);
|
||||
UINT8 frame;
|
||||
|
||||
|
@ -500,8 +504,9 @@ static int pivotlist_get(lua_State *L)
|
|||
luaL_error(L, "invalid frame %s", field);
|
||||
|
||||
// bypass LUA_PushUserdata
|
||||
userdata = lua_newuserdata(L, sizeof(void *));
|
||||
*userdata = &framepivot[frame];
|
||||
container = lua_newuserdata(L, sizeof *container);
|
||||
container->sprinfo = sprinfo;
|
||||
container->frame = frame;
|
||||
luaL_getmetatable(L, META_FRAMEPIVOT);
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
|
@ -511,11 +516,10 @@ static int pivotlist_get(lua_State *L)
|
|||
|
||||
static int pivotlist_set(lua_State *L)
|
||||
{
|
||||
// Because I already know it's a spriteframepivot_t anyway
|
||||
spriteframepivot_t *pivotlist = *((spriteframepivot_t **)lua_touserdata(L, 1));
|
||||
//spriteframepivot_t *framepivot = *((spriteframepivot_t **)luaL_checkudata(L, 1, META_FRAMEPIVOT));
|
||||
spriteinfo_t *sprinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_PIVOTLIST));
|
||||
const char *field = luaL_checkstring(L, 2);
|
||||
UINT8 frame;
|
||||
int okcool = 0;
|
||||
|
||||
if (!lua_lumploading)
|
||||
return luaL_error(L, "Do not alter spriteframepivot_t from within a hook or coroutine!");
|
||||
|
@ -530,14 +534,18 @@ static int pivotlist_set(lua_State *L)
|
|||
|
||||
// pivot[] is a table
|
||||
if (lua_istable(L, 3))
|
||||
return PopPivotSubTable(pivotlist, L, 3, frame);
|
||||
okcool = PopPivotSubTable(sprinfo->pivot, L, 3, frame);
|
||||
// pivot[] is userdata
|
||||
else if (lua_isuserdata(L, 3))
|
||||
{
|
||||
spriteframepivot_t *copypivot = *((spriteframepivot_t **)luaL_checkudata(L, 3, META_FRAMEPIVOT));
|
||||
memcpy(&pivotlist[frame], copypivot, sizeof(spriteframepivot_t));
|
||||
struct PivotFrame *container = luaL_checkudata(L, 3, META_FRAMEPIVOT);
|
||||
memcpy(&sprinfo->pivot[frame], &container->sprinfo->pivot[container->frame], sizeof(spriteframepivot_t));
|
||||
okcool = 1;
|
||||
}
|
||||
|
||||
if (okcool)
|
||||
set_bit_array(sprinfo->available, frame);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -549,7 +557,8 @@ static int pivotlist_num(lua_State *L)
|
|||
|
||||
static int framepivot_get(lua_State *L)
|
||||
{
|
||||
spriteframepivot_t *framepivot = *((spriteframepivot_t **)luaL_checkudata(L, 1, META_FRAMEPIVOT));
|
||||
struct PivotFrame *container = luaL_checkudata(L, 1, META_FRAMEPIVOT);
|
||||
spriteframepivot_t *framepivot = &container->sprinfo->pivot[container->frame];
|
||||
const char *field = luaL_checkstring(L, 2);
|
||||
|
||||
I_Assert(framepivot != NULL);
|
||||
|
@ -572,7 +581,9 @@ static int framepivot_get(lua_State *L)
|
|||
|
||||
static int framepivot_set(lua_State *L)
|
||||
{
|
||||
spriteframepivot_t *framepivot = *((spriteframepivot_t **)luaL_checkudata(L, 1, META_FRAMEPIVOT));
|
||||
struct PivotFrame *container = luaL_checkudata(L, 1, META_FRAMEPIVOT);
|
||||
spriteframepivot_t *framepivot = &container->sprinfo->pivot[container->frame];
|
||||
UINT8 *available = container->sprinfo->available;
|
||||
const char *field = luaL_checkstring(L, 2);
|
||||
|
||||
if (!lua_lumploading)
|
||||
|
@ -585,9 +596,15 @@ static int framepivot_set(lua_State *L)
|
|||
I_Assert(framepivot != NULL);
|
||||
|
||||
if (fastcmp("x", field))
|
||||
{
|
||||
framepivot->x = luaL_checkinteger(L, 3);
|
||||
set_bit_array(available, container->frame);
|
||||
}
|
||||
else if (fastcmp("y", field))
|
||||
{
|
||||
framepivot->y = luaL_checkinteger(L, 3);
|
||||
set_bit_array(available, container->frame);
|
||||
}
|
||||
// TODO: 2.3: delete
|
||||
else if (fastcmp("rotaxis", field))
|
||||
LUA_UsageWarning(L, "\"rotaxis\" is deprecated and will be removed.")
|
||||
|
|
|
@ -96,7 +96,7 @@ patch_t *Patch_GetRotatedSprite(
|
|||
|
||||
patch = W_CachePatchNum(lump, PU_SPRITE);
|
||||
|
||||
if (sprinfo->available)
|
||||
if (R_IsSpriteInfoAvailable(sprinfo, frame))
|
||||
{
|
||||
xpivot = sprinfo->pivot[frame].x;
|
||||
ypivot = sprinfo->pivot[frame].y;
|
||||
|
|
|
@ -1597,6 +1597,8 @@ static void R_ParseSpriteInfoFrame(struct ParseSpriteInfoState *parser)
|
|||
Z_Free(sprinfoToken);
|
||||
}
|
||||
|
||||
set_bit_array(parser->info->available, frameID);
|
||||
|
||||
if (parser->spr2)
|
||||
{
|
||||
INT32 i;
|
||||
|
@ -1672,7 +1674,6 @@ static void R_ParseSpriteInfo(boolean spr2)
|
|||
|
||||
// allocate a spriteinfo
|
||||
parser.info = Z_Calloc(sizeof(spriteinfo_t), PU_STATIC, NULL);
|
||||
parser.info->available = true;
|
||||
|
||||
// Left Curly Brace
|
||||
sprinfoToken = M_GetToken(NULL);
|
||||
|
@ -1788,3 +1789,8 @@ void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps)
|
|||
R_ParseSPRTINFOLump(wadnum, i);
|
||||
}
|
||||
}
|
||||
|
||||
boolean R_IsSpriteInfoAvailable(spriteinfo_t *info, UINT8 frame)
|
||||
{
|
||||
return info && in_bit_array(info->available, frame);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// SONIC ROBO BLAST 2
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 1993-1996 by id Software, Inc.
|
||||
// Copyright (C) 2018-2024 by Lactozilla.
|
||||
// Copyright (C) 2019-2024 by Sonic Team Junior.
|
||||
// Copyright (C) 2018-2025 by Lactozilla.
|
||||
// Copyright (C) 2019-2025 by Sonic Team Junior.
|
||||
//
|
||||
// This program is free software distributed under the
|
||||
// terms of the GNU General Public License, version 2.
|
||||
|
@ -100,8 +100,8 @@ typedef struct
|
|||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 available[BIT_ARRAY_SIZE(MAXFRAMENUM)];
|
||||
spriteframepivot_t pivot[MAXFRAMENUM];
|
||||
boolean available;
|
||||
} spriteinfo_t;
|
||||
|
||||
// PNG support
|
||||
|
@ -126,4 +126,6 @@ extern spriteinfo_t spriteinfo[NUMSPRITES];
|
|||
void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps);
|
||||
void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum);
|
||||
|
||||
boolean R_IsSpriteInfoAvailable(spriteinfo_t *info, UINT8 frame);
|
||||
|
||||
#endif // __R_PICFORMATS__
|
||||
|
|
Loading…
Reference in a new issue