From 7054b8658e45da7fdc23fe9b7e2366b64bf66620 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 8 Nov 2023 02:01:06 +0300 Subject: [PATCH] Fix sprite freeslots behaving differently from vanilla (same as for MT_ and S_) --- src/dehacked.c | 14 +++++++++++--- src/lua_script.c | 14 ++------------ src/lua_script.h | 3 +-- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index e283d80cf..b34303c20 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -642,6 +642,9 @@ static void readfreeslots(MYFILE *f) strncpy(sprnames[i],word,4); //sprnames[i][4] = 0; CONS_Printf("Sprite SPR_%s allocated.\n",word); + + LUA_InvalidateMathlibCache(va("SPR_%s", word)); + used_spr[(i-SPR_FIRSTFREESLOT)/8] |= 1<<(i%8); // Okay, this sprite slot has been named now. break; } @@ -654,7 +657,7 @@ static void readfreeslots(MYFILE *f) if (!FREE_STATES[i]) { CONS_Printf("State S_%s allocated.\n",word); - LUA_InvalidateMathlibStateCache(word); + LUA_InvalidateMathlibCache(va("S_%s", word)); FREE_STATES[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); strcpy(FREE_STATES[i],word); @@ -671,7 +674,7 @@ static void readfreeslots(MYFILE *f) if (!FREE_MOBJS[i]) { CONS_Printf("MobjType MT_%s allocated.\n",word); - LUA_InvalidateMathlibMobjCache(word); + LUA_InvalidateMathlibCache(va("MT_%s", word)); FREE_MOBJS[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); strcpy(FREE_MOBJS[i],word); @@ -9199,6 +9202,11 @@ static inline int lib_freeslot(lua_State *L) } // Found a free slot! CONS_Printf("Sprite SPR_%s allocated.\n",word); + + lua_pushcfunction(L, lua_glib_invalidate_cache); + lua_pushfstring(L, "SPR_%s", word); + lua_call(L, 1, 0); + 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. @@ -9427,7 +9435,7 @@ static int lua_enumlib_sprite_get(lua_State *L) const char *s = lua_tostring(L, 1); for (int i = 0; i < NUMSPRITES; i++) { - if (fastncmp(s+4, sprnames[i], 4)) + if (!sprnames[i][4] && fastncmp(s+4, sprnames[i], 4)) { lua_pushinteger(L, i); return 1; diff --git a/src/lua_script.c b/src/lua_script.c index 51c15062a..29901bc3d 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -405,23 +405,13 @@ fixed_t LUA_EvalMath(const char *word) return res; } -void LUA_InvalidateMathlibMobjCache(const char *name) +void LUA_InvalidateMathlibCache(const char *name) { // No state => no cache => nothing to invalidate :3 if (mL == NULL) return; lua_pushcfunction(mL, lua_glib_invalidate_cache); - lua_pushfstring(mL, "MT_%s", name); - lua_call(mL, 1, 0); -} - -void LUA_InvalidateMathlibStateCache(const char *name) -{ - // No state => no cache => nothing to invalidate :3 - if (mL == NULL) return; - - lua_pushcfunction(mL, lua_glib_invalidate_cache); - lua_pushfstring(mL, "S_%s", name); + lua_pushstring(mL, name); lua_call(mL, 1, 0); } diff --git a/src/lua_script.h b/src/lua_script.h index 82768c1d5..8ea5f3a89 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -49,8 +49,7 @@ void LUA_DumpFile(const char *filename); fixed_t LUA_EvalMath(const char *word); // Need better name for this ;-; -void LUA_InvalidateMathlibMobjCache(const char *name); -void LUA_InvalidateMathlibStateCache(const char *name); +void LUA_InvalidateMathlibCache(const char *name); void LUA_PushUserdata(lua_State *L, void *data, const char *meta); void LUA_InvalidateUserdata(void *data);