Debian Codegraph @

code/client/client.h

raw symbols SCIP
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 Quake III Arena source code; 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 "../qcommon/q_shared.h"
25 #include "../qcommon/qcommon.h"
26 #include "../renderercommon/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 #ifdef USE_HTTP
34 #include "cl_http.h"
35 #endif /* USE_HTTP */
36
37 #ifdef USE_VOIP
38 #include <opus.h>
39 #endif
40
41 // file full of random crap that gets used to create cl_guid
42 #define QKEY_FILE "qkey"
43 #define QKEY_SIZE 2048
44
45 #define RETRANSMIT_TIMEOUT 3000 // time between connection packet retransmits
46
47 // snapshots are a view of the server at a given time
48 typedef struct {
49 qboolean valid; // cleared if delta parsing was invalid
50 int snapFlags; // rate delayed and dropped commands
51
52 int serverTime; // server time the message is valid for (in msec)
53
54 int messageNum; // copied from netchan->incoming_sequence
55 int deltaNum; // messageNum the delta is from
56 int ping; // time from when cmdNum-1 was sent to time packet was reeceived
57 byte areamask[MAX_MAP_AREA_BYTES]; // portalarea visibility bits
58
59 int cmdNum; // the next cmdNum the server is expecting
60 playerState_t ps; // complete information about the current player at this time
61
62 int numEntities; // all of the entities that need to be presented
63 int parseEntitiesNum; // at the time of this snapshot
64
65 int serverCommandNum; // execute all commands up to this before
66 // making the snapshot current
67 } clSnapshot_t;
68
69
70
71 /*
72 =============================================================================
73
74 the clientActive_t structure is wiped completely at every
75 new gamestate_t, potentially several times during an established connection
76
77 =============================================================================
78 */
79
80 typedef struct {
81 int p_cmdNumber; // cl.cmdNumber when packet was sent
82 int p_serverTime; // usercmd->serverTime when packet was sent
83 int p_realtime; // cls.realtime when packet was sent
84 } outPacket_t;
85
86 // the parseEntities array must be large enough to hold PACKET_BACKUP frames of
87 // entities, so that when a delta compressed message arives from the server
88 // it can be un-deltad from the original
89 #define MAX_PARSE_ENTITIES ( PACKET_BACKUP * MAX_SNAPSHOT_ENTITIES )
90
91 extern int g_console_field_width;
92
93 typedef struct {
94 int timeoutcount; // it requres several frames in a timeout condition
95 // to disconnect, preventing debugging breaks from
96 // causing immediate disconnects on continue
97 clSnapshot_t snap; // latest received from server
98
99 int serverTime; // may be paused during play
100 int oldServerTime; // to prevent time from flowing bakcwards
101 int oldFrameServerTime; // to check tournament restarts
102 int serverTimeDelta; // cl.serverTime = cls.realtime + cl.serverTimeDelta
103 // this value changes as net lag varies
104 qboolean extrapolatedSnapshot; // set if any cgame frame has been forced to extrapolate
105 // cleared when CL_AdjustTimeDelta looks at it
106 qboolean newSnapshots; // set on parse of any valid packet
107
108 gameState_t gameState; // configstrings
109 char mapname[MAX_QPATH]; // extracted from CS_SERVERINFO
110
111 int parseEntitiesNum; // index (not anded off) into cl_parse_entities[]
112
113 int mouseDx[2], mouseDy[2]; // added to by mouse events
114 int mouseIndex;
115 int joystickAxis[MAX_JOYSTICK_AXIS]; // set by joystick events
116
117 // cgame communicates a few values to the client system
118 int cgameUserCmdValue; // current weapon to add to usercmd_t
119 float cgameSensitivity;
120
121 // cmds[cmdNumber] is the predicted command, [cmdNumber-1] is the last
122 // properly generated command
123 usercmd_t cmds[CMD_BACKUP]; // each mesage will send several old cmds
124 int cmdNumber; // incremented each frame, because multiple
125 // frames may need to be packed into a single packet
126
127 outPacket_t outPackets[PACKET_BACKUP]; // information about each packet we have sent out
128
129 // the client maintains its own idea of view angles, which are
130 // sent to the server each frame. It is cleared to 0 upon entering each level.
131 // the server sends a delta each frame which is added to the locally
132 // tracked view angles to account for standing on rotating objects,
133 // and teleport direction changes
134 vec3_t viewangles;
135
136 int serverId; // included in each client message so the server
137 // can tell if it is for a prior map_restart
138 // big stuff at end of structure so most offsets are 15 bits or less
139 clSnapshot_t snapshots[PACKET_BACKUP];
140
141 entityState_t entityBaselines[MAX_GENTITIES]; // for delta compression when not in previous frame
142
143 entityState_t parseEntities[MAX_PARSE_ENTITIES];
144 } clientActive_t;
145
146 extern clientActive_t cl;
147
148 /*
149 =============================================================================
150
151 the clientConnection_t structure is wiped when disconnecting from a server,
152 either to go to a full screen console, play a demo, or connect to a different server
153
154 A connection can be to either a server through the network layer or a
155 demo through a file.
156
157 =============================================================================
158 */
159
160 #define MAX_TIMEDEMO_DURATIONS 4096
161
162 typedef struct {
163
164 connstate_t state; // connection status
165
166 int clientNum;
167 int lastPacketSentTime; // for retransmits during connection
168 int lastPacketTime; // for timeouts
169
170 char servername[MAX_OSPATH]; // name of server from original connect (used by reconnect)
171 netadr_t serverAddress;
172 int connectTime; // for connection retransmits
173 int connectPacketCount; // for display on connection dialog
174 char serverMessage[MAX_STRING_TOKENS]; // for display on connection dialog
175
176 int challenge; // from the server to use for connecting
177 int checksumFeed; // from the server for checksum calculations
178
179 // these are our reliable messages that go to the server
180 int reliableSequence;
181 int reliableAcknowledge; // the last one the server has executed
182 char reliableCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS];
183
184 // server message (unreliable) and command (reliable) sequence
185 // numbers are NOT cleared at level changes, but continue to
186 // increase as long as the connection is valid
187
188 // message sequence is used by both the network layer and the
189 // delta compression layer
190 int serverMessageSequence;
191
192 // reliable messages received from server
193 int serverCommandSequence;
194 int lastExecutedServerCommand; // last server command grabbed or executed with CL_GetServerCommand
195 char serverCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS];
196
197 // file transfer from server
198 fileHandle_t download;
199 char downloadTempName[MAX_OSPATH];
200 char downloadName[MAX_OSPATH];
201 #ifdef USE_HTTP
202 qboolean httpUsed;
203 qboolean disconnectedForHttpDownload;
204 char downloadURL[MAX_OSPATH];
205 #endif /* USE_HTTP */
206 int sv_allowDownload;
207 char sv_dlURL[MAX_CVAR_VALUE_STRING];
208 int downloadNumber;
209 int downloadBlock; // block we are waiting for
210 int downloadCount; // how many bytes we got
211 int downloadSize; // how many bytes we got
212 char downloadList[MAX_INFO_STRING]; // list of paks we need to download
213 qboolean downloadRestart; // if true, we need to do another FS_Restart because we downloaded a pak
214
215 // demo information
216 char demoName[MAX_QPATH];
217 qboolean spDemoRecording;
218 qboolean demorecording;
219 qboolean demoplaying;
220 qboolean demowaiting; // don't record until a non-delta message is received
221 qboolean firstDemoFrameSkipped;
222 fileHandle_t demofile;
223
224 int timeDemoFrames; // counter of rendered frames
225 int timeDemoStart; // cls.realtime before first frame
226 int timeDemoBaseTime; // each frame will be at this time + frameNum * 50
227 int timeDemoLastFrame;// time the last frame was rendered
228 int timeDemoMinDuration; // minimum frame duration
229 int timeDemoMaxDuration; // maximum frame duration
230 unsigned char timeDemoDurations[ MAX_TIMEDEMO_DURATIONS ]; // log of frame durations
231
232 float aviVideoFrameRemainder;
233 float aviSoundFrameRemainder;
234
235 #ifdef USE_VOIP
236 qboolean voipEnabled;
237 qboolean voipCodecInitialized;
238
239 // incoming data...
240 // !!! FIXME: convert from parallel arrays to array of a struct.
241 OpusDecoder *opusDecoder[MAX_CLIENTS];
242 byte voipIncomingGeneration[MAX_CLIENTS];
243 int voipIncomingSequence[MAX_CLIENTS];
244 float voipGain[MAX_CLIENTS];
245 qboolean voipIgnore[MAX_CLIENTS];
246 qboolean voipMuteAll;
247
248 // outgoing data...
249 // if voipTargets[i / 8] & (1 << (i % 8)),
250 // then we are sending to clientnum i.
251 uint8_t voipTargets[(MAX_CLIENTS + 7) / 8];
252 uint8_t voipFlags;
253 OpusEncoder *opusEncoder;
254 int voipOutgoingDataSize;
255 int voipOutgoingDataFrames;
256 int voipOutgoingSequence;
257 byte voipOutgoingGeneration;
258 byte voipOutgoingData[1024];
259 float voipPower;
260 #endif
261
262 #ifdef LEGACY_PROTOCOL
263 qboolean compat;
264 #endif
265
266 // big stuff at end of structure so most offsets are 15 bits or less
267 netchan_t netchan;
268 } clientConnection_t;
269
270 extern clientConnection_t clc;
271
272 /*
273 ==================================================================
274
275 the clientStatic_t structure is never wiped, and is used even when
276 no client connection is active at all
277 (except when CL_Shutdown is called)
278
279 ==================================================================
280 */
281
282 typedef struct {
283 netadr_t adr;
284 int start;
285 int time;
286 char info[MAX_INFO_STRING];
287 } ping_t;
288
289 typedef struct {
290 netadr_t adr;
291 char hostName[MAX_HOSTNAME_LENGTH];
292 char mapName[MAX_NAME_LENGTH];
293 char game[MAX_NAME_LENGTH];
294 int netType;
295 int gameType;
296 int clients;
297 int maxClients;
298 int minPing;
299 int maxPing;
300 int ping;
301 qboolean visible;
302 int punkbuster;
303 int g_humanplayers;
304 int g_needpass;
305 } serverInfo_t;
306
307 typedef struct {
308 qboolean cddialog; // bring up the cd needed dialog next frame
309
310 // when the server clears the hunk, all of these must be restarted
311 qboolean rendererStarted;
312 qboolean soundStarted;
313 qboolean soundRegistered;
314 qboolean uiStarted;
315 qboolean cgameStarted;
316
317 int framecount;
318 int frametime; // msec since last frame
319
320 int realtime; // ignores pause
321 int realFrametime; // ignoring pause, so console always works
322
323 int numlocalservers;
324 serverInfo_t localServers[MAX_OTHER_SERVERS];
325
326 int numglobalservers;
327 serverInfo_t globalServers[MAX_GLOBAL_SERVERS];
328 // additional global servers
329 int numGlobalServerAddresses;
330 netadr_t globalServerAddresses[MAX_GLOBAL_SERVERS];
331
332 int numfavoriteservers;
333 serverInfo_t favoriteServers[MAX_OTHER_SERVERS];
334
335 int pingUpdateSource; // source currently pinging or updating
336
337 // update server info
338 netadr_t updateServer;
339 char updateChallenge[MAX_TOKEN_CHARS];
340 char updateInfoString[MAX_INFO_STRING];
341
342 netadr_t authorizeServer;
343
344 netadr_t rconAddress;
345
346 // rendering info
347 glconfig_t glconfig;
348 qhandle_t charSetShader;
349 qhandle_t whiteShader;
350 qhandle_t consoleShader;
351 } clientStatic_t;
352
353 extern clientStatic_t cls;
354
355 extern char cl_oldGame[MAX_QPATH];
356 extern qboolean cl_oldGameSet;
357
358 //=============================================================================
359
360 extern vm_t *cgvm; // interface to cgame dll or vm
361 extern vm_t *uivm; // interface to ui dll or vm
362 extern refexport_t re; // interface to refresh .dll
363
364
365 //
366 // cvars
367 //
368 extern cvar_t *cl_nodelta;
369 extern cvar_t *cl_debugMove;
370 extern cvar_t *cl_noprint;
371 extern cvar_t *cl_timegraph;
372 extern cvar_t *cl_maxpackets;
373 extern cvar_t *cl_packetdup;
374 extern cvar_t *cl_shownet;
375 extern cvar_t *cl_showSend;
376 extern cvar_t *cl_timeNudge;
377 extern cvar_t *cl_showTimeDelta;
378 extern cvar_t *cl_freezeDemo;
379
380 extern cvar_t *cl_yawspeed;
381 extern cvar_t *cl_pitchspeed;
382 extern cvar_t *cl_run;
383 extern cvar_t *cl_anglespeedkey;
384
385 extern cvar_t *cl_sensitivity;
386 extern cvar_t *cl_freelook;
387
388 extern cvar_t *cl_mouseAccel;
389 extern cvar_t *cl_mouseAccelOffset;
390 extern cvar_t *cl_mouseAccelStyle;
391 extern cvar_t *cl_showMouseRate;
392
393 extern cvar_t *m_pitch;
394 extern cvar_t *m_yaw;
395 extern cvar_t *m_forward;
396 extern cvar_t *m_side;
397 extern cvar_t *m_filter;
398
399 extern cvar_t *j_pitch;
400 extern cvar_t *j_yaw;
401 extern cvar_t *j_forward;
402 extern cvar_t *j_side;
403 extern cvar_t *j_up;
404 extern cvar_t *j_pitch_axis;
405 extern cvar_t *j_yaw_axis;
406 extern cvar_t *j_forward_axis;
407 extern cvar_t *j_side_axis;
408 extern cvar_t *j_up_axis;
409
410 extern cvar_t *cl_timedemo;
411 extern cvar_t *cl_aviFrameRate;
412 extern cvar_t *cl_aviMotionJpeg;
413
414 extern cvar_t *cl_activeAction;
415
416 extern cvar_t *cl_allowDownload;
417 extern cvar_t *cl_downloadMethod;
418 extern cvar_t *cl_conXOffset;
419 extern cvar_t *cl_inGameVideo;
420
421 extern cvar_t *cl_lanForcePackets;
422 extern cvar_t *cl_autoRecordDemo;
423
424 extern cvar_t *cl_consoleKeys;
425
426 #ifdef USE_MUMBLE
427 extern cvar_t *cl_useMumble;
428 extern cvar_t *cl_mumbleScale;
429 #endif
430
431 #ifdef USE_VOIP
432 // cl_voipSendTarget is a string: "all" to broadcast to everyone, "none" to
433 // send to no one, or a comma-separated list of client numbers:
434 // "0,7,2,23" ... an empty string is treated like "all".
435 extern cvar_t *cl_voipUseVAD;
436 extern cvar_t *cl_voipVADThreshold;
437 extern cvar_t *cl_voipSend;
438 extern cvar_t *cl_voipSendTarget;
439 extern cvar_t *cl_voipGainDuringCapture;
440 extern cvar_t *cl_voipCaptureMult;
441 extern cvar_t *cl_voipShowMeter;
442 extern cvar_t *cl_voip;
443
444 // 20ms at 48k
445 #define VOIP_MAX_FRAME_SAMPLES ( 20 * 48 )
446
447 // 3 frame is 60ms of audio, the max opus will encode at once
448 #define VOIP_MAX_PACKET_FRAMES 3
449 #define VOIP_MAX_PACKET_SAMPLES ( VOIP_MAX_FRAME_SAMPLES * VOIP_MAX_PACKET_FRAMES )
450 #endif
451
452 //=================================================
453
454 //
455 // cl_main
456 //
457
458 void CL_Init (void);
459 void CL_AddReliableCommand(const char *cmd, qboolean isDisconnectCmd);
460
461 void CL_StartHunkUsers( qboolean rendererOnly );
462
463 void CL_Disconnect_f (void);
464 void CL_GetChallengePacket (void);
465 void CL_Vid_Restart_f( void );
466 void CL_Snd_Restart_f (void);
467 void CL_StartDemoLoop( void );
468 void CL_NextDemo( void );
469 void CL_ReadDemoMessage( void );
470 void CL_StopRecord_f(void);
471
472 void CL_InitDownloads(void);
473 void CL_NextDownload(void);
474
475 void CL_GetPing( int n, char *buf, int buflen, int *pingtime );
476 void CL_GetPingInfo( int n, char *buf, int buflen );
477 void CL_ClearPing( int n );
478 int CL_GetPingQueueCount( void );
479
480 void CL_ShutdownRef( void );
481 void CL_InitRef( void );
482 qboolean CL_CDKeyValidate( const char *key, const char *checksum );
483 int CL_ServerStatus( char *serverAddress, char *serverStatusString, int maxLen );
484
485 qboolean CL_CheckPaused(void);
486
487 //
488 // cl_input
489 //
490 typedef struct {
491 int down[2]; // key nums holding it down
492 unsigned downtime; // msec timestamp
493 unsigned msec; // msec down this frame if both a down and up happened
494 qboolean active; // current state
495 qboolean wasPressed; // set when down, not cleared when up
496 } kbutton_t;
497
498 void CL_InitInput(void);
499 void CL_ShutdownInput(void);
500 void CL_SendCmd (void);
501 void CL_ClearState (void);
502 void CL_ReadPackets (void);
503
504 void CL_WritePacket( void );
505 void IN_CenterView (void);
506
507 void CL_VerifyCode( void );
508
509 float CL_KeyState (kbutton_t *key);
510 int Key_StringToKeynum( char *str );
511 char *Key_KeynumToString (int keynum);
512
513 //
514 // cl_parse.c
515 //
516 extern int cl_connectedToPureServer;
517 extern int cl_connectedToCheatServer;
518
519 #ifdef USE_VOIP
520 void CL_Voip_f( void );
521 #endif
522
523 void CL_SystemInfoChanged( void );
524 void CL_ParseServerMessage( msg_t *msg );
525
526 //====================================================================
527
528 void CL_ServerInfoPacket( netadr_t from, msg_t *msg );
529 void CL_LocalServers_f( void );
530 void CL_GlobalServers_f( void );
531 void CL_FavoriteServers_f( void );
532 void CL_Ping_f( void );
533 qboolean CL_UpdateVisiblePings_f( int source );
534
535
536 //
537 // console
538 //
539 extern int g_smallchar_width;
540 extern int g_smallchar_height;
541
542 void Con_DrawCharacter (int cx, int line, int num);
543
544 void Con_CheckResize (void);
545 void Con_Init(void);
546 void Con_Shutdown(void);
547 void Con_Clear_f (void);
548 void Con_ToggleConsole_f (void);
549 void Con_DrawNotify (void);
550 void Con_ClearNotify (void);
551 void Con_RunConsole (void);
552 void Con_DrawConsole (void);
553 void Con_PageUp( void );
554 void Con_PageDown( void );
555 void Con_Top( void );
556 void Con_Bottom( void );
557 void Con_Close( void );
558
559 void CL_LoadConsoleHistory( void );
560 void CL_SaveConsoleHistory( void );
561
562 //
563 // cl_scrn.c
564 //
565 void SCR_Init (void);
566 void SCR_UpdateScreen (void);
567
568 void SCR_DebugGraph (float value);
569
570 int SCR_GetBigStringWidth( const char *str ); // returns in virtual 640x480 coordinates
571
572 void SCR_AdjustFrom640( float *x, float *y, float *w, float *h );
573 void SCR_FillRect( float x, float y, float width, float height,
574 const float *color );
575 void SCR_DrawPic( float x, float y, float width, float height, qhandle_t hShader );
576 void SCR_DrawNamedPic( float x, float y, float width, float height, const char *picname );
577
578 void SCR_DrawBigString( int x, int y, const char *s, float alpha, qboolean noColorEscape ); // draws a string with embedded color control characters with fade
579 void SCR_DrawBigStringColor( int x, int y, const char *s, vec4_t color, qboolean noColorEscape ); // ignores embedded color control characters
580 void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, qboolean forceColor, qboolean noColorEscape );
581 void SCR_DrawSmallChar( int x, int y, int ch );
582
583
584 //
585 // cl_cin.c
586 //
587
588 void CL_PlayCinematic_f( void );
589 void SCR_DrawCinematic (void);
590 void SCR_RunCinematic (void);
591 void SCR_StopCinematic (void);
592 int CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits);
593 e_status CIN_StopCinematic(int handle);
594 e_status CIN_RunCinematic (int handle);
595 void CIN_DrawCinematic (int handle);
596 void CIN_SetExtents (int handle, int x, int y, int w, int h);
597 void CIN_SetLooping (int handle, qboolean loop);
598 void CIN_UploadCinematic(int handle);
599 void CIN_CloseAllVideos(void);
600
601 //
602 // cl_cgame.c
603 //
604 void CL_InitCGame( void );
605 void CL_ShutdownCGame( void );
606 qboolean CL_GameCommand( void );
607 void CL_CGameRendering( stereoFrame_t stereo );
608 void CL_SetCGameTime( void );
609 void CL_FirstSnapshot( void );
610 void CL_ShaderStateChanged(void);
611
612 //
613 // cl_ui.c
614 //
615 void CL_InitUI( void );
616 void CL_ShutdownUI( void );
617 int Key_GetCatcher( void );
618 void Key_SetCatcher( int catcher );
619 void LAN_LoadCachedServers( void );
620 void LAN_SaveServersToCache( void );
621
622
623 //
624 // cl_net_chan.c
625 //
626 void CL_Netchan_Transmit( netchan_t *chan, msg_t* msg); //int length, const byte *data );
627 qboolean CL_Netchan_Process( netchan_t *chan, msg_t *msg );
628
629 //
630 // cl_avi.c
631 //
632 qboolean CL_OpenAVIForWriting( const char *filename );
633 void CL_TakeVideoFrame( void );
634 void CL_WriteAVIVideoFrame( const byte *imageBuffer, int size );
635 void CL_WriteAVIAudioFrame( const byte *pcmBuffer, int size );
636 qboolean CL_CloseAVI( void );
637 qboolean CL_VideoRecording( void );
638
639 //
640 // cl_main.c
641 //
642 void CL_WriteDemoMessage ( msg_t *msg, int headerBytes );
643