I want to be able to stack skins in a sprite2 block

This commit is contained in:
Jaime Passos 2019-09-29 12:41:15 -03:00
parent 82be346091
commit 4a0848acd7

View file

@ -3622,21 +3622,18 @@ next_token:
#undef SYMBOLCONVERT #undef SYMBOLCONVERT
// pain // pain
static void R_ParseSpriteInfoFrame(spritenum_t sprnum, playersprite_t spr2num, INT32 skinnum) static spriteinfo_t *R_ParseSpriteInfoFrame(void)
{ {
spriteinfo_t *sprinfo;
char *sprinfoToken; char *sprinfoToken;
size_t sprinfoTokenLength; size_t sprinfoTokenLength;
char *frameChar; char *frameChar;
UINT8 frameFrame; UINT8 frameFrame;
boolean sprite2available = (spr2num != NUMPLAYERSPRITES);
#ifdef ROTSPRITE #ifdef ROTSPRITE
INT16 frameXPivot = 0; INT16 frameXPivot = 0;
INT16 frameYPivot = 0; INT16 frameYPivot = 0;
#endif #endif
if (sprite2available && (skinnum == -1))
I_Error("Error parsing SPRTINFO lump: Missing skin for sprite2 definition");
// Sprite identifier // Sprite identifier
sprinfoToken = M_GetToken(NULL); sprinfoToken = M_GetToken(NULL);
if (sprinfoToken == NULL) if (sprinfoToken == NULL)
@ -3696,26 +3693,18 @@ static void R_ParseSpriteInfoFrame(spritenum_t sprnum, playersprite_t spr2num, I
Z_Free(sprinfoToken); Z_Free(sprinfoToken);
} }
if (sprite2available) // allocate a spriteinfo
{ sprinfo = Z_Calloc(sizeof(spriteinfo_t), PU_STATIC, NULL);
skin_t *skin = &skins[skinnum]; sprinfo->available = true;
spriteinfo_t *sprinfo = skin->sprinfo;
sprinfo[spr2num].available = true; // set fields
#ifdef ROTSPRITE
sprinfo->pivot[frameFrame].x = frameXPivot;
sprinfo->pivot[frameFrame].y = frameYPivot;
#endif
#ifdef ROTSPRITE // then return the spriteinfo
sprinfo[spr2num].pivot[frameFrame].x = frameXPivot; return sprinfo;
sprinfo[spr2num].pivot[frameFrame].y = frameYPivot;
#endif
}
else
{
spriteinfo[sprnum].available = true;
#ifdef ROTSPRITE
spriteinfo[sprnum].pivot[frameFrame].x = frameXPivot;
spriteinfo[sprnum].pivot[frameFrame].y = frameYPivot;
#endif
}
} }
static void R_ParseSpriteInfo(boolean spr2) static void R_ParseSpriteInfo(boolean spr2)
@ -3726,7 +3715,8 @@ static void R_ParseSpriteInfo(boolean spr2)
spritenum_t sprnum = NUMSPRITES; spritenum_t sprnum = NUMSPRITES;
playersprite_t spr2num = NUMPLAYERSPRITES; playersprite_t spr2num = NUMPLAYERSPRITES;
INT32 i; INT32 i;
INT32 skinnum = -1; INT32 skinnumbers[MAXSKINS];
INT32 foundskins = 0;
// Sprite name // Sprite name
sprinfoToken = M_GetToken(NULL); sprinfoToken = M_GetToken(NULL);
@ -3793,33 +3783,53 @@ static void R_ParseSpriteInfo(boolean spr2)
{ {
if (stricmp(sprinfoToken, "SKIN")==0) if (stricmp(sprinfoToken, "SKIN")==0)
{ {
INT32 skinnum;
char *skinName = NULL; char *skinName = NULL;
if (!spr2) if (!spr2)
I_Error("Error parsing SPRTINFO lump: \"SKIN\" token found outside of a sprite2 definition"); I_Error("Error parsing SPRTINFO lump: \"SKIN\" token found outside of a sprite2 definition");
Z_Free(sprinfoToken);
// Skin name // Skin name
sprinfoToken = M_GetToken(NULL); sprinfoToken = M_GetToken(NULL);
if (sprinfoToken == NULL) if (sprinfoToken == NULL)
{ {
I_Error("Error parsing SPRTINFO lump: Unexpected end of file where skin frame should be"); I_Error("Error parsing SPRTINFO lump: Unexpected end of file where skin frame should be");
} }
sprinfoTokenLength = strlen(sprinfoToken);
// copy skin name yada yada
sprinfoTokenLength = strlen(sprinfoToken);
skinName = (char *)Z_Malloc((sprinfoTokenLength+1)*sizeof(char),PU_STATIC,NULL); skinName = (char *)Z_Malloc((sprinfoTokenLength+1)*sizeof(char),PU_STATIC,NULL);
M_Memcpy(skinName,sprinfoToken,sprinfoTokenLength*sizeof(char)); M_Memcpy(skinName,sprinfoToken,sprinfoTokenLength*sizeof(char));
skinName[sprinfoTokenLength] = '\0'; skinName[sprinfoTokenLength] = '\0';
strlwr(skinName);
Z_Free(sprinfoToken); Z_Free(sprinfoToken);
strlwr(skinName);
skinnum = R_SkinAvailable(skinName); skinnum = R_SkinAvailable(skinName);
if (skinnum == -1) if (skinnum == -1)
I_Error("Error parsing SPRTINFO lump: Unknown skin \"%s\"", skinName); I_Error("Error parsing SPRTINFO lump: Unknown skin \"%s\"", skinName);
skinnumbers[foundskins] = skinnum;
foundskins++;
} }
else if (stricmp(sprinfoToken, "FRAME")==0) else if (stricmp(sprinfoToken, "FRAME")==0)
{ {
spriteinfo_t *info = R_ParseSpriteInfoFrame();
Z_Free(sprinfoToken); Z_Free(sprinfoToken);
R_ParseSpriteInfoFrame(sprnum, spr2num, skinnum); if (spr2)
{
if (!foundskins)
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]];
spriteinfo_t *sprinfo = skin->sprinfo;
M_Memcpy(&sprinfo[spr2num], info, sizeof(spriteinfo_t));
}
}
else
M_Memcpy(&spriteinfo[sprnum], info, sizeof(spriteinfo_t));
Z_Free(info);
} }
else else
{ {