]> git.xonotic.org Git - xonotic/darkplaces.git/blob - client.h
protocol/dp8: Implement parting messages
[xonotic/darkplaces.git] / client.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // client.h
21
22 #ifndef CLIENT_H
23 #define CLIENT_H
24
25 #include "matrixlib.h"
26 #include "snd_main.h"
27 #include "view.h"
28 #include "cap.h"
29 #include "cl_parse.h"
30 #include "cl_particles.h"
31 #include "r_stats.h"
32
33 // flags for rtlight rendering
34 #define LIGHTFLAG_NORMALMODE 1
35 #define LIGHTFLAG_REALTIMEMODE 2
36
37 typedef struct tridecal_s
38 {
39         // color and initial alpha value
40         float                   texcoord2f[3][2];
41         float                   vertex3f[3][3];
42         float                   color4f[3][4];
43         float                   plane[4]; // backface culling
44         // how long this decal has lived so far (the actual fade begins at cl_decals_time)
45         float                   lived;
46         // if >= 0 this indicates the decal should follow an animated triangle
47         int                             triangleindex;
48         // for visibility culling
49         int                             surfaceindex;
50         // old decals are killed to obey cl_decals_max
51         unsigned int    decalsequence;
52 }
53 tridecal_t;
54
55 typedef struct decalsystem_s
56 {
57         model_t *model;
58         double lastupdatetime;
59         int maxdecals;
60         int freedecal;
61         int numdecals;
62         tridecal_t *decals;
63         float *vertex3f;
64         float *texcoord2f;
65         float *color4f;
66         int *element3i;
67         unsigned short *element3s;
68 }
69 decalsystem_t;
70
71 typedef struct effect_s
72 {
73         int active;
74         vec3_t origin;
75         double starttime;
76         float framerate;
77         model_t *model;
78         int startframe;
79         int endframe;
80         // these are for interpolation
81         int frame;
82         double frame1time;
83         double frame2time;
84 }
85 cl_effect_t;
86
87 typedef struct beam_s
88 {
89         int             entity;
90         // draw this as lightning polygons, or a model?
91         int             lightning;
92         struct model_s  *model;
93         float   endtime;
94         vec3_t  start, end;
95 }
96 beam_t;
97
98 typedef struct rtlight_particle_s
99 {
100         float origin[3];
101         float color[3];
102 }
103 rtlight_particle_t;
104
105 typedef struct rtlight_s
106 {
107         // note that the world to light matrices are inversely scaled (divided) by lightradius
108
109         // core properties
110         /// matrix for transforming light filter coordinates to world coordinates
111         matrix4x4_t matrix_lighttoworld;
112         /// matrix for transforming world coordinates to light filter coordinates
113         matrix4x4_t matrix_worldtolight;
114         /// typically 1 1 1, can be lower (dim) or higher (overbright)
115         vec3_t color;
116         /// size of the light (remove?)
117         vec_t radius;
118         /// light filter
119         char cubemapname[64];
120         /// light style to monitor for brightness
121         int style;
122         /// whether light should render shadows (see castshadows for whether it actually does this frame)
123         int shadow;
124         /// intensity of corona to render
125         vec_t corona;
126         /// radius scale of corona to render (1.0 means same as light radius)
127         vec_t coronasizescale;
128         /// ambient intensity to render
129         vec_t ambientscale;
130         /// diffuse intensity to render
131         vec_t diffusescale;
132         /// specular intensity to render
133         vec_t specularscale;
134         /// LIGHTFLAG_* flags
135         int flags;
136
137         // generated properties
138         /// used only for casting shadows
139         vec3_t shadoworigin;
140         /// culling
141         vec3_t cullmins;
142         vec3_t cullmaxs;
143         /// when r_shadow_culllights_trace is set, this is refreshed by each successful trace.
144         double trace_timer;
145
146         // rendering properties, updated each time a light is rendered
147         // this is rtlight->color * d_lightstylevalue
148         vec3_t currentcolor;
149         /// used by corona updates, due to occlusion query
150         float corona_visibility;
151         unsigned int corona_queryindex_visiblepixels;
152         unsigned int corona_queryindex_allpixels;
153         /// this is R_GetCubemap(rtlight->cubemapname)
154         rtexture_t *currentcubemap;
155         /// set by R_Shadow_PrepareLight to decide whether R_Shadow_DrawLight should draw it
156         qbool draw;
157         /// set by R_Shadow_PrepareLight to indicate whether R_Shadow_DrawShadowMaps should do anything
158         qbool castshadows;
159         /// these fields are set by R_Shadow_PrepareLight for later drawing
160         int cached_numlightentities;
161         int cached_numlightentities_noselfshadow;
162         int cached_numshadowentities;
163         int cached_numshadowentities_noselfshadow;
164         int cached_numsurfaces;
165         struct entity_render_s **cached_lightentities;
166         struct entity_render_s **cached_lightentities_noselfshadow;
167         struct entity_render_s **cached_shadowentities;
168         struct entity_render_s **cached_shadowentities_noselfshadow;
169         unsigned char *cached_shadowtrispvs;
170         unsigned char *cached_lighttrispvs;
171         int *cached_surfacelist;
172         // reduced light cullbox from GetLightInfo
173         vec3_t cached_cullmins;
174         vec3_t cached_cullmaxs;
175         // current shadow-caster culling planes based on view
176         // (any geometry outside these planes can not contribute to the visible
177         //  shadows in any way, and thus can be culled safely)
178         int cached_numfrustumplanes;
179         mplane_t cached_frustumplanes[5]; // see R_Shadow_ComputeShadowCasterCullingPlanes
180
181         /// static light info
182         /// true if this light should be compiled as a static light
183         int isstatic;
184         /// true if this is a compiled world light, cleared if the light changes
185         int compiled;
186         /// the size that this light should have (assuming no scene LOD kicking in to reduce it)
187         int shadowmapsidesize;
188         /// position of this light in the shadowmap atlas
189         int shadowmapatlasposition[2];
190         /// size of one side of this light in the shadowmap atlas (for omnidirectional shadowmaps this is the min corner of a 2x3 arrangement, or a 4x3 arrangement in the case of noselfshadow entities being present)
191         int shadowmapatlassidesize;
192         /// optimized and culled mesh to render for world entity shadows
193         shadowmesh_t *static_meshchain_shadow_shadowmap;
194         /// used for visibility testing (more exact than bbox)
195         int static_numleafs;
196         int static_numleafpvsbytes;
197         int *static_leaflist;
198         unsigned char *static_leafpvs;
199         /// surfaces seen by light
200         int static_numsurfaces;
201         int *static_surfacelist;
202         /// flag bits indicating which triangles of the world model should cast
203         /// shadows, and which ones should be lit
204         ///
205         /// this avoids redundantly scanning the triangles in each surface twice
206         /// for whether they should cast shadows, once in culling and once in the
207         /// actual shadowmarklist production.
208         int static_numshadowtrispvsbytes;
209         unsigned char *static_shadowtrispvs;
210         /// this allows the lighting batch code to skip backfaces andother culled
211         /// triangles not relevant for lighting
212         /// (important on big surfaces such as terrain)
213         int static_numlighttrispvsbytes;
214         unsigned char *static_lighttrispvs;
215         /// masks of all shadowmap sides that have any potential static receivers or casters
216         int static_shadowmap_receivers;
217         int static_shadowmap_casters;
218         /// particle-tracing cache for global illumination
219         int particlecache_numparticles;
220         int particlecache_maxparticles;
221         int particlecache_updateparticle;
222         rtlight_particle_t *particlecache_particles;
223
224         /// bouncegrid light info
225         float bouncegrid_photoncolor[3];
226         float bouncegrid_photons;
227         int bouncegrid_hits;
228         int bouncegrid_traces;
229         float bouncegrid_effectiveradius;
230 }
231 rtlight_t;
232
233 typedef struct dlight_s
234 {
235         // destroy light after this time
236         // (dlight only)
237         vec_t die;
238         // the entity that owns this light (can be NULL)
239         // (dlight only)
240         struct entity_render_s *ent;
241         // location
242         // (worldlight: saved to .rtlights file)
243         vec3_t origin;
244         // worldlight orientation
245         // (worldlight only)
246         // (worldlight: saved to .rtlights file)
247         vec3_t angles;
248         // dlight orientation/scaling/location
249         // (dlight only)
250         matrix4x4_t matrix;
251         // color of light
252         // (worldlight: saved to .rtlights file)
253         vec3_t color;
254         // cubemap name to use on this light
255         // (worldlight: saved to .rtlights file)
256         char cubemapname[64];
257         // make light flash while selected
258         // (worldlight only)
259         int selected;
260         // brightness (not really radius anymore)
261         // (worldlight: saved to .rtlights file)
262         vec_t radius;
263         // drop intensity this much each second
264         // (dlight only)
265         vec_t decay;
266         // intensity value which is dropped over time
267         // (dlight only)
268         vec_t intensity;
269         // initial values for intensity to modify
270         // (dlight only)
271         vec_t initialradius;
272         vec3_t initialcolor;
273         // light style which controls intensity of this light
274         // (worldlight: saved to .rtlights file)
275         int style;
276         // cast shadows
277         // (worldlight: saved to .rtlights file)
278         int shadow;
279         // corona intensity
280         // (worldlight: saved to .rtlights file)
281         vec_t corona;
282         // radius scale of corona to render (1.0 means same as light radius)
283         // (worldlight: saved to .rtlights file)
284         vec_t coronasizescale;
285         // ambient intensity to render
286         // (worldlight: saved to .rtlights file)
287         vec_t ambientscale;
288         // diffuse intensity to render
289         // (worldlight: saved to .rtlights file)
290         vec_t diffusescale;
291         // specular intensity to render
292         // (worldlight: saved to .rtlights file)
293         vec_t specularscale;
294         // LIGHTFLAG_* flags
295         // (worldlight: saved to .rtlights file)
296         int flags;
297         // linked list of world lights
298         // (worldlight only)
299         struct dlight_s *next;
300         // embedded rtlight struct for renderer
301         // (worldlight only)
302         rtlight_t rtlight;
303 }
304 dlight_t;
305
306 // this is derived from processing of the framegroupblend array
307 // note: technically each framegroupblend can produce two of these, but that
308 // never happens in practice because no one blends between more than 2
309 // framegroups at once
310 #define MAX_FRAMEBLENDS (MAX_FRAMEGROUPBLENDS * 2)
311 typedef struct frameblend_s
312 {
313         int subframe;
314         float lerp;
315 }
316 frameblend_t;
317
318 // LadyHavoc: this struct is intended for the renderer but some fields are
319 // used by the client.
320 //
321 // The renderer should not rely on any changes to this struct to be persistent
322 // across multiple frames because temp entities are wiped every frame, but it
323 // is acceptable to cache things in this struct that are not critical.
324 //
325 // For example the r_cullentities_trace code does such caching.
326 typedef struct entity_render_s
327 {
328         // location
329         //vec3_t origin;
330         // orientation
331         //vec3_t angles;
332         // transform matrix for model to world
333         matrix4x4_t matrix;
334         // transform matrix for world to model
335         matrix4x4_t inversematrix;
336         // opacity (alpha) of the model
337         float alpha;
338         // size the model is shown
339         float scale;
340         // transparent sorting offset
341         float transparent_offset;
342
343         // NULL = no model
344         model_t *model;
345         // number of the entity represents, or 0 for non-network entities
346         int entitynumber;
347         // literal colormap colors for renderer, if both are 0 0 0 it is not colormapped
348         vec3_t colormap_pantscolor;
349         vec3_t colormap_shirtcolor;
350         // light, particles, etc
351         int effects;
352         // qw CTF flags and other internal-use-only effect bits
353         int internaleffects;
354         // for Alias models
355         int skinnum;
356         // render flags
357         int flags;
358
359         // colormod tinting of models
360         float colormod[3];
361         float glowmod[3];
362
363         // interpolated animation - active framegroups and blend factors
364         framegroupblend_t framegroupblend[MAX_FRAMEGROUPBLENDS];
365
366         // time of last model change (for shader animations)
367         double shadertime;
368
369         // calculated by the renderer (but not persistent)
370
371         // calculated during R_AddModelEntities
372         vec3_t mins, maxs;
373         // subframe numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use subframeblend[0].subframe
374         frameblend_t frameblend[MAX_FRAMEBLENDS];
375         // skeletal animation data (if skeleton.relativetransforms is not NULL, it overrides frameblend)
376         skeleton_t *skeleton;
377
378         // animation cache (pointers allocated using R_FrameData_Alloc)
379         // ONLY valid during R_RenderView!  may be NULL (not cached)
380         float          *animcache_vertex3f;
381         r_meshbuffer_t *animcache_vertex3f_vertexbuffer;
382         int             animcache_vertex3f_bufferoffset;
383         float          *animcache_normal3f;
384         r_meshbuffer_t *animcache_normal3f_vertexbuffer;
385         int             animcache_normal3f_bufferoffset;
386         float          *animcache_svector3f;
387         r_meshbuffer_t *animcache_svector3f_vertexbuffer;
388         int             animcache_svector3f_bufferoffset;
389         float          *animcache_tvector3f;
390         r_meshbuffer_t *animcache_tvector3f_vertexbuffer;
391         int             animcache_tvector3f_bufferoffset;
392         // gpu-skinning shader needs transforms in a certain format, we have to
393         // upload this to a uniform buffer for the shader to use, and also keep a
394         // backup copy in system memory for the dynamic batch fallback code
395         // if this is not NULL, the other animcache variables are NULL
396         float *animcache_skeletaltransform3x4;
397         r_meshbuffer_t *animcache_skeletaltransform3x4buffer;
398         int animcache_skeletaltransform3x4offset;
399         int animcache_skeletaltransform3x4size;
400
401         // CL_UpdateEntityShading reads these fields
402         // used only if RENDER_CUSTOMIZEDMODELLIGHT is set
403         vec3_t custommodellight_ambient;
404         vec3_t custommodellight_diffuse;
405         vec3_t custommodellight_lightdir;
406         // CSQC entities get their shading from the root of their attachment chain
407         float custommodellight_origin[3];
408
409         // derived lighting parameters (CL_UpdateEntityShading)
410
411         // used by MATERIALFLAG_FULLBRIGHT which is MATERIALFLAG_MODELLIGHT with
412         // this as ambient color, along with MATERIALFLAG_NORTLIGHT
413         float render_fullbright[3];
414         // color tint for the base pass glow textures if any
415         float render_glowmod[3];
416         // MATERIALFLAG_MODELLIGHT uses these parameters
417         float render_modellight_ambient[3];
418         float render_modellight_diffuse[3];
419         float render_modellight_lightdir_world[3];
420         float render_modellight_lightdir_local[3];
421         float render_modellight_specular[3];
422         // lightmap rendering (not MATERIALFLAG_MODELLIGHT)
423         float render_lightmap_ambient[3];
424         float render_lightmap_diffuse[3];
425         float render_lightmap_specular[3];
426         // rtlights use these colors for the materials on this entity
427         float render_rtlight_diffuse[3];
428         float render_rtlight_specular[3];
429         // ignore lightmap and use fixed lighting settings on this entity (e.g. FULLBRIGHT)
430         qbool render_modellight_forced;
431         // do not process per pixel lights on this entity at all (like MATERIALFLAG_NORTLIGHT)
432         qbool render_rtlight_disabled;
433         // use the 3D lightmap from q3bsp on this entity
434         qbool render_lightgrid;
435
436         // storage of decals on this entity
437         // (note: if allowdecals is set, be sure to call R_DecalSystem_Reset on removal!)
438         int allowdecals;
439         decalsystem_t decalsystem;
440
441         // FIELDS UPDATED BY RENDERER:
442         // last time visible during trace culling
443         double last_trace_visibility;
444
445         // user wavefunc parameters (from csqc)
446         vec_t userwavefunc_param[Q3WAVEFUNC_USER_COUNT];
447 }
448 entity_render_t;
449
450 typedef struct entity_persistent_s
451 {
452         vec3_t trail_origin; // previous position for particle trail spawning
453         vec3_t oldorigin; // lerp
454         vec3_t oldangles; // lerp
455         vec3_t neworigin; // lerp
456         vec3_t newangles; // lerp
457         vec_t lerpstarttime; // lerp
458         vec_t lerpdeltatime; // lerp
459         float muzzleflash; // muzzleflash intensity, fades over time
460         float trail_time; // residual error accumulation for particle trail spawning (to keep spacing across frames)
461         qbool trail_allowed; // set to false by teleports, true by update code, prevents bad lerps
462 }
463 entity_persistent_t;
464
465 typedef struct entity_s
466 {
467         // baseline state (default values)
468         entity_state_t state_baseline;
469         // previous state (interpolating from this)
470         entity_state_t state_previous;
471         // current state (interpolating to this)
472         entity_state_t state_current;
473
474         // used for regenerating parts of render
475         entity_persistent_t persistent;
476
477         // the only data the renderer should know about
478         entity_render_t render;
479 }
480 entity_t;
481
482 typedef struct lightstyle_s
483 {
484         int             length;
485         char    map[MAX_STYLESTRING];
486 } lightstyle_t;
487
488 typedef struct scoreboard_s
489 {
490         char    name[MAX_SCOREBOARDNAME];
491         int             frags;
492         int             colors; // two 4 bit fields
493         // QW fields:
494         int             qw_userid;
495         char    qw_userinfo[MAX_USERINFO_STRING];
496         float   qw_entertime;
497         int             qw_ping;
498         int             qw_packetloss;
499         int             qw_movementloss;
500         int             qw_spectator;
501         char    qw_team[8];
502         char    qw_skin[MAX_QPATH];
503 } scoreboard_t;
504
505 typedef struct cshift_s
506 {
507         float   destcolor[3];
508         float   percent;                // 0-255
509         float   alphafade;      // (any speed)
510 } cshift_t;
511
512 #define CSHIFT_CONTENTS 0
513 #define CSHIFT_DAMAGE   1
514 #define CSHIFT_BONUS    2
515 #define CSHIFT_POWERUP  3
516 #define CSHIFT_VCSHIFT  4
517 #define NUM_CSHIFTS             5
518
519 #define NAME_LENGTH     64
520
521
522 //
523 // client_state_t should hold all pieces of the client state
524 //
525
526 #define SIGNONS         4                       // signon messages to receive before connected
527
528 typedef enum cactive_e
529 {
530         ca_uninitialized,       // during early startup
531         ca_dedicated,           // a dedicated server with no ability to start a client
532         ca_disconnected,        // full screen console with no connection
533         ca_connected            // valid netcon, talking to a server
534 }
535 cactive_t;
536
537 typedef enum qw_downloadtype_e
538 {
539         dl_none,
540         dl_single,
541         dl_skin,
542         dl_model,
543         dl_sound
544 }
545 qw_downloadtype_t;
546
547 #define CL_MAX_DOWNLOADACKS 4
548
549 typedef struct cl_downloadack_s
550 {
551         int start, size;
552 }
553 cl_downloadack_t;
554
555 typedef struct cl_soundstats_s
556 {
557         int mixedsounds;
558         int totalsounds;
559         int latency_milliseconds;
560 }
561 cl_soundstats_t;
562
563 //
564 // the client_static_t structure is persistent through an arbitrary number
565 // of server connections
566 //
567 typedef struct client_static_s
568 {
569         cactive_t state;
570
571         // all client memory allocations go in these pools
572         mempool_t *levelmempool;
573         mempool_t *permanentmempool;
574
575 // demo loop control
576         // -1 = don't play demos
577         int demonum;
578         // list of demos in loop
579         char demos[MAX_DEMOS][MAX_DEMONAME];
580         // the actively playing demo (set by CL_PlayDemo)
581         char demoname[MAX_QPATH];
582
583 // demo recording info must be here, because record is started before
584 // entering a map (and clearing client_state_t)
585         qbool demorecording;
586         fs_offset_t demo_lastcsprogssize;
587         int demo_lastcsprogscrc;
588         qbool demoplayback;
589         qbool demostarting; // set if currently starting a demo, to stop -demo from quitting when switching to another demo
590         qbool timedemo;
591         // -1 = use normal cd track
592         int forcetrack;
593         qfile_t *demofile;
594         // realtime at second frame of timedemo (LadyHavoc: changed to double)
595         double td_starttime;
596         int td_frames; // total frames parsed
597         double td_onesecondnexttime;
598         double td_onesecondframes;
599         double td_onesecondrealtime;
600         double td_onesecondminfps;
601         double td_onesecondmaxfps;
602         double td_onesecondavgfps;
603         int td_onesecondavgcount;
604         // LadyHavoc: pausedemo
605         qbool demopaused;
606
607         // sound mixer statistics for showsound display
608         cl_soundstats_t soundstats;
609
610         qbool connect_trying;
611         int connect_remainingtries;
612         double connect_nextsendtime;
613         lhnetsocket_t *connect_mysocket;
614         lhnetaddress_t connect_address;
615         lhnetaddress_t rcon_address;
616         // protocol version of the server we're connected to
617         // (kept outside client_state_t because it's used between levels)
618         protocolversion_t protocol;
619
620 #define MAX_RCONS 16
621         int rcon_trying;
622         lhnetaddress_t rcon_addresses[MAX_RCONS];
623         char rcon_commands[MAX_RCONS][MAX_INPUTLINE];
624         double rcon_timeout[MAX_RCONS];
625         int rcon_ringpos;
626
627 // connection information
628         // 0 to SIGNONS
629         int signon;
630         // network connection
631         netconn_t *netcon;
632
633         // download information
634         // (note: qw_download variables are also used)
635         cl_downloadack_t dp_downloadack[CL_MAX_DOWNLOADACKS];
636
637         // input sequence numbers are not reset on level change, only connect
638         unsigned int servermovesequence;
639
640         // quakeworld stuff below
641
642         // value of "qport" cvar at time of connection
643         int qw_qport;
644         // copied from cls.netcon->qw. variables every time they change, or set by demos (which have no cls.netcon)
645         unsigned int qw_incoming_sequence;
646         unsigned int qw_outgoing_sequence;
647
648         // current file download buffer (only saved when file is completed)
649         char qw_downloadname[MAX_QPATH];
650         unsigned char *qw_downloadmemory;
651         int qw_downloadmemorycursize;
652         int qw_downloadmemorymaxsize;
653         int qw_downloadnumber;
654         int qw_downloadpercent;
655         qw_downloadtype_t qw_downloadtype;
656         // transfer rate display
657         double qw_downloadspeedtime;
658         int qw_downloadspeedcount;
659         int qw_downloadspeedrate;
660         qbool qw_download_deflate;
661
662         // current file upload buffer (for uploading screenshots to server)
663         unsigned char *qw_uploaddata;
664         int qw_uploadsize;
665         int qw_uploadpos;
666
667         // user infostring
668         // this normally contains the following keys in quakeworld:
669         // password spectator name team skin topcolor bottomcolor rate noaim msg *ver *ip
670         char userinfo[MAX_USERINFO_STRING];
671
672         // extra user info for the "connect" command
673         char connect_userinfo[MAX_USERINFO_STRING];
674
675 #ifdef CONFIG_VIDEO_CAPTURE
676         // video capture stuff
677         capturevideostate_t capturevideo;
678 #endif
679
680         // crypto channel
681         crypto_t crypto;
682
683         // ProQuake compatibility stuff
684         int proquake_servermod; // 0 = not proquake, 1 = proquake
685         int proquake_serverversion; // actual proquake server version * 10 (3.40 = 34, etc)
686         int proquake_serverflags; // 0 (PQF_CHEATFREE not supported)
687
688         // don't write-then-read csprogs.dat (useful for demo playback)
689         unsigned char *caughtcsprogsdata;
690         fs_offset_t caughtcsprogsdatasize;
691
692         int r_speeds_graph_length;
693         int r_speeds_graph_current;
694         int *r_speeds_graph_data;
695
696         // graph scales
697         int r_speeds_graph_datamin[r_stat_count];
698         int r_speeds_graph_datamax[r_stat_count];
699 }
700 client_static_t;
701
702 extern client_static_t  cls;
703
704 //[515]: csqc
705 typedef struct
706 {
707         qbool drawworld;
708         qbool drawenginesbar;
709         qbool drawcrosshair;
710 }csqc_vidvars_t;
711
712 typedef enum cl_parsingtextmode_e
713 {
714         CL_PARSETEXTMODE_NONE,
715         CL_PARSETEXTMODE_PING,
716         CL_PARSETEXTMODE_STATUS,
717         CL_PARSETEXTMODE_STATUS_PLAYERID,
718         CL_PARSETEXTMODE_STATUS_PLAYERIP
719 }
720 cl_parsingtextmode_t;
721
722 typedef struct cl_locnode_s
723 {
724         struct cl_locnode_s *next;
725         char *name;
726         vec3_t mins, maxs;
727 }
728 cl_locnode_t;
729
730 typedef struct showlmp_s
731 {
732         qbool   isactive;
733         float           x;
734         float           y;
735         char            label[32];
736         char            pic[128];
737 }
738 showlmp_t;
739
740 //
741 // the client_state_t structure is wiped completely at every
742 // server signon
743 //
744 typedef struct client_state_s
745 {
746         // true if playing in a local game and no one else is connected
747         int islocalgame;
748
749         // send a clc_nop periodically until connected
750         float sendnoptime;
751
752         // current input being accumulated by mouse/joystick/etc input
753         usercmd_t cmd;
754         // latest moves sent to the server that have not been confirmed yet
755         usercmd_t movecmd[CL_MAX_USERCMDS];
756
757 // information for local display
758         // health, etc
759         int stats[MAX_CL_STATS];
760         float *statsf; // points to stats[] array
761         // last known inventory bit flags, for blinking
762         int olditems;
763         // cl.time of acquiring item, for blinking
764         float item_gettime[32];
765         // last known STAT_ACTIVEWEAPON
766         int activeweapon;
767         // cl.time of changing STAT_ACTIVEWEAPON
768         float weapontime;
769         // use pain anim frame if cl.time < this
770         float faceanimtime;
771         // for stair smoothing
772         float stairsmoothz;
773         double stairsmoothtime;
774
775         // color shifts for damage, powerups
776         cshift_t cshifts[NUM_CSHIFTS];
777         // and content types
778         cshift_t prev_cshifts[NUM_CSHIFTS];
779
780 // the client maintains its own idea of view angles, which are
781 // sent to the server each frame.  The server sets punchangle when
782 // the view is temporarily offset, and an angle reset commands at the start
783 // of each level and after teleporting.
784
785         // mviewangles is read from demo
786         // viewangles is either client controlled or lerped from mviewangles
787         vec3_t mviewangles[2], viewangles;
788         // update by server, used by qc to do weapon recoil
789         vec3_t mpunchangle[2], punchangle;
790         // update by server, can be used by mods to kick view around
791         vec3_t mpunchvector[2], punchvector;
792         // update by server, used for lean+bob (0 is newest)
793         vec3_t mvelocity[2], velocity;
794         // update by server, can be used by mods for zooming
795         vec_t mviewzoom[2], viewzoom;
796         // if true interpolation the mviewangles and other interpolation of the
797         // player is disabled until the next network packet
798         // this is used primarily by teleporters, and when spectating players
799         // special checking of the old fixangle[1] is used to differentiate
800         // between teleporting and spectating
801         qbool fixangle[2];
802
803         // client movement simulation
804         // these fields are only updated by CL_ClientMovement (called by CL_SendMove after parsing each network packet)
805         // set by CL_ClientMovement_Replay functions
806         qbool movement_predicted;
807         // if true the CL_ClientMovement_Replay function will update origin, etc
808         qbool movement_replay;
809         // simulated data (this is valid even if cl.movement is false)
810         vec3_t movement_origin;
811         vec3_t movement_velocity;
812         // whether the replay should allow a jump at the first sequence
813         qbool movement_replay_canjump;
814
815         // previous gun angles (for leaning effects)
816         vec3_t gunangles_prev;
817         vec3_t gunangles_highpass;
818         vec3_t gunangles_adjustment_lowpass;
819         vec3_t gunangles_adjustment_highpass;
820         // previous gun angles (for leaning effects)
821         vec3_t gunorg_prev;
822         vec3_t gunorg_highpass;
823         vec3_t gunorg_adjustment_lowpass;
824         vec3_t gunorg_adjustment_highpass;
825
826 // pitch drifting vars
827         float idealpitch;
828         float pitchvel;
829         qbool nodrift;
830         float driftmove;
831         double laststop;
832
833 //[515]: added for csqc purposes
834         float sensitivityscale;
835         csqc_vidvars_t csqc_vidvars;    //[515]: these parms must be set to true by default
836         qbool csqc_wantsmousemove;
837         struct model_s *csqc_model_precache[MAX_MODELS];
838
839         // local amount for smoothing stepups
840         //float crouch;
841
842         // sent by server
843         qbool paused;
844         qbool onground;
845         qbool inwater;
846
847         // used by bob
848         qbool oldonground;
849         double lastongroundtime;
850         double hitgroundtime;
851         float bob2_smooth;
852         float bobfall_speed;
853         float bobfall_swing;
854         double calcrefdef_prevtime;
855
856         // don't change view angle, full screen, etc
857         int intermission;
858         // latched at intermission start
859         double completed_time;
860
861         // the timestamp of the last two messages
862         double mtime[2];
863
864         // clients view of time, time should be between mtime[0] and mtime[1] to
865         // generate a lerp point for other data, oldtime is the previous frame's
866         // value of time, frametime is the difference between time and oldtime
867         // note: cl.time may be beyond cl.mtime[0] if packet loss is occuring, it
868         // is only forcefully limited when a packet is received
869         double time, oldtime;
870         // how long it has been since the previous client frame in real time
871         // (not game time, for that use cl.time - cl.oldtime)
872         double realframetime;
873
874         // used by cl_nettimesyncboundmode 7
875 #define NUM_TS_ERRORS 32 // max 256
876         unsigned char ts_error_num;
877         float ts_error_stor[NUM_TS_ERRORS];
878
879         // fade var for fading while dead
880         float deathfade;
881
882         // motionblur alpha level variable
883         float motionbluralpha;
884
885         // copy of realtime from last recieved message, for net trouble icon
886         float last_received_message;
887
888 // information that is static for the entire time connected to a server
889         struct model_s *model_precache[MAX_MODELS];
890         struct sfx_s *sound_precache[MAX_SOUNDS];
891
892         // FIXME: this is a lot of memory to be keeping around, this really should be dynamically allocated and freed somehow
893         char model_name[MAX_MODELS][MAX_QPATH];
894         char sound_name[MAX_SOUNDS][MAX_QPATH];
895
896         // for display on solo scoreboard
897         char worldmessage[40]; // map title (not related to filename)
898         // variants of map name
899         char worldbasename[MAX_QPATH]; // %s
900         char worldname[MAX_QPATH]; // maps/%s.bsp
901         char worldnamenoextension[MAX_QPATH]; // maps/%s
902         // cl_entitites[cl.viewentity] = player
903         int viewentity;
904         // the real player entity (normally same as viewentity,
905         // different than viewentity if mod uses chasecam or other tricks)
906         int realplayerentity;
907         // this is updated to match cl.viewentity whenever it is in the clients
908         // range, basically this is used in preference to cl.realplayerentity for
909         // most purposes because when spectating another player it should show
910         // their information rather than yours
911         int playerentity;
912         // max players that can be in this game
913         int maxclients;
914         // type of game (deathmatch, coop, singleplayer)
915         int gametype;
916
917         // models and sounds used by engine code (particularly cl_parse.c)
918         model_t *model_bolt;
919         model_t *model_bolt2;
920         model_t *model_bolt3;
921         model_t *model_beam;
922         sfx_t *sfx_wizhit;
923         sfx_t *sfx_knighthit;
924         sfx_t *sfx_tink1;
925         sfx_t *sfx_ric1;
926         sfx_t *sfx_ric2;
927         sfx_t *sfx_ric3;
928         sfx_t *sfx_r_exp3;
929         // indicates that the file "sound/misc/talk2.wav" was found (for use by team chat messages)
930         qbool foundteamchatsound;
931
932 // refresh related state
933
934         // cl_entitites[0].model
935         struct model_s *worldmodel;
936
937         // the gun model
938         entity_t viewent;
939
940         // cd audio
941         int cdtrack, looptrack;
942
943 // frag scoreboard
944
945         // [cl.maxclients]
946         scoreboard_t *scores;
947
948         // keep track of svc_print parsing state (analyzes ping reports and status reports)
949         cl_parsingtextmode_t parsingtextmode;
950         int parsingtextplayerindex;
951         // set by scoreboard code when sending ping command, this causes the next ping results to be hidden
952         // (which could eat the wrong ping report if the player issues one
953         //  manually, but they would still see a ping report, just a later one
954         //  caused by the scoreboard code rather than the one they intentionally
955         //  issued)
956         int parsingtextexpectingpingforscores;
957
958         // entity database stuff
959         // latest received entity frame numbers
960 #define LATESTFRAMENUMS 32
961         int latestframenumsposition;
962         int latestframenums[LATESTFRAMENUMS];
963         unsigned int latestsendnums[LATESTFRAMENUMS];
964         entityframe_database_t *entitydatabase;
965         entityframe4_database_t *entitydatabase4;
966         entityframeqw_database_t *entitydatabaseqw;
967
968         // keep track of quake entities because they need to be killed if they get stale
969         int lastquakeentity;
970         unsigned char isquakeentity[MAX_EDICTS];
971
972         // bounding boxes for clientside movement
973         vec3_t playerstandmins;
974         vec3_t playerstandmaxs;
975         vec3_t playercrouchmins;
976         vec3_t playercrouchmaxs;
977
978         // old decals are killed based on this
979         unsigned int decalsequence;
980
981         int max_entities;
982         int max_csqcrenderentities;
983         int max_static_entities;
984         int max_effects;
985         int max_beams;
986         int max_dlights;
987         int max_lightstyle;
988         int max_brushmodel_entities;
989         int max_particles;
990         int max_showlmps;
991
992         entity_t *entities;
993         entity_render_t *csqcrenderentities;
994         unsigned char *entities_active;
995         entity_t *static_entities;
996         cl_effect_t *effects;
997         beam_t *beams;
998         dlight_t *dlights;
999         lightstyle_t *lightstyle;
1000         int *brushmodel_entities;
1001         particle_t *particles;
1002         showlmp_t *showlmps;
1003
1004         int num_entities;
1005         int num_static_entities;
1006         int num_brushmodel_entities;
1007         int num_effects;
1008         int num_beams;
1009         int num_dlights;
1010         int num_particles;
1011         int num_decals;
1012         int num_showlmps;
1013
1014         double particles_updatetime;
1015         double decals_updatetime;
1016         int free_particle;
1017         int free_decal;
1018
1019         // cl_serverextension_download feature
1020         int loadmodel_current;
1021         int downloadmodel_current;
1022         int loadmodel_total;
1023         int loadsound_current;
1024         int downloadsound_current;
1025         int loadsound_total;
1026         qbool downloadcsqc;
1027         qbool loadcsqc;
1028         qbool loadbegun;
1029         qbool loadfinished;
1030
1031         // quakeworld stuff
1032
1033         // local copy of the server infostring
1034         char qw_serverinfo[MAX_SERVERINFO_STRING];
1035
1036         // time of last qw "pings" command sent to server while showing scores
1037         double last_ping_request;
1038
1039         // used during connect
1040         int qw_servercount;
1041
1042         // updated from serverinfo
1043         int qw_teamplay;
1044
1045         // unused: indicates whether the player is spectating
1046         // use cl.scores[cl.playerentity-1].qw_spectator instead
1047         //qbool qw_spectator;
1048
1049         // time accumulated since an input packet was sent
1050         float timesincepacket;
1051
1052         // movement parameters for client prediction
1053         unsigned int moveflags;
1054         float movevars_wallfriction;
1055         float movevars_waterfriction;
1056         float movevars_friction;
1057         float movevars_timescale;
1058         float movevars_gravity;
1059         float movevars_stopspeed;
1060         float movevars_maxspeed;
1061         float movevars_spectatormaxspeed;
1062         float movevars_accelerate;
1063         float movevars_airaccelerate;
1064         float movevars_wateraccelerate;
1065         float movevars_entgravity;
1066         float movevars_jumpvelocity;
1067         float movevars_edgefriction;
1068         float movevars_maxairspeed;
1069         float movevars_stepheight;
1070         float movevars_airaccel_qw;
1071         float movevars_airaccel_qw_stretchfactor;
1072         float movevars_airaccel_sideways_friction;
1073         float movevars_airstopaccelerate;
1074         float movevars_airstrafeaccelerate;
1075         float movevars_maxairstrafespeed;
1076         float movevars_airstrafeaccel_qw;
1077         float movevars_aircontrol;
1078         float movevars_aircontrol_power;
1079         float movevars_aircontrol_penalty;
1080         float movevars_warsowbunny_airforwardaccel;
1081         float movevars_warsowbunny_accel;
1082         float movevars_warsowbunny_topspeed;
1083         float movevars_warsowbunny_turnaccel;
1084         float movevars_warsowbunny_backtosideratio;
1085         float movevars_ticrate;
1086         float movevars_airspeedlimit_nonqw;
1087
1088         // models used by qw protocol
1089         int qw_modelindex_spike;
1090         int qw_modelindex_player;
1091         int qw_modelindex_flag;
1092         int qw_modelindex_s_explod;
1093
1094         vec3_t qw_intermission_origin;
1095         vec3_t qw_intermission_angles;
1096
1097         // 255 is the most nails the QW protocol could send
1098         int qw_num_nails;
1099         vec_t qw_nails[255][6];
1100
1101         float qw_weaponkick;
1102
1103         unsigned int qw_validsequence;
1104
1105         unsigned int qw_deltasequence[QW_UPDATE_BACKUP];
1106
1107         // csqc stuff:
1108         // server entity number corresponding to a clientside entity
1109         unsigned short csqc_server2csqcentitynumber[MAX_EDICTS];
1110         qbool csqc_loaded;
1111         vec3_t csqc_vieworigin;
1112         vec3_t csqc_viewangles;
1113         vec3_t csqc_vieworiginfromengine;
1114         vec3_t csqc_viewanglesfromengine;
1115         matrix4x4_t csqc_viewmodelmatrixfromengine;
1116         qbool csqc_usecsqclistener;
1117         matrix4x4_t csqc_listenermatrix;
1118         char csqc_printtextbuf[MAX_INPUTLINE];
1119
1120         // collision culling data
1121         world_t world;
1122
1123         // loc file stuff (points and boxes describing locations in the level)
1124         cl_locnode_t *locnodes;
1125         // this is updated to cl.movement_origin whenever health is < 1
1126         // used by %d print in say/say_team messages if cl_locs_enable is on
1127         vec3_t lastdeathorigin;
1128
1129         // processing buffer used by R_BuildLightMap, reallocated as needed,
1130         // freed on each level change
1131         size_t buildlightmapmemorysize;
1132         unsigned char *buildlightmapmemory;
1133
1134         // used by EntityState5_ReadUpdate
1135         skeleton_t *engineskeletonobjects;
1136 }
1137 client_state_t;
1138
1139 //
1140 // cvars
1141 //
1142 extern cvar_t cl_name;
1143 extern cvar_t cl_color;
1144 extern cvar_t cl_rate;
1145 extern cvar_t cl_rate_burstsize;
1146 extern cvar_t cl_pmodel;
1147 extern cvar_t cl_playermodel;
1148 extern cvar_t cl_playerskin;
1149
1150 extern cvar_t rcon_password;
1151 extern cvar_t rcon_address;
1152
1153 extern cvar_t cl_upspeed;
1154 extern cvar_t cl_forwardspeed;
1155 extern cvar_t cl_backspeed;
1156 extern cvar_t cl_sidespeed;
1157
1158 extern cvar_t cl_movespeedkey;
1159
1160 extern cvar_t cl_yawspeed;
1161 extern cvar_t cl_pitchspeed;
1162
1163 extern cvar_t cl_anglespeedkey;
1164
1165 extern cvar_t cl_autofire;
1166
1167 extern cvar_t cl_shownet;
1168 extern cvar_t cl_nolerp;
1169 extern cvar_t cl_nettimesyncfactor;
1170 extern cvar_t cl_nettimesyncboundmode;
1171 extern cvar_t cl_nettimesyncboundtolerance;
1172
1173 extern cvar_t cl_pitchdriftspeed;
1174 extern cvar_t lookspring;
1175 extern cvar_t lookstrafe;
1176 extern cvar_t sensitivity;
1177
1178 extern cvar_t freelook;
1179
1180 extern cvar_t m_pitch;
1181 extern cvar_t m_yaw;
1182 extern cvar_t m_forward;
1183 extern cvar_t m_side;
1184
1185 extern cvar_t cl_autodemo;
1186 extern cvar_t cl_autodemo_nameformat;
1187 extern cvar_t cl_autodemo_delete;
1188
1189 extern cvar_t r_draweffects;
1190
1191 extern cvar_t cl_explosions_alpha_start;
1192 extern cvar_t cl_explosions_alpha_end;
1193 extern cvar_t cl_explosions_size_start;
1194 extern cvar_t cl_explosions_size_end;
1195 extern cvar_t cl_explosions_lifetime;
1196 extern cvar_t cl_stainmaps;
1197 extern cvar_t cl_stainmaps_clearonload;
1198
1199 extern cvar_t cl_prydoncursor;
1200 extern cvar_t cl_prydoncursor_notrace;
1201
1202 extern cvar_t cl_locs_enable;
1203
1204 extern client_state_t cl;
1205
1206 extern void CL_AllocLightFlash (entity_render_t *ent, matrix4x4_t *matrix, float radius, float red, float green, float blue, float decay, float lifetime, char *cubemapname, int style, int shadowenable, vec_t corona, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags);
1207
1208 cl_locnode_t *CL_Locs_FindNearest(const vec3_t point);
1209 void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point);
1210
1211 //=============================================================================
1212
1213 //
1214 // cl_main
1215 //
1216
1217 double CL_Frame(double time);
1218
1219 void CL_Shutdown (void);
1220 void CL_Init (void);
1221
1222 void CL_StartVideo(void);
1223
1224 void CL_EstablishConnection(const char *host, int firstarg);
1225
1226 void CL_Disconnect (qbool kicked, const char *reason, ... );
1227 void CL_Disconnect_f(cmd_state_t *cmd);
1228
1229 void CL_UpdateRenderEntity(entity_render_t *ent);
1230 void CL_SetEntityColormapColors(entity_render_t *ent, int colormap);
1231 void CL_UpdateViewEntities(void);
1232
1233 //
1234 // cl_input
1235 //
1236 typedef struct kbutton_s
1237 {
1238         int             down[2];                // key nums holding it down
1239         int             state;                  // low bit is down state
1240 }
1241 kbutton_t;
1242
1243 extern  kbutton_t       in_mlook, in_klook;
1244 extern  kbutton_t       in_strafe;
1245 extern  kbutton_t       in_speed;
1246
1247 void CL_InitInput (void);
1248 void CL_SendMove (void);
1249
1250 void CL_ValidateState(entity_state_t *s);
1251 void CL_MoveLerpEntityStates(entity_t *ent);
1252 void CL_LerpUpdate(entity_t *e);
1253 void CL_ParseTEnt (void);
1254 void CL_NewBeam (int ent, vec3_t start, vec3_t end, model_t *m, int lightning);
1255 void CL_RelinkBeams (void);
1256 void CL_Beam_CalculatePositions (const beam_t *b, vec3_t start, vec3_t end);
1257 void CL_ClientMovement_Replay(void);
1258
1259 void CL_ClearTempEntities (void);
1260 entity_render_t *CL_NewTempEntity (double shadertime);
1261
1262 void CL_Effect(vec3_t org, model_t *model, int startframe, int framecount, float framerate);
1263
1264 void CL_ClearState (void);
1265 void CL_ExpandEntities(int num);
1266 void CL_ExpandCSQCRenderEntities(int num);
1267 void CL_SetInfo(const char *key, const char *value, qbool send, qbool allowstarkey, qbool allowmodel, qbool quiet);
1268
1269
1270 void CL_UpdateWorld (void);
1271 void CL_WriteToServer (void);
1272 void CL_Input (void);
1273 extern int cl_ignoremousemoves;
1274
1275
1276 float CL_KeyState (kbutton_t *key);
1277
1278 //
1279 // cl_cmd.c
1280 //
1281 /// adds the string as a clc_stringcmd to the client message.
1282 /// (used when there is no reason to generate a local command to do it)
1283 void CL_ForwardToServer (const char *s);
1284
1285 /// adds the current command line as a clc_stringcmd to the client message.
1286 /// things like godmode, noclip, etc, are commands directed to the server,
1287 /// so when they are typed in at the console, they will need to be forwarded.
1288 void CL_ForwardToServer_f (cmd_state_t *cmd);
1289 void CL_InitCommands(void);
1290
1291
1292 //
1293 // cl_demo.c
1294 //
1295 void CL_StopPlayback(void);
1296 void CL_ReadDemoMessage(void);
1297 void CL_WriteDemoMessage(sizebuf_t *mesage);
1298
1299 void CL_CutDemo(unsigned char **buf, fs_offset_t *filesize);
1300 void CL_PasteDemo(unsigned char **buf, fs_offset_t *filesize);
1301
1302 void CL_PlayDemo(const char *demo);
1303 void CL_NextDemo(void);
1304 void CL_Stop_f(cmd_state_t *cmd);
1305 void CL_Record_f(cmd_state_t *cmd);
1306 void CL_PlayDemo_f(cmd_state_t *cmd);
1307 void CL_TimeDemo_f(cmd_state_t *cmd);
1308
1309 void CL_Demo_Init(void);
1310
1311
1312 #include "cl_screen.h"
1313
1314 extern qbool sb_showscores;
1315
1316 typedef enum waterlevel_e
1317 {
1318         WATERLEVEL_NONE,
1319         WATERLEVEL_WETFEET,
1320         WATERLEVEL_SWIMMING,
1321         WATERLEVEL_SUBMERGED
1322 }
1323 waterlevel_t;
1324
1325 typedef struct cl_clientmovement_state_s
1326 {
1327         // entity to be ignored for movement
1328         struct prvm_edict_s *self;
1329         // position
1330         vec3_t origin;
1331         vec3_t velocity;
1332         // current bounding box (different if crouched vs standing)
1333         vec3_t mins;
1334         vec3_t maxs;
1335         // currently on the ground
1336         qbool onground;
1337         // currently crouching
1338         qbool crouched;
1339         // what kind of water (SUPERCONTENTS_LAVA for instance)
1340         int watertype;
1341         // how deep
1342         waterlevel_t waterlevel;
1343         // weird hacks when jumping out of water
1344         // (this is in seconds and counts down to 0)
1345         float waterjumptime;
1346
1347         // user command
1348         usercmd_t cmd;
1349 }
1350 cl_clientmovement_state_t;
1351 void CL_ClientMovement_PlayerMove_Frame(cl_clientmovement_state_t *s);
1352
1353 // warpzone prediction hack (CSQC builtin)
1354 void CL_RotateMoves(const matrix4x4_t *m);
1355
1356 typedef enum meshname_e {
1357         MESH_SCENE, // CSQC R_PolygonBegin, potentially also engine particles and debug stuff
1358         MESH_UI,
1359         NUM_MESHENTITIES,
1360 } meshname_t;
1361 extern entity_t cl_meshentities[NUM_MESHENTITIES];
1362 extern model_t cl_meshentitymodels[NUM_MESHENTITIES];
1363 extern const char *cl_meshentitynames[NUM_MESHENTITIES];
1364 #define CL_Mesh_Scene() (&cl_meshentitymodels[MESH_SCENE])
1365 #define CL_Mesh_UI() (&cl_meshentitymodels[MESH_UI])
1366 void CL_MeshEntities_Scene_Clear(void);
1367 void CL_MeshEntities_Scene_AddRenderEntity(void);
1368 void CL_MeshEntities_Scene_FinalizeRenderEntity(void);
1369 void CL_UpdateEntityShading(void);
1370
1371 void CL_NewFrameReceived(int num);
1372 void CL_ParseEntityLump(char *entitystring);
1373 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius);
1374 void CL_RelinkLightFlashes(void);
1375 void CL_Beam_AddPolygons(const beam_t *b);
1376 void CL_UpdateMoveVars(void);
1377 void CL_Locs_Reload_f(cmd_state_t *cmd);
1378
1379 #endif
1380