mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
Use R_GetSpriteNumByName everywhere
This commit is contained in:
parent
45d54c38f7
commit
a6b71826f9
5 changed files with 29 additions and 43 deletions
|
@ -450,17 +450,19 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
|
|||
}
|
||||
else if (fastncmp("SPR_",word,4)) {
|
||||
p = word+4;
|
||||
for (i = 0; i < NUMSPRITES; i++)
|
||||
if (fastcmp(p,sprnames[i])) {
|
||||
// updating overridden sprnames is not implemented for soc parser,
|
||||
// so don't use cache
|
||||
if (mathlib)
|
||||
lua_pushinteger(L, i);
|
||||
else
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
if (mathlib) return luaL_error(L, "sprite '%s' could not be found.\n", word);
|
||||
i = R_GetSpriteNumByName(p);
|
||||
if (i != NUMSPRITES)
|
||||
{
|
||||
// updating overridden sprnames is not implemented for soc parser,
|
||||
// so don't use cache
|
||||
if (mathlib)
|
||||
lua_pushinteger(L, i);
|
||||
else
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
else if (mathlib)
|
||||
return luaL_error(L, "sprite '%s' could not be found.\n", word);
|
||||
return 0;
|
||||
}
|
||||
else if (fastncmp("SPR2_",word,5)) {
|
||||
|
|
|
@ -4180,9 +4180,9 @@ spritenum_t get_sprite(const char *word)
|
|||
return atoi(word);
|
||||
if (fastncmp("SPR_",word,4))
|
||||
word += 4; // take off the SPR_
|
||||
for (i = 0; i < NUMSPRITES; i++)
|
||||
if (!strcmp(word, sprnames[i]))
|
||||
return i;
|
||||
i = R_GetSpriteNumByName(word);
|
||||
if (i != NUMSPRITES)
|
||||
return i;
|
||||
deh_warning("Couldn't find sprite named 'SPR_%s'",word);
|
||||
return SPR_NULL;
|
||||
}
|
||||
|
|
|
@ -492,9 +492,7 @@ static int libd_getSpritePatch(lua_State *L)
|
|||
else if (lua_isstring(L, 1)) // sprite prefix name given, e.g. "THOK"
|
||||
{
|
||||
const char *name = lua_tostring(L, 1);
|
||||
for (i = 0; i < NUMSPRITES; i++)
|
||||
if (fastcmp(name, sprnames[i]))
|
||||
break;
|
||||
i = R_GetSpriteNumByName(name);
|
||||
if (i >= NUMSPRITES)
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -88,12 +88,12 @@ static int lib_getSprname(lua_State *L)
|
|||
else if (lua_isstring(L, 1))
|
||||
{
|
||||
const char *name = lua_tostring(L, 1);
|
||||
for (i = 0; i < NUMSPRITES; i++)
|
||||
if (fastcmp(name, sprnames[i]))
|
||||
{
|
||||
lua_pushinteger(L, i);
|
||||
return 1;
|
||||
}
|
||||
i = R_GetSpriteNumByName(name);
|
||||
if (i != NUMSPRITES)
|
||||
{
|
||||
lua_pushinteger(L, i);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -245,22 +245,15 @@ static int lib_getSpriteInfo(lua_State *L)
|
|||
if (lua_isstring(L, 1))
|
||||
{
|
||||
const char *name = lua_tostring(L, 1);
|
||||
INT32 spr;
|
||||
for (spr = 0; spr < NUMSPRITES; spr++)
|
||||
{
|
||||
if (fastcmp(name, sprnames[spr]))
|
||||
{
|
||||
i = spr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == NUMSPRITES)
|
||||
INT32 spr = R_GetSpriteNumByName(name);
|
||||
if (spr == NUMSPRITES)
|
||||
{
|
||||
char *check;
|
||||
i = strtol(name, &check, 10);
|
||||
if (check == name || *check != '\0')
|
||||
return luaL_error(L, "unknown sprite name %s", name);
|
||||
}
|
||||
i = spr;
|
||||
}
|
||||
else
|
||||
i = luaL_checkinteger(L, 1);
|
||||
|
|
|
@ -1592,16 +1592,9 @@ static void R_ParseSpriteInfo(boolean spr2)
|
|||
|
||||
if (!spr2)
|
||||
{
|
||||
for (i = 0; i <= NUMSPRITES; i++)
|
||||
{
|
||||
if (i == NUMSPRITES)
|
||||
I_Error("Error parsing SPRTINFO lump: Unknown sprite name \"%s\"", newSpriteName);
|
||||
if (!strcmp(newSpriteName, sprnames[i]))
|
||||
{
|
||||
sprnum = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
sprnum = R_GetSpriteNumByName(newSpriteName);
|
||||
if (sprnum == NUMSPRITES)
|
||||
I_Error("Error parsing SPRTINFO lump: Unknown sprite name \"%s\"", newSpriteName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue