Merge branch 'spr2-freeslots' into 'master'

Spr2 freeslots

Needed for Miles, generally a good idea to have around anyway. Considering Miles uses it without problems, seems to work fine.

See merge request !24
This commit is contained in:
Monster Iestyn 2016-08-04 16:24:37 -04:00
commit 5b2705ef48
5 changed files with 49 additions and 10 deletions

View File

@ -673,6 +673,22 @@ static void readfreeslots(MYFILE *f)
break;
}
}
else if (fastcmp(type, "SPR2"))
{
// Search if we already have an SPR2 by that name...
for (i = SPR2_FIRSTFREESLOT; i < (int)free_spr2; i++)
if (memcmp(spr2names[i],word,4) == 0)
break;
// We found it? (Two mods using the same SPR2 name?) Then don't allocate another one.
if (i < (int)free_spr2)
continue;
// Copy in the spr2 name and increment free_spr2.
if (free_spr2 < NUMPLAYERSPRITES) {
strncpy(spr2names[free_spr2],word,4);
spr2names[free_spr2++][4] = 0;
} else
CONS_Alert(CONS_WARNING, "Ran out of free SPR2 slots!\n");
}
else
deh_warning("Freeslots: unknown enum class '%s' for '%s_%s'", type, type, word);
}
@ -7873,7 +7889,7 @@ static inline int lib_freeslot(lua_State *L)
lua_pushinteger(L, sfx);
r++;
} else
return r;
CONS_Alert(CONS_WARNING, "Ran out of free SFX slots!\n");
}
else if (fastcmp(type, "SPR"))
{
@ -7900,7 +7916,7 @@ static inline int lib_freeslot(lua_State *L)
break;
}
if (j > SPR_LASTFREESLOT)
return r;
CONS_Alert(CONS_WARNING, "Ran out of free sprite slots!\n");
}
else if (fastcmp(type, "S"))
{
@ -7915,7 +7931,7 @@ static inline int lib_freeslot(lua_State *L)
break;
}
if (i == NUMSTATEFREESLOTS)
return r;
CONS_Alert(CONS_WARNING, "Ran out of free State slots!\n");
}
else if (fastcmp(type, "MT"))
{
@ -7930,7 +7946,26 @@ static inline int lib_freeslot(lua_State *L)
break;
}
if (i == NUMMOBJFREESLOTS)
return r;
CONS_Alert(CONS_WARNING, "Ran out of free MobjType slots!\n");
}
else if (fastcmp(type, "SPR2"))
{
// Search if we already have an SPR2 by that name...
enum playersprite i;
for (i = SPR2_FIRSTFREESLOT; i < free_spr2; i++)
if (memcmp(spr2names[i],word,4) == 0)
break;
// We don't, so allocate a new one.
if (i >= free_spr2) {
if (free_spr2 < NUMPLAYERSPRITES)
{
CONS_Printf("Sprite SPR2_%s allocated.\n",word);
strncpy(spr2names[free_spr2],word,4);
spr2names[free_spr2++][4] = 0;
} else
CONS_Alert(CONS_WARNING, "Ran out of free SPR2 slots!\n");
}
r++;
}
Z_Free(s);
lua_remove(L, 1);
@ -8097,7 +8132,7 @@ static inline int lib_getenum(lua_State *L)
}
else if (fastncmp("SPR2_",word,4)) {
p = word+5;
for (i = 0; i < NUMPLAYERSPRITES; i++)
for (i = 0; i < (fixed_t)free_spr2; i++)
if (!spr2names[i][4])
{
// special 3-char cases, e.g. SPR2_RUN

View File

@ -103,6 +103,7 @@ char spr2names[NUMPLAYERSPRITES][5] =
"SRID",
"SFLT"
};
enum playersprite free_spr2 = SPR2_FIRSTFREESLOT;
// Doesn't work with g++, needs actionf_p1 (don't modify this comment)
state_t states[NUMSTATES] =

View File

@ -625,6 +625,8 @@ enum playersprite
SPR2_SRID,
SPR2_SFLT,
SPR2_FIRSTFREESLOT,
SPR2_LASTFREESLOT = SPR2_FIRSTFREESLOT + NUMSPRITEFREESLOTS - 1,
NUMPLAYERSPRITES
};
@ -3030,8 +3032,9 @@ typedef struct
extern state_t states[NUMSTATES];
extern char sprnames[NUMSPRITES + 1][5];
char spr2names[NUMPLAYERSPRITES][5];
extern char spr2names[NUMPLAYERSPRITES][5];
extern state_t *astate;
extern enum playersprite free_spr2;
typedef enum mobj_type
{

View File

@ -105,7 +105,7 @@ static int lib_getSpr2name(lua_State *L)
if (lua_isnumber(L, 1))
{
i = lua_tonumber(L, 1);
if (i > NUMPLAYERSPRITES)
if (i >= free_spr2)
return 0;
lua_pushlstring(L, spr2names[i], 4);
return 1;
@ -113,7 +113,7 @@ static int lib_getSpr2name(lua_State *L)
else if (lua_isstring(L, 1))
{
const char *name = lua_tostring(L, 1);
for (i = 0; i < NUMPLAYERSPRITES; i++)
for (i = 0; i < free_spr2; i++)
if (fastcmp(name, spr2names[i]))
{
lua_pushinteger(L, i);
@ -125,7 +125,7 @@ static int lib_getSpr2name(lua_State *L)
static int lib_spr2namelen(lua_State *L)
{
lua_pushinteger(L, NUMPLAYERSPRITES);
lua_pushinteger(L, free_spr2);
return 1;
}

View File

@ -2667,7 +2667,7 @@ next_token:
if (z < lastlump) lastlump = z;
// load all sprite sets we are aware of.
for (sprite2 = 0; sprite2 < NUMPLAYERSPRITES; sprite2++)
for (sprite2 = 0; sprite2 < free_spr2; sprite2++)
R_AddSingleSpriteDef(spr2names[sprite2], &skin->sprites[sprite2], wadnum, lump, lastlump);
}