No longer store wadnum in sprnames

This commit is contained in:
LJ Sonic 2024-03-14 13:56:47 +01:00
parent 4018a7fa0f
commit 9ca5ce01f1
4 changed files with 2 additions and 22 deletions

View file

@ -59,23 +59,14 @@ static inline int lib_freeslot(lua_State *L)
}
else if (fastcmp(type, "SPR"))
{
char wad;
spritenum_t j;
lua_getfield(L, LUA_REGISTRYINDEX, "WAD");
wad = (char)lua_tointeger(L, -1);
lua_pop(L, 1);
for (j = SPR_FIRSTFREESLOT; j <= SPR_LASTFREESLOT; j++)
{
if (used_spr[(j-SPR_FIRSTFREESLOT)/8] & (1<<(j%8)))
{
if (!sprnames[j][4] && memcmp(sprnames[j],word,4)==0)
sprnames[j][4] = wad;
continue; // Already allocated, next.
}
// Found a free slot!
CONS_Printf("Sprite SPR_%s allocated.\n",word);
strncpy(sprnames[j],word,4);
//sprnames[j][4] = 0;
used_spr[(j-SPR_FIRSTFREESLOT)/8] |= 1<<(j%8); // Okay, this sprite slot has been named now.
// Lua needs to update the value in _G if it exists
LUA_UpdateSprName(word, j);
@ -456,7 +447,7 @@ 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 (!sprnames[i][4] && fastncmp(p,sprnames[i],4)) {
if (fastncmp(p,sprnames[i],4)) {
// updating overridden sprnames is not implemented for soc parser,
// so don't use cache
if (mathlib)

View file

@ -443,14 +443,9 @@ void readfreeslots(MYFILE *f)
for (i = SPR_FIRSTFREESLOT; i <= SPR_LASTFREESLOT; i++)
{
if (used_spr[(i-SPR_FIRSTFREESLOT)/8] & (1<<(i%8)))
{
if (!sprnames[i][4] && memcmp(sprnames[i],word,4)==0)
sprnames[i][4] = (char)f->wad;
continue; // Already allocated, next.
}
// Found a free slot!
strncpy(sprnames[i],word,4);
//sprnames[i][4] = 0;
used_spr[(i-SPR_FIRSTFREESLOT)/8] |= 1<<(i%8); // Okay, this sprite slot has been named now.
// Lua needs to update the value in _G if it exists
LUA_UpdateSprName(word, i);
@ -4183,7 +4178,7 @@ spritenum_t get_sprite(const char *word)
if (fastncmp("SPR_",word,4))
word += 4; // take off the SPR_
for (i = 0; i < NUMSPRITES; i++)
if (!sprnames[i][4] && memcmp(word,sprnames[i],4)==0)
if (memcmp(word,sprnames[i],4)==0)
return i;
deh_warning("Couldn't find sprite named 'SPR_%s'",word);
return SPR_NULL;

View file

@ -622,9 +622,6 @@ static inline boolean LUA_LoadFile(MYFILE *f, char *name)
if (!gL) // Lua needs to be initialized
LUA_ClearState();
lua_pushinteger(gL, f->wad);
lua_setfield(gL, LUA_REGISTRYINDEX, "WAD");
lua_pushcfunction(gL, LUA_GetErrorMessage);
errorhandlerindex = lua_gettop(gL);

View file

@ -480,9 +480,6 @@ void R_AddSpriteDefs(UINT16 wadnum)
//
for (i = 0; i < numsprites; i++)
{
if (sprnames[i][4] && wadnum >= (UINT16)sprnames[i][4])
continue;
if (R_AddSingleSpriteDef(sprnames[i], &sprites[i], wadnum, start, end))
{
// if a new sprite was added (not just replaced)