From 87b816e408fec280637957af9e08bd1f20bbceb6 Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Sat, 14 Dec 2019 15:28:24 -0600 Subject: [PATCH 01/11] Added PlayerThink hook --- src/lua_hook.h | 2 ++ src/lua_hooklib.c | 2 ++ src/p_user.c | 23 ++++++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 6617bca93..073773f52 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -51,6 +51,7 @@ enum hook { hook_PlayerCanDamage, hook_PlayerQuit, hook_IntermissionThinker, + hook_PlayerThink, hook_MAX // last hook }; @@ -93,5 +94,6 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj); // Hook for P_PlayerAft UINT8 LUAh_PlayerCanDamage(player_t *player, mobj_t *mobj); // Hook for P_PlayerCanDamage void LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting void LUAh_IntermissionThinker(void); // Hook for Y_Ticker +#define LUAh_PlayerThink(player) LUAh_PlayerHook(player, hook_PlayerThink) // Hook for P_PlayerThink #endif diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index ef87d0b6f..30ab27da1 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -62,6 +62,7 @@ const char *const hookNames[hook_MAX+1] = { "PlayerCanDamage", "PlayerQuit", "IntermissionThinker", + "PlayerThink", NULL }; @@ -205,6 +206,7 @@ static int lib_addHook(lua_State *L) case hook_PlayerCanDamage: case hook_ShieldSpawn: case hook_ShieldSpecial: + case hook_PlayerThink: lastp = &playerhooks; break; case hook_LinedefExecute: diff --git a/src/p_user.c b/src/p_user.c index ea42a2c36..6b9cde62a 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -11313,7 +11313,12 @@ void P_PlayerThink(player_t *player) player->playerstate = PST_REBORN; } if (player->playerstate == PST_REBORN) + { +#ifdef HAVE_BLUA + LUAh_PlayerThink(player); +#endif return; + } } #ifdef SEENAMES @@ -11414,7 +11419,12 @@ void P_PlayerThink(player_t *player) player->lives = 0; if (player->playerstate == PST_DEAD) + { +#ifdef HAVE_BLUA + LUAh_PlayerThink(player); return; +#endif + } } } @@ -11533,7 +11543,9 @@ void P_PlayerThink(player_t *player) { player->mo->flags2 &= ~MF2_SHADOW; P_DeathThink(player); - +#ifdef HAVE_BLUA + LUAh_PlayerThink(player); +#endif return; } @@ -11574,7 +11586,12 @@ void P_PlayerThink(player_t *player) if (player->spectator && cmd->buttons & BT_ATTACK && !player->powers[pw_flashing] && G_GametypeHasSpectators()) { if (P_SpectatorJoinGame(player)) + { +#ifdef HAVE_BLUA + LUAh_PlayerThink(player); +#endif return; // player->mo was removed. + } } // Even if not NiGHTS, pull in nearby objects when walking around as John Q. Elliot. @@ -11675,6 +11692,10 @@ void P_PlayerThink(player_t *player) P_MovePlayer(player); } +#ifdef HAVE_BLUA + LUAh_PlayerThink(player); +#endif + if (!player->mo) return; // P_MovePlayer removed player->mo. From fce6ea03842e8ad0b9d90dbe3229dcbc327e3d76 Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Sat, 14 Dec 2019 19:32:49 -0600 Subject: [PATCH 02/11] Fixed mistake with #endif placement --- src/p_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_user.c b/src/p_user.c index 22f92791a..3baf8cd04 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -11422,8 +11422,8 @@ void P_PlayerThink(player_t *player) { #ifdef HAVE_BLUA LUAh_PlayerThink(player); - return; #endif + return; } } } From fc70164f93722414057e728e5de477f75ee6f131 Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Tue, 17 Dec 2019 18:41:26 -0600 Subject: [PATCH 03/11] Don't execute LUAh_PlayerThink(player) for respawning bots --- src/p_user.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 3baf8cd04..6682c128b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -11313,12 +11313,7 @@ void P_PlayerThink(player_t *player) player->playerstate = PST_REBORN; } if (player->playerstate == PST_REBORN) - { -#ifdef HAVE_BLUA - LUAh_PlayerThink(player); -#endif return; - } } #ifdef SEENAMES From 3fc1069082fa3cc60e2b1929e0a25571007e1ad9 Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Tue, 17 Dec 2019 19:20:46 -0600 Subject: [PATCH 04/11] Don't run the LUAh_PlayerThink function if the time ran out in Race or Competition --- src/p_user.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 6682c128b..0ec02c3f4 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -11414,12 +11414,7 @@ void P_PlayerThink(player_t *player) player->lives = 0; if (player->playerstate == PST_DEAD) - { -#ifdef HAVE_BLUA - LUAh_PlayerThink(player); -#endif return; - } } } From c1815bfe11ee173264b8419e3f5745184c5e6f4d Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Thu, 19 Dec 2019 15:07:28 -0600 Subject: [PATCH 05/11] Revert "Don't execute LUAh_PlayerThink(player) for respawning bots" This reverts commit fc70164f93722414057e728e5de477f75ee6f131. --- src/p_user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/p_user.c b/src/p_user.c index 0ec02c3f4..83e28ece3 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -11313,7 +11313,12 @@ void P_PlayerThink(player_t *player) player->playerstate = PST_REBORN; } if (player->playerstate == PST_REBORN) + { +#ifdef HAVE_BLUA + LUAh_PlayerThink(player); +#endif return; + } } #ifdef SEENAMES From e82b3174519d76c4698ef1ee8162e70d4f8d14ef Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Thu, 19 Dec 2019 15:07:34 -0600 Subject: [PATCH 06/11] Revert "Don't run the LUAh_PlayerThink function if the time ran out in Race or Competition" This reverts commit 3fc1069082fa3cc60e2b1929e0a25571007e1ad9. --- src/p_user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/p_user.c b/src/p_user.c index 83e28ece3..3baf8cd04 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -11419,7 +11419,12 @@ void P_PlayerThink(player_t *player) player->lives = 0; if (player->playerstate == PST_DEAD) + { +#ifdef HAVE_BLUA + LUAh_PlayerThink(player); +#endif return; + } } } From 9f82cdb4010cd38994cfc09e5b75212085050230 Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Thu, 19 Dec 2019 16:41:25 -0600 Subject: [PATCH 07/11] Added CalculateCamera Hook --- src/lua_hook.h | 2 ++ src/lua_hooklib.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/p_user.c | 33 ++++++++++++++++++++------------- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 073773f52..4b31fda28 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -52,6 +52,7 @@ enum hook { hook_PlayerQuit, hook_IntermissionThinker, hook_PlayerThink, + hook_CalculateCamera, 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_IntermissionThinker(void); // Hook for Y_Ticker #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 diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 30ab27da1..b7e544ed0 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -63,6 +63,7 @@ const char *const hookNames[hook_MAX+1] = { "PlayerQuit", "IntermissionThinker", "PlayerThink", + "CalculateCamera", NULL }; @@ -207,6 +208,7 @@ static int lib_addHook(lua_State *L) case hook_ShieldSpawn: case hook_ShieldSpecial: case hook_PlayerThink: + case hook_CalculateCamera: lastp = &playerhooks; break; 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 diff --git a/src/p_user.c b/src/p_user.c index 3baf8cd04..6eedec10f 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -12626,22 +12626,29 @@ void P_PlayerAfterThink(player_t *player) if (thiscam) { - if (!thiscam->chase) // bob view only if looking through the player's eyes - { - P_CalcHeight(player); - P_CalcPostImg(player); - } +#ifdef HAVE_BLUA + if (LUAh_CalculateCamera(player, thiscam)) + {;} else +#endif { - // defaults to make sure 1st person cam doesn't do anything weird on startup - 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; + if (!thiscam->chase) // bob view only if looking through the player's eyes + { + P_CalcHeight(player); + P_CalcPostImg(player); + } else - player->viewz = player->mo->z + player->viewheight; - if (server || addedtogame) - P_MoveChaseCamera(player, thiscam, false); // calculate the camera movement + { + // defaults to make sure 1st person cam doesn't do anything weird on startup + 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 + } } } From c1465c5accd1844db55b86696f062879aa24f313 Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Thu, 19 Dec 2019 17:17:17 -0600 Subject: [PATCH 08/11] Fix CalculateCamera compiling error --- src/lua_hook.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lua_hook.h b/src/lua_hook.h index 4b31fda28..6bdcada24 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -14,6 +14,7 @@ #include "r_defs.h" #include "d_player.h" +#include "p_local.h" enum hook { hook_NetVars=0, From f5c2341f59a98dfc2ac9009cc3bbb69fde160005 Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Thu, 19 Dec 2019 17:21:46 -0600 Subject: [PATCH 09/11] Revert "Fix CalculateCamera compiling error" This reverts commit c1465c5accd1844db55b86696f062879aa24f313. --- src/lua_hook.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 6bdcada24..4b31fda28 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -14,7 +14,6 @@ #include "r_defs.h" #include "d_player.h" -#include "p_local.h" enum hook { hook_NetVars=0, From 124a0754a60e896cfd86546c37ac7350d2937e34 Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Thu, 19 Dec 2019 17:21:55 -0600 Subject: [PATCH 10/11] Revert "Added CalculateCamera Hook" This reverts commit 9f82cdb4010cd38994cfc09e5b75212085050230. --- src/lua_hook.h | 2 -- src/lua_hooklib.c | 41 ----------------------------------------- src/p_user.c | 35 ++++++++++++++--------------------- 3 files changed, 14 insertions(+), 64 deletions(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 4b31fda28..073773f52 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -52,7 +52,6 @@ enum hook { hook_PlayerQuit, hook_IntermissionThinker, hook_PlayerThink, - hook_CalculateCamera, hook_MAX // last hook }; @@ -96,6 +95,5 @@ 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_IntermissionThinker(void); // Hook for Y_Ticker #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 diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index b7e544ed0..30ab27da1 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -63,7 +63,6 @@ const char *const hookNames[hook_MAX+1] = { "PlayerQuit", "IntermissionThinker", "PlayerThink", - "CalculateCamera", NULL }; @@ -208,7 +207,6 @@ static int lib_addHook(lua_State *L) case hook_ShieldSpawn: case hook_ShieldSpecial: case hook_PlayerThink: - case hook_CalculateCamera: lastp = &playerhooks; break; case hook_LinedefExecute: @@ -1350,43 +1348,4 @@ 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 diff --git a/src/p_user.c b/src/p_user.c index d42b08c5f..c2834f777 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -12626,29 +12626,22 @@ void P_PlayerAfterThink(player_t *player) if (thiscam) { -#ifdef HAVE_BLUA - if (LUAh_CalculateCamera(player, thiscam)) - {;} - else -#endif + if (!thiscam->chase) // bob view only if looking through the player's eyes { - if (!thiscam->chase) // bob view only if looking through the player's eyes - { - P_CalcHeight(player); - P_CalcPostImg(player); - } + P_CalcHeight(player); + P_CalcPostImg(player); + } + else + { + // defaults to make sure 1st person cam doesn't do anything weird on startup + 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 - { - // defaults to make sure 1st person cam doesn't do anything weird on startup - 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 - } + player->viewz = player->mo->z + player->viewheight; + if (server || addedtogame) + P_MoveChaseCamera(player, thiscam, false); // calculate the camera movement } } From 745cced08e560475da66795bc119b65f4128a60a Mon Sep 17 00:00:00 2001 From: Zachary McAlpin Date: Sat, 28 Dec 2019 17:40:47 -0600 Subject: [PATCH 11/11] Execute LUAh_PlayerThink(player) at the end if the player has a valid mobj_t object --- src/p_user.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 1c9d1c051..b26615b46 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -11700,12 +11700,13 @@ void P_PlayerThink(player_t *player) P_MovePlayer(player); } -#ifdef HAVE_BLUA - LUAh_PlayerThink(player); -#endif - if (!player->mo) + { +#ifdef HAVE_BLUA + LUAh_PlayerThink(player); +#endif return; // P_MovePlayer removed player->mo. + } // deez New User eXperiences. { @@ -12137,6 +12138,11 @@ void P_PlayerThink(player_t *player) dashmode = 0; } #undef dashmode + +#ifdef HAVE_BLUA + LUAh_PlayerThink(player); +#endif + /* // Colormap verification {