Use R_GetSpriteNumByName everywhere

This commit is contained in:
LJ Sonic 2024-03-16 17:00:59 +01:00
parent 45d54c38f7
commit a6b71826f9
5 changed files with 29 additions and 43 deletions

View file

@ -450,8 +450,9 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
} }
else if (fastncmp("SPR_",word,4)) { else if (fastncmp("SPR_",word,4)) {
p = word+4; p = word+4;
for (i = 0; i < NUMSPRITES; i++) i = R_GetSpriteNumByName(p);
if (fastcmp(p,sprnames[i])) { if (i != NUMSPRITES)
{
// updating overridden sprnames is not implemented for soc parser, // updating overridden sprnames is not implemented for soc parser,
// so don't use cache // so don't use cache
if (mathlib) if (mathlib)
@ -460,7 +461,8 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
CacheAndPushConstant(L, word, i); CacheAndPushConstant(L, word, i);
return 1; return 1;
} }
if (mathlib) return luaL_error(L, "sprite '%s' could not be found.\n", word); else if (mathlib)
return luaL_error(L, "sprite '%s' could not be found.\n", word);
return 0; return 0;
} }
else if (fastncmp("SPR2_",word,5)) { else if (fastncmp("SPR2_",word,5)) {

View file

@ -4180,8 +4180,8 @@ spritenum_t get_sprite(const char *word)
return atoi(word); return atoi(word);
if (fastncmp("SPR_",word,4)) if (fastncmp("SPR_",word,4))
word += 4; // take off the SPR_ word += 4; // take off the SPR_
for (i = 0; i < NUMSPRITES; i++) i = R_GetSpriteNumByName(word);
if (!strcmp(word, sprnames[i])) if (i != NUMSPRITES)
return i; return i;
deh_warning("Couldn't find sprite named 'SPR_%s'",word); deh_warning("Couldn't find sprite named 'SPR_%s'",word);
return SPR_NULL; return SPR_NULL;

View file

@ -492,9 +492,7 @@ static int libd_getSpritePatch(lua_State *L)
else if (lua_isstring(L, 1)) // sprite prefix name given, e.g. "THOK" else if (lua_isstring(L, 1)) // sprite prefix name given, e.g. "THOK"
{ {
const char *name = lua_tostring(L, 1); const char *name = lua_tostring(L, 1);
for (i = 0; i < NUMSPRITES; i++) i = R_GetSpriteNumByName(name);
if (fastcmp(name, sprnames[i]))
break;
if (i >= NUMSPRITES) if (i >= NUMSPRITES)
return 0; return 0;
} }

View file

@ -88,8 +88,8 @@ static int lib_getSprname(lua_State *L)
else if (lua_isstring(L, 1)) else if (lua_isstring(L, 1))
{ {
const char *name = lua_tostring(L, 1); const char *name = lua_tostring(L, 1);
for (i = 0; i < NUMSPRITES; i++) i = R_GetSpriteNumByName(name);
if (fastcmp(name, sprnames[i])) if (i != NUMSPRITES)
{ {
lua_pushinteger(L, i); lua_pushinteger(L, i);
return 1; return 1;
@ -245,22 +245,15 @@ static int lib_getSpriteInfo(lua_State *L)
if (lua_isstring(L, 1)) if (lua_isstring(L, 1))
{ {
const char *name = lua_tostring(L, 1); const char *name = lua_tostring(L, 1);
INT32 spr; INT32 spr = R_GetSpriteNumByName(name);
for (spr = 0; spr < NUMSPRITES; spr++) if (spr == NUMSPRITES)
{
if (fastcmp(name, sprnames[spr]))
{
i = spr;
break;
}
}
if (i == NUMSPRITES)
{ {
char *check; char *check;
i = strtol(name, &check, 10); i = strtol(name, &check, 10);
if (check == name || *check != '\0') if (check == name || *check != '\0')
return luaL_error(L, "unknown sprite name %s", name); return luaL_error(L, "unknown sprite name %s", name);
} }
i = spr;
} }
else else
i = luaL_checkinteger(L, 1); i = luaL_checkinteger(L, 1);

View file

@ -1592,16 +1592,9 @@ static void R_ParseSpriteInfo(boolean spr2)
if (!spr2) if (!spr2)
{ {
for (i = 0; i <= NUMSPRITES; i++) sprnum = R_GetSpriteNumByName(newSpriteName);
{ if (sprnum == NUMSPRITES)
if (i == NUMSPRITES)
I_Error("Error parsing SPRTINFO lump: Unknown sprite name \"%s\"", newSpriteName); I_Error("Error parsing SPRTINFO lump: Unknown sprite name \"%s\"", newSpriteName);
if (!strcmp(newSpriteName, sprnames[i]))
{
sprnum = i;
break;
}
}
} }
else else
{ {