No longer store wadnum in sprnames

This commit is contained in:
LJ Sonic 2024-03-14 13:56:47 +01:00 committed by NepDisk
parent dede660e89
commit 3f30e97609
4 changed files with 6 additions and 23 deletions

View file

@ -59,23 +59,14 @@ static inline int lib_freeslot(lua_State *L)
} }
else if (fastcmp(type, "SPR")) else if (fastcmp(type, "SPR"))
{ {
char wad;
spritenum_t j; 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++) for (j = SPR_FIRSTFREESLOT; j <= SPR_LASTFREESLOT; j++)
{ {
if (used_spr[(j-SPR_FIRSTFREESLOT)/8] & (1<<(j%8))) 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. continue; // Already allocated, next.
}
// Found a free slot! // Found a free slot!
CONS_Printf("Sprite SPR_%s allocated.\n",word); CONS_Printf("Sprite SPR_%s allocated.\n",word);
strncpy(sprnames[j],word,4); 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. 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 needs to update the value in _G if it exists
LUA_UpdateSprName(word, j); LUA_UpdateSprName(word, j);
@ -489,7 +480,7 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
return 1; return 1;
} }
for (i = 0; i < NUMSPRITES; i++) 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, // updating overridden sprnames is not implemented for soc parser,
// so don't use cache // so don't use cache
if (mathlib) if (mathlib)
@ -737,7 +728,7 @@ void LUA_UpdateSprName(const char *name, lua_Integer value)
if (!lua_isnil(gL, -1)) if (!lua_isnil(gL, -1))
{ {
lua_pushstring(gL, name); lua_pushstring(gL, fullname);
lua_pushinteger(gL, value); lua_pushinteger(gL, value);
lua_rawset(gL, LUA_GLOBALSINDEX); lua_rawset(gL, LUA_GLOBALSINDEX);
} }

View file

@ -430,15 +430,10 @@ void readfreeslots(MYFILE *f)
for (i = SPR_FIRSTFREESLOT; i <= SPR_LASTFREESLOT; i++) for (i = SPR_FIRSTFREESLOT; i <= SPR_LASTFREESLOT; i++)
{ {
if (used_spr[(i-SPR_FIRSTFREESLOT)/8] & (1<<(i%8))) 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. continue; // Already allocated, next.
}
// Found a free slot! // Found a free slot!
strncpy(sprnames[i],word,4);
//sprnames[i][4] = 0;
CONS_Printf("Sprite SPR_%s allocated.\n",word); CONS_Printf("Sprite SPR_%s allocated.\n",word);
strncpy(sprnames[i],word,4);
used_spr[(i-SPR_FIRSTFREESLOT)/8] |= 1<<(i%8); // Okay, this sprite slot has been named now. 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 needs to update the value in _G if it exists
LUA_UpdateSprName(word, i); LUA_UpdateSprName(word, i);
@ -4313,7 +4308,7 @@ spritenum_t get_sprite(const char *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++) 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; 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

@ -618,11 +618,11 @@ static inline void LUA_LoadFile(MYFILE *f, char *name, boolean noresults)
if (!name) if (!name)
name = wadfiles[f->wad]->filename; name = wadfiles[f->wad]->filename;
CONS_Printf("Loading Lua script from %s\n", name); CONS_Printf("Loading Lua script from %s\n", name);
if (!gL) // Lua needs to be initialized if (!gL) // Lua needs to be initialized
LUA_ClearState(); LUA_ClearState();
lua_pushinteger(gL, f->wad);
lua_setfield(gL, LUA_REGISTRYINDEX, "WAD");
lua_lumploading++; // turn on loading flag lua_lumploading++; // turn on loading flag

View file

@ -543,9 +543,6 @@ void R_AddSpriteDefs(UINT16 wadnum)
// //
for (i = 0; i < numsprites; i++) 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 (R_AddSingleSpriteDef(sprnames[i], &sprites[i], wadnum, start, end))
{ {
#ifdef HWRENDER #ifdef HWRENDER