client.h (16005B)
1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Foobar; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 // client.h -- primary header for client 23 24 #include "../game/q_shared.h" 25 #include "../qcommon/qcommon.h" 26 #include "../renderer/tr_public.h" 27 #include "../ui/ui_public.h" 28 #include "keys.h" 29 #include "snd_public.h" 30 #include "../cgame/cg_public.h" 31 #include "../game/bg_public.h" 32 33 #define RETRANSMIT_TIMEOUT 3000 // time between connection packet retransmits 34 35 36 // snapshots are a view of the server at a given time 37 typedef struct { 38 qboolean valid; // cleared if delta parsing was invalid 39 int snapFlags; // rate delayed and dropped commands 40 41 int serverTime; // server time the message is valid for (in msec) 42 43 int messageNum; // copied from netchan->incoming_sequence 44 int deltaNum; // messageNum the delta is from 45 int ping; // time from when cmdNum-1 was sent to time packet was reeceived 46 byte areamask[MAX_MAP_AREA_BYTES]; // portalarea visibility bits 47 48 int cmdNum; // the next cmdNum the server is expecting 49 playerState_t ps; // complete information about the current player at this time 50 51 int numEntities; // all of the entities that need to be presented 52 int parseEntitiesNum; // at the time of this snapshot 53 54 int serverCommandNum; // execute all commands up to this before 55 // making the snapshot current 56 } clSnapshot_t; 57 58 59 60 /* 61 ============================================================================= 62 63 the clientActive_t structure is wiped completely at every 64 new gamestate_t, potentially several times during an established connection 65 66 ============================================================================= 67 */ 68 69 typedef struct { 70 int p_cmdNumber; // cl.cmdNumber when packet was sent 71 int p_serverTime; // usercmd->serverTime when packet was sent 72 int p_realtime; // cls.realtime when packet was sent 73 } outPacket_t; 74 75 // the parseEntities array must be large enough to hold PACKET_BACKUP frames of 76 // entities, so that when a delta compressed message arives from the server 77 // it can be un-deltad from the original 78 #define MAX_PARSE_ENTITIES 2048 79 80 extern int g_console_field_width; 81 82 typedef struct { 83 int timeoutcount; // it requres several frames in a timeout condition 84 // to disconnect, preventing debugging breaks from 85 // causing immediate disconnects on continue 86 clSnapshot_t snap; // latest received from server 87 88 int serverTime; // may be paused during play 89 int oldServerTime; // to prevent time from flowing bakcwards 90 int oldFrameServerTime; // to check tournament restarts 91 int serverTimeDelta; // cl.serverTime = cls.realtime + cl.serverTimeDelta 92 // this value changes as net lag varies 93 qboolean extrapolatedSnapshot; // set if any cgame frame has been forced to extrapolate 94 // cleared when CL_AdjustTimeDelta looks at it 95 qboolean newSnapshots; // set on parse of any valid packet 96 97 gameState_t gameState; // configstrings 98 char mapname[MAX_QPATH]; // extracted from CS_SERVERINFO 99 100 int parseEntitiesNum; // index (not anded off) into cl_parse_entities[] 101 102 int mouseDx[2], mouseDy[2]; // added to by mouse events 103 int mouseIndex; 104 int joystickAxis[MAX_JOYSTICK_AXIS]; // set by joystick events 105 106 // cgame communicates a few values to the client system 107 int cgameUserCmdValue; // current weapon to add to usercmd_t 108 float cgameSensitivity; 109 110 // cmds[cmdNumber] is the predicted command, [cmdNumber-1] is the last 111 // properly generated command 112 usercmd_t cmds[CMD_BACKUP]; // each mesage will send several old cmds 113 int cmdNumber; // incremented each frame, because multiple 114 // frames may need to be packed into a single packet 115 116 outPacket_t outPackets[PACKET_BACKUP]; // information about each packet we have sent out 117 118 // the client maintains its own idea of view angles, which are 119 // sent to the server each frame. It is cleared to 0 upon entering each level. 120 // the server sends a delta each frame which is added to the locally 121 // tracked view angles to account for standing on rotating objects, 122 // and teleport direction changes 123 vec3_t viewangles; 124 125 int serverId; // included in each client message so the server 126 // can tell if it is for a prior map_restart 127 // big stuff at end of structure so most offsets are 15 bits or less 128 clSnapshot_t snapshots[PACKET_BACKUP]; 129 130 entityState_t entityBaselines[MAX_GENTITIES]; // for delta compression when not in previous frame 131 132 entityState_t parseEntities[MAX_PARSE_ENTITIES]; 133 } clientActive_t; 134 135 extern clientActive_t cl; 136 137 /* 138 ============================================================================= 139 140 the clientConnection_t structure is wiped when disconnecting from a server, 141 either to go to a full screen console, play a demo, or connect to a different server 142 143 A connection can be to either a server through the network layer or a 144 demo through a file. 145 146 ============================================================================= 147 */ 148 149 150 typedef struct { 151 152 int clientNum; 153 int lastPacketSentTime; // for retransmits during connection 154 int lastPacketTime; // for timeouts 155 156 netadr_t serverAddress; 157 int connectTime; // for connection retransmits 158 int connectPacketCount; // for display on connection dialog 159 char serverMessage[MAX_STRING_TOKENS]; // for display on connection dialog 160 161 int challenge; // from the server to use for connecting 162 int checksumFeed; // from the server for checksum calculations 163 164 // these are our reliable messages that go to the server 165 int reliableSequence; 166 int reliableAcknowledge; // the last one the server has executed 167 char reliableCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS]; 168 169 // server message (unreliable) and command (reliable) sequence 170 // numbers are NOT cleared at level changes, but continue to 171 // increase as long as the connection is valid 172 173 // message sequence is used by both the network layer and the 174 // delta compression layer 175 int serverMessageSequence; 176 177 // reliable messages received from server 178 int serverCommandSequence; 179 int lastExecutedServerCommand; // last server command grabbed or executed with CL_GetServerCommand 180 char serverCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS]; 181 182 // file transfer from server 183 fileHandle_t download; 184 char downloadTempName[MAX_OSPATH]; 185 char downloadName[MAX_OSPATH]; 186 int downloadNumber; 187 int downloadBlock; // block we are waiting for 188 int downloadCount; // how many bytes we got 189 int downloadSize; // how many bytes we got 190 char downloadList[MAX_INFO_STRING]; // list of paks we need to download 191 qboolean downloadRestart; // if true, we need to do another FS_Restart because we downloaded a pak 192 193 // demo information 194 char demoName[MAX_QPATH]; 195 qboolean spDemoRecording; 196 qboolean demorecording; 197 qboolean demoplaying; 198 qboolean demowaiting; // don't record until a non-delta message is received 199 qboolean firstDemoFrameSkipped; 200 fileHandle_t demofile; 201 202 int timeDemoFrames; // counter of rendered frames 203 int timeDemoStart; // cls.realtime before first frame 204 int timeDemoBaseTime; // each frame will be at this time + frameNum * 50 205 206 // big stuff at end of structure so most offsets are 15 bits or less 207 netchan_t netchan; 208 } clientConnection_t; 209 210 extern clientConnection_t clc; 211 212 /* 213 ================================================================== 214 215 the clientStatic_t structure is never wiped, and is used even when 216 no client connection is active at all 217 218 ================================================================== 219 */ 220 221 typedef struct { 222 netadr_t adr; 223 int start; 224 int time; 225 char info[MAX_INFO_STRING]; 226 } ping_t; 227 228 typedef struct { 229 netadr_t adr; 230 char hostName[MAX_NAME_LENGTH]; 231 char mapName[MAX_NAME_LENGTH]; 232 char game[MAX_NAME_LENGTH]; 233 int netType; 234 int gameType; 235 int clients; 236 int maxClients; 237 int minPing; 238 int maxPing; 239 int ping; 240 qboolean visible; 241 int punkbuster; 242 } serverInfo_t; 243 244 typedef struct { 245 byte ip[4]; 246 unsigned short port; 247 } serverAddress_t; 248 249 typedef struct { 250 connstate_t state; // connection status 251 int keyCatchers; // bit flags 252 253 qboolean cddialog; // bring up the cd needed dialog next frame 254 255 char servername[MAX_OSPATH]; // name of server from original connect (used by reconnect) 256 257 // when the server clears the hunk, all of these must be restarted 258 qboolean rendererStarted; 259 qboolean soundStarted; 260 qboolean soundRegistered; 261 qboolean uiStarted; 262 qboolean cgameStarted; 263 264 int framecount; 265 int frametime; // msec since last frame 266 267 int realtime; // ignores pause 268 int realFrametime; // ignoring pause, so console always works 269 270 int numlocalservers; 271 serverInfo_t localServers[MAX_OTHER_SERVERS]; 272 273 int numglobalservers; 274 serverInfo_t globalServers[MAX_GLOBAL_SERVERS]; 275 // additional global servers 276 int numGlobalServerAddresses; 277 serverAddress_t globalServerAddresses[MAX_GLOBAL_SERVERS]; 278 279 int numfavoriteservers; 280 serverInfo_t favoriteServers[MAX_OTHER_SERVERS]; 281 282 int nummplayerservers; 283 serverInfo_t mplayerServers[MAX_OTHER_SERVERS]; 284 285 int pingUpdateSource; // source currently pinging or updating 286 287 int masterNum; 288 289 // update server info 290 netadr_t updateServer; 291 char updateChallenge[MAX_TOKEN_CHARS]; 292 char updateInfoString[MAX_INFO_STRING]; 293 294 netadr_t authorizeServer; 295 296 // rendering info 297 glconfig_t glconfig; 298 qhandle_t charSetShader; 299 qhandle_t whiteShader; 300 qhandle_t consoleShader; 301 } clientStatic_t; 302 303 extern clientStatic_t cls; 304 305 //============================================================================= 306 307 extern vm_t *cgvm; // interface to cgame dll or vm 308 extern vm_t *uivm; // interface to ui dll or vm 309 extern refexport_t re; // interface to refresh .dll 310 311 312 // 313 // cvars 314 // 315 extern cvar_t *cl_nodelta; 316 extern cvar_t *cl_debugMove; 317 extern cvar_t *cl_noprint; 318 extern cvar_t *cl_timegraph; 319 extern cvar_t *cl_maxpackets; 320 extern cvar_t *cl_packetdup; 321 extern cvar_t *cl_shownet; 322 extern cvar_t *cl_showSend; 323 extern cvar_t *cl_timeNudge; 324 extern cvar_t *cl_showTimeDelta; 325 extern cvar_t *cl_freezeDemo; 326 327 extern cvar_t *cl_yawspeed; 328 extern cvar_t *cl_pitchspeed; 329 extern cvar_t *cl_run; 330 extern cvar_t *cl_anglespeedkey; 331 332 extern cvar_t *cl_sensitivity; 333 extern cvar_t *cl_freelook; 334 335 extern cvar_t *cl_mouseAccel; 336 extern cvar_t *cl_showMouseRate; 337 338 extern cvar_t *m_pitch; 339 extern cvar_t *m_yaw; 340 extern cvar_t *m_forward; 341 extern cvar_t *m_side; 342 extern cvar_t *m_filter; 343 344 extern cvar_t *cl_timedemo; 345 346 extern cvar_t *cl_activeAction; 347 348 extern cvar_t *cl_allowDownload; 349 extern cvar_t *cl_conXOffset; 350 extern cvar_t *cl_inGameVideo; 351 352 //================================================= 353 354 // 355 // cl_main 356 // 357 358 void CL_Init (void); 359 void CL_FlushMemory(void); 360 void CL_ShutdownAll(void); 361 void CL_AddReliableCommand( const char *cmd ); 362 363 void CL_StartHunkUsers( void ); 364 365 void CL_Disconnect_f (void); 366 void CL_GetChallengePacket (void); 367 void CL_Vid_Restart_f( void ); 368 void CL_Snd_Restart_f (void); 369 void CL_StartDemoLoop( void ); 370 void CL_NextDemo( void ); 371 void CL_ReadDemoMessage( void ); 372 373 void CL_InitDownloads(void); 374 void CL_NextDownload(void); 375 376 void CL_GetPing( int n, char *buf, int buflen, int *pingtime ); 377 void CL_GetPingInfo( int n, char *buf, int buflen ); 378 void CL_ClearPing( int n ); 379 int CL_GetPingQueueCount( void ); 380 381 void CL_ShutdownRef( void ); 382 void CL_InitRef( void ); 383 qboolean CL_CDKeyValidate( const char *key, const char *checksum ); 384 int CL_ServerStatus( char *serverAddress, char *serverStatusString, int maxLen ); 385 386 387 // 388 // cl_input 389 // 390 typedef struct { 391 int down[2]; // key nums holding it down 392 unsigned downtime; // msec timestamp 393 unsigned msec; // msec down this frame if both a down and up happened 394 qboolean active; // current state 395 qboolean wasPressed; // set when down, not cleared when up 396 } kbutton_t; 397 398 extern kbutton_t in_mlook, in_klook; 399 extern kbutton_t in_strafe; 400 extern kbutton_t in_speed; 401 402 void CL_InitInput (void); 403 void CL_SendCmd (void); 404 void CL_ClearState (void); 405 void CL_ReadPackets (void); 406 407 void CL_WritePacket( void ); 408 void IN_CenterView (void); 409 410 void CL_VerifyCode( void ); 411 412 float CL_KeyState (kbutton_t *key); 413 char *Key_KeynumToString (int keynum); 414 415 // 416 // cl_parse.c 417 // 418 extern int cl_connectedToPureServer; 419 420 void CL_SystemInfoChanged( void ); 421 void CL_ParseServerMessage( msg_t *msg ); 422 423 //==================================================================== 424 425 void CL_ServerInfoPacket( netadr_t from, msg_t *msg ); 426 void CL_LocalServers_f( void ); 427 void CL_GlobalServers_f( void ); 428 void CL_FavoriteServers_f( void ); 429 void CL_Ping_f( void ); 430 qboolean CL_UpdateVisiblePings_f( int source ); 431 432 433 // 434 // console 435 // 436 void Con_DrawCharacter (int cx, int line, int num); 437 438 void Con_CheckResize (void); 439 void Con_Init (void); 440 void Con_Clear_f (void); 441 void Con_ToggleConsole_f (void); 442 void Con_DrawNotify (void); 443 void Con_ClearNotify (void); 444 void Con_RunConsole (void); 445 void Con_DrawConsole (void); 446 void Con_PageUp( void ); 447 void Con_PageDown( void ); 448 void Con_Top( void ); 449 void Con_Bottom( void ); 450 void Con_Close( void ); 451 452 453 // 454 // cl_scrn.c 455 // 456 void SCR_Init (void); 457 void SCR_UpdateScreen (void); 458 459 void SCR_DebugGraph (float value, int color); 460 461 int SCR_GetBigStringWidth( const char *str ); // returns in virtual 640x480 coordinates 462 463 void SCR_AdjustFrom640( float *x, float *y, float *w, float *h ); 464 void SCR_FillRect( float x, float y, float width, float height, 465 const float *color ); 466 void SCR_DrawPic( float x, float y, float width, float height, qhandle_t hShader ); 467 void SCR_DrawNamedPic( float x, float y, float width, float height, const char *picname ); 468 469 void SCR_DrawBigString( int x, int y, const char *s, float alpha ); // draws a string with embedded color control characters with fade 470 void SCR_DrawBigStringColor( int x, int y, const char *s, vec4_t color ); // ignores embedded color control characters 471 void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, qboolean forceColor ); 472 void SCR_DrawSmallChar( int x, int y, int ch ); 473 474 475 // 476 // cl_cin.c 477 // 478 479 void CL_PlayCinematic_f( void ); 480 void SCR_DrawCinematic (void); 481 void SCR_RunCinematic (void); 482 void SCR_StopCinematic (void); 483 int CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits); 484 e_status CIN_StopCinematic(int handle); 485 e_status CIN_RunCinematic (int handle); 486 void CIN_DrawCinematic (int handle); 487 void CIN_SetExtents (int handle, int x, int y, int w, int h); 488 void CIN_SetLooping (int handle, qboolean loop); 489 void CIN_UploadCinematic(int handle); 490 void CIN_CloseAllVideos(void); 491 492 // 493 // cl_cgame.c 494 // 495 void CL_InitCGame( void ); 496 void CL_ShutdownCGame( void ); 497 qboolean CL_GameCommand( void ); 498 void CL_CGameRendering( stereoFrame_t stereo ); 499 void CL_SetCGameTime( void ); 500 void CL_FirstSnapshot( void ); 501 void CL_ShaderStateChanged(void); 502 503 // 504 // cl_ui.c 505 // 506 void CL_InitUI( void ); 507 void CL_ShutdownUI( void ); 508 int Key_GetCatcher( void ); 509 void Key_SetCatcher( int catcher ); 510 void LAN_LoadCachedServers(); 511 void LAN_SaveServersToCache(); 512 513 514 // 515 // cl_net_chan.c 516 // 517 void CL_Netchan_Transmit( netchan_t *chan, msg_t* msg); //int length, const byte *data ); 518 void CL_Netchan_TransmitNextFragment( netchan_t *chan ); 519 qboolean CL_Netchan_Process( netchan_t *chan, msg_t *msg );