]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
Fix mod_q1bsp_zero_hullsize_cutoff only applying to HLBSP in some cases
[xonotic/darkplaces.git] / cl_main.c
index d9256f16917dc859b178a7e8ce71cbd4c67ef71b..fe1840aff42db97cb43db2ec931f381da739312b 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -107,6 +107,10 @@ cvar_t cl_maxfps = {CF_CLIENT | CF_ARCHIVE, "cl_maxfps", "0", "maximum fps cap,
 cvar_t cl_maxfps_alwayssleep = {CF_CLIENT | CF_ARCHIVE, "cl_maxfps_alwayssleep","1", "gives up some processing time to other applications each frame, value in milliseconds, disabled if cl_maxfps is 0"};
 cvar_t cl_maxidlefps = {CF_CLIENT | CF_ARCHIVE, "cl_maxidlefps", "20", "maximum fps cap when the game is not the active window (makes cpu time available to other programs"};
 
+cvar_t cl_areagrid_link_SOLID_NOT = {CF_CLIENT, "cl_areagrid_link_SOLID_NOT", "1", "set to 0 to prevent SOLID_NOT entities from being linked to the area grid, and unlink any that are already linked (in the code paths that would otherwise link them), for better performance"};
+cvar_t cl_gameplayfix_nudgeoutofsolid_separation = {CF_CLIENT, "cl_gameplayfix_nudgeoutofsolid_separation", "0.03125", "keep objects this distance apart to prevent collision issues on seams"};
+
+
 client_static_t        cls;
 client_state_t cl;
 
@@ -360,11 +364,26 @@ Sends a disconnect message to the server
 This is also called on Host_Error, so it shouldn't cause any errors
 =====================
 */
-void CL_Disconnect(void)
+
+void CL_DisconnectEx(qbool kicked, const char *fmt, ... )
 {
+       va_list argptr;
+       char reason[512];
+
        if (cls.state == ca_dedicated)
                return;
 
+       if(fmt)
+       {
+               va_start(argptr,fmt);
+               dpvsnprintf(reason,sizeof(reason),fmt,argptr);
+               va_end(argptr);
+       }
+       else
+       {
+               dpsnprintf(reason, sizeof(reason), "Disconnect by user");
+       }
+
        if (Sys_CheckParm("-profilegameonly"))
                Sys_AllowProfiling(false);
 
@@ -372,11 +391,13 @@ void CL_Disconnect(void)
 
        Con_DPrintf("CL_Disconnect\n");
 
-    Cvar_SetValueQuick(&csqc_progcrc, -1);
+       Cvar_SetValueQuick(&csqc_progcrc, -1);
        Cvar_SetValueQuick(&csqc_progsize, -1);
        CL_VM_ShutDown();
-// stop sounds (especially looping!)
-       S_StopAllSounds ();
+       // stop sounds (especially looping!)
+       S_StopAllSounds();
+       // prevent dlcache assets from this server from interfering with the next one
+       FS_UnloadPacks_dlcache();
 
        cl.parsingtextexpectingpingforscores = 0; // just in case no reply has come yet
 
@@ -395,32 +416,41 @@ void CL_Disconnect(void)
        else if (cls.netcon)
        {
                sizebuf_t buf;
-               unsigned char bufdata[8];
+               unsigned char bufdata[520];
                if (cls.demorecording)
-                       CL_Stop_f(cmd_client);
+                       CL_Stop_f(cmd_local);
 
-               // send disconnect message 3 times to improve chances of server
-               // receiving it (but it still fails sometimes)
-               memset(&buf, 0, sizeof(buf));
-               buf.data = bufdata;
-               buf.maxsize = sizeof(bufdata);
-               if (cls.protocol == PROTOCOL_QUAKEWORLD)
+               if(!kicked)
                {
-                       Con_DPrint("Sending drop command\n");
-                       MSG_WriteByte(&buf, qw_clc_stringcmd);
-                       MSG_WriteString(&buf, "drop");
-               }
-               else
-               {
-                       Con_DPrint("Sending clc_disconnect\n");
-                       MSG_WriteByte(&buf, clc_disconnect);
+                       // send disconnect message 3 times to improve chances of server
+                       // receiving it (but it still fails sometimes)
+                       memset(&buf, 0, sizeof(buf));
+                       buf.data = bufdata;
+                       buf.maxsize = sizeof(bufdata);
+                       if (cls.protocol == PROTOCOL_QUAKEWORLD)
+                       {
+                               Con_DPrint("Sending drop command\n");
+                               MSG_WriteByte(&buf, qw_clc_stringcmd);
+                               MSG_WriteString(&buf, "drop");
+                       }
+                       else
+                       {
+                               Con_DPrint("Sending clc_disconnect\n");
+                               MSG_WriteByte(&buf, clc_disconnect);
+                               if(cls.protocol == PROTOCOL_DARKPLACES8)
+                                       MSG_WriteString(&buf, reason);
+                       }
+                       NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
+                       NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
+                       NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
                }
-               NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
-               NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
-               NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
+
                NetConn_Close(cls.netcon);
                cls.netcon = NULL;
-               Con_Printf("Disconnected\n");
+               if(fmt)
+                       Con_Printf("Disconnect: %s\n", reason);
+               else
+                       Con_Printf("Disconnected\n");
        }
        cls.state = ca_disconnected;
        cl.islocalgame = false;
@@ -428,8 +458,18 @@ void CL_Disconnect(void)
        cls.demoplayback = cls.timedemo = host.restless = false;
        cls.signon = 0;
 
+       Cvar_Callback(&cl_netport);
+
        // If we're dropped mid-connection attempt, it won't clear otherwise.
        SCR_ClearLoadingScreen(false);
+
+       if(host.hook.SV_Shutdown)
+               host.hook.SV_Shutdown();
+}
+
+void CL_Disconnect(void)
+{
+       CL_DisconnectEx(false, NULL);
 }
 
 /*
@@ -510,9 +550,7 @@ static void CL_Connect_f(cmd_state_t *cmd)
 
 void CL_Disconnect_f(cmd_state_t *cmd)
 {
-       CL_Disconnect ();
-       if (sv.active)
-               SV_Shutdown ();
+       Cmd_Argc(cmd) < 1 ? CL_Disconnect() : CL_DisconnectEx(false, Cmd_Argv(cmd, 1));
 }
 
 
@@ -553,8 +591,8 @@ void CL_EstablishConnection(const char *address, int firstarg)
                {
                        int i;
                        *cls.connect_userinfo = 0;
-                       for(i = firstarg; i+2 <= Cmd_Argc(cmd_client); i += 2)
-                               InfoString_SetValue(cls.connect_userinfo, sizeof(cls.connect_userinfo), Cmd_Argv(cmd_client, i), Cmd_Argv(cmd_client, i+1));
+                       for(i = firstarg; i+2 <= Cmd_Argc(cmd_local); i += 2)
+                               InfoString_SetValue(cls.connect_userinfo, sizeof(cls.connect_userinfo), Cmd_Argv(cmd_local, i), Cmd_Argv(cmd_local, i+1));
                }
                else if(firstarg < -1)
                {
@@ -566,6 +604,7 @@ void CL_EstablishConnection(const char *address, int firstarg)
 #ifdef CONFIG_MENU
                M_Update_Return_Reason("Trying to connect...");
 #endif
+               SCR_BeginLoadingPlaque(false);
        }
        else
        {
@@ -2490,11 +2529,34 @@ static void CL_MeshEntities_Restart(void)
        for (i = 0; i < NUM_MESHENTITIES; i++)
        {
                ent = cl_meshentities + i;
+               Mod_Mesh_Destroy(ent->render.model);
                Mod_Mesh_Create(ent->render.model, cl_meshentitynames[i]);
        }
 }
 
-static void CL_MeshEntities_Init(void)
+static void CL_MeshEntities_Start(void)
+{
+       int i;
+       entity_t *ent;
+       for(i = 0; i < NUM_MESHENTITIES; i++)
+       {
+               ent = cl_meshentities + i;
+               Mod_Mesh_Create(ent->render.model, cl_meshentitynames[i]);
+       }
+}
+
+static void CL_MeshEntities_Shutdown(void)
+{
+       int i;
+       entity_t *ent;
+       for(i = 0; i < NUM_MESHENTITIES; i++)
+       {
+               ent = cl_meshentities + i;
+               Mod_Mesh_Destroy(ent->render.model);
+       }
+}
+
+void CL_MeshEntities_Init(void)
 {
        int i;
        entity_t *ent;
@@ -2530,7 +2592,7 @@ static void CL_MeshEntities_Init(void)
                CL_UpdateRenderEntity(&ent->render);
        }
        cl_meshentities[MESH_UI].render.flags = RENDER_NOSELFSHADOW;
-       R_RegisterModule("cl_meshentities", CL_MeshEntities_Restart, CL_MeshEntities_Restart, CL_MeshEntities_Restart, CL_MeshEntities_Restart, CL_MeshEntities_Restart);
+       R_RegisterModule("CL_MeshEntities", CL_MeshEntities_Start, CL_MeshEntities_Shutdown, CL_MeshEntities_Restart, CL_MeshEntities_Restart, CL_MeshEntities_Restart);
 }
 
 void CL_MeshEntities_Scene_Clear(void)
@@ -2552,10 +2614,6 @@ void CL_MeshEntities_Scene_FinalizeRenderEntity(void)
        VectorCopy(ent->render.model->normalmaxs, ent->render.maxs);
 }
 
-static void CL_MeshEntities_Shutdown(void)
-{
-}
-
 extern cvar_t r_overheadsprites_pushback;
 extern cvar_t r_fullbright_directed_pitch_relative;
 extern cvar_t r_fullbright_directed_pitch;
@@ -2751,7 +2809,6 @@ double CL_Frame (double time)
        static double clframetime;
        static double cl_timer = 0;
        static double time1 = 0, time2 = 0, time3 = 0;
-       static double wait;
        int pass1, pass2, pass3;
 
        CL_VM_PreventInformationLeaks();
@@ -2761,6 +2818,11 @@ double CL_Frame (double time)
        SndSys_SendKeyEvents();
        Sys_SendKeyEvents();
 
+       /*
+        * If the accumulator hasn't become positive, don't
+        * run the frame. Everything that happens before this
+        * point will happen even if we're sleeping this frame.
+        */
        if((cl_timer += time) < 0)
                return cl_timer;
 
@@ -2794,9 +2856,8 @@ double CL_Frame (double time)
                {
                        clframetime = cl.realframetime = max(cl_timer, 1.0 / cl_maxfps.value);
                        // when running slow, we need to sleep to keep input responsive
-                       wait = bound(0, cl_maxfps_alwayssleep.value * 1000, 100000);
-                       if (wait > 0)
-                               Sys_Sleep((int)wait);
+                       if (cl_maxfps_alwayssleep.value > 0)
+                               Sys_Sleep((int)bound(0, cl_maxfps_alwayssleep.value * 1000, 100000));
                }
                else if (!vid_activewindow && cl_maxidlefps.value >= 1 && !cls.timedemo)
                        clframetime = cl.realframetime = max(cl_timer, 1.0 / cl_maxidlefps.value);
@@ -3077,15 +3138,19 @@ void CL_Init (void)
                Cvar_RegisterVariable (&cl_maxfps_alwayssleep);
                Cvar_RegisterVariable (&cl_maxidlefps);
 
+               Cvar_RegisterVariable (&cl_areagrid_link_SOLID_NOT);
+               Cvar_RegisterVariable (&cl_gameplayfix_nudgeoutofsolid_separation);
+
                CL_Parse_Init();
                CL_Particles_Init();
                CL_Screen_Init();
-               CL_MeshEntities_Init();
 
                CL_Video_Init();
 
+               Cvar_Callback(&cl_netport);
+
                host.hook.ConnectLocal = CL_EstablishConnection_Local;
-               host.hook.Disconnect = CL_Disconnect;
+               host.hook.Disconnect = CL_DisconnectEx;
                host.hook.CL_Intermission = CL_Intermission;
                host.hook.ToggleMenu = CL_ToggleMenu_Hook;
        }