Added CalculateCamera Hook

This commit is contained in:
Zachary McAlpin 2019-12-19 16:41:25 -06:00
parent e82b317451
commit 9f82cdb401
3 changed files with 63 additions and 13 deletions

View File

@ -52,6 +52,7 @@ enum hook {
hook_PlayerQuit, hook_PlayerQuit,
hook_IntermissionThinker, hook_IntermissionThinker,
hook_PlayerThink, hook_PlayerThink,
hook_CalculateCamera,
hook_MAX // last hook hook_MAX // last hook
}; };
@ -95,5 +96,6 @@ UINT8 LUAh_PlayerCanDamage(player_t *player, mobj_t *mobj); // Hook for P_Player
void LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting void LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting
void LUAh_IntermissionThinker(void); // Hook for Y_Ticker void LUAh_IntermissionThinker(void); // Hook for Y_Ticker
#define LUAh_PlayerThink(player) LUAh_PlayerHook(player, hook_PlayerThink) // Hook for P_PlayerThink #define LUAh_PlayerThink(player) LUAh_PlayerHook(player, hook_PlayerThink) // Hook for P_PlayerThink
boolean LUAh_CalculateCamera(player_t *player, camera_t *camera); // Hook for P_PlayerAfterThink Camera calculations
#endif #endif

View File

@ -63,6 +63,7 @@ const char *const hookNames[hook_MAX+1] = {
"PlayerQuit", "PlayerQuit",
"IntermissionThinker", "IntermissionThinker",
"PlayerThink", "PlayerThink",
"CalculateCamera",
NULL NULL
}; };
@ -207,6 +208,7 @@ static int lib_addHook(lua_State *L)
case hook_ShieldSpawn: case hook_ShieldSpawn:
case hook_ShieldSpecial: case hook_ShieldSpecial:
case hook_PlayerThink: case hook_PlayerThink:
case hook_CalculateCamera:
lastp = &playerhooks; lastp = &playerhooks;
break; break;
case hook_LinedefExecute: case hook_LinedefExecute:
@ -1348,4 +1350,43 @@ void LUAh_IntermissionThinker(void)
} }
} }
boolean LUAh_CalculateCamera(player_t *player, camera_t *camera)
{
hook_p hookp;
boolean hooked;
if (!gL || !(hooksAvailable[hook_CalculateCamera/8] & (1<<(hook_CalculateCamera%8))))
return 0;
lua_settop(gL, 0);
for (hookp = playerhooks; hookp; hookp = hookp->next)
{
if (hookp->type != hook_CalculateCamera)
continue;
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, player, META_PLAYER);
LUA_PushUserdata(gL, camera, META_CAMERA);
}
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
lua_gettable(gL, LUA_REGISTRYINDEX);
lua_pushvalue(gL, -3);
lua_pushvalue(gL, -3);
if (lua_pcall(gL, 2, 1, 0)) {
if (!hookp->error || cv_debug & DBG_LUA)
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
lua_pop(gL, 1);
hookp->error = true;
continue;
}
if (lua_toboolean(gL, -1))
hooked = true;
lua_pop(gL, 1);
}
lua_settop(gL, 0);
return hooked;
}
#endif #endif

View File

@ -12626,22 +12626,29 @@ void P_PlayerAfterThink(player_t *player)
if (thiscam) if (thiscam)
{ {
if (!thiscam->chase) // bob view only if looking through the player's eyes #ifdef HAVE_BLUA
{ if (LUAh_CalculateCamera(player, thiscam))
P_CalcHeight(player); {;}
P_CalcPostImg(player);
}
else else
#endif
{ {
// defaults to make sure 1st person cam doesn't do anything weird on startup if (!thiscam->chase) // bob view only if looking through the player's eyes
player->deltaviewheight = 0; {
player->viewheight = FixedMul(41*player->height/48, player->mo->scale); P_CalcHeight(player);
if (player->mo->eflags & MFE_VERTICALFLIP) P_CalcPostImg(player);
player->viewz = player->mo->z + player->mo->height - player->viewheight; }
else else
player->viewz = player->mo->z + player->viewheight; {
if (server || addedtogame) // defaults to make sure 1st person cam doesn't do anything weird on startup
P_MoveChaseCamera(player, thiscam, false); // calculate the camera movement player->deltaviewheight = 0;
player->viewheight = FixedMul(41*player->height/48, player->mo->scale);
if (player->mo->eflags & MFE_VERTICALFLIP)
player->viewz = player->mo->z + player->mo->height - player->viewheight;
else
player->viewz = player->mo->z + player->viewheight;
if (server || addedtogame)
P_MoveChaseCamera(player, thiscam, false); // calculate the camera movement
}
} }
} }