Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

client.h

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 // client.h -- primary header for client
00023 
00024 #include "../game/q_shared.h"
00025 #include "../qcommon/qcommon.h"
00026 #include "../renderer/tr_public.h"
00027 #include "../ui/ui_public.h"
00028 #include "keys.h"
00029 #include "snd_public.h"
00030 #include "../cgame/cg_public.h"
00031 #include "../game/bg_public.h"
00032 
00033 #define RETRANSMIT_TIMEOUT  3000    // time between connection packet retransmits
00034 
00035 
00036 // snapshots are a view of the server at a given time
00037 typedef struct {
00038     qboolean        valid;          // cleared if delta parsing was invalid
00039     int             snapFlags;      // rate delayed and dropped commands
00040 
00041     int             serverTime;     // server time the message is valid for (in msec)
00042 
00043     int             messageNum;     // copied from netchan->incoming_sequence
00044     int             deltaNum;       // messageNum the delta is from
00045     int             ping;           // time from when cmdNum-1 was sent to time packet was reeceived
00046     byte            areamask[MAX_MAP_AREA_BYTES];       // portalarea visibility bits
00047 
00048     int             cmdNum;         // the next cmdNum the server is expecting
00049     playerState_t   ps;                     // complete information about the current player at this time
00050 
00051     int             numEntities;            // all of the entities that need to be presented
00052     int             parseEntitiesNum;       // at the time of this snapshot
00053 
00054     int             serverCommandNum;       // execute all commands up to this before
00055                                             // making the snapshot current
00056 } clSnapshot_t;
00057 
00058 
00059 
00060 /*
00061 =============================================================================
00062 
00063 the clientActive_t structure is wiped completely at every
00064 new gamestate_t, potentially several times during an established connection
00065 
00066 =============================================================================
00067 */
00068 
00069 typedef struct {
00070     int     p_cmdNumber;        // cl.cmdNumber when packet was sent
00071     int     p_serverTime;       // usercmd->serverTime when packet was sent
00072     int     p_realtime;         // cls.realtime when packet was sent
00073 } outPacket_t;
00074 
00075 // the parseEntities array must be large enough to hold PACKET_BACKUP frames of
00076 // entities, so that when a delta compressed message arives from the server
00077 // it can be un-deltad from the original 
00078 #define MAX_PARSE_ENTITIES  2048
00079 
00080 extern int g_console_field_width;
00081 
00082 typedef struct {
00083     int         timeoutcount;       // it requres several frames in a timeout condition
00084                                     // to disconnect, preventing debugging breaks from
00085                                     // causing immediate disconnects on continue
00086     clSnapshot_t    snap;           // latest received from server
00087 
00088     int         serverTime;         // may be paused during play
00089     int         oldServerTime;      // to prevent time from flowing bakcwards
00090     int         oldFrameServerTime; // to check tournament restarts
00091     int         serverTimeDelta;    // cl.serverTime = cls.realtime + cl.serverTimeDelta
00092                                     // this value changes as net lag varies
00093     qboolean    extrapolatedSnapshot;   // set if any cgame frame has been forced to extrapolate
00094                                     // cleared when CL_AdjustTimeDelta looks at it
00095     qboolean    newSnapshots;       // set on parse of any valid packet
00096 
00097     gameState_t gameState;          // configstrings
00098     char        mapname[MAX_QPATH]; // extracted from CS_SERVERINFO
00099 
00100     int         parseEntitiesNum;   // index (not anded off) into cl_parse_entities[]
00101 
00102     int         mouseDx[2], mouseDy[2]; // added to by mouse events
00103     int         mouseIndex;
00104     int         joystickAxis[MAX_JOYSTICK_AXIS];    // set by joystick events
00105 
00106     // cgame communicates a few values to the client system
00107     int         cgameUserCmdValue;  // current weapon to add to usercmd_t
00108     float       cgameSensitivity;
00109 
00110     // cmds[cmdNumber] is the predicted command, [cmdNumber-1] is the last
00111     // properly generated command
00112     usercmd_t   cmds[CMD_BACKUP];   // each mesage will send several old cmds
00113     int         cmdNumber;          // incremented each frame, because multiple
00114                                     // frames may need to be packed into a single packet
00115 
00116     outPacket_t outPackets[PACKET_BACKUP];  // information about each packet we have sent out
00117 
00118     // the client maintains its own idea of view angles, which are
00119     // sent to the server each frame.  It is cleared to 0 upon entering each level.
00120     // the server sends a delta each frame which is added to the locally
00121     // tracked view angles to account for standing on rotating objects,
00122     // and teleport direction changes
00123     vec3_t      viewangles;
00124 
00125     int         serverId;           // included in each client message so the server
00126                                                 // can tell if it is for a prior map_restart
00127     // big stuff at end of structure so most offsets are 15 bits or less
00128     clSnapshot_t    snapshots[PACKET_BACKUP];
00129 
00130     entityState_t   entityBaselines[MAX_GENTITIES]; // for delta compression when not in previous frame
00131 
00132     entityState_t   parseEntities[MAX_PARSE_ENTITIES];
00133 } clientActive_t;
00134 
00135 extern  clientActive_t      cl;
00136 
00137 /*
00138 =============================================================================
00139 
00140 the clientConnection_t structure is wiped when disconnecting from a server,
00141 either to go to a full screen console, play a demo, or connect to a different server
00142 
00143 A connection can be to either a server through the network layer or a
00144 demo through a file.
00145 
00146 =============================================================================
00147 */
00148 
00149 
00150 typedef struct {
00151 
00152     int         clientNum;
00153     int         lastPacketSentTime;         // for retransmits during connection
00154     int         lastPacketTime;             // for timeouts
00155 
00156     netadr_t    serverAddress;
00157     int         connectTime;                // for connection retransmits
00158     int         connectPacketCount;         // for display on connection dialog
00159     char        serverMessage[MAX_STRING_TOKENS];   // for display on connection dialog
00160 
00161     int         challenge;                  // from the server to use for connecting
00162     int         checksumFeed;               // from the server for checksum calculations
00163 
00164     // these are our reliable messages that go to the server
00165     int         reliableSequence;
00166     int         reliableAcknowledge;        // the last one the server has executed
00167     char        reliableCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS];
00168 
00169     // server message (unreliable) and command (reliable) sequence
00170     // numbers are NOT cleared at level changes, but continue to
00171     // increase as long as the connection is valid
00172 
00173     // message sequence is used by both the network layer and the
00174     // delta compression layer
00175     int         serverMessageSequence;
00176 
00177     // reliable messages received from server
00178     int         serverCommandSequence;
00179     int         lastExecutedServerCommand;      // last server command grabbed or executed with CL_GetServerCommand
00180     char        serverCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS];
00181 
00182     // file transfer from server
00183     fileHandle_t download;
00184     char        downloadTempName[MAX_OSPATH];
00185     char        downloadName[MAX_OSPATH];
00186     int         downloadNumber;
00187     int         downloadBlock;  // block we are waiting for
00188     int         downloadCount;  // how many bytes we got
00189     int         downloadSize;   // how many bytes we got
00190     char        downloadList[MAX_INFO_STRING]; // list of paks we need to download
00191     qboolean    downloadRestart;    // if true, we need to do another FS_Restart because we downloaded a pak
00192 
00193     // demo information
00194     char        demoName[MAX_QPATH];
00195     qboolean    spDemoRecording;
00196     qboolean    demorecording;
00197     qboolean    demoplaying;
00198     qboolean    demowaiting;    // don't record until a non-delta message is received
00199     qboolean    firstDemoFrameSkipped;
00200     fileHandle_t    demofile;
00201 
00202     int         timeDemoFrames;     // counter of rendered frames
00203     int         timeDemoStart;      // cls.realtime before first frame
00204     int         timeDemoBaseTime;   // each frame will be at this time + frameNum * 50
00205 
00206     // big stuff at end of structure so most offsets are 15 bits or less
00207     netchan_t   netchan;
00208 } clientConnection_t;
00209 
00210 extern  clientConnection_t clc;
00211 
00212 /*
00213 ==================================================================
00214 
00215 the clientStatic_t structure is never wiped, and is used even when
00216 no client connection is active at all
00217 
00218 ==================================================================
00219 */
00220 
00221 typedef struct {
00222     netadr_t    adr;
00223     int         start;
00224     int         time;
00225     char        info[MAX_INFO_STRING];
00226 } ping_t;
00227 
00228 typedef struct {
00229     netadr_t    adr;
00230     char        hostName[MAX_NAME_LENGTH];
00231     char        mapName[MAX_NAME_LENGTH];
00232     char        game[MAX_NAME_LENGTH];
00233     int         netType;
00234     int         gameType;
00235     int         clients;
00236     int         maxClients;
00237     int         minPing;
00238     int         maxPing;
00239     int         ping;
00240     qboolean    visible;
00241     int         punkbuster;
00242 } serverInfo_t;
00243 
00244 typedef struct {
00245     byte    ip[4];
00246     unsigned short  port;
00247 } serverAddress_t;
00248 
00249 typedef struct {
00250     connstate_t state;              // connection status
00251     int         keyCatchers;        // bit flags
00252 
00253     qboolean    cddialog;           // bring up the cd needed dialog next frame
00254 
00255     char        servername[MAX_OSPATH];     // name of server from original connect (used by reconnect)
00256 
00257     // when the server clears the hunk, all of these must be restarted
00258     qboolean    rendererStarted;
00259     qboolean    soundStarted;
00260     qboolean    soundRegistered;
00261     qboolean    uiStarted;
00262     qboolean    cgameStarted;
00263 
00264     int         framecount;
00265     int         frametime;          // msec since last frame
00266 
00267     int         realtime;           // ignores pause
00268     int         realFrametime;      // ignoring pause, so console always works
00269 
00270     int         numlocalservers;
00271     serverInfo_t    localServers[MAX_OTHER_SERVERS];
00272 
00273     int         numglobalservers;
00274     serverInfo_t  globalServers[MAX_GLOBAL_SERVERS];
00275     // additional global servers
00276     int         numGlobalServerAddresses;
00277     serverAddress_t     globalServerAddresses[MAX_GLOBAL_SERVERS];
00278 
00279     int         numfavoriteservers;
00280     serverInfo_t    favoriteServers[MAX_OTHER_SERVERS];
00281 
00282     int         nummplayerservers;
00283     serverInfo_t    mplayerServers[MAX_OTHER_SERVERS];
00284 
00285     int pingUpdateSource;       // source currently pinging or updating
00286 
00287     int masterNum;
00288 
00289     // update server info
00290     netadr_t    updateServer;
00291     char        updateChallenge[MAX_TOKEN_CHARS];
00292     char        updateInfoString[MAX_INFO_STRING];
00293 
00294     netadr_t    authorizeServer;
00295 
00296     // rendering info
00297     glconfig_t  glconfig;
00298     qhandle_t   charSetShader;
00299     qhandle_t   whiteShader;
00300     qhandle_t   consoleShader;
00301 } clientStatic_t;
00302 
00303 extern  clientStatic_t      cls;
00304 
00305 //=============================================================================
00306 
00307 extern  vm_t            *cgvm;  // interface to cgame dll or vm
00308 extern  vm_t            *uivm;  // interface to ui dll or vm
00309 extern  refexport_t     re;     // interface to refresh .dll
00310 
00311 
00312 //
00313 // cvars
00314 //
00315 extern  cvar_t  *cl_nodelta;
00316 extern  cvar_t  *cl_debugMove;
00317 extern  cvar_t  *cl_noprint;
00318 extern  cvar_t  *cl_timegraph;
00319 extern  cvar_t  *cl_maxpackets;
00320 extern  cvar_t  *cl_packetdup;
00321 extern  cvar_t  *cl_shownet;
00322 extern  cvar_t  *cl_showSend;
00323 extern  cvar_t  *cl_timeNudge;
00324 extern  cvar_t  *cl_showTimeDelta;
00325 extern  cvar_t  *cl_freezeDemo;
00326 
00327 extern  cvar_t  *cl_yawspeed;
00328 extern  cvar_t  *cl_pitchspeed;
00329 extern  cvar_t  *cl_run;
00330 extern  cvar_t  *cl_anglespeedkey;
00331 
00332 extern  cvar_t  *cl_sensitivity;
00333 extern  cvar_t  *cl_freelook;
00334 
00335 extern  cvar_t  *cl_mouseAccel;
00336 extern  cvar_t  *cl_showMouseRate;
00337 
00338 extern  cvar_t  *m_pitch;
00339 extern  cvar_t  *m_yaw;
00340 extern  cvar_t  *m_forward;
00341 extern  cvar_t  *m_side;
00342 extern  cvar_t  *m_filter;
00343 
00344 extern  cvar_t  *cl_timedemo;
00345 
00346 extern  cvar_t  *cl_activeAction;
00347 
00348 extern  cvar_t  *cl_allowDownload;
00349 extern  cvar_t  *cl_conXOffset;
00350 extern  cvar_t  *cl_inGameVideo;
00351 
00352 //=================================================
00353 
00354 //
00355 // cl_main
00356 //
00357 
00358 void CL_Init (void);
00359 void CL_FlushMemory(void);
00360 void CL_ShutdownAll(void);
00361 void CL_AddReliableCommand( const char *cmd );
00362 
00363 void CL_StartHunkUsers( void );
00364 
00365 void CL_Disconnect_f (void);
00366 void CL_GetChallengePacket (void);
00367 void CL_Vid_Restart_f( void );
00368 void CL_Snd_Restart_f (void);
00369 void CL_StartDemoLoop( void );
00370 void CL_NextDemo( void );
00371 void CL_ReadDemoMessage( void );
00372 
00373 void CL_InitDownloads(void);
00374 void CL_NextDownload(void);
00375 
00376 void CL_GetPing( int n, char *buf, int buflen, int *pingtime );
00377 void CL_GetPingInfo( int n, char *buf, int buflen );
00378 void CL_ClearPing( int n );
00379 int CL_GetPingQueueCount( void );
00380 
00381 void CL_ShutdownRef( void );
00382 void CL_InitRef( void );
00383 qboolean CL_CDKeyValidate( const char *key, const char *checksum );
00384 int CL_ServerStatus( char *serverAddress, char *serverStatusString, int maxLen );
00385 
00386 
00387 //
00388 // cl_input
00389 //
00390 typedef struct {
00391     int         down[2];        // key nums holding it down
00392     unsigned    downtime;       // msec timestamp
00393     unsigned    msec;           // msec down this frame if both a down and up happened
00394     qboolean    active;         // current state
00395     qboolean    wasPressed;     // set when down, not cleared when up
00396 } kbutton_t;
00397 
00398 extern  kbutton_t   in_mlook, in_klook;
00399 extern  kbutton_t   in_strafe;
00400 extern  kbutton_t   in_speed;
00401 
00402 void CL_InitInput (void);
00403 void CL_SendCmd (void);
00404 void CL_ClearState (void);
00405 void CL_ReadPackets (void);
00406 
00407 void CL_WritePacket( void );
00408 void IN_CenterView (void);
00409 
00410 void CL_VerifyCode( void );
00411 
00412 float CL_KeyState (kbutton_t *key);
00413 char *Key_KeynumToString (int keynum);
00414 
00415 //
00416 // cl_parse.c
00417 //
00418 extern int cl_connectedToPureServer;
00419 
00420 void CL_SystemInfoChanged( void );
00421 void CL_ParseServerMessage( msg_t *msg );
00422 
00423 //====================================================================
00424 
00425 void    CL_ServerInfoPacket( netadr_t from, msg_t *msg );
00426 void    CL_LocalServers_f( void );
00427 void    CL_GlobalServers_f( void );
00428 void    CL_FavoriteServers_f( void );
00429 void    CL_Ping_f( void );
00430 qboolean CL_UpdateVisiblePings_f( int source );
00431 
00432 
00433 //
00434 // console
00435 //
00436 void Con_DrawCharacter (int cx, int line, int num);
00437 
00438 void Con_CheckResize (void);
00439 void Con_Init (void);
00440 void Con_Clear_f (void);
00441 void Con_ToggleConsole_f (void);
00442 void Con_DrawNotify (void);
00443 void Con_ClearNotify (void);
00444 void Con_RunConsole (void);
00445 void Con_DrawConsole (void);
00446 void Con_PageUp( void );
00447 void Con_PageDown( void );
00448 void Con_Top( void );
00449 void Con_Bottom( void );
00450 void Con_Close( void );
00451 
00452 
00453 //
00454 // cl_scrn.c
00455 //
00456 void    SCR_Init (void);
00457 void    SCR_UpdateScreen (void);
00458 
00459 void    SCR_DebugGraph (float value, int color);
00460 
00461 int     SCR_GetBigStringWidth( const char *str );   // returns in virtual 640x480 coordinates
00462 
00463 void    SCR_AdjustFrom640( float *x, float *y, float *w, float *h );
00464 void    SCR_FillRect( float x, float y, float width, float height, 
00465                      const float *color );
00466 void    SCR_DrawPic( float x, float y, float width, float height, qhandle_t hShader );
00467 void    SCR_DrawNamedPic( float x, float y, float width, float height, const char *picname );
00468 
00469 void    SCR_DrawBigString( int x, int y, const char *s, float alpha );          // draws a string with embedded color control characters with fade
00470 void    SCR_DrawBigStringColor( int x, int y, const char *s, vec4_t color );    // ignores embedded color control characters
00471 void    SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, qboolean forceColor );
00472 void    SCR_DrawSmallChar( int x, int y, int ch );
00473 
00474 
00475 //
00476 // cl_cin.c
00477 //
00478 
00479 void CL_PlayCinematic_f( void );
00480 void SCR_DrawCinematic (void);
00481 void SCR_RunCinematic (void);
00482 void SCR_StopCinematic (void);
00483 int CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits);
00484 e_status CIN_StopCinematic(int handle);
00485 e_status CIN_RunCinematic (int handle);
00486 void CIN_DrawCinematic (int handle);
00487 void CIN_SetExtents (int handle, int x, int y, int w, int h);
00488 void CIN_SetLooping (int handle, qboolean loop);
00489 void CIN_UploadCinematic(int handle);
00490 void CIN_CloseAllVideos(void);
00491 
00492 //
00493 // cl_cgame.c
00494 //
00495 void CL_InitCGame( void );
00496 void CL_ShutdownCGame( void );
00497 qboolean CL_GameCommand( void );
00498 void CL_CGameRendering( stereoFrame_t stereo );
00499 void CL_SetCGameTime( void );
00500 void CL_FirstSnapshot( void );
00501 void CL_ShaderStateChanged(void);
00502 
00503 //
00504 // cl_ui.c
00505 //
00506 void CL_InitUI( void );
00507 void CL_ShutdownUI( void );
00508 int Key_GetCatcher( void );
00509 void Key_SetCatcher( int catcher );
00510 void LAN_LoadCachedServers();
00511 void LAN_SaveServersToCache();
00512 
00513 
00514 //
00515 // cl_net_chan.c
00516 //
00517 void CL_Netchan_Transmit( netchan_t *chan, msg_t* msg); //int length, const byte *data );
00518 void CL_Netchan_TransmitNextFragment( netchan_t *chan );
00519 qboolean CL_Netchan_Process( netchan_t *chan, msg_t *msg );

Generated on Thu Aug 25 12:37:27 2005 for Quake III Arena by  doxygen 1.3.9.1