]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
host: Add two hooks for disconnecting and toggling the menu
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 5 Oct 2020 18:03:45 +0000 (18:03 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 5 Oct 2020 18:03:45 +0000 (18:03 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12996 d7cf8633-e32d-0410-b094-e92efae38249

cl_demo.c
cl_main.c
host.h
sv_ccmds.c

index 186174e9b506d4dc93b4bf260c5b98d9fc6b6d20..4b91f9e3fdc6589a65c991b5c1b81d8beca63983 100644 (file)
--- 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;
+
 }
 
 /*
index d758cec83fab938b79cb1f7f504e96d1f965fcb3..17c3fee27053be28382b68427221a5feeb09ef1a 100644 (file)
--- 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 5b6f51d24950617164e963f5fd6609630513d709..d4beddfd7db806cb35783519730b787e0fa63ac5 100644 (file)
--- 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;
index 613ae309475acb20a3fbe15bf22cb0601a98c9ae..78954aa8b37e25d249c76f5eb1b059134869615a 100644 (file)
@@ -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);