From 5eaa2172eaf1eeba152ff4096feaffd9857d9284 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Mon, 5 Oct 2020 18:03:45 +0000 Subject: [PATCH] host: Add two hooks for disconnecting and toggling the menu git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12996 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_demo.c | 2 ++ cl_main.c | 12 ++++++++++++ host.h | 2 ++ sv_ccmds.c | 28 ++++++++-------------------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/cl_demo.c b/cl_demo.c index 186174e9..4b91f9e3 100644 --- a/cl_demo.c +++ b/cl_demo.c @@ -100,6 +100,8 @@ void CL_StopPlayback (void) if (Sys_CheckParm("-demo") || Sys_CheckParm("-capturedemo")) host.state = host_shutdown; + cls.demonum = -1; + } /* diff --git a/cl_main.c b/cl_main.c index d758cec8..17c3fee2 100644 --- a/cl_main.c +++ b/cl_main.c @@ -340,6 +340,16 @@ void CL_ExpandCSQCRenderEntities(int num) } } +static void CL_ToggleMenu_Hook(void) +{ +#ifdef CONFIG_MENU + // remove menu + if (key_dest == key_menu || key_dest == key_menu_grabbed) + MR_ToggleMenu(0); +#endif + key_dest = key_game; +} + extern cvar_t rcon_secure; /* @@ -3060,6 +3070,8 @@ void CL_Init (void) CL_Video_Init(); host.hook.ConnectLocal = CL_EstablishConnection_Local; + host.hook.Disconnect = CL_Disconnect; host.hook.CL_Intermission = CL_Intermission; + host.hook.ToggleMenu = CL_ToggleMenu_Hook; } } diff --git a/host.h b/host.h index 5b6f51d2..d4beddfd 100644 --- a/host.h +++ b/host.h @@ -29,6 +29,8 @@ typedef struct host_s struct { void (*ConnectLocal)(void); + void (*Disconnect)(void); + void (*ToggleMenu)(void); qbool (*CL_Intermission)(void); // Quake compatibility qbool (*SV_CanSave)(void); // Quake compatibility } hook; diff --git a/sv_ccmds.c b/sv_ccmds.c index 613ae309..78954aa8 100644 --- a/sv_ccmds.c +++ b/sv_ccmds.c @@ -61,9 +61,9 @@ static void SV_Map_f(cmd_state_t *cmd) if (gamemode == GAME_DELUXEQUAKE) Cvar_Set(&cvars_all, "warpmark", ""); - cls.demonum = -1; // stop demo loop in case this fails + if(host.hook.Disconnect) + host.hook.Disconnect(); - CL_Disconnect (); SV_Shutdown(); if(svs.maxclients != svs.maxclients_next) @@ -74,12 +74,8 @@ static void SV_Map_f(cmd_state_t *cmd) svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients); } -#ifdef CONFIG_MENU - // remove menu - if (key_dest == key_menu || key_dest == key_menu_grabbed) - MR_ToggleMenu(0); -#endif - key_dest = key_game; + if(host.hook.ToggleMenu) + host.hook.ToggleMenu(); svs.serverflags = 0; // haven't completed an episode yet strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level)); @@ -112,12 +108,8 @@ static void SV_Changelevel_f(cmd_state_t *cmd) return; } -#ifdef CONFIG_MENU - // remove menu - if (key_dest == key_menu || key_dest == key_menu_grabbed) - MR_ToggleMenu(0); -#endif - key_dest = key_game; + if(host.hook.ToggleMenu) + host.hook.ToggleMenu(); SV_SaveSpawnparms (); strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level)); @@ -149,12 +141,8 @@ static void SV_Restart_f(cmd_state_t *cmd) return; } -#ifdef CONFIG_MENU - // remove menu - if (key_dest == key_menu || key_dest == key_menu_grabbed) - MR_ToggleMenu(0); -#endif - key_dest = key_game; + if(host.hook.ToggleMenu) + host.hook.ToggleMenu(); strlcpy(mapname, sv.name, sizeof(mapname)); SV_SpawnServer(mapname); -- 2.39.2