]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
host: Move out some client and server code
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 16 Oct 2020 22:46:01 +0000 (22:46 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 16 Oct 2020 22:46:01 +0000 (22:46 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13015 d7cf8633-e32d-0410-b094-e92efae38249

14 files changed:
cd_shared.c
cl_main.c
cl_video.c
client.h
host.c
host.h
menu.c
model_shared.c
prvm_exec.c
r_modules.c
sv_main.c
sys.h
sys_shared.c
vid_shared.c

index b5b520007593171cbc6db44bff65bf0421a601de..0f2f6fd1bd513d70566d09f15f071ce4db11b7da 100644 (file)
@@ -122,7 +122,7 @@ static void CDAudio_Play_byName (const char *trackname, qbool looping, qbool try
        sfx_t* sfx;
        char filename[MAX_QPATH];
 
-       Host_StartVideo();
+       CL_StartVideo();
 
        if (!enabled)
                return;
@@ -275,7 +275,7 @@ static void CD_f(cmd_state_t *cmd)
        command = Cmd_Argv(cmd, 1);
 
        if (strcasecmp(command, "remap") != 0)
-               Host_StartVideo();
+               CL_StartVideo();
 
        if (strcasecmp(command, "on") == 0)
        {
index 17c3fee27053be28382b68427221a5feeb09ef1a..2a2b9976d204dd82cc6e41bf67c9c3e1b1e6cf50 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -2728,6 +2728,21 @@ void CL_UpdateEntityShading(void)
                CL_UpdateEntityShading_Entity(r_refdef.scene.entities[i]);
 }
 
+qbool vid_opened = false;
+void CL_StartVideo(void)
+{
+       if (!vid_opened && cls.state != ca_dedicated)
+       {
+               vid_opened = true;
+#ifdef WIN32
+               // make sure we open sockets before opening video because the Windows Firewall "unblock?" dialog can screw up the graphics context on some graphics drivers
+               NetConn_UpdateSockets();
+#endif
+               VID_Start();
+               CDAudio_Startup();
+       }
+}
+
 extern cvar_t host_framerate;
 extern cvar_t host_speeds;
 
index 7ecf3f196135d63cc268c7e41f542805642a7468..2804661b2b8c38c437ac6a51a779a27ee89b32e0 100644 (file)
@@ -577,7 +577,7 @@ void CL_DrawVideo(void)
 
 void CL_VideoStart(char *filename, const char *subtitlesfile)
 {
-       Host_StartVideo();
+       CL_StartVideo();
 
        if( cl_videos->state != CLVIDEO_UNUSED )
                CL_CloseVideo( cl_videos );
@@ -615,7 +615,7 @@ static void CL_PlayVideo_f(cmd_state_t *cmd)
        char name[MAX_QPATH], subtitlesfile[MAX_QPATH];
        const char *extension;
 
-       Host_StartVideo();
+       CL_StartVideo();
 
        if (Sys_CheckParm("-benchmark"))
                return;
index 7d185561ce88121eef5cead4426e8ec544e3ec6f..b4e8eb7a3b7df2a167045cd0b21784d5770d89ce 100644 (file)
--- a/client.h
+++ b/client.h
@@ -1214,6 +1214,8 @@ double CL_Frame(double time);
 void CL_Shutdown (void);
 void CL_Init (void);
 
+void CL_StartVideo(void);
+
 void CL_EstablishConnection(const char *host, int firstarg);
 
 void CL_Disconnect (void);
diff --git a/host.c b/host.c
index 584b38174a75ddd0b13c82900d77a42bdd4018ea..72b588eb39e3dc1e4d48c5930e3edc9a70ee2574 100644 (file)
--- a/host.c
+++ b/host.c
@@ -131,7 +131,6 @@ void Host_Error (const char *error, ...)
        PRVM_Crash(MVM_prog);
 #endif
 
-       cl.csqc_loaded = false;
        Cvar_SetValueQuick(&csqc_progcrc, -1);
        Cvar_SetValueQuick(&csqc_progsize, -1);
 
@@ -150,56 +149,6 @@ void Host_Error (const char *error, ...)
        Host_AbortCurrentFrame();
 }
 
-static void Host_ServerOptions (void)
-{
-       int i;
-
-       // general default
-       svs.maxclients = 8;
-
-// COMMANDLINEOPTION: Server: -dedicated [playerlimit] starts a dedicated server (with a command console), default playerlimit is 8
-// COMMANDLINEOPTION: Server: -listen [playerlimit] starts a multiplayer server with graphical client, like singleplayer but other players can connect, default playerlimit is 8
-       // if no client is in the executable or -dedicated is specified on
-       // commandline, start a dedicated server
-       i = Sys_CheckParm ("-dedicated");
-       if (i || !cl_available)
-       {
-               cls.state = ca_dedicated;
-               // check for -dedicated specifying how many players
-               if (i && i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1)
-                       svs.maxclients = atoi (sys.argv[i+1]);
-               if (Sys_CheckParm ("-listen"))
-                       Con_Printf ("Only one of -dedicated or -listen can be specified\n");
-               // default sv_public on for dedicated servers (often hosted by serious administrators), off for listen servers (often hosted by clueless users)
-               Cvar_SetValue(&cvars_all, "sv_public", 1);
-       }
-       else if (cl_available)
-       {
-               // client exists and not dedicated, check if -listen is specified
-               cls.state = ca_disconnected;
-               i = Sys_CheckParm ("-listen");
-               if (i)
-               {
-                       // default players unless specified
-                       if (i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1)
-                               svs.maxclients = atoi (sys.argv[i+1]);
-               }
-               else
-               {
-                       // default players in some games, singleplayer in most
-                       if (gamemode != GAME_GOODVSBAD2 && !IS_NEXUIZ_DERIVED(gamemode) && gamemode != GAME_BATTLEMECH)
-                               svs.maxclients = 1;
-               }
-       }
-
-       svs.maxclients = svs.maxclients_next = bound(1, svs.maxclients, MAX_SCOREBOARD);
-
-       svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
-
-       if (svs.maxclients > 1 && !deathmatch.integer && !coop.integer)
-               Cvar_SetValueQuick(&deathmatch, 1);
-}
-
 /*
 ==================
 Host_Quit_f
@@ -522,21 +471,6 @@ void Host_Main(void)
 
 //============================================================================
 
-qbool vid_opened = false;
-void Host_StartVideo(void)
-{
-       if (!vid_opened && cls.state != ca_dedicated)
-       {
-               vid_opened = true;
-#ifdef WIN32
-               // make sure we open sockets before opening video because the Windows Firewall "unblock?" dialog can screw up the graphics context on some graphics drivers
-               NetConn_UpdateSockets();
-#endif
-               VID_Start();
-               CDAudio_Startup();
-       }
-}
-
 char engineversion[128];
 
 qbool sys_nostdout = false;
@@ -713,7 +647,6 @@ static void Host_Init (void)
        World_Init();
        SV_Init();
        Host_InitLocal();
-       Host_ServerOptions();
 
        Thread_Init();
        TaskQueue_Init();
@@ -740,7 +673,7 @@ static void Host_Init (void)
 
        host.state = host_active;
 
-       Host_StartVideo();
+       CL_StartVideo();
 
        Log_Start();
 
diff --git a/host.h b/host.h
index d4beddfd7db806cb35783519730b787e0fa63ac5..9def0939602ac3062f76b1f564acb33a9d6df8c5 100644 (file)
--- a/host.h
+++ b/host.h
@@ -42,7 +42,6 @@ void Host_InitCommands(void);
 void Host_Main(void);
 double Host_Frame(double time);
 void Host_Shutdown(void);
-void Host_StartVideo(void);
 void Host_Error(const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN;
 void Host_LockSession(void);
 void Host_UnlockSession(void);
diff --git a/menu.c b/menu.c
index 8dd7693440103fa8333cea295a4d1fb8a5b3633b..95202cacc0d2282f035f1c34fcd7ff0075035c74 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -5470,7 +5470,7 @@ static void Call_MR_ToggleMenu_f(cmd_state_t *cmd)
 {
        int m;
        m = ((Cmd_Argc(cmd) < 2) ? -1 : atoi(Cmd_Argv(cmd, 1)));
-       Host_StartVideo();
+       CL_StartVideo();
        if(MR_ToggleMenu)
                MR_ToggleMenu(m);
 }
index 9a269a62a0e36d624846a09987ae90f9d959a9d7..5c69dd23e1d1d575e74f693eecaf7f425f89b46a 100644 (file)
@@ -641,7 +641,7 @@ model_t *Mod_ForName(const char *name, qbool crash, qbool checkdisk, const char
 
        // FIXME: So we don't crash if a server is started early.
        if(!vid_opened)
-               Host_StartVideo();
+               CL_StartVideo();
 
        model = Mod_FindName(name, parentname);
        if (!model->loaded || checkdisk)
index eb4217d8e63dbf5ed526f2e6f70beee87f602c64..fd0ff40b9f5fe802adea919a93cc0e288c68a419 100644 (file)
@@ -715,6 +715,9 @@ extern cvar_t prvm_errordump;
 void PRVM_Crash(prvm_prog_t *prog)
 {
        char vabuf[1024];
+
+       cl.csqc_loaded = false;
+
        if (prog == NULL)
                return;
        if (!prog->loaded)
index 4c5f930868db1476c39cd67e36aa2a1a4f206ecf..904977146ece0e69771e7ebe2cb1a1838c4b5650 100644 (file)
@@ -80,7 +80,7 @@ void R_Modules_Shutdown(void)
 
 void R_Modules_Restart_f(cmd_state_t *cmd)
 {
-       Host_StartVideo();
+       CL_StartVideo();
        Con_Print("restarting renderer\n");
        R_Modules_Shutdown();
        R_Modules_Start();
index a5fc047f587421c3fe72a582042a09a9f4f1ed33..5b5b22ce42b3cb63dca508892a85e27a89479079 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -456,6 +456,56 @@ static qbool SV_CanSave(void)
        
 }
 
+static void SV_ServerOptions (void)
+{
+       int i;
+
+       // general default
+       svs.maxclients = 8;
+
+// COMMANDLINEOPTION: Server: -dedicated [playerlimit] starts a dedicated server (with a command console), default playerlimit is 8
+// COMMANDLINEOPTION: Server: -listen [playerlimit] starts a multiplayer server with graphical client, like singleplayer but other players can connect, default playerlimit is 8
+       // if no client is in the executable or -dedicated is specified on
+       // commandline, start a dedicated server
+       i = Sys_CheckParm ("-dedicated");
+       if (i || !cl_available)
+       {
+               cls.state = ca_dedicated;
+               // check for -dedicated specifying how many players
+               if (i && i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1)
+                       svs.maxclients = atoi (sys.argv[i+1]);
+               if (Sys_CheckParm ("-listen"))
+                       Con_Printf ("Only one of -dedicated or -listen can be specified\n");
+               // default sv_public on for dedicated servers (often hosted by serious administrators), off for listen servers (often hosted by clueless users)
+               Cvar_SetValue(&cvars_all, "sv_public", 1);
+       }
+       else if (cl_available)
+       {
+               // client exists and not dedicated, check if -listen is specified
+               cls.state = ca_disconnected;
+               i = Sys_CheckParm ("-listen");
+               if (i)
+               {
+                       // default players unless specified
+                       if (i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1)
+                               svs.maxclients = atoi (sys.argv[i+1]);
+               }
+               else
+               {
+                       // default players in some games, singleplayer in most
+                       if (gamemode != GAME_GOODVSBAD2 && !IS_NEXUIZ_DERIVED(gamemode) && gamemode != GAME_BATTLEMECH)
+                               svs.maxclients = 1;
+               }
+       }
+
+       svs.maxclients = svs.maxclients_next = bound(1, svs.maxclients, MAX_SCOREBOARD);
+
+       svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
+
+       if (svs.maxclients > 1 && !deathmatch.integer && !coop.integer)
+               Cvar_SetValueQuick(&deathmatch, 1);
+}
+
 /*
 ===============
 SV_Init
@@ -655,6 +705,7 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_mapformat_is_quake2);
        Cvar_RegisterVariable (&sv_mapformat_is_quake3);
 
+       SV_ServerOptions();
        SV_InitOperatorCommands();
        host.hook.SV_CanSave = SV_CanSave;
 
diff --git a/sys.h b/sys.h
index 0852662d582c70ad9a9b28c4c2684bb78c9f50d7..df7e81ae25c288e723027ae64b05dff9f9d462c8 100644 (file)
--- a/sys.h
+++ b/sys.h
@@ -171,6 +171,8 @@ typedef struct dllfunction_s
 }
 dllfunction_t;
 
+qbool Sys_LoadSelf(dllhandle_t *handle);
+
 /*! Loads a library. 
  * \param dllnames a NULL terminated array of possible names for the DLL you want to load.
  * \param handle
index 39c50682347a206ecec75b00e1a42c1a29b57fa6..2149dff6c71e8c0a3f1f81e1b307f3861c0d6bc4 100644 (file)
@@ -116,6 +116,21 @@ static qbool Sys_LoadLibraryFunctions(dllhandle_t dllhandle, const dllfunction_t
        return false;
 }
 
+qbool Sys_LoadSelf(dllhandle_t *handle)
+{
+       dllhandle_t dllhandle = 0;
+
+       if (handle == NULL)
+               return false;
+#ifdef WIN32
+       dllhandle = LoadLibrary (NULL);
+#else
+       dllhandle = dlopen (NULL, RTLD_NOW | RTLD_GLOBAL);
+#endif
+       *handle = dllhandle;
+       return true;
+}
+
 qbool Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
 {
 #ifdef SUPPORTDLL
index f2813eccbd563eae6591dc88a8dcbe90b3910171..df8662d5afdcbd969fe9d806d9b604c30e62108e 100644 (file)
@@ -1501,7 +1501,7 @@ const char *vidfallbacks[][2] =
        {NULL, NULL}
 };
 
-// this is only called once by Host_StartVideo and again on each FS_GameDir_f
+// this is only called once by CL_StartVideo and again on each FS_GameDir_f
 void VID_Start(void)
 {
        int i = 0;