diff --git a/src/deh_lua.c b/src/deh_lua.c index 3176f5d69..3d6d8b455 100644 --- a/src/deh_lua.c +++ b/src/deh_lua.c @@ -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)) { diff --git a/src/deh_soc.c b/src/deh_soc.c index 5e068313d..269598459 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -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; } diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index ddd6c6888..d6771f108 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -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; } diff --git a/src/lua_infolib.c b/src/lua_infolib.c index cff72deb4..eeb1067a3 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -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); diff --git a/src/r_picformats.c b/src/r_picformats.c index a75f15baf..d71657021 100644 --- a/src/r_picformats.c +++ b/src/r_picformats.c @@ -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 {