1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
|
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// client.h -- primary header for client
#include "com_local.h"
#include "q_list.h"
#include "files.h"
#include "sys_public.h"
#include "pmove.h"
#include "bsp.h"
#include "cmodel.h"
#include "protocol.h"
#include "q_msg.h"
#include "net_sock.h"
#include "net_chan.h"
#include "q_field.h"
#include "ref_public.h"
#include "key_public.h"
#include "snd_public.h"
#include "cl_public.h"
#include "ui_public.h"
#include "sv_public.h"
#if USE_ZLIB
#include <zlib.h>
#endif
//=============================================================================
typedef struct centity_s {
entity_state_t current;
entity_state_t prev; // will always be valid, but might just be a copy of current
vec3_t mins, maxs;
int serverframe; // if not current, this ent isn't in the frame
int trailcount; // for diminishing grenade trails
vec3_t lerp_origin; // for trails (variable hz)
int fly_stoptime;
} centity_t;
#define MAX_CLIENTWEAPONMODELS 20 // PGM -- upped from 16 to fit the chainfist vwep
typedef struct clientinfo_s {
char name[MAX_QPATH];
qhandle_t skin;
qhandle_t icon;
char model_name[MAX_QPATH];
char skin_name[MAX_QPATH];
qhandle_t model;
qhandle_t weaponmodel[MAX_CLIENTWEAPONMODELS];
} clientinfo_t;
typedef struct {
unsigned sent; // time sent, for calculating pings
unsigned rcvd; // time rcvd, for calculating pings
unsigned cmdNumber; // current cmdNumber for this frame
} client_history_t;
typedef struct {
qboolean valid;
int number;
int delta;
byte areabits[MAX_MAP_AREAS / 8];
int areabytes;
player_state_t ps;
int clientNum;
int numEntities;
int firstEntity;
} server_frame_t;
typedef enum {
LOAD_MAP,
LOAD_MODELS,
LOAD_IMAGES,
LOAD_CLIENTS,
LOAD_SOUNDS,
LOAD_FINISH
} load_state_t;
//
// the client_state_t structure is wiped completely at every
// server map change
//
typedef struct client_state_s {
int timeoutcount;
unsigned lastTransmitTime;
unsigned lastTransmitCmdNumber;
qboolean sendPacketNow;
usercmd_t cmd;
usercmd_t cmds[CMD_BACKUP]; // each mesage will send several old cmds
unsigned cmdNumber;
short predicted_origins[CMD_BACKUP][3]; // for debug comparing against server
client_history_t history[CMD_BACKUP];
int initialSeq;
float predicted_step; // for stair up smoothing
unsigned predicted_step_time;
unsigned predicted_step_frame;
vec3_t move;
vec3_t predicted_origin; // generated by CL_PredictMovement
vec3_t predicted_angles;
vec3_t predicted_velocity;
vec3_t prediction_error;
// rebuilt each valid frame
centity_t *solidEntities[MAX_PACKET_ENTITIES];
int numSolidEntities;
entity_state_t baselines[MAX_EDICTS];
entity_state_t entityStates[MAX_PARSE_ENTITIES];
int numEntityStates;
server_frame_t frames[UPDATE_BACKUP];
server_frame_t frame; // received from server
server_frame_t oldframe;
int servertime;
int serverdelta;
frameflags_t frameflags;
int lastframe;
int demoframe;
int demodelta;
byte dcs[CS_BITMAP_BYTES];
// the client maintains its own idea of view angles, which are
// sent to the server each frame. It is cleared to 0 upon entering each level.
// the server sends a delta each frame which is added to the locally
// tracked view angles to account for standing on rotating objects,
// and teleport direction changes
vec3_t viewangles;
#if USE_SMOOTH_DELTA_ANGLES
short delta_angles[3]; // interpolated
#endif
int time; // this is the time value that the client
// is rendering at. always <= cls.realtime
float lerpfrac; // between oldframe and frame
int frametime; // fixed server frame time
float framefrac;
refdef_t refdef;
int lightlevel;
vec3_t v_forward, v_right, v_up; // set when refdef.angles is set
qboolean thirdPersonView;
// predicted values, used for smooth player entity movement in thirdperson view
vec3_t playerEntityOrigin;
vec3_t playerEntityAngles;
//
// transient data from server
//
char layout[MAX_STRING_CHARS]; // general 2D overlay
int inventory[MAX_ITEMS];
qboolean putaway;
//
// server state information
//
int servercount; // server identification for prespawns
char gamedir[MAX_QPATH];
int clientNum; // never changed during gameplay, set by serverdata packet
int maxclients;
pmoveParams_t pmp;
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
char mapname[MAX_QPATH]; // short format - q2dm1, etc
#if USE_AUTOREPLY
unsigned reply_time;
unsigned reply_delta;
#endif
load_state_t load_state;
unsigned load_time[ LOAD_FINISH + 1 ];
//
// locally derived information from server state
//
bsp_t *bsp;
qhandle_t model_draw[MAX_MODELS];
mmodel_t *model_clip[MAX_MODELS];
qhandle_t sound_precache[MAX_SOUNDS];
qhandle_t image_precache[MAX_IMAGES];
clientinfo_t clientinfo[MAX_CLIENTS];
clientinfo_t baseclientinfo;
char weaponModels[MAX_CLIENTWEAPONMODELS][MAX_QPATH];
int numWeaponModels;
} client_state_t;
extern client_state_t cl;
int CL_GetSoundInfo( vec3_t origin, vec3_t forward, vec3_t right, vec3_t up );
/*
==================================================================
the client_static_t structure is persistant through an arbitrary number
of server connections
==================================================================
*/
#define CONNECT_DELAY 3000
typedef enum {
ca_uninitialized,
ca_disconnected, // not talking to a server
ca_challenging, // sending getchallenge packets to the server
ca_connecting, // sending connect packets to the server
ca_connected, // netchan_t established, waiting for svc_serverdata
ca_loading, // loading level data
ca_precached, // loaded level data, waiting for svc_frame
ca_active // game views should be displayed
} connstate_t;
typedef struct client_static_s {
connstate_t state;
keydest_t key_dest;
active_t active;
qboolean ref_initialized;
qboolean _unused1;
qboolean _unused2;
int userinfo_modified;
cvar_t *userinfo_updates[MAX_PACKET_USERINFOS];
// this is set each time a CVAR_USERINFO variable is changed
// so that the client knows to send it to the server
int framecount;
unsigned realtime; // always increasing, no clamping, etc
float frametime; // seconds since last frame
unsigned measureFramecount;
unsigned measureTime;
int fps, ping;
// connection information
netadr_t serverAddress;
char servername[MAX_OSPATH]; // name of server from original connect
unsigned connect_time; // for connection retransmits
int connect_count;
char messageString[MAX_STRING_CHARS];
qboolean passive;
#if USE_ZLIB
z_stream z;
#endif
int quakePort; // a 16 bit value that allows quake servers
// to work around address translating routers
netchan_t *netchan;
int serverProtocol; // in case we are doing some kind of version hack
int protocolVersion; // minor version
int challenge; // from the server to use for connecting
struct {
fileHandle_t file; // file transfer from server
char temp[MAX_QPATH];
char name[MAX_QPATH];
int percent;
} download;
// demo recording info must be here, so it isn't cleared on level change
struct {
fileHandle_t playback;
fileHandle_t recording;
unsigned time_start;
unsigned time_frames;
int file_size;
int file_offset;
int file_percent;
sizebuf_t buffer;
qboolean paused;
} demo;
} client_static_t;
extern client_static_t cls;
//=============================================================================
#define NOPART_GRENADE_EXPLOSION 1
#define NOPART_GRENADE_TRAIL 2
#define NOPART_ROCKET_EXPLOSION 4
#define NOPART_ROCKET_TRAIL 8
#define NOPART_BLOOD 16
#define NOEXP_GRENADE 1
#define NOEXP_ROCKET 2
//
// cvars
//
extern cvar_t *cl_gun;
extern cvar_t *cl_add_blend;
extern cvar_t *cl_add_lights;
extern cvar_t *cl_add_particles;
extern cvar_t *cl_add_entities;
extern cvar_t *cl_predict;
extern cvar_t *cl_footsteps;
extern cvar_t *cl_noskins;
extern cvar_t *cl_kickangles;
extern cvar_t *cl_rollhack;
extern cvar_t *cl_shownet;
extern cvar_t *cl_showmiss;
extern cvar_t *cl_showclamp;
extern cvar_t *cl_vwep;
extern cvar_t *cl_disable_particles;
extern cvar_t *cl_disable_explosions;
extern cvar_t *cl_chat_notify;
extern cvar_t *cl_chat_sound;
extern cvar_t *cl_chat_filter;
extern cvar_t *cl_disconnectcmd;
extern cvar_t *cl_changemapcmd;
extern cvar_t *cl_beginmapcmd;
extern cvar_t *cl_gibs;
extern cvar_t *cl_demo_local_fov;
extern cvar_t *cl_thirdperson;
extern cvar_t *cl_thirdperson_angle;
extern cvar_t *cl_thirdperson_range;
extern cvar_t *cl_async;
//
// userinfo
//
extern cvar_t *info_password;
extern cvar_t *info_spectator;
extern cvar_t *info_name;
extern cvar_t *info_skin;
extern cvar_t *info_rate;
extern cvar_t *info_fov;
extern cvar_t *info_msg;
extern cvar_t *info_hand;
extern cvar_t *info_gender;
extern cvar_t *info_uf;
typedef struct cdlight_s {
int key; // so entities can reuse same entry
vec3_t color;
vec3_t origin;
float radius;
float die; // stop lighting after this time
float decay; // drop this each second
float minlight; // don't add when contributing less
} cdlight_t;
extern centity_t cl_entities[MAX_EDICTS];
extern cdlight_t cl_dlights[MAX_DLIGHTS];
//=============================================================================
void CL_AddNetgraph (void);
//ROGUE
typedef struct cl_sustain_s {
int id;
int type;
int endtime;
int nextthink;
int thinkinterval;
vec3_t org;
vec3_t dir;
int color;
int count;
int magnitude;
void (*think)(struct cl_sustain_s *self);
} cl_sustain_t;
#define MAX_SUSTAINS 32
void CL_ParticleSteamEffect2(cl_sustain_t *self);
void CL_TeleporterParticles (entity_state_t *ent);
void CL_ParticleEffect (vec3_t org, vec3_t dir, int color, int count);
void CL_ParticleEffect2 (vec3_t org, vec3_t dir, int color, int count);
// RAFAEL
void CL_ParticleEffect3 (vec3_t org, vec3_t dir, int color, int count);
//=================================================
// ========
// PGM
typedef struct cparticle_s{
struct cparticle_s *next;
float time;
vec3_t org;
vec3_t vel;
vec3_t accel;
float color;
float colorvel;
float alpha;
float alphavel;
color_t rgb;
} cparticle_t;
#define PARTICLE_GRAVITY 40
#define BLASTER_PARTICLE_COLOR 0xe0
// PMM
#define INSTANT_PARTICLE -10000.0
// PGM
// ========
void CL_InitEffects (void);
void CL_ClearEffects (void);
void CL_ClearTEnts (void);
void CL_BlasterTrail (vec3_t start, vec3_t end);
void CL_QuadTrail (vec3_t start, vec3_t end);
void CL_RailTrail (vec3_t start, vec3_t end);
void CL_BubbleTrail (vec3_t start, vec3_t end);
void CL_FlagTrail (vec3_t start, vec3_t end, float color);
// RAFAEL
void CL_IonripperTrail (vec3_t start, vec3_t end);
// ========
// PGM
void CL_BlasterParticles2 (vec3_t org, vec3_t dir, unsigned int color);
void CL_BlasterTrail2 (vec3_t start, vec3_t end);
void CL_DebugTrail (vec3_t start, vec3_t end);
void CL_SmokeTrail (vec3_t start, vec3_t end, int colorStart, int colorRun, int spacing);
void CL_Flashlight (int ent, vec3_t pos);
void CL_ForceWall (vec3_t start, vec3_t end, int color);
void CL_FlameEffects (centity_t *ent, vec3_t origin);
void CL_GenericParticleEffect (vec3_t org, vec3_t dir, int color, int count, int numcolors, int dirspread, float alphavel);
void CL_BubbleTrail2 (vec3_t start, vec3_t end, int dist);
void CL_Heatbeam (vec3_t start, vec3_t end);
void CL_ParticleSteamEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude);
void CL_TrackerTrail (vec3_t start, vec3_t end, int particleColor);
void CL_Tracker_Explode(vec3_t origin);
void CL_TagTrail (vec3_t start, vec3_t end, float color);
void CL_ColorFlash (vec3_t pos, int ent, int intensity, float r, float g, float b);
void CL_Tracker_Shell(vec3_t origin);
void CL_MonsterPlasma_Shell(vec3_t origin);
void CL_ColorExplosionParticles (vec3_t org, int color, int run);
void CL_ParticleSmokeEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude);
void CL_Widowbeamout (cl_sustain_t *self);
void CL_Nukeblast (cl_sustain_t *self);
void CL_WidowSplash (vec3_t org);
// PGM
// ========
void CL_ParseTEnt (void);
void CL_ParseMuzzleFlash (void);
void CL_ParseMuzzleFlash2 (void);
void SmokeAndFlash(vec3_t origin);
void CL_SetLightstyle( int index, const char *string, size_t length );
void CL_RunParticles (void);
void CL_RunDLights (void);
void CL_RunLightStyles (void);
void CL_AddEntities (void);
void CL_AddDLights (void);
void CL_AddTEnts (void);
void CL_AddLightStyles (void);
//=================================================
//
// cl_main
//
void CL_Init (void);
void CL_Quit_f (void);
void CL_Disconnect( comErrorType_t type, const char *text );
void CL_RequestNextDownload (void);
void CL_ClearState (void);
void CL_RestartFilesystem( void );
void CL_RestartRefresh( void );
void CL_ClientCommand( const char *string );
void CL_UpdateLocalFovSetting( void );
void CL_LoadState( load_state_t state );
void CL_SendRcon( const netadr_t *adr, const char *pass, const char *cmd );
const char *CL_Server_g( const char *partial, int argnum, int state );
// the sound code makes callbacks to the client for entitiy position
// information, so entities can be dynamically re-spatialized
void CL_GetEntitySoundOrigin( int ent, vec3_t org );
//
// cl_input
//
void IN_Init( void );
void IN_Shutdown( void );
void IN_Frame( void );
void IN_Activate( void );
void CL_RegisterInput( void );
void CL_UpdateCmd( int msec );
void CL_FinalizeCmd( void );
void CL_SendCmd( void );
//
// cl_parse.c
//
qboolean CL_CheckOrDownloadFile( const char *filename );
void CL_ParseServerMessage (void);
void CL_LoadClientinfo (clientinfo_t *ci, const char *s);
void CL_Download_f (void);
void CL_DeltaFrame( void );
//
// cl_view.c
//
extern int gun_frame;
extern qhandle_t gun_model;
void V_Init( void );
void V_Shutdown( void );
void V_RenderView( void );
void V_AddEntity (entity_t *ent);
void V_AddParticle( particle_t *p );
void V_AddLight (vec3_t org, float intensity, float r, float g, float b);
void V_AddLightStyle (int style, vec4_t value);
void CL_PrepRefresh (void);
//
// cl_tent.c
//
void CL_RegisterTEntSounds (void);
void CL_RegisterTEntModels (void);
void CL_SmokeAndFlash(vec3_t origin);
#define LASER_FADE_NOT 1
#define LASER_FADE_ALPHA 2
#define LASER_FADE_RGBA 3
typedef struct laser_s {
entity_t ent;
vec3_t start;
vec3_t end;
int fadeType;
qboolean indexed;
color_t color;
float width;
int lifeTime;
int startTime;
} laser_t;
laser_t *CL_AllocLaser( void );
//
// cl_pred.c
//
void CL_PredictMovement (void);
void CL_CheckPredictionError (void);
//
// cl_fx.c
//
cdlight_t *CL_AllocDlight (int key);
void CL_BigTeleportParticles (vec3_t org);
void CL_RocketTrail (vec3_t start, vec3_t end, centity_t *old);
void CL_DiminishingTrail (vec3_t start, vec3_t end, centity_t *old, int flags);
void CL_FlyEffect (centity_t *ent, vec3_t origin);
void CL_BfgParticles (entity_t *ent);
void CL_AddParticles (void);
void CL_EntityEvent (entity_state_t *ent);
// RAFAEL
void CL_TrapParticles (entity_t *ent);
//
// cl_demo.c
//
void CL_InitDemos( void );
void CL_DemoFrame( void );
void CL_EmitZeroFrame( void );
void CL_WriteDemoMessage( sizebuf_t *buf );
void CL_EmitDemoFrame( void );
void CL_Stop_f( void );
demoInfo_t *CL_GetDemoInfo( const char *path, demoInfo_t *info );
//
// cl_locs.c
//
void LOC_Init( void );
void LOC_LoadLocations( void );
void LOC_FreeLocations( void );
void LOC_UpdateCvars( void );
void LOC_AddLocationsToScene( void );
//
// cl_console.c
//
void Con_Init( void );
void Con_PostInit( void );
void Con_Shutdown( void );
void Con_DrawConsole( void );
void Con_RunConsole( void );
void Con_Print( const char *txt );
void Con_ClearNotify_f( void );
void Con_ToggleConsole_f (void);
void Con_ClearTyping( void );
void Con_Close( void );
void Con_SkipNotify( qboolean skip );
void Con_RegisterMedia( void );
void Key_Console( int key );
void Key_Message( int key );
void Char_Console( int key );
void Char_Message( int key );
//
// cl_ref.c
//
void CL_InitRefresh( void );
void CL_ShutdownRefresh( void );
void CL_RunRefresh( void );
//
// cl_ui.c
//
void CL_InitUI( void );
void CL_ShutdownUI( void );
//
// cl_scrn.c
//
extern cvar_t *scr_viewsize;
extern cvar_t *scr_draw2d;
extern cvar_t *crosshair;
extern qhandle_t crosshair_pic;
extern int crosshair_width, crosshair_height;
extern qhandle_t scr_net;
extern qhandle_t scr_font;
extern glconfig_t scr_glconfig;
extern vrect_t scr_vrect; // position of render window
extern int scr_hudWidth;
extern int scr_hudHeight;
void SCR_Init (void);
void SCR_Shutdown( void );
void SCR_UpdateScreen (void);
void SCR_SizeUp( void );
void SCR_SizeDown( void );
void SCR_CenterPrint( const char *str );
void SCR_BeginLoadingPlaque( void );
void SCR_EndLoadingPlaque( void );
void SCR_DebugGraph ( float value, int color );
void SCR_TouchPics ( void );
void SCR_RegisterMedia( void );
void SCR_ModeChanged( void );
void SCR_RunConsole (void);
void SCR_ExecuteLayoutString( const char *s );
void SCR_DrawInventory( void );
void SCR_DrawPause( void );
void SCR_DrawNet( void );
void SCR_DrawCenterString( void );
//
// cl_cin.c
//
void SCR_PlayCinematic( const char *name );
qboolean SCR_DrawCinematic( void );
void SCR_RunCinematic( void );
void SCR_StopCinematic( void );
void SCR_FinishCinematic( void );
//
// cl_draw.c
//
void SCR_InitDraw( void );
void SCR_ShutdownDraw( void );
void SCR_Draw2D( void );
void SCR_DrawLoading( void );
float SCR_FadeAlpha( unsigned startTime, unsigned visTime, unsigned fadeTime );
#if USE_CHATHUD
void SCR_ClearChatHUD_f( void );
void SCR_AddToChatHUD( const char *string );
#endif
void SCR_LagSample( void );
void SCR_LagClear( void );
int SCR_DrawStringEx( int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font );
void SCR_DrawStringMulti( int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font );
//
// cl_keys.c
//
void Key_Init( void );
void Key_Event( unsigned key, qboolean down, unsigned time );
void Key_CharEvent( int key );
void Key_WriteBindings( fileHandle_t f );
//
// cl_aastat.c
//
void CL_InitAscii( void );
|