From b4d1fade5fa6fc9ba9501388f92f0dd8394f10ad Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 5 Sep 2022 10:03:10 -0700 Subject: [PATCH] Apply b4fa98d2f to lua_hudlib.c Continued from 544812a45 --- src/lua_hook.h | 8 +- src/lua_hooklib.c | 8 +- src/lua_hud.h | 6 +- src/lua_hudlib.c | 238 +++++----------------------------------------- 4 files changed, 34 insertions(+), 226 deletions(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index fc6a5f4ee..2c69e6b03 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -1,4 +1,4 @@ -// SONIC ROBO BLAST 2 + //----------------------------------------------------------------------------- // Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2022 by Sonic Team Junior. @@ -15,6 +15,8 @@ #include "s_sound.h" #include "d_event.h" +#include "lua_hudlib_drawlist.h" + /* Do you know what an 'X Macro' is? Such a macro is called over each element of a list and expands the input. I use it for the hook lists because both an enum @@ -110,12 +112,12 @@ ENUM (STRING_HOOK); /* dead simple, LUA_HOOK(GameQuit) */ #define LUA_HOOK(type) LUA_HookVoid(HOOK(type)) -#define LUA_HUDHOOK(type) LUA_HookHUD(HUD_HOOK(type)) +//#define LUA_HUDHOOK(type) LUA_HookHUD(HUD_HOOK(type)) extern boolean hook_cmd_running; void LUA_HookVoid(int hook); -void LUA_HookHUD(int hook); +void LUA_HookHUD(huddrawlist_h, int hook); int LUA_HookMobj(mobj_t *, int hook); int LUA_Hook2Mobj(mobj_t *, mobj_t *, int hook); diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index dc5069319..b2029cc95 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -630,6 +630,7 @@ int LUA_HookTiccmd(player_t *player, ticcmd_t *cmd, int hook_type) return hook.status; } +<<<<<<< Updated upstream int LUA_HookKey(event_t *event, int hook_type) { Hook_State hook; @@ -641,7 +642,10 @@ int LUA_HookKey(event_t *event, int hook_type) return hook.status; } -void LUA_HookHUD(int hook_type) +void LUA_HookHUD(int hook_type, huddrawlist_h list) +======= +void LUA_HookHUD(huddrawlist_h list, int hook_type) +>>>>>>> Stashed changes { const hook_t * map = &hudHookIds[hook_type]; Hook_State hook; @@ -650,7 +654,7 @@ void LUA_HookHUD(int hook_type) start_hook_stack(); begin_hook_values(&hook); - LUA_SetHudHook(hook_type); + LUA_SetHudHook(hook_type, list); hud_running = true; // local hook init_hook_call(&hook, 0, res_none); diff --git a/src/lua_hud.h b/src/lua_hud.h index 35db4ef87..fc91811f0 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -47,10 +47,6 @@ extern boolean hud_running; boolean LUA_HudEnabled(enum hud option); -void LUAh_GameHUD(player_t *stplyr, huddrawlist_h list); -void LUAh_ScoresHUD(huddrawlist_h list); -void LUAh_TitleHUD(huddrawlist_h list); -void LUAh_TitleCardHUD(player_t *stplayr, huddrawlist_h list); -void LUAh_IntermissionHUD(huddrawlist_h list); +void LUA_SetHudHook(int hook, huddrawlist_h list); #endif // __LUA_HUD_H__ diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index ad6555541..c8d0d3b10 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -29,14 +29,13 @@ #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" +#include "lua_hook.h" #define HUDONLY if (!hud_running) return luaL_error(L, "HUD rendering code should not be called outside of rendering hooks!"); boolean hud_running = false; static UINT8 hud_enabled[(hud_MAX/8)+1]; -static UINT8 hudAvailable; // hud hooks field - static UINT8 camnum = 1; // must match enum hud in lua_hud.h @@ -79,21 +78,6 @@ static const char *const patch_opt[] = { "topoffset", NULL}; -enum hudhook { - hudhook_game = 0, - hudhook_scores, - hudhook_intermission, - hudhook_title, - hudhook_titlecard -}; -static const char *const hudhook_opt[] = { - "game", - "scores", - "intermission", - "title", - "titlecard", - NULL}; - // alignment types for v.drawString enum align { align_left = 0, @@ -1249,6 +1233,8 @@ static luaL_Reg lib_draw[] = { {NULL, NULL} }; +static int lib_draw_ref; + // // lib_hud // @@ -1282,28 +1268,7 @@ static int lib_hudenabled(lua_State *L) } // add a HUD element for rendering -static int lib_hudadd(lua_State *L) -{ - enum hudhook field; - - luaL_checktype(L, 1, LUA_TFUNCTION); - field = luaL_checkoption(L, 2, "game", hudhook_opt); - - if (!lua_lumploading) - return luaL_error(L, "This function cannot be called from within a hook or coroutine!"); - - lua_getfield(L, LUA_REGISTRYINDEX, "HUD"); - I_Assert(lua_istable(L, -1)); - lua_rawgeti(L, -1, field+2); // HUD[2+] - I_Assert(lua_istable(L, -1)); - lua_remove(L, -2); - - lua_pushvalue(L, 1); - lua_rawseti(L, -2, (int)(lua_objlen(L, -2) + 1)); - - hudAvailable |= 1<