Instead of only performing a hook if the Lua Hook loop determines its type to be the one we want, actively continue through the loop if it's NOT. This optimisation was performed while preparing the following commit; I have generously split them out for less shitty commit-by-commit review.

This commit is contained in:
toaster 2019-06-19 12:28:57 +01:00
parent ef6e00e8a2
commit 28dfeb344b
1 changed files with 594 additions and 541 deletions

View File

@ -250,8 +250,10 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which)
// Look for all generic mobj hooks
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
if (hookp->type == which)
{
if (hookp->type != which)
continue;
if (lua_gettop(gL) == 0)
LUA_PushUserdata(gL, mo, META_MOBJ);
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
@ -270,8 +272,10 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which)
}
for (hookp = mobjhooks[mo->type]; hookp; hookp = hookp->next)
if (hookp->type == which)
{
if (hookp->type != which)
continue;
if (lua_gettop(gL) == 0)
LUA_PushUserdata(gL, mo, META_MOBJ);
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
@ -303,8 +307,10 @@ boolean LUAh_PlayerHook(player_t *plr, enum hook which)
lua_settop(gL, 0);
for (hookp = playerhooks; hookp; hookp = hookp->next)
if (hookp->type == which)
{
if (hookp->type != which)
continue;
if (lua_gettop(gL) == 0)
LUA_PushUserdata(gL, plr, META_PLAYER);
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
@ -337,8 +343,10 @@ void LUAh_MapChange(INT16 mapnumber)
lua_pushinteger(gL, mapnumber);
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_MapChange)
{
if (hookp->type != hook_MapChange)
continue;
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
lua_gettable(gL, LUA_REGISTRYINDEX);
lua_pushvalue(gL, -2);
@ -359,8 +367,10 @@ void LUAh_MapLoad(void)
lua_pushinteger(gL, gamemap);
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_MapLoad)
{
if (hookp->type != hook_MapLoad)
continue;
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
lua_gettable(gL, LUA_REGISTRYINDEX);
lua_pushvalue(gL, -2);
@ -381,8 +391,10 @@ void LUAh_PlayerJoin(int playernum)
lua_pushinteger(gL, playernum);
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_PlayerJoin)
{
if (hookp->type != hook_PlayerJoin)
continue;
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
lua_gettable(gL, LUA_REGISTRYINDEX);
lua_pushvalue(gL, -2);
@ -400,8 +412,10 @@ void LUAh_ThinkFrame(void)
return;
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_ThinkFrame)
{
if (hookp->type != hook_ThinkFrame)
continue;
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
lua_gettable(gL, LUA_REGISTRYINDEX);
if (lua_pcall(gL, 0, 0, 0)) {
@ -427,8 +441,10 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which)
// Look for all generic mobj collision hooks
for (hookp = mobjcollidehooks[MT_NULL]; hookp; hookp = hookp->next)
if (hookp->type == which)
{
if (hookp->type != which)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, thing1, META_MOBJ);
@ -456,8 +472,10 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which)
}
for (hookp = mobjcollidehooks[thing1->type]; hookp; hookp = hookp->next)
if (hookp->type == which)
{
if (hookp->type != which)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, thing1, META_MOBJ);
@ -557,8 +575,10 @@ boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher)
// Look for all generic touch special hooks
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
if (hookp->type == hook_TouchSpecial)
{
if (hookp->type != hook_TouchSpecial)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, special, META_MOBJ);
@ -581,8 +601,10 @@ boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher)
}
for (hookp = mobjhooks[special->type]; hookp; hookp = hookp->next)
if (hookp->type == hook_TouchSpecial)
{
if (hookp->type != hook_TouchSpecial)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, special, META_MOBJ);
@ -622,8 +644,10 @@ UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32
// Look for all generic should damage hooks
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
if (hookp->type == hook_ShouldDamage)
{
if (hookp->type != hook_ShouldDamage)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, target, META_MOBJ);
@ -655,8 +679,9 @@ UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32
}
for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next)
if (hookp->type == hook_ShouldDamage)
{
if (hookp->type != hook_ShouldDamage)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, target, META_MOBJ);
@ -707,8 +732,10 @@ boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32
// Look for all generic mobj damage hooks
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
if (hookp->type == hook_MobjDamage)
{
if (hookp->type != hook_MobjDamage)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, target, META_MOBJ);
@ -735,8 +762,10 @@ boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32
}
for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next)
if (hookp->type == hook_MobjDamage)
{
if (hookp->type != hook_MobjDamage)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, target, META_MOBJ);
@ -782,8 +811,10 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8
// Look for all generic mobj death hooks
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
if (hookp->type == hook_MobjDeath)
{
if (hookp->type != hook_MobjDeath)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, target, META_MOBJ);
@ -808,8 +839,10 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8
}
for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next)
if (hookp->type == hook_MobjDeath)
{
if (hookp->type != hook_MobjDeath)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, target, META_MOBJ);
@ -850,8 +883,10 @@ boolean LUAh_BotTiccmd(player_t *bot, ticcmd_t *cmd)
lua_settop(gL, 0);
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_BotTiccmd)
{
if (hookp->type != hook_BotTiccmd)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, bot, META_PLAYER);
@ -888,9 +923,11 @@ boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
lua_settop(gL, 0);
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_BotAI
&& (hookp->s.skinname == NULL || !strcmp(hookp->s.skinname, ((skin_t*)tails->skin)->name)))
{
if (hookp->type != hook_BotAI
|| (hookp->s.skinname && strcmp(hookp->s.skinname, ((skin_t*)tails->skin)->name)))
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, sonic, META_MOBJ);
@ -949,8 +986,10 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
lua_settop(gL, 0);
for (hookp = linedefexecutorhooks; hookp; hookp = hookp->next)
if (!strcmp(hookp->s.funcname, line->text))
{
if (strcmp(hookp->s.funcname, line->text))
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, line, META_LINE);
@ -981,8 +1020,10 @@ boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg)
lua_settop(gL, 0);
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_PlayerMsg)
{
if (hookp->type != hook_PlayerMsg)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, &players[source], META_PLAYER); // Source player
@ -1035,9 +1076,11 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8
lua_settop(gL, 0);
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_HurtMsg
&& (hookp->s.mt == MT_NULL || (inflictor && hookp->s.mt == inflictor->type)))
{
if (hookp->type != hook_HurtMsg
|| (hookp->s.mt && !(inflictor && hookp->s.mt == inflictor->type)))
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, player, META_PLAYER);
@ -1084,8 +1127,10 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc)
// stack: tables, archFunc
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_NetVars)
{
if (hookp->type != hook_NetVars)
continue;
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
lua_gettable(gL, LUA_REGISTRYINDEX);
lua_pushvalue(gL, -2); // archFunc
@ -1107,8 +1152,10 @@ boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing)
// Look for all generic mobj map thing spawn hooks
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
if (hookp->type == hook_MapThingSpawn)
{
if (hookp->type != hook_MapThingSpawn)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, mo, META_MOBJ);
@ -1131,8 +1178,10 @@ boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing)
}
for (hookp = mobjhooks[mo->type]; hookp; hookp = hookp->next)
if (hookp->type == hook_MapThingSpawn)
{
if (hookp->type != hook_MapThingSpawn)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, mo, META_MOBJ);
@ -1169,8 +1218,10 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
lua_settop(gL, 0);
for (hookp = playerhooks; hookp; hookp = hookp->next)
if (hookp->type == hook_FollowMobj)
{
if (hookp->type != hook_FollowMobj)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, player, META_PLAYER);
@ -1205,8 +1256,10 @@ void LUAh_PlayerQuit(player_t *plr, int reason)
lua_settop(gL, 0);
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_PlayerQuit)
{
if (hookp->type != hook_PlayerQuit)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit