]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
physics: fix and refactor unsticking
[xonotic/darkplaces.git] / cl_main.c
index fb456b06c4fedc0fbf53b34c03a9fc8d2c476c3e..b4d7760c328b40db27b44b224684aa11557fc521 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -104,9 +104,13 @@ cvar_t cl_minfps_qualityhysteresis = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_quality
 cvar_t cl_minfps_qualitystepmax = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualitystepmax", "0.1", "maximum quality change in a single frame"};
 cvar_t cl_minfps_force = {CF_CLIENT, "cl_minfps_force", "0", "also apply quality reductions in timedemo/capturevideo"};
 cvar_t cl_maxfps = {CF_CLIENT | CF_ARCHIVE, "cl_maxfps", "0", "maximum fps cap, 0 = unlimited, if game is running faster than this it will wait before running another frame (useful to make cpu time available to other programs)"};
-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_maxfps_alwayssleep = {CF_CLIENT | CF_ARCHIVE, "cl_maxfps_alwayssleep", "0", "gives up some processing time to other applications each frame, value in milliseconds, disabled if a timedemo is running"};
 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;
 
@@ -253,7 +257,7 @@ void CL_SetInfo(const char *key, const char *value, qbool send, qbool allowstark
                        MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
                        MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "setinfo \"%s\" \"%s\"", key, value));
                }
-               else if (!strcasecmp(key, "name"))
+               else if (!strcasecmp(key, "_cl_name") || !strcasecmp(key, "name"))
                {
                        MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
                        MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "name \"%s\"", value));
@@ -340,6 +344,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;
 
 /*
@@ -350,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);
 
@@ -362,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
 
@@ -385,41 +416,66 @@ 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);
+                               // DP8 TODO: write a simpler func that Sys_HandleCrash() calls
+                               // to send a disconnect message indicating we crashed
+                       }
+                       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");
+
+               // It's possible for a server to disconnect a player with an empty reason
+               // which is checked here rather than above so we don't print "Disconnect by user".
+               if(fmt && reason[0] != '\0')
+                       dpsnprintf(cl_connect_status, sizeof(cl_connect_status), "Disconnect: %s", reason);
+               else
+                       dp_strlcpy(cl_connect_status, "Disconnected", sizeof(cl_connect_status));
+               Con_Printf("%s\n", cl_connect_status);
        }
        cls.state = ca_disconnected;
        cl.islocalgame = false;
-
-       cls.demoplayback = cls.timedemo = host.restless = false;
        cls.signon = 0;
+       cls.demoplayback = cls.timedemo = host.restless = false;
+       Cvar_Callback(&vid_vsync); // might need to re-enable vsync
+
+       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);
 }
 
 /*
@@ -430,7 +486,7 @@ This command causes the client to wait for the signon messages again.
 This is sent just before a server changes levels
 ==================
 */
-void CL_Reconnect_f(cmd_state_t *cmd)
+static void CL_Reconnect_f(cmd_state_t *cmd)
 {
        char temp[128];
        // if not connected, reconnect to the most recent server
@@ -442,7 +498,7 @@ void CL_Reconnect_f(cmd_state_t *cmd)
                if (temp[0])
                        CL_EstablishConnection(temp, -1);
                else
-                       Con_Printf("Reconnect to what server?  (you have not connected to a server yet)\n");
+                       Con_Printf(CON_WARN "Reconnect to what server?  (you have not connected to a server yet)\n");
                return;
        }
        // if connected, do something based on protocol
@@ -500,9 +556,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));
 }
 
 
@@ -524,19 +578,13 @@ void CL_EstablishConnection(const char *address, int firstarg)
        if (Sys_CheckParm("-benchmark"))
                return;
 
-       // clear menu's connect error message
-#ifdef CONFIG_MENU
-       M_Update_Return_Reason("");
-#endif
-
        // make sure the client ports are open before attempting to connect
        NetConn_UpdateSockets();
 
        if (LHNETADDRESS_FromString(&cls.connect_address, address, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
        {
-               // Disconnect from the current server, or stop a running demo.
                cls.connect_trying = true;
-               cls.connect_remainingtries = 3;
+               cls.connect_remainingtries = 10;
                cls.connect_nextsendtime = 0;
 
                // only NOW, set connect_userinfo
@@ -544,8 +592,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)
                {
@@ -554,16 +602,13 @@ void CL_EstablishConnection(const char *address, int firstarg)
                        *cls.connect_userinfo = 0;
                }
 
-#ifdef CONFIG_MENU
-               M_Update_Return_Reason("Trying to connect...");
-#endif
+               dp_strlcpy(cl_connect_status, "Connect: pending...", sizeof(cl_connect_status));
+               SCR_BeginLoadingPlaque(false);
        }
        else
        {
-               Con_Print("Unable to find a suitable network socket to connect to server.\n");
-#ifdef CONFIG_MENU
-               M_Update_Return_Reason("No network");
-#endif
+               Con_Printf(CON_ERROR "Connect: failed, unable to find a network socket suitable to reach %s\n", address);
+               dp_strlcpy(cl_connect_status, "Connect: failed, no network", sizeof(cl_connect_status));
        }
 }
 
@@ -573,6 +618,11 @@ static void CL_EstablishConnection_Local(void)
                CL_EstablishConnection("local:1", -2);
 }
 
+static qbool CL_Intermission(void)
+{
+       return cl.intermission;
+}
+
 /*
 ==============
 CL_PrintEntities_f
@@ -608,7 +658,7 @@ List information on all models in the client modelindex
 static void CL_ModelIndexList_f(cmd_state_t *cmd)
 {
        int i;
-       dp_model_t *model;
+       model_t *model;
 
        // Print Header
        Con_Printf("%3s: %-30s %-8s %-8s\n", "ID", "Name", "Type", "Triangles");
@@ -655,7 +705,7 @@ void CL_UpdateRenderEntity(entity_render_t *ent)
 {
        vec3_t org;
        vec_t scale;
-       dp_model_t *model = ent->model;
+       model_t *model = ent->model;
        // update the inverse matrix for the renderer
        Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
        // update the animation blend state
@@ -765,7 +815,7 @@ entity_render_t *CL_NewTempEntity(double shadertime)
        return render;
 }
 
-void CL_Effect(vec3_t org, dp_model_t *model, int startframe, int framecount, float framerate)
+void CL_Effect(vec3_t org, model_t *model, int startframe, int framecount, float framerate)
 {
        int i;
        cl_effect_t *e;
@@ -840,7 +890,7 @@ void CL_AllocLightFlash(entity_render_t *ent, matrix4x4_t *matrix, float radius,
                dl->die = 0;
        dl->cubemapname[0] = 0;
        if (cubemapname && cubemapname[0])
-               strlcpy(dl->cubemapname, cubemapname, sizeof(dl->cubemapname));
+               dp_strlcpy(dl->cubemapname, cubemapname, sizeof(dl->cubemapname));
        dl->style = style;
        dl->shadow = shadowenable;
        dl->corona = corona;
@@ -1122,6 +1172,7 @@ static void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qbool interp
        // someone or watching a cutscene of some sort
        if (cl_nolerp.integer || cls.timedemo)
                interpolate = false;
+
        if (e == cl.entities + cl.playerentity && cl.movement_predicted && (!cl.fixangle[1] || !cl.fixangle[0]))
        {
                VectorCopy(cl.movement_origin, origin);
@@ -2040,7 +2091,7 @@ void CL_UpdateWorld(void)
                CL_UpdateViewModel();
 
                // when csqc is loaded, it will call this in CSQC_UpdateView
-               if (!cl.csqc_loaded)
+               if (!CLVM_prog->loaded || CLVM_prog->flag & PRVM_CSQC_SIMPLE)
                {
                        // clear the CL_Mesh_Scene() used for some engine effects
                        CL_MeshEntities_Scene_Clear();
@@ -2109,7 +2160,7 @@ static void CL_Fog_HeightTexture_f(cmd_state_t *cmd)
        r_refdef.fog_end = atof(Cmd_Argv(cmd, 7));
        r_refdef.fog_height = atof(Cmd_Argv(cmd, 8));
        r_refdef.fog_fadedepth = atof(Cmd_Argv(cmd, 9));
-       strlcpy(r_refdef.fog_height_texturename, Cmd_Argv(cmd, 10), sizeof(r_refdef.fog_height_texturename));
+       dp_strlcpy(r_refdef.fog_height_texturename, Cmd_Argv(cmd, 10), sizeof(r_refdef.fog_height_texturename));
 }
 
 
@@ -2174,7 +2225,7 @@ void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point)
        cl_locnode_t *loc;
        loc = CL_Locs_FindNearest(point);
        if (loc)
-               strlcpy(buffer, loc->name, buffersize);
+               dp_strlcpy(buffer, loc->name, buffersize);
        else
                dpsnprintf(buffer, buffersize, "LOC=%.0f:%.0f:%.0f", point[0], point[1], point[2]);
 }
@@ -2462,7 +2513,7 @@ void CL_Locs_Reload_f(cmd_state_t *cmd)
 }
 
 entity_t cl_meshentities[NUM_MESHENTITIES];
-dp_model_t cl_meshentitymodels[NUM_MESHENTITIES];
+model_t cl_meshentitymodels[NUM_MESHENTITIES];
 const char *cl_meshentitynames[NUM_MESHENTITIES] =
 {
        "MESH_SCENE",
@@ -2474,13 +2525,36 @@ static void CL_MeshEntities_Restart(void)
        int i;
        entity_t *ent;
        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_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_Init(void)
+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;
@@ -2516,7 +2590,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)
@@ -2538,10 +2612,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;
@@ -2714,24 +2784,38 @@ 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();
+       }
+}
+
 extern cvar_t host_framerate;
 extern cvar_t host_speeds;
-
+extern qbool serverlist_querystage;
 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;
+       float maxfps;
 
        CL_VM_PreventInformationLeaks();
 
-       // get new key events
-       Key_EventQueue_Unblock();
-       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;
 
@@ -2739,7 +2823,11 @@ double CL_Frame (double time)
        if (cl_timer > 0.1)
                cl_timer = 0.1;
 
-       if (cls.state != ca_dedicated && (cl_timer > 0 || cls.timedemo || ((vid_activewindow ? cl_maxfps : cl_maxidlefps).value < 1)))
+       // Run at full speed when querying servers, compared to waking up early to parse
+       // this is simpler and gives pings more representative of what can be expected when playing.
+       maxfps = (vid_activewindow || serverlist_querystage ? cl_maxfps : cl_maxidlefps).value;
+
+       if (cls.state != ca_dedicated && (cl_timer > 0 || cls.timedemo || maxfps <= 0))
        {
                R_TimeReport("---");
                Collision_Cache_NewFrame();
@@ -2748,7 +2836,6 @@ double CL_Frame (double time)
                // decide the simulation time
                if (cls.capturevideo.active)
                {
-                       //***
                        if (cls.capturevideo.realtime)
                                clframetime = cl.realframetime = max(time, 1.0 / cls.capturevideo.framerate);
                        else
@@ -2757,22 +2844,19 @@ double CL_Frame (double time)
                                cl.realframetime = max(time, clframetime);
                        }
                }
-               else if (vid_activewindow && cl_maxfps.value >= 1 && !cls.timedemo)
-
-#else
-               if (vid_activewindow && cl_maxfps.value >= 1 && !cls.timedemo)
+               else
 #endif
                {
-                       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 (maxfps <= 0 || cls.timedemo)
+                               clframetime = cl.realframetime = cl_timer;
+                       else
+                               // networking assumes at least 10fps
+                               clframetime = cl.realframetime = bound(cl_timer, 1 / maxfps, 0.1);
+
+                       // on some legacy systems, we need to sleep to keep input responsive
+                       if (cl_maxfps_alwayssleep.value > 0 && !cls.timedemo)
+                               Sys_Sleep(min(cl_maxfps_alwayssleep.value / 1000, 0.05));
                }
-               else if (!vid_activewindow && cl_maxidlefps.value >= 1 && !cls.timedemo)
-                       clframetime = cl.realframetime = max(cl_timer, 1.0 / cl_maxidlefps.value);
-               else
-                       clframetime = cl.realframetime = cl_timer;
 
                // apply slowmo scaling
                clframetime *= cl.movevars_timescale;
@@ -2888,7 +2972,6 @@ void CL_Shutdown (void)
                MR_Shutdown();
 #endif
 
-       CDAudio_Shutdown ();
        S_Terminate ();
        
        R_Modules_Shutdown();
@@ -2900,7 +2983,6 @@ void CL_Shutdown (void)
        CL_MeshEntities_Shutdown();
 
        Key_Shutdown();
-       S_Shutdown();
 
        Mem_FreePool (&cls.permanentmempool);
        Mem_FreePool (&cls.levelmempool);
@@ -2932,7 +3014,6 @@ void CL_Init (void)
                VID_Init();
                Render_Init();
                S_Init();
-               CDAudio_Init();
                Key_Init();
                V_Init();
 
@@ -3022,7 +3103,8 @@ void CL_Init (void)
 
                // for QW connections
                Cvar_RegisterVariable(&qport);
-               Cvar_SetValueQuick(&qport, (rand() * RAND_MAX + rand()) & 0xffff);
+               // multiplying by RAND_MAX necessary for Windows, for which RAND_MAX is only 32767.
+               Cvar_SetValueQuick(&qport, ((unsigned int)rand() * RAND_MAX + (unsigned int)rand()) & 0xffff);
 
                Cmd_AddCommand(CF_CLIENT, "timerefresh", CL_TimeRefresh_f, "turn quickly and print rendering statistcs");
 
@@ -3048,13 +3130,20 @@ 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_DisconnectEx;
+               host.hook.CL_Intermission = CL_Intermission;
+               host.hook.ToggleMenu = CL_ToggleMenu_Hook;
        }
 }