X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=cl_main.c;h=619a9e6bc9733a715f9332646f750bdc7f8f9b14;hp=1f079bb7b5fd1621abcf534a2b6d6511940e9afa;hb=HEAD;hpb=d1c3f1065fde02ed39b7eecc2d9b9a637388d091 diff --git a/cl_main.c b/cl_main.c index 1f079bb7..71443f14 100644 --- a/cl_main.c +++ b/cl_main.c @@ -32,68 +32,86 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // we need to declare some mouse variables here, because the menu system // references them even when on a unix system. -cvar_t csqc_progname = {CVAR_CLIENT | CVAR_SERVER, "csqc_progname","csprogs.dat","name of csprogs.dat file to load"}; -cvar_t csqc_progcrc = {CVAR_CLIENT | CVAR_READONLY, "csqc_progcrc","-1","CRC of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"}; -cvar_t csqc_progsize = {CVAR_CLIENT | CVAR_READONLY, "csqc_progsize","-1","file size of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"}; -cvar_t csqc_usedemoprogs = {CVAR_CLIENT, "csqc_usedemoprogs","1","use csprogs stored in demos"}; -cvar_t csqc_polygons_defaultmaterial_nocullface = {CVAR_CLIENT, "csqc_polygons_defaultmaterial_nocullface", "0", "use 'cull none' behavior in the default shader for rendering R_PolygonBegin - warning: enabling this is not consistent with FTEQW behavior on this feature"}; +cvar_t csqc_progname = {CF_CLIENT | CF_SERVER, "csqc_progname","csprogs.dat","name of csprogs.dat file to load"}; +cvar_t csqc_progcrc = {CF_CLIENT | CF_READONLY, "csqc_progcrc","-1","CRC of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"}; +cvar_t csqc_progsize = {CF_CLIENT | CF_READONLY, "csqc_progsize","-1","file size of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"}; +cvar_t csqc_usedemoprogs = {CF_CLIENT, "csqc_usedemoprogs","1","use csprogs stored in demos"}; +cvar_t csqc_polygons_defaultmaterial_nocullface = {CF_CLIENT, "csqc_polygons_defaultmaterial_nocullface", "0", "use 'cull none' behavior in the default shader for rendering R_PolygonBegin - warning: enabling this is not consistent with FTEQW behavior on this feature"}; +cvar_t csqc_lowres = {CF_CLIENT, "csqc_lowres", "0", "make EXT_CSQC functions CSQC_UpdateView(), setproperty(), getproperty() use the virtual 2D resolution (FTEQW/QSS behaviour) instead of the real resolution (DP behaviour); this mode is always used for the CSQC_SIMPLE (aka hud-only) CSQC_DrawHud() parameters; see cvars vid_conheight and vid_conwidth"}; -cvar_t cl_shownet = {CVAR_CLIENT, "cl_shownet","0","1 = print packet size, 2 = print packet message list"}; -cvar_t cl_nolerp = {CVAR_CLIENT, "cl_nolerp", "0","network update smoothing"}; -cvar_t cl_lerpexcess = {CVAR_CLIENT, "cl_lerpexcess", "0","maximum allowed lerp excess (hides, not fixes, some packet loss)"}; -cvar_t cl_lerpanim_maxdelta_server = {CVAR_CLIENT, "cl_lerpanim_maxdelta_server", "0.1","maximum frame delta for smoothing between server-controlled animation frames (when 0, one network frame)"}; -cvar_t cl_lerpanim_maxdelta_framegroups = {CVAR_CLIENT, "cl_lerpanim_maxdelta_framegroups", "0.1","maximum frame delta for smoothing between framegroups (when 0, one network frame)"}; +cvar_t cl_shownet = {CF_CLIENT, "cl_shownet","0","1 = print packet size, 2 = print packet message list"}; +cvar_t cl_nolerp = {CF_CLIENT, "cl_nolerp", "0","network update smoothing"}; +cvar_t cl_lerpexcess = {CF_CLIENT, "cl_lerpexcess", "0","maximum allowed lerp excess (hides, not fixes, some packet loss)"}; +cvar_t cl_lerpanim_maxdelta_server = {CF_CLIENT, "cl_lerpanim_maxdelta_server", "0.1","maximum frame delta for smoothing between server-controlled animation frames (when 0, one network frame)"}; +cvar_t cl_lerpanim_maxdelta_framegroups = {CF_CLIENT, "cl_lerpanim_maxdelta_framegroups", "0.1","maximum frame delta for smoothing between framegroups (when 0, one network frame)"}; -cvar_t cl_itembobheight = {CVAR_CLIENT, "cl_itembobheight", "0","how much items bob up and down (try 8)"}; -cvar_t cl_itembobspeed = {CVAR_CLIENT, "cl_itembobspeed", "0.5","how frequently items bob up and down"}; +cvar_t cl_itembobheight = {CF_CLIENT, "cl_itembobheight", "0","how much items bob up and down (try 8)"}; +cvar_t cl_itembobspeed = {CF_CLIENT, "cl_itembobspeed", "0.5","how frequently items bob up and down"}; -cvar_t lookspring = {CVAR_CLIENT | CVAR_SAVE, "lookspring","0","returns pitch to level with the floor when no longer holding a pitch key"}; -cvar_t lookstrafe = {CVAR_CLIENT | CVAR_SAVE, "lookstrafe","0","move instead of turning"}; -cvar_t sensitivity = {CVAR_CLIENT | CVAR_SAVE, "sensitivity","3","mouse speed multiplier"}; +cvar_t lookspring = {CF_CLIENT | CF_ARCHIVE, "lookspring","0","returns pitch to level with the floor when no longer holding a pitch key"}; +cvar_t lookstrafe = {CF_CLIENT | CF_ARCHIVE, "lookstrafe","0","move instead of turning"}; +cvar_t sensitivity = {CF_CLIENT | CF_ARCHIVE, "sensitivity","3","mouse speed multiplier"}; -cvar_t m_pitch = {CVAR_CLIENT | CVAR_SAVE, "m_pitch","0.022","mouse pitch speed multiplier"}; -cvar_t m_yaw = {CVAR_CLIENT | CVAR_SAVE, "m_yaw","0.022","mouse yaw speed multiplier"}; -cvar_t m_forward = {CVAR_CLIENT | CVAR_SAVE, "m_forward","1","mouse forward speed multiplier"}; -cvar_t m_side = {CVAR_CLIENT | CVAR_SAVE, "m_side","0.8","mouse side speed multiplier"}; +cvar_t m_pitch = {CF_CLIENT | CF_ARCHIVE, "m_pitch","0.022","mouse pitch speed multiplier"}; +cvar_t m_yaw = {CF_CLIENT | CF_ARCHIVE, "m_yaw","0.022","mouse yaw speed multiplier"}; +cvar_t m_forward = {CF_CLIENT | CF_ARCHIVE, "m_forward","1","mouse forward speed multiplier"}; +cvar_t m_side = {CF_CLIENT | CF_ARCHIVE, "m_side","0.8","mouse side speed multiplier"}; -cvar_t freelook = {CVAR_CLIENT | CVAR_SAVE, "freelook", "1","mouse controls pitch instead of forward/back"}; +cvar_t freelook = {CF_CLIENT | CF_ARCHIVE, "freelook", "1","mouse controls pitch instead of forward/back"}; -cvar_t cl_autodemo = {CVAR_CLIENT | CVAR_SAVE, "cl_autodemo", "0", "records every game played, using the date/time and map name to name the demo file" }; -cvar_t cl_autodemo_nameformat = {CVAR_CLIENT | CVAR_SAVE, "cl_autodemo_nameformat", "autodemos/%Y-%m-%d_%H-%M", "The format of the cl_autodemo filename, followed by the map name (the date is encoded using strftime escapes)" }; -cvar_t cl_autodemo_delete = {CVAR_CLIENT, "cl_autodemo_delete", "0", "Delete demos after recording. This is a bitmask, bit 1 gives the default, bit 0 the value for the current demo. Thus, the values are: 0 = disabled; 1 = delete current demo only; 2 = delete all demos except the current demo; 3 = delete all demos from now on" }; +cvar_t cl_autodemo = {CF_CLIENT | CF_ARCHIVE, "cl_autodemo", "0", "records every game played, using the date/time and map name to name the demo file" }; +cvar_t cl_autodemo_nameformat = {CF_CLIENT | CF_ARCHIVE, "cl_autodemo_nameformat", "autodemos/%Y-%m-%d_%H-%M", "The format of the cl_autodemo filename, followed by the map name (the date is encoded using strftime escapes)" }; +cvar_t cl_autodemo_delete = {CF_CLIENT, "cl_autodemo_delete", "0", "Delete demos after recording. This is a bitmask, bit 1 gives the default, bit 0 the value for the current demo. Thus, the values are: 0 = disabled; 1 = delete current demo only; 2 = delete all demos except the current demo; 3 = delete all demos from now on" }; +cvar_t cl_startdemos = {CF_CLIENT | CF_ARCHIVE, "cl_startdemos", "1", "1 enables the `startdemos` loop used in Quake and some mods, 0 goes straight to the menu"}; -cvar_t r_draweffects = {CVAR_CLIENT, "r_draweffects", "1","renders temporary sprite effects"}; +cvar_t r_draweffects = {CF_CLIENT, "r_draweffects", "1","renders temporary sprite effects"}; -cvar_t cl_explosions_alpha_start = {CVAR_CLIENT | CVAR_SAVE, "cl_explosions_alpha_start", "1.5","starting alpha of an explosion shell"}; -cvar_t cl_explosions_alpha_end = {CVAR_CLIENT | CVAR_SAVE, "cl_explosions_alpha_end", "0","end alpha of an explosion shell (just before it disappears)"}; -cvar_t cl_explosions_size_start = {CVAR_CLIENT | CVAR_SAVE, "cl_explosions_size_start", "16","starting size of an explosion shell"}; -cvar_t cl_explosions_size_end = {CVAR_CLIENT | CVAR_SAVE, "cl_explosions_size_end", "128","ending alpha of an explosion shell (just before it disappears)"}; -cvar_t cl_explosions_lifetime = {CVAR_CLIENT | CVAR_SAVE, "cl_explosions_lifetime", "0.5","how long an explosion shell lasts"}; +cvar_t cl_explosions_alpha_start = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_alpha_start", "1.5","starting alpha of an explosion shell"}; +cvar_t cl_explosions_alpha_end = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_alpha_end", "0","end alpha of an explosion shell (just before it disappears)"}; +cvar_t cl_explosions_size_start = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_size_start", "16","starting size of an explosion shell"}; +cvar_t cl_explosions_size_end = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_size_end", "128","ending alpha of an explosion shell (just before it disappears)"}; +cvar_t cl_explosions_lifetime = {CF_CLIENT | CF_ARCHIVE, "cl_explosions_lifetime", "0.5","how long an explosion shell lasts"}; -cvar_t cl_stainmaps = {CVAR_CLIENT | CVAR_SAVE, "cl_stainmaps", "0","stains lightmaps, much faster than decals but blurred"}; -cvar_t cl_stainmaps_clearonload = {CVAR_CLIENT | CVAR_SAVE, "cl_stainmaps_clearonload", "1","clear stainmaps on map restart"}; +cvar_t cl_stainmaps = {CF_CLIENT | CF_ARCHIVE, "cl_stainmaps", "0","stains lightmaps, much faster than decals but blurred"}; +cvar_t cl_stainmaps_clearonload = {CF_CLIENT | CF_ARCHIVE, "cl_stainmaps_clearonload", "1","clear stainmaps on map restart"}; -cvar_t cl_beams_polygons = {CVAR_CLIENT | CVAR_SAVE, "cl_beams_polygons", "1","use beam polygons instead of models"}; -cvar_t cl_beams_quakepositionhack = {CVAR_CLIENT | CVAR_SAVE, "cl_beams_quakepositionhack", "1", "makes your lightning gun appear to fire from your waist (as in Quake and QuakeWorld)"}; -cvar_t cl_beams_instantaimhack = {CVAR_CLIENT | CVAR_SAVE, "cl_beams_instantaimhack", "0", "makes your lightning gun aiming update instantly"}; -cvar_t cl_beams_lightatend = {CVAR_CLIENT | CVAR_SAVE, "cl_beams_lightatend", "0", "make a light at the end of the beam"}; +cvar_t cl_beams_polygons = {CF_CLIENT | CF_ARCHIVE, "cl_beams_polygons", "1","use beam polygons instead of models"}; +cvar_t cl_beams_quakepositionhack = {CF_CLIENT | CF_ARCHIVE, "cl_beams_quakepositionhack", "1", "makes your lightning gun appear to fire from your waist (as in Quake and QuakeWorld)"}; +cvar_t cl_beams_instantaimhack = {CF_CLIENT | CF_ARCHIVE, "cl_beams_instantaimhack", "0", "makes your lightning gun aiming update instantly"}; +cvar_t cl_beams_lightatend = {CF_CLIENT | CF_ARCHIVE, "cl_beams_lightatend", "0", "make a light at the end of the beam"}; -cvar_t cl_deathfade = {CVAR_CLIENT | CVAR_SAVE, "cl_deathfade", "0", "fade screen to dark red when dead, value represents how fast the fade is (higher is faster)"}; +cvar_t cl_deathfade = {CF_CLIENT | CF_ARCHIVE, "cl_deathfade", "0", "fade screen to dark red when dead, value represents how fast the fade is (higher is faster)"}; -cvar_t cl_noplayershadow = {CVAR_CLIENT | CVAR_SAVE, "cl_noplayershadow", "0","hide player shadow"}; +cvar_t cl_noplayershadow = {CF_CLIENT | CF_ARCHIVE, "cl_noplayershadow", "0","hide player shadow"}; -cvar_t cl_dlights_decayradius = {CVAR_CLIENT | CVAR_SAVE, "cl_dlights_decayradius", "1", "reduces size of light flashes over time"}; -cvar_t cl_dlights_decaybrightness = {CVAR_CLIENT | CVAR_SAVE, "cl_dlights_decaybrightness", "1", "reduces brightness of light flashes over time"}; +cvar_t cl_dlights_decayradius = {CF_CLIENT | CF_ARCHIVE, "cl_dlights_decayradius", "1", "reduces size of light flashes over time"}; +cvar_t cl_dlights_decaybrightness = {CF_CLIENT | CF_ARCHIVE, "cl_dlights_decaybrightness", "1", "reduces brightness of light flashes over time"}; -cvar_t qport = {CVAR_CLIENT, "qport", "0", "identification key for playing on qw servers (allows you to maintain a connection to a quakeworld server even if your port changes)"}; +cvar_t qport = {CF_CLIENT, "qport", "0", "identification key for playing on qw servers (allows you to maintain a connection to a quakeworld server even if your port changes)"}; -cvar_t cl_prydoncursor = {CVAR_CLIENT, "cl_prydoncursor", "0", "enables a mouse pointer which is able to click on entities in the world, useful for point and click mods, see PRYDON_CLIENTCURSOR extension in dpextensions.qc"}; -cvar_t cl_prydoncursor_notrace = {CVAR_CLIENT, "cl_prydoncursor_notrace", "0", "disables traceline used in prydon cursor reporting to the game, saving some cpu time"}; +cvar_t cl_prydoncursor = {CF_CLIENT, "cl_prydoncursor", "0", "enables a mouse pointer which is able to click on entities in the world, useful for point and click mods, see PRYDON_CLIENTCURSOR extension in dpextensions.qc"}; +cvar_t cl_prydoncursor_notrace = {CF_CLIENT, "cl_prydoncursor_notrace", "0", "disables traceline used in prydon cursor reporting to the game, saving some cpu time"}; -cvar_t cl_deathnoviewmodel = {CVAR_CLIENT, "cl_deathnoviewmodel", "1", "hides gun model when dead"}; +cvar_t cl_deathnoviewmodel = {CF_CLIENT, "cl_deathnoviewmodel", "1", "hides gun model when dead"}; + +cvar_t cl_locs_enable = {CF_CLIENT | CF_ARCHIVE, "locs_enable", "1", "enables replacement of certain % codes in chat messages: %l (location), %d (last death location), %h (health), %a (armor), %x (rockets), %c (cells), %r (rocket launcher status), %p (powerup status), %w (weapon status), %t (current time in level)"}; +cvar_t cl_locs_show = {CF_CLIENT, "locs_show", "0", "shows defined locations for editing purposes"}; + +cvar_t cl_minfps = {CF_CLIENT | CF_ARCHIVE, "cl_minfps", "40", "minimum fps target - while the rendering performance is below this, it will drift toward lower quality"}; +cvar_t cl_minfps_fade = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_fade", "1", "how fast the quality adapts to varying framerate"}; +cvar_t cl_minfps_qualitymax = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualitymax", "1", "highest allowed drawdistance multiplier"}; +cvar_t cl_minfps_qualitymin = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualitymin", "0.25", "lowest allowed drawdistance multiplier"}; +cvar_t cl_minfps_qualitymultiply = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualitymultiply", "0.2", "multiplier for quality changes in quality change per second render time (1 assumes linearity of quality and render time)"}; +cvar_t cl_minfps_qualityhysteresis = {CF_CLIENT | CF_ARCHIVE, "cl_minfps_qualityhysteresis", "0.05", "reduce all quality increments by this to reduce flickering"}; +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", "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"}; -cvar_t cl_locs_enable = {CVAR_CLIENT | CVAR_SAVE, "locs_enable", "1", "enables replacement of certain % codes in chat messages: %l (location), %d (last death location), %h (health), %a (armor), %x (rockets), %c (cells), %r (rocket launcher status), %p (powerup status), %w (weapon status), %t (current time in level)"}; -cvar_t cl_locs_show = {CVAR_CLIENT, "locs_show", "0", "shows defined locations for editing purposes"}; client_static_t cls; client_state_t cl; @@ -135,7 +153,7 @@ void CL_ClearState(void) // tweak these if the game runs out cl.max_csqcrenderentities = 0; - cl.max_entities = MAX_ENITIES_INITIAL; + cl.max_entities = MAX_ENTITIES_INITIAL; cl.max_static_entities = MAX_STATICENTITIES; cl.max_effects = MAX_EFFECTS; cl.max_beams = MAX_BEAMS; @@ -209,13 +227,13 @@ void CL_ClearState(void) CL_Screen_NewMap(); } -extern cvar_t topcolor; -extern cvar_t bottomcolor; +extern cvar_t cl_topcolor; +extern cvar_t cl_bottomcolor; -void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allowstarkey, qboolean allowmodel, qboolean quiet) +void CL_SetInfo(const char *key, const char *value, qbool send, qbool allowstarkey, qbool allowmodel, qbool quiet) { int i; - qboolean fail = false; + qbool fail = false; char vabuf[1024]; if (!allowstarkey && key[0] == '*') fail = true; @@ -241,7 +259,7 @@ void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allo 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)); @@ -259,12 +277,12 @@ void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allo else if (!strcasecmp(key, "topcolor")) { MSG_WriteByte(&cls.netcon->message, clc_stringcmd); - MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "color %i %i", atoi(value), bottomcolor.integer)); + MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "color %i %i", atoi(value), cl_bottomcolor.integer)); } else if (!strcasecmp(key, "bottomcolor")) { MSG_WriteByte(&cls.netcon->message, clc_stringcmd); - MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "color %i %i", topcolor.integer, atoi(value))); + MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "color %i %i", cl_topcolor.integer, atoi(value))); } else if (!strcasecmp(key, "rate")) { @@ -328,6 +346,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; /* @@ -338,23 +366,40 @@ 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 (COM_CheckParm("-profilegameonly")) + 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); Curl_Clear_forthismap(); 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 @@ -373,41 +418,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 = 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); } /* @@ -418,7 +488,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 @@ -430,7 +500,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 @@ -488,9 +558,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)); } @@ -503,30 +571,22 @@ CL_EstablishConnection Host should be either "local" or a net address ===================== */ -void CL_EstablishConnection(const char *host, int firstarg) +void CL_EstablishConnection(const char *address, int firstarg) { if (cls.state == ca_dedicated) return; // don't connect to a server if we're benchmarking a demo - if (COM_CheckParm("-benchmark")) + if (Sys_CheckParm("-benchmark")) return; - // clear menu's connect error message -#ifdef CONFIG_MENU - M_Update_Return_Reason(""); -#endif - - // Disconnect from the current server, or stop a running demo. - CL_Disconnect(); - // make sure the client ports are open before attempting to connect NetConn_UpdateSockets(); - if (LHNETADDRESS_FromString(&cls.connect_address, host, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address))) + if (LHNETADDRESS_FromString(&cls.connect_address, address, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address))) { cls.connect_trying = true; - cls.connect_remainingtries = 3; + cls.connect_remainingtries = 10; cls.connect_nextsendtime = 0; // only NOW, set connect_userinfo @@ -534,8 +594,8 @@ void CL_EstablishConnection(const char *host, 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) { @@ -544,19 +604,27 @@ void CL_EstablishConnection(const char *host, 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)); } } +static void CL_EstablishConnection_Local(void) +{ + if(cls.state == ca_disconnected) + CL_EstablishConnection("local:1", -2); +} + +static qbool CL_Intermission(void) +{ + return cl.intermission; +} + /* ============== CL_PrintEntities_f @@ -592,7 +660,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"); @@ -639,7 +707,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 @@ -749,11 +817,11 @@ entity_render_t *CL_NewTempEntity(double shadertime) return render; } -void CL_Effect(vec3_t org, int modelindex, 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; - if (!modelindex) // sanity check + if (!model) // sanity check return; if (framerate < 1) { @@ -771,7 +839,7 @@ void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float continue; e->active = true; VectorCopy(org, e->origin); - e->modelindex = modelindex; + e->model = model; e->starttime = cl.time; e->startframe = startframe; e->endframe = startframe + framecount; @@ -824,7 +892,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; @@ -1012,7 +1080,7 @@ void CL_SetEntityColormapColors(entity_render_t *ent, int colormap) } // note this is a recursive function, recursionlimit should be 32 or so on the initial call -static void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolate) +static void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qbool interpolate) { const matrix4x4_t *matrix; matrix4x4_t blendmatrix, tempmatrix, matrix2; @@ -1106,6 +1174,7 @@ static void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean int // 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); @@ -1771,7 +1840,7 @@ static void CL_RelinkEffects(void) } // normal stuff - entrender->model = CL_GetModelByIndex(e->modelindex); + entrender->model = e->model; entrender->alpha = 1; VectorSet(entrender->colormod, 1, 1, 1); VectorSet(entrender->glowmod, 1, 1, 1); @@ -2024,7 +2093,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(); @@ -2093,7 +2162,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)); } @@ -2158,7 +2227,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]); } @@ -2446,7 +2515,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", @@ -2460,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; @@ -2488,7 +2580,8 @@ static void CL_MeshEntities_Init(void) VectorSet(ent->render.render_modellight_ambient, 1, 1, 1); VectorSet(ent->render.render_modellight_diffuse, 0, 0, 0); VectorSet(ent->render.render_modellight_specular, 0, 0, 0); - VectorSet(ent->render.render_modellight_lightdir, 0, 0, 1); + VectorSet(ent->render.render_modellight_lightdir_world, 0, 0, 1); + VectorSet(ent->render.render_modellight_lightdir_local, 0, 0, 1); // local doesn't matter because no diffuse/specular color VectorSet(ent->render.render_lightmap_ambient, 0, 0, 0); VectorSet(ent->render.render_lightmap_diffuse, 1, 1, 1); VectorSet(ent->render.render_lightmap_specular, 1, 1, 1); @@ -2499,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) @@ -2521,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; @@ -2664,7 +2753,7 @@ static void CL_UpdateEntityShading_Entity(entity_render_t *ent) ent->render_modellight_ambient[q] = a[q] * ent->colormod[q]; ent->render_modellight_diffuse[q] = c[q] * ent->colormod[q]; ent->render_modellight_specular[q] = c[q]; - ent->render_modellight_lightdir[q] = dir[q]; + ent->render_modellight_lightdir_world[q] = dir[q]; ent->render_lightmap_ambient[q] = ent->colormod[q] * r_refdef.scene.ambientintensity; ent->render_lightmap_diffuse[q] = ent->colormod[q] * r_refdef.scene.lightmapintensity; ent->render_lightmap_specular[q] = r_refdef.scene.lightmapintensity; @@ -2680,9 +2769,12 @@ static void CL_UpdateEntityShading_Entity(entity_render_t *ent) for (q = 0; q < 3; q++) ent->render_rtlight_diffuse[q] = ent->render_rtlight_specular[q] = q; - if (VectorLength2(ent->render_modellight_lightdir) == 0) - VectorSet(ent->render_modellight_lightdir, 0, 0, 1); // have to set SOME valid vector here - VectorNormalize(ent->render_modellight_lightdir); + if (VectorLength2(ent->render_modellight_lightdir_world) == 0) + VectorSet(ent->render_modellight_lightdir_world, 0, 0, 1); // have to set SOME valid vector here + VectorNormalize(ent->render_modellight_lightdir_world); + // transform into local space for the entity as well + Matrix4x4_Transform3x3(&ent->inversematrix, ent->render_modellight_lightdir_world, ent->render_modellight_lightdir_local); + VectorNormalize(ent->render_modellight_lightdir_local); } @@ -2694,6 +2786,173 @@ 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 uint8_t serverlist_querystage; +double CL_Frame (double time) +{ + static double clframetime; + static double cl_timer = 0; + static double time1 = 0, time2 = 0, time3 = 0; + int pass1, pass2, pass3; + float maxfps; + + CL_VM_PreventInformationLeaks(); + + /* + * 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; + + // limit the frametime steps to no more than 100ms each + if (cl_timer > 0.1) + cl_timer = 0.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(); + R_TimeReport("photoncache"); +#ifdef CONFIG_VIDEO_CAPTURE + // decide the simulation time + if (cls.capturevideo.active) + { + if (cls.capturevideo.realtime) + clframetime = cl.realframetime = max(time, 1.0 / cls.capturevideo.framerate); + else + { + clframetime = 1.0 / cls.capturevideo.framerate; + cl.realframetime = max(time, clframetime); + } + } + else +#endif + { + 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)); + } + + // apply slowmo scaling + clframetime *= cl.movevars_timescale; + // scale playback speed of demos by slowmo cvar + if (cls.demoplayback) + { + clframetime *= host_timescale.value; + // if demo playback is paused, don't advance time at all + if (cls.demopaused) + clframetime = 0; + } + else + { + // host_framerate overrides all else + if (host_framerate.value) + clframetime = host_framerate.value; + + if (cl.paused || host.paused) + clframetime = 0; + } + + if (cls.timedemo) + clframetime = cl.realframetime = cl_timer; + + // deduct the frame time from the accumulator + cl_timer -= cl.realframetime; + + cl.oldtime = cl.time; + cl.time += clframetime; + + // update video + if (host_speeds.integer) + time1 = Sys_DirtyTime(); + R_TimeReport("pre-input"); + + // Collect input into cmd + CL_Input(); + + R_TimeReport("input"); + + // check for new packets + NetConn_ClientFrame(); + + // read a new frame from a demo if needed + CL_ReadDemoMessage(); + R_TimeReport("clientnetwork"); + + // now that packets have been read, send input to server + CL_SendMove(); + R_TimeReport("sendmove"); + + // update client world (interpolate entities, create trails, etc) + CL_UpdateWorld(); + R_TimeReport("lerpworld"); + + CL_Video_Frame(); + + R_TimeReport("client"); + + CL_UpdateScreen(); + R_TimeReport("render"); + + if (host_speeds.integer) + time2 = Sys_DirtyTime(); + + // update audio + if(cl.csqc_usecsqclistener) + { + S_Update(&cl.csqc_listenermatrix); + cl.csqc_usecsqclistener = false; + } + else + S_Update(&r_refdef.view.matrix); + + CDAudio_Update(); + R_TimeReport("audio"); + + // reset gathering of mouse input + in_mouse_x = in_mouse_y = 0; + + if (host_speeds.integer) + { + pass1 = (int)((time1 - time3)*1000000); + time3 = Sys_DirtyTime(); + pass2 = (int)((time2 - time1)*1000000); + pass3 = (int)((time3 - time2)*1000000); + Con_Printf("%6ius total %6ius server %6ius gfx %6ius snd\n", + pass1+pass2+pass3, pass1, pass2, pass3); + } + } + // if there is some time remaining from this frame, reset the timer + return cl_timer >= 0 ? 0 : cl_timer; +} + /* =========== CL_Shutdown @@ -2701,11 +2960,32 @@ CL_Shutdown */ void CL_Shutdown (void) { + // be quiet while shutting down + S_StopAllSounds(); + + // disconnect client from server if active + CL_Disconnect(); + + CL_Video_Shutdown(); + +#ifdef CONFIG_MENU + // Shutdown menu + if(MR_Shutdown) + MR_Shutdown(); +#endif + + S_Terminate (); + + R_Modules_Shutdown(); + VID_Shutdown(); + CL_Screen_Shutdown(); CL_Particles_Shutdown(); CL_Parse_Shutdown(); CL_MeshEntities_Shutdown(); + Key_Shutdown(); + Mem_FreePool (&cls.permanentmempool); Mem_FreePool (&cls.levelmempool); } @@ -2719,11 +2999,13 @@ void CL_Init (void) { if (cls.state == ca_dedicated) { - Cmd_AddCommand(CMD_SERVER, "disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)"); + Cmd_AddCommand(CF_SERVER, "disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)"); } else { - Con_DPrintf("Initializing client\n"); + Con_Printf("Initializing client\n"); + + Cvar_SetValueQuick(&host_isclient, 1); R_Modules_Init(); Palette_Init(); @@ -2734,9 +3016,8 @@ void CL_Init (void) VID_Init(); Render_Init(); S_Init(); - CDAudio_Init(); Key_Init(); - + V_Init(); cls.levelmempool = Mem_AllocPool("client (per-level memory)", 0, NULL); cls.permanentmempool = Mem_AllocPool("client (long term memory)", 0, NULL); @@ -2755,6 +3036,8 @@ void CL_Init (void) // // register our commands // + CL_InitCommands(); + Cvar_RegisterVariable (&cl_upspeed); Cvar_RegisterVariable (&cl_forwardspeed); Cvar_RegisterVariable (&cl_backspeed); @@ -2784,20 +3067,20 @@ void CL_Init (void) CL_Demo_Init(); - Cmd_AddCommand(CMD_CLIENT, "entities", CL_PrintEntities_f, "print information on network entities known to client"); - Cmd_AddCommand(CMD_CLIENT, "disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)"); - Cmd_AddCommand(CMD_CLIENT, "connect", CL_Connect_f, "connect to a server by IP address or hostname"); - Cmd_AddCommand(CMD_CLIENT | CMD_CLIENT_FROM_SERVER, "reconnect", CL_Reconnect_f, "reconnect to the last server you were on, or resets a quakeworld connection (do not use if currently playing on a netquake server)"); + Cmd_AddCommand(CF_CLIENT, "entities", CL_PrintEntities_f, "print information on network entities known to client"); + Cmd_AddCommand(CF_CLIENT, "disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)"); + Cmd_AddCommand(CF_CLIENT, "connect", CL_Connect_f, "connect to a server by IP address or hostname"); + Cmd_AddCommand(CF_CLIENT | CF_CLIENT_FROM_SERVER, "reconnect", CL_Reconnect_f, "reconnect to the last server you were on, or resets a quakeworld connection (do not use if currently playing on a netquake server)"); // Support Client-side Model Index List - Cmd_AddCommand(CMD_CLIENT, "cl_modelindexlist", CL_ModelIndexList_f, "list information on all models in the client modelindex"); + Cmd_AddCommand(CF_CLIENT, "cl_modelindexlist", CL_ModelIndexList_f, "list information on all models in the client modelindex"); // Support Client-side Sound Index List - Cmd_AddCommand(CMD_CLIENT, "cl_soundindexlist", CL_SoundIndexList_f, "list all sounds in the client soundindex"); + Cmd_AddCommand(CF_CLIENT, "cl_soundindexlist", CL_SoundIndexList_f, "list all sounds in the client soundindex"); - Cmd_AddCommand(CMD_CLIENT, "fog", CL_Fog_f, "set global fog parameters (density red green blue [alpha [mindist [maxdist [top [fadedepth]]]]])"); - Cmd_AddCommand(CMD_CLIENT, "fog_heighttexture", CL_Fog_HeightTexture_f, "set global fog parameters (density red green blue alpha mindist maxdist top depth textures/mapname/fogheight.tga)"); + Cmd_AddCommand(CF_CLIENT, "fog", CL_Fog_f, "set global fog parameters (density red green blue [alpha [mindist [maxdist [top [fadedepth]]]]])"); + Cmd_AddCommand(CF_CLIENT, "fog_heighttexture", CL_Fog_HeightTexture_f, "set global fog parameters (density red green blue alpha mindist maxdist top depth textures/mapname/fogheight.tga)"); - Cmd_AddCommand(CMD_CLIENT, "cl_areastats", CL_AreaStats_f, "prints statistics on entity culling during collision traces"); + Cmd_AddCommand(CF_CLIENT, "cl_areastats", CL_AreaStats_f, "prints statistics on entity culling during collision traces"); Cvar_RegisterVariable(&r_draweffects); Cvar_RegisterVariable(&cl_explosions_alpha_start); @@ -2822,29 +3105,48 @@ 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(CMD_CLIENT, "timerefresh", CL_TimeRefresh_f, "turn quickly and print rendering statistcs"); + Cmd_AddCommand(CF_CLIENT, "timerefresh", CL_TimeRefresh_f, "turn quickly and print rendering statistcs"); Cvar_RegisterVariable(&cl_locs_enable); Cvar_RegisterVariable(&cl_locs_show); - Cmd_AddCommand(CMD_CLIENT, "locs_add", CL_Locs_Add_f, "add a point or box location (usage: x y z[ x y z] \"name\", if two sets of xyz are supplied it is a box, otherwise point)"); - Cmd_AddCommand(CMD_CLIENT, "locs_removenearest", CL_Locs_RemoveNearest_f, "remove the nearest point or box (note: you need to be very near a box to remove it)"); - Cmd_AddCommand(CMD_CLIENT, "locs_clear", CL_Locs_Clear_f, "remove all loc points/boxes"); - Cmd_AddCommand(CMD_CLIENT, "locs_reload", CL_Locs_Reload_f, "reload .loc file for this map"); - Cmd_AddCommand(CMD_CLIENT, "locs_save", CL_Locs_Save_f, "save .loc file for this map containing currently defined points and boxes"); + Cmd_AddCommand(CF_CLIENT, "locs_add", CL_Locs_Add_f, "add a point or box location (usage: x y z[ x y z] \"name\", if two sets of xyz are supplied it is a box, otherwise point)"); + Cmd_AddCommand(CF_CLIENT, "locs_removenearest", CL_Locs_RemoveNearest_f, "remove the nearest point or box (note: you need to be very near a box to remove it)"); + Cmd_AddCommand(CF_CLIENT, "locs_clear", CL_Locs_Clear_f, "remove all loc points/boxes"); + Cmd_AddCommand(CF_CLIENT, "locs_reload", CL_Locs_Reload_f, "reload .loc file for this map"); + Cmd_AddCommand(CF_CLIENT, "locs_save", CL_Locs_Save_f, "save .loc file for this map containing currently defined points and boxes"); Cvar_RegisterVariable(&csqc_polygons_defaultmaterial_nocullface); + Cvar_RegisterVariable(&csqc_lowres); + + Cvar_RegisterVariable (&cl_minfps); + Cvar_RegisterVariable (&cl_minfps_fade); + Cvar_RegisterVariable (&cl_minfps_qualitymax); + Cvar_RegisterVariable (&cl_minfps_qualitymin); + Cvar_RegisterVariable (&cl_minfps_qualitystepmax); + Cvar_RegisterVariable (&cl_minfps_qualityhysteresis); + Cvar_RegisterVariable (&cl_minfps_qualitymultiply); + Cvar_RegisterVariable (&cl_minfps_force); + Cvar_RegisterVariable (&cl_maxfps); + 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(); - #ifdef CONFIG_MENU - Cbuf_InsertText(&cmd_client,"menu_start\n"); - #endif + 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; } }