This commit is contained in:
Jaime Passos 2019-11-14 14:12:36 -03:00
parent 10d1b63ff2
commit 8506d420a6
6 changed files with 60 additions and 28 deletions

View File

@ -868,6 +868,8 @@ static void readspriteframe(MYFILE *f, spriteinfo_t *sprinfo, UINT8 frame)
sprinfo->pivot[frame].x = value;
else if (fastcmp(word, "YPIVOT"))
sprinfo->pivot[frame].y = value;
else if (fastcmp(word, "ROTAXIS"))
sprinfo->pivot[frame].rotaxis = value;
#endif
else
{
@ -893,6 +895,11 @@ static void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2)
spriteinfo_t *info = Z_Calloc(sizeof(spriteinfo_t), PU_STATIC, NULL);
info->available = true;
#ifdef ROTSPRITE
if ((sprites != NULL) && (!sprite2))
R_FreeSingleRotSprite(&sprites[num]);
#endif
do
{
lastline = f->curpos;
@ -1006,7 +1013,7 @@ static void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2)
break;
}
// read sprite frame and store it on the spriteinfo_t struct
// read sprite frame and store it in the spriteinfo_t struct
readspriteframe(f, info, frame);
if (sprite2)
{
@ -1018,8 +1025,12 @@ static void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2)
}
for (i = 0; i < foundskins; i++)
{
skin_t *skin = &skins[skinnumbers[i]];
size_t skinnum = skinnumbers[i];
skin_t *skin = &skins[skinnum];
spriteinfo_t *sprinfo = skin->sprinfo;
#ifdef ROTSPRITE
R_FreeSkinRotSprite(skinnum);
#endif
M_Memcpy(&sprinfo[num], info, sizeof(spriteinfo_t));
}
}

View File

@ -269,7 +269,7 @@ static int lib_getSpriteInfo(lua_State *L)
#ifdef ROTSPRITE
static int PopPivotSubTable(spriteframepivot_t *pivot, lua_State *L, int stk, int idx)
{
int ok = 0;
int okcool = 0;
switch (lua_type(L, stk))
{
case LUA_TTABLE:
@ -312,14 +312,14 @@ static int PopPivotSubTable(spriteframepivot_t *pivot, lua_State *L, int stk, in
pivot[idx].rotaxis = (UINT8)value;
else if (ikey == -1 && (key != NULL))
FIELDERROR("pivot key", va("invalid option %s", key));
ok = 1;
okcool = 1;
lua_pop(L, 1);
}
break;
default:
TYPEERROR("sprite pivot", LUA_TTABLE, lua_type(L, stk))
}
return ok;
return okcool;
}
static int PopPivotTable(spriteinfo_t *info, lua_State *L, int stk)
@ -376,7 +376,11 @@ static int lib_setSpriteInfo(lua_State *L)
UINT32 i = luaL_checkinteger(L, 1);
if (i == 0 || i >= NUMSPRITES)
return luaL_error(L, "spriteinfo[] index %d out of range (1 - %d)", i, NUMSPRITES-1);
info = &spriteinfo[i]; // get the sfxinfo to assign to.
#ifdef ROTSPRITE
if (sprites != NULL)
R_FreeSingleRotSprite(&sprites[i]);
#endif
info = &spriteinfo[i]; // get the spriteinfo to assign to.
}
luaL_checktype(L, 2, LUA_TTABLE); // check that we've been passed a table.
lua_remove(L, 1); // pop sprite num, don't need it any more.
@ -467,6 +471,9 @@ static int spriteinfo_set(lua_State *L)
lua_settop(L, 1); // leave only one value
#ifdef ROTSPRITE
if (sprites != NULL)
R_FreeSingleRotSprite(&sprites[sprinfo-spriteinfo]);
if (fastcmp(field, "pivot"))
{
// pivot[] is a table
@ -597,7 +604,7 @@ static int framepivot_set(lua_State *L)
else if (fastcmp("y", field))
framepivot->y = luaL_checkinteger(L, 3);
else if (fastcmp("rotaxis", field))
framepivot->rotaxis = (rotaxis_t)(luaL_checkinteger(L, 3));
framepivot->rotaxis = luaL_checkinteger(L, 3);
else
return luaL_error(L, va("Field %s does not exist in spriteframepivot_t", field));

View File

@ -3510,20 +3510,6 @@ boolean P_AddWadFile(const char *wadfilename)
if (!mapsadded)
CONS_Printf(M_GetText("No maps added\n"));
#ifdef ROTSPRITE
for (i = 0; i < NUMSPRITES; i++)
R_FreeRotSprite(&sprites[i]);
for (i = 0; i < MAXSKINS; i++)
{
spritedef_t *skinsprites = skins[i].sprites;
for (j = 0; j < NUMPLAYERSPRITES*2; j++)
{
R_FreeRotSprite(skinsprites);
skinsprites++;
}
}
#endif
R_LoadSpriteInfoLumps(wadnum, numlumps);
#ifdef HWRENDER

View File

@ -940,6 +940,11 @@ static void R_ParseSpriteInfo(boolean spr2)
info = Z_Calloc(sizeof(spriteinfo_t), PU_STATIC, NULL);
info->available = true;
#ifdef ROTSPRITE
if ((sprites != NULL) && (!spr2))
R_FreeSingleRotSprite(&sprites[sprnum]);
#endif
// Left Curly Brace
sprinfoToken = M_GetToken(NULL);
if (sprinfoToken == NULL)
@ -997,8 +1002,12 @@ static void R_ParseSpriteInfo(boolean spr2)
I_Error("Error parsing SPRTINFO lump: No skins specified in this sprite2 definition");
for (i = 0; i < foundskins; i++)
{
skin_t *skin = &skins[skinnumbers[i]];
size_t skinnum = skinnumbers[i];
skin_t *skin = &skins[skinnum];
spriteinfo_t *sprinfo = skin->sprinfo;
#ifdef ROTSPRITE
R_FreeSkinRotSprite(skinnum);
#endif
M_Memcpy(&sprinfo[spr2num], info, sizeof(spriteinfo_t));
}
}
@ -1293,11 +1302,11 @@ void R_CacheRotSprite(spritenum_t sprnum, UINT8 frame, spriteinfo_t *sprinfo, sp
}
//
// R_FreeRotSprite
// R_FreeSingleRotSprite
//
// Free sprite rotation data from memory.
// Free sprite rotation data from memory, for a single spritedef.
//
void R_FreeRotSprite(spritedef_t *spritedef)
void R_FreeSingleRotSprite(spritedef_t *spritedef)
{
UINT8 frame;
INT32 rot, ang;
@ -1343,4 +1352,22 @@ void R_FreeRotSprite(spritedef_t *spritedef)
}
}
}
//
// R_FreeSkinRotSprite
//
// Free sprite rotation data from memory, for a skin.
// Calls R_FreeSingleRotSprite.
//
void R_FreeSkinRotSprite(size_t skinnum)
{
size_t i;
skin_t *skin = &skins[skinnum];
spritedef_t *skinsprites = skin->sprites;
for (i = 0; i < NUMPLAYERSPRITES*2; i++)
{
R_FreeSingleRotSprite(skinsprites);
skinsprites++;
}
}
#endif

View File

@ -67,7 +67,8 @@ void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum);
// rotsprite
#ifdef ROTSPRITE
void R_CacheRotSprite(spritenum_t sprnum, UINT8 frame, spriteinfo_t *sprinfo, spriteframe_t *sprframe, INT32 rot, UINT8 flip);
void R_FreeRotSprite(spritedef_t *spritedef);
void R_FreeSingleRotSprite(spritedef_t *spritedef);
void R_FreeSkinRotSprite(size_t skinnum);
extern fixed_t cosang2rad[ROTANGLES];
extern fixed_t sinang2rad[ROTANGLES];
#endif

View File

@ -244,7 +244,7 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef,
if (spritedef->numframes) // (then spriteframes is not null)
{
#ifdef ROTSPRITE
R_FreeRotSprite(spritedef);
R_FreeSingleRotSprite(spritedef);
#endif
// copy the already defined sprite frames
M_Memcpy(sprtemp, spritedef->spriteframes,
@ -394,7 +394,7 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef,
spritedef->numframes < maxframe) // more frames are defined ?
{
#ifdef ROTSPRITE
R_FreeRotSprite(spritedef);
R_FreeSingleRotSprite(spritedef);
#endif
Z_Free(spritedef->spriteframes);
spritedef->spriteframes = NULL;