From c6fc75c379a0596791c06b314fe098ffd263d4e4 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jul 2026 19:21:32 +0200 Subject: [PATCH] print performance warning for lua scripts using mobj hooks without specific mobjtype thx indev for help <3 these may trash performance quite hard at times and are not visible from just perfstats most of the time --- src/lua_hooklib.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index bed23cf36..76bfa6479 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -574,10 +574,48 @@ static int call_string_hooks(Hook_State *hook) return calls; } +FUNCINLINE static ATTRINLINE int call_mobj_type_hooks(Hook_State *hook, mobjtype_t mobj_type) +{ + static UINT8 seen = 0; // so we dont have to check all this shit constantly + int numCalls = call_mapped(hook, &mobjHookIds[mobj_type][hook->hook_type]); + + if (!seen && numCalls > 0 && mobj_type == MT_NULL && ( + hook->hook_type == MOBJ_HOOK(MobjThinker ) + || hook->hook_type == MOBJ_HOOK(MobjCollide ) + || hook->hook_type == MOBJ_HOOK(MobjMoveCollide) + || hook->hook_type == MOBJ_HOOK(MobjFuse ) + || hook->hook_type == MOBJ_HOOK(MobjThinker ) + || hook->hook_type == MOBJ_HOOK(BossThinker ) + )) + { + seen = 1; + CONS_Alert( + CONS_WARNING, "%s\n", va( + "%s hooks not attached to a specific mobj type may cause performance issues!", + mobjHookNames[hook->hook_type]) + ); + + // print which script triggered it, ty indev <3 + for (int k = 0; k < mobjHookIds[mobj_type][hook->hook_type].numHooks; ++k) + { + lua_getref(gL, hookRefs[mobjHookIds[mobj_type][hook->hook_type].ids[k].id]); + + lua_Debug ar; + lua_getinfo(gL, ">S", &ar); + + CONS_Printf("%s:%d\n", ar.short_src, ar.linedefined); + } + } + + return numCalls; +} + +/* FUNCINLINE static ATTRINLINE int call_mobj_type_hooks(Hook_State *hook, mobjtype_t mobj_type) { return call_mapped(hook, &mobjHookIds[mobj_type][hook->hook_type]); } +*/ static int call_hooks (