From e94e5beabfcb20d1f63aade90d154605e4e517cb Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 26 Jan 2026 17:30:09 +0100 Subject: [PATCH] lua hooklib: use NUMMOBJTYPES to detect mobj hooks removes the "force_mobj" field, gives a suprising perf boost from my timedemo testing +6-7fps (164 - 169/170fps) this does however will prevent the generic hook from being called if the mobj being passed ever should be NULL This shouldnt ever happen, vanilla assumes this aswell and way worse things would happen there, but just wanted to note --- src/lua_hooklib.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index e571f7649..ec8d38df4 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -199,7 +199,7 @@ FUNCINLINE static ATTRINLINE void add_hook(hook_t *map) FUNCINLINE static ATTRINLINE void add_mobj_hook(lua_State *L, int hook_type) { - mobjtype_t mobj_type = luaL_optnumber(L, 3, MT_NULL); + mobjtype_t mobj_type = luaL_optnumber(L, 3, MT_NULL); luaL_argcheck(L, mobj_type < NUMMOBJTYPES, 3, "invalid mobjtype_t"); @@ -296,8 +296,7 @@ struct Hook_State { INT32 status;/* return status to calling function */ void * userdata; int hook_type; - mobjtype_t mobj_type;/* >0 if mobj hook */ - boolean force_mobj;// allows mobj_type equal 0 + mobjtype_t mobj_type;/* force_mobj = false; - return init_hook_type(hook, default_status, - hook_type, 0, NULL, + hook_type, NUMMOBJTYPES, NULL, hookIds[hook_type].numHooks); } @@ -381,8 +378,6 @@ FUNCINLINE static ATTRINLINE boolean prepare_mobj_hook const mobjtype_t mobj_type = primary_mobj ? primary_mobj->type : NUMMOBJTYPES; - hook->force_mobj = true; - return init_hook_type(hook, default_status, hook_type, mobj_type, NULL, mobj_hook_available(hook_type, mobj_type)); @@ -395,10 +390,8 @@ FUNCINLINE static ATTRINLINE boolean prepare_string_hook int hook_type, const char * string ){ - hook->force_mobj = false; - if (init_hook_type(hook, default_status, - hook_type, 0, string, + hook_type, NUMMOBJTYPES, string, stringHooks[hook_type].ref)) { lua_pushstring(gL, string); @@ -414,7 +407,7 @@ FUNCINLINE static ATTRINLINE boolean prepare_hud_hook int hook_type ){ return init_hook_type(hook, 0, - hook_type, 0, NULL, + hook_type, NUMMOBJTYPES, NULL, hudHookIds[hook_type].numHooks); } @@ -554,14 +547,11 @@ static int call_hooks { calls += call_string_hooks(hook); } - else if (hook->force_mobj) + else if (hook->mobj_type < NUMMOBJTYPES) { /* call generic mobj hooks first */ calls += call_mobj_type_hooks(hook, MT_NULL); - - if (hook->mobj_type < NUMMOBJTYPES) - calls += call_mobj_type_hooks(hook, hook->mobj_type); - + calls += call_mobj_type_hooks(hook, hook->mobj_type); ps_lua_mobjhooks.value.i += calls; } else