]> icculus.org git repositories - divverent/darkplaces.git/blob - client.h
implemented r_shadow_culltriangles cvar (on by default), this improves lighting perfo...
[divverent/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
27 // LordHavoc: 256 dynamic lights
28 #define MAX_DLIGHTS 256
29
30 // this is the maximum number of input packets that can be lost without a
31 // misprediction
32 #define CL_MAX_USERCMDS 16
33
34 // flags for rtlight rendering
35 #define LIGHTFLAG_NORMALMODE 1
36 #define LIGHTFLAG_REALTIMEMODE 2
37
38 typedef struct effect_s
39 {
40         int active;
41         vec3_t origin;
42         float starttime;
43         float framerate;
44         int modelindex;
45         int startframe;
46         int endframe;
47         // these are for interpolation
48         int frame;
49         double frame1time;
50         double frame2time;
51 }
52 cl_effect_t;
53
54 typedef struct beam_s
55 {
56         int             entity;
57         // draw this as lightning polygons, or a model?
58         int             lightning;
59         struct model_s  *model;
60         float   endtime;
61         vec3_t  start, end;
62 }
63 beam_t;
64
65 typedef struct rtlight_s
66 {
67         // shadow volumes are done entirely in model space, so there are no matrices for dealing with them...  they just use the origin
68
69         // note that the world to light matrices are inversely scaled (divided) by lightradius
70
71         // core properties
72         // matrix for transforming world coordinates to light filter coordinates
73         matrix4x4_t matrix_worldtolight;
74         // typically 1 1 1, can be lower (dim) or higher (overbright)
75         vec3_t color;
76         // size of the light (remove?)
77         vec_t radius;
78         // light filter
79         char cubemapname[64];
80         // light style to monitor for brightness
81         int style;
82         // whether light should render shadows
83         int shadow;
84         // intensity of corona to render
85         vec_t corona;
86         // radius scale of corona to render (1.0 means same as light radius)
87         vec_t coronasizescale;
88         // ambient intensity to render
89         vec_t ambientscale;
90         // diffuse intensity to render
91         vec_t diffusescale;
92         // specular intensity to render
93         vec_t specularscale;
94         // LIGHTFLAG_* flags
95         int flags;
96
97         // generated properties
98         // used only for shadow volumes
99         vec3_t shadoworigin;
100         // culling
101         vec3_t cullmins;
102         vec3_t cullmaxs;
103         // culling
104         //vec_t cullradius;
105         // squared cullradius
106         //vec_t cullradius2;
107
108         // rendering properties, updated each time a light is rendered
109         // this is rtlight->color * d_lightstylevalue
110         vec3_t currentcolor;
111         // this is R_Shadow_Cubemap(rtlight->cubemapname)
112         rtexture_t *currentcubemap;
113
114         // static light info
115         // true if this light should be compiled as a static light
116         int isstatic;
117         // true if this is a compiled world light, cleared if the light changes
118         int compiled;
119         // premade shadow volumes to render for world entity
120         shadowmesh_t *static_meshchain_shadow;
121         // used for visibility testing (more exact than bbox)
122         int static_numleafs;
123         int static_numleafpvsbytes;
124         int *static_leaflist;
125         unsigned char *static_leafpvs;
126         // surfaces seen by light
127         int static_numsurfaces;
128         int *static_surfacelist;
129         // flag bits indicating which triangles of the world model should cast
130         // shadows, and which ones should be lit
131         //
132         // this avoids redundantly scanning the triangles in each surface twice
133         // for whether they should cast shadows, once in culling and once in the
134         // actual shadowmarklist production.
135         int static_numshadowtrispvsbytes;
136         unsigned char *static_shadowtrispvs;
137         // this allows the lighting batch code to skip backfaces andother culled
138         // triangles not relevant for lighting
139         // (important on big surfaces such as terrain)
140         int static_numlighttrispvsbytes;
141         unsigned char *static_lighttrispvs;
142 }
143 rtlight_t;
144
145 typedef struct dlight_s
146 {
147         // destroy light after this time
148         // (dlight only)
149         vec_t die;
150         // the entity that owns this light (can be NULL)
151         // (dlight only)
152         struct entity_render_s *ent;
153         // location
154         // (worldlight: saved to .rtlights file)
155         vec3_t origin;
156         // worldlight orientation
157         // (worldlight only)
158         // (worldlight: saved to .rtlights file)
159         vec3_t angles;
160         // dlight orientation/scaling/location
161         // (dlight only)
162         matrix4x4_t matrix;
163         // color of light
164         // (worldlight: saved to .rtlights file)
165         vec3_t color;
166         // cubemap name to use on this light
167         // (worldlight: saved to .rtlights file)
168         char cubemapname[64];
169         // make light flash while selected
170         // (worldlight only)
171         int selected;
172         // brightness (not really radius anymore)
173         // (worldlight: saved to .rtlights file)
174         vec_t radius;
175         // drop intensity this much each second
176         // (dlight only)
177         vec_t decay;
178         // intensity value which is dropped over time
179         // (dlight only)
180         vec_t intensity;
181         // initial values for intensity to modify
182         // (dlight only)
183         vec_t initialradius;
184         vec3_t initialcolor;
185         // light style which controls intensity of this light
186         // (worldlight: saved to .rtlights file)
187         int style;
188         // cast shadows
189         // (worldlight: saved to .rtlights file)
190         int shadow;
191         // corona intensity
192         // (worldlight: saved to .rtlights file)
193         vec_t corona;
194         // radius scale of corona to render (1.0 means same as light radius)
195         // (worldlight: saved to .rtlights file)
196         vec_t coronasizescale;
197         // ambient intensity to render
198         // (worldlight: saved to .rtlights file)
199         vec_t ambientscale;
200         // diffuse intensity to render
201         // (worldlight: saved to .rtlights file)
202         vec_t diffusescale;
203         // specular intensity to render
204         // (worldlight: saved to .rtlights file)
205         vec_t specularscale;
206         // LIGHTFLAG_* flags
207         // (worldlight: saved to .rtlights file)
208         int flags;
209         // linked list of world lights
210         // (worldlight only)
211         struct dlight_s *next;
212         // embedded rtlight struct for renderer
213         // (worldlight only)
214         rtlight_t rtlight;
215 }
216 dlight_t;
217
218 typedef struct frameblend_s
219 {
220         int frame;
221         float lerp;
222 }
223 frameblend_t;
224
225 // LordHavoc: this struct is intended for the renderer but some fields are
226 // used by the client.
227 typedef struct entity_render_s
228 {
229         // location
230         //vec3_t origin;
231         // orientation
232         //vec3_t angles;
233         // transform matrix for model to world
234         matrix4x4_t matrix;
235         // transform matrix for world to model
236         matrix4x4_t inversematrix;
237         // opacity (alpha) of the model
238         float alpha;
239         // size the model is shown
240         float scale;
241
242         // NULL = no model
243         model_t *model;
244         // current uninterpolated animation frame (for things which do not use interpolation)
245         int frame;
246         // entity shirt and pants colors (-1 if not colormapped)
247         int colormap;
248         // literal colors for renderer
249         vec3_t colormap_pantscolor;
250         vec3_t colormap_shirtcolor;
251         // light, particles, etc
252         int effects;
253         // for Alias models
254         int skinnum;
255         // render flags
256         int flags;
257
258         // colormod tinting of models
259         float colormod[3];
260
261         // interpolated animation
262
263         // frame that the model is interpolating from
264         int frame1;
265         // frame that the model is interpolating to
266         int frame2;
267         // interpolation factor, usually computed from frame2time
268         float framelerp;
269         // time frame1 began playing (for framegroup animations)
270         double frame1time;
271         // time frame2 began playing (for framegroup animations)
272         double frame2time;
273
274         // calculated by the renderer (but not persistent)
275
276         // calculated during R_AddModelEntities
277         vec3_t mins, maxs;
278         // 4 frame numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use frame instead
279         frameblend_t frameblend[4];
280
281         // current lighting from map
282         vec3_t modellight_ambient;
283         vec3_t modellight_diffuse; // q3bsp
284         vec3_t modellight_lightdir; // q3bsp
285
286         // last time visible during trace culling
287         double last_trace_visibility;
288 }
289 entity_render_t;
290
291 typedef struct entity_persistent_s
292 {
293         vec3_t trail_origin;
294
295         // particle trail
296         float trail_time;
297
298         // muzzleflash fading
299         float muzzleflash;
300
301         // interpolated movement
302
303         // start time of move
304         float lerpstarttime;
305         // time difference from start to end of move
306         float lerpdeltatime;
307         // the move itself, start and end
308         float oldorigin[3];
309         float oldangles[3];
310         float neworigin[3];
311         float newangles[3];
312 }
313 entity_persistent_t;
314
315 typedef struct entity_s
316 {
317         // baseline state (default values)
318         entity_state_t state_baseline;
319         // previous state (interpolating from this)
320         entity_state_t state_previous;
321         // current state (interpolating to this)
322         entity_state_t state_current;
323
324         // used for regenerating parts of render
325         entity_persistent_t persistent;
326
327         // the only data the renderer should know about
328         entity_render_t render;
329 }
330 entity_t;
331
332 typedef struct usercmd_s
333 {
334         vec3_t  viewangles;
335
336 // intended velocities
337         float   forwardmove;
338         float   sidemove;
339         float   upmove;
340
341         vec3_t  cursor_screen;
342         vec3_t  cursor_start;
343         vec3_t  cursor_end;
344         vec3_t  cursor_impact;
345         vec3_t  cursor_normal;
346         vec_t   cursor_fraction;
347         int             cursor_entitynumber;
348
349         double time;
350         double receivetime;
351         int msec; // for qw moves
352         int buttons;
353         int impulse;
354         int sequence;
355         qboolean applied; // if false we're still accumulating a move
356 } usercmd_t;
357
358 typedef struct lightstyle_s
359 {
360         int             length;
361         char    map[MAX_STYLESTRING];
362 } lightstyle_t;
363
364 typedef struct scoreboard_s
365 {
366         char    name[MAX_SCOREBOARDNAME];
367         int             frags;
368         int             colors; // two 4 bit fields
369         // QW fields:
370         int             qw_userid;
371         char    qw_userinfo[MAX_USERINFO_STRING];
372         float   qw_entertime;
373         int             qw_ping;
374         int             qw_packetloss;
375         int             qw_spectator;
376         char    qw_team[8];
377         char    qw_skin[MAX_QPATH];
378 } scoreboard_t;
379
380 typedef struct cshift_s
381 {
382         float   destcolor[3];
383         float   percent;                // 0-256
384 } cshift_t;
385
386 #define CSHIFT_CONTENTS 0
387 #define CSHIFT_DAMAGE   1
388 #define CSHIFT_BONUS    2
389 #define CSHIFT_POWERUP  3
390 #define CSHIFT_VCSHIFT  4
391 #define NUM_CSHIFTS             5
392
393 #define NAME_LENGTH     64
394
395
396 //
397 // client_state_t should hold all pieces of the client state
398 //
399
400 #define SIGNONS         4                       // signon messages to receive before connected
401
402 #define MAX_DEMOS               8
403 #define MAX_DEMONAME    16
404
405 typedef enum cactive_e
406 {
407         ca_dedicated,           // a dedicated server with no ability to start a client
408         ca_disconnected,        // full screen console with no connection
409         ca_connected            // valid netcon, talking to a server
410 }
411 cactive_t;
412
413 typedef enum qw_downloadtype_e
414 {
415         dl_none,
416         dl_single,
417         dl_skin,
418         dl_model,
419         dl_sound
420 }
421 qw_downloadtype_t;
422
423 typedef enum capturevideoformat_e
424 {
425         CAPTUREVIDEOFORMAT_AVI_I420
426 }
427 capturevideoformat_t;
428
429 typedef struct capturevideostate_s
430 {
431         double starttime;
432         double framerate;
433         // for AVI saving some values have to be written after capture ends
434         fs_offset_t videofile_totalframes_offset1;
435         fs_offset_t videofile_totalframes_offset2;
436         fs_offset_t videofile_totalsampleframes_offset;
437         qfile_t *videofile;
438         qboolean active;
439         qboolean realtime;
440         qboolean error;
441         capturevideoformat_t format;
442         int soundrate;
443         int frame;
444         int soundsampleframe; // for AVI saving
445         unsigned char *buffer;
446         sizebuf_t riffbuffer;
447         unsigned char riffbufferdata[128];
448         // note: riffindex buffer has an allocated ->data member, not static like most!
449         sizebuf_t riffindexbuffer;
450         int riffstacklevel;
451         fs_offset_t riffstackstartoffset[4];
452         short rgbtoyuvscaletable[3][3][256];
453         unsigned char yuvnormalizetable[3][256];
454         char basename[64];
455 }
456 capturevideostate_t;
457
458 #define CL_MAX_DOWNLOADACKS 4
459
460 typedef struct cl_downloadack_s
461 {
462         int start, size;
463 }
464 cl_downloadack_t;
465
466 //
467 // the client_static_t structure is persistent through an arbitrary number
468 // of server connections
469 //
470 typedef struct client_static_s
471 {
472         cactive_t state;
473
474         // all client memory allocations go in these pools
475         mempool_t *levelmempool;
476         mempool_t *permanentmempool;
477
478 // demo loop control
479         // -1 = don't play demos
480         int demonum;
481         // list of demos in loop
482         char demos[MAX_DEMOS][MAX_DEMONAME];
483         // the actively playing demo (set by CL_PlayDemo_f)
484         char demoname[64];
485
486 // demo recording info must be here, because record is started before
487 // entering a map (and clearing client_state_t)
488         qboolean demorecording;
489         qboolean demoplayback;
490         qboolean timedemo;
491         // -1 = use normal cd track
492         int forcetrack;
493         qfile_t *demofile;
494         // to meter out one message a frame
495         int td_lastframe;
496         // host_framecount at start
497         int td_startframe;
498         // realtime at second frame of timedemo (LordHavoc: changed to double)
499         double td_starttime;
500         double td_onesecondnexttime;
501         double td_onesecondframes;
502         double td_onesecondminframes;
503         double td_onesecondmaxframes;
504         double td_onesecondavgframes;
505         int td_onesecondavgcount;
506         // LordHavoc: pausedemo
507         qboolean demopaused;
508
509         qboolean connect_trying;
510         int connect_remainingtries;
511         double connect_nextsendtime;
512         lhnetsocket_t *connect_mysocket;
513         lhnetaddress_t connect_address;
514         // protocol version of the server we're connected to
515         // (kept outside client_state_t because it's used between levels)
516         protocolversion_t protocol;
517
518 // connection information
519         // 0 to SIGNONS
520         int signon;
521         // network connection
522         netconn_t *netcon;
523
524         // download information
525         // (note: qw_download variables are also used)
526         cl_downloadack_t dp_downloadack[CL_MAX_DOWNLOADACKS];
527
528         // input sequence numbers are not reset on level change, only connect
529         int movesequence;
530         int servermovesequence;
531
532         // quakeworld stuff below
533
534         // value of "qport" cvar at time of connection
535         int qw_qport;
536         // copied from cls.netcon->qw. variables every time they change, or set by demos (which have no cls.netcon)
537         int qw_incoming_sequence;
538         int qw_outgoing_sequence;
539
540         // current file download buffer (only saved when file is completed)
541         char qw_downloadname[MAX_QPATH];
542         unsigned char *qw_downloadmemory;
543         int qw_downloadmemorycursize;
544         int qw_downloadmemorymaxsize;
545         int qw_downloadnumber;
546         int qw_downloadpercent;
547         qw_downloadtype_t qw_downloadtype;
548         // transfer rate display
549         double qw_downloadspeedtime;
550         int qw_downloadspeedcount;
551         int qw_downloadspeedrate;
552
553         // current file upload buffer (for uploading screenshots to server)
554         unsigned char *qw_uploaddata;
555         int qw_uploadsize;
556         int qw_uploadpos;
557
558         // user infostring
559         // this normally contains the following keys in quakeworld:
560         // password spectator name team skin topcolor bottomcolor rate noaim msg *ver *ip
561         char userinfo[MAX_USERINFO_STRING];
562
563         // video capture stuff
564         capturevideostate_t capturevideo;
565 }
566 client_static_t;
567
568 extern client_static_t  cls;
569
570 typedef struct client_movementqueue_s
571 {
572         double time;
573         float frametime;
574         int sequence;
575         float viewangles[3];
576         float move[3];
577         qboolean jump;
578         qboolean crouch;
579 }
580 client_movementqueue_t;
581
582 //[515]: csqc
583 typedef struct
584 {
585         qboolean drawworld;
586         qboolean drawenginesbar;
587         qboolean drawcrosshair;
588 }csqc_vidvars_t;
589
590 typedef enum
591 {
592         PARTICLE_BILLBOARD = 0,
593         PARTICLE_SPARK = 1,
594         PARTICLE_ORIENTED_DOUBLESIDED = 2,
595         PARTICLE_BEAM = 3
596 }
597 porientation_t;
598
599 typedef enum
600 {
601         PBLEND_ALPHA = 0,
602         PBLEND_ADD = 1,
603         PBLEND_MOD = 2
604 }
605 pblend_t;
606
607 typedef struct particletype_s
608 {
609         pblend_t blendmode;
610         porientation_t orientation;
611         qboolean lighting;
612 }
613 particletype_t;
614
615 typedef enum
616 {
617         pt_alphastatic, pt_static, pt_spark, pt_beam, pt_rain, pt_raindecal, pt_snow, pt_bubble, pt_blood, pt_smoke, pt_decal, pt_entityparticle, pt_total
618 }
619 ptype_t;
620
621 typedef struct particle_s
622 {
623         particletype_t *type;
624         int                     texnum;
625         vec3_t          org;
626         vec3_t          vel; // velocity of particle, or orientation of decal, or end point of beam
627         float           size;
628         float           sizeincrease; // rate of size change per second
629         float           alpha; // 0-255
630         float           alphafade; // how much alpha reduces per second
631         float           time2; // used for snow fluttering and decal fade
632         float           bounce; // how much bounce-back from a surface the particle hits (0 = no physics, 1 = stop and slide, 2 = keep bouncing forever, 1.5 is typical)
633         float           gravity; // how much gravity affects this particle (1.0 = normal gravity, 0.0 = none)
634         float           airfriction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
635         float           liquidfriction; // how much liquid friction affects this object (objects with a low mass/size ratio tend to get more liquid friction)
636         unsigned char           color[4];
637         unsigned int            owner; // decal stuck to this entity
638         model_t         *ownermodel; // model the decal is stuck to (used to make sure the entity is still alive)
639         vec3_t          relativeorigin; // decal at this location in entity's coordinate space
640         vec3_t          relativedirection; // decal oriented this way relative to entity's coordinate space
641 }
642 particle_t;
643
644 typedef enum cl_parsingtextmode_e
645 {
646         CL_PARSETEXTMODE_NONE,
647         CL_PARSETEXTMODE_PING,
648         CL_PARSETEXTMODE_STATUS,
649         CL_PARSETEXTMODE_STATUS_PLAYERID,
650         CL_PARSETEXTMODE_STATUS_PLAYERIP
651 }
652 cl_parsingtextmode_t;
653
654 //
655 // the client_state_t structure is wiped completely at every
656 // server signon
657 //
658 typedef struct client_state_s
659 {
660         // true if playing in a local game and no one else is connected
661         int islocalgame;
662
663         // send a clc_nop periodically until connected
664         float sendnoptime;
665
666         // current input being accumulated by mouse/joystick/etc input
667         usercmd_t cmd;
668         // latest moves sent to the server that have not been confirmed yet
669         usercmd_t movecmd[CL_MAX_USERCMDS];
670
671 // information for local display
672         // health, etc
673         int stats[MAX_CL_STATS];
674         // last known inventory bit flags, for blinking
675         int olditems;
676         // cl.time of acquiring item, for blinking
677         float item_gettime[32];
678         // last known STAT_ACTIVEWEAPON
679         int activeweapon;
680         // cl.time of changing STAT_ACTIVEWEAPON
681         float weapontime;
682         // use pain anim frame if cl.time < this
683         float faceanimtime;
684         // for stair smoothing
685         float stairsmoothz;
686         double stairsmoothtime;
687
688         // color shifts for damage, powerups
689         cshift_t cshifts[NUM_CSHIFTS];
690         // and content types
691         cshift_t prev_cshifts[NUM_CSHIFTS];
692
693 // the client maintains its own idea of view angles, which are
694 // sent to the server each frame.  The server sets punchangle when
695 // the view is temporarily offset, and an angle reset commands at the start
696 // of each level and after teleporting.
697
698         // mviewangles is read from demo
699         // viewangles is either client controlled or lerped from mviewangles
700         vec3_t mviewangles[2], viewangles;
701         // update by server, used by qc to do weapon recoil
702         vec3_t mpunchangle[2], punchangle;
703         // update by server, can be used by mods to kick view around
704         vec3_t mpunchvector[2], punchvector;
705         // update by server, used for lean+bob (0 is newest)
706         vec3_t mvelocity[2], velocity;
707         // update by server, can be used by mods for zooming
708         vec_t mviewzoom[2], viewzoom;
709         // if true interpolation the mviewangles and other interpolation of the
710         // player is disabled until the next network packet
711         // this is used primarily by teleporters, and when spectating players
712         // special checking of the old fixangle[1] is used to differentiate
713         // between teleporting and spectating
714         qboolean fixangle[2];
715
716         // client movement simulation
717         // these fields are only updated by CL_ClientMovement (called by CL_SendMove after parsing each network packet)
718         // set by CL_ClientMovement_Replay functions
719         qboolean movement_predicted;
720         // this is set true by svc_time parsing and causes a new movement to be
721         // queued for prediction purposes
722         qboolean movement_needupdate;
723         // timestamps of latest two predicted moves for interpolation
724         double movement_time[4];
725         // simulated data (this is valid even if cl.movement is false)
726         vec3_t movement_origin;
727         vec3_t movement_oldorigin;
728         vec3_t movement_velocity;
729         // queue of proposed moves
730         int movement_numqueue;
731         client_movementqueue_t movement_queue[256];
732         // whether the replay should allow a jump at the first sequence
733         qboolean movement_replay_canjump;
734
735 // pitch drifting vars
736         float idealpitch;
737         float pitchvel;
738         qboolean nodrift;
739         float driftmove;
740         double laststop;
741
742 //[515]: added for csqc purposes
743         float sensitivityscale;
744         csqc_vidvars_t csqc_vidvars;    //[515]: these parms must be set to true by default
745         qboolean csqc_wantsmousemove;
746         struct model_s *csqc_model_precache[MAX_MODELS];
747
748         // local amount for smoothing stepups
749         //float crouch;
750
751         // sent by server
752         qboolean paused;
753         qboolean onground;
754         qboolean inwater;
755
756         // used by bob
757         qboolean oldonground;
758         double lastongroundtime;
759         double hitgroundtime;
760
761         // don't change view angle, full screen, etc
762         int intermission;
763         // latched at intermission start
764         double completed_time;
765
766         // the timestamp of the last two messages
767         double mtime[2];
768
769         // clients view of time, time should be between mtime[0] and mtime[1] to
770         // generate a lerp point for other data, oldtime is the previous frame's
771         // value of time, frametime is the difference between time and oldtime
772         // note: cl.time may be beyond cl.mtime[0] if packet loss is occuring, it
773         // is only forcefully limited when a packet is received
774         double time, oldtime;
775         // how long it has been since the previous client frame in real time
776         // (not game time, for that use cl.time - cl.oldtime)
777         double realframetime;
778
779         // copy of realtime from last recieved message, for net trouble icon
780         float last_received_message;
781
782 // information that is static for the entire time connected to a server
783         struct model_s *model_precache[MAX_MODELS];
784         struct sfx_s *sound_precache[MAX_SOUNDS];
785
786         // FIXME: this is a lot of memory to be keeping around, this really should be dynamically allocated and freed somehow
787         char model_name[MAX_MODELS][MAX_QPATH];
788         char sound_name[MAX_SOUNDS][MAX_QPATH];
789
790         // for display on solo scoreboard
791         char levelname[40];
792         // cl_entitites[cl.viewentity] = player
793         int viewentity;
794         // the real player entity (normally same as viewentity,
795         // different than viewentity if mod uses chasecam or other tricks)
796         int playerentity;
797         // max players that can be in this game
798         int maxclients;
799         // type of game (deathmatch, coop, singleplayer)
800         int gametype;
801
802         // models and sounds used by engine code (particularly cl_parse.c)
803         model_t *model_bolt;
804         model_t *model_bolt2;
805         model_t *model_bolt3;
806         model_t *model_beam;
807         sfx_t *sfx_wizhit;
808         sfx_t *sfx_knighthit;
809         sfx_t *sfx_tink1;
810         sfx_t *sfx_ric1;
811         sfx_t *sfx_ric2;
812         sfx_t *sfx_ric3;
813         sfx_t *sfx_r_exp3;
814
815 // refresh related state
816
817         // cl_entitites[0].model
818         struct model_s *worldmodel;
819
820         // the gun model
821         entity_t viewent;
822
823         // cd audio
824         int cdtrack, looptrack;
825
826 // frag scoreboard
827
828         // [cl.maxclients]
829         scoreboard_t *scores;
830
831         // keep track of svc_print parsing state (analyzes ping reports and status reports)
832         cl_parsingtextmode_t parsingtextmode;
833         int parsingtextplayerindex;
834         // set by scoreboard code when sending ping command, this causes the next ping results to be hidden
835         // (which could eat the wrong ping report if the player issues one
836         //  manually, but they would still see a ping report, just a later one
837         //  caused by the scoreboard code rather than the one they intentionally
838         //  issued)
839         int parsingtextexpectingpingforscores;
840
841         // entity database stuff
842         // latest received entity frame numbers
843 #define LATESTFRAMENUMS 3
844         int latestframenums[LATESTFRAMENUMS];
845         entityframe_database_t *entitydatabase;
846         entityframe4_database_t *entitydatabase4;
847         entityframeqw_database_t *entitydatabaseqw;
848
849         // keep track of quake entities because they need to be killed if they get stale
850         int lastquakeentity;
851         unsigned char isquakeentity[MAX_EDICTS];
852
853         // bounding boxes for clientside movement
854         vec3_t playerstandmins;
855         vec3_t playerstandmaxs;
856         vec3_t playercrouchmins;
857         vec3_t playercrouchmaxs;
858
859         int max_entities;
860         int max_static_entities;
861         int max_temp_entities;
862         int max_effects;
863         int max_beams;
864         int max_dlights;
865         int max_lightstyle;
866         int max_brushmodel_entities;
867         int max_particles;
868
869         entity_t *entities;
870         unsigned char *entities_active;
871         entity_t *static_entities;
872         entity_t *temp_entities;
873         cl_effect_t *effects;
874         beam_t *beams;
875         dlight_t *dlights;
876         lightstyle_t *lightstyle;
877         int *brushmodel_entities;
878         particle_t *particles;
879
880         int num_entities;
881         int num_static_entities;
882         int num_temp_entities;
883         int num_brushmodel_entities;
884         int num_effects;
885         int num_beams;
886         int num_dlights;
887         int num_particles;
888
889         int free_particle;
890
891         // cl_serverextension_download feature
892         int loadmodel_current;
893         int downloadmodel_current;
894         int loadmodel_total;
895         int loadsound_current;
896         int downloadsound_current;
897         int loadsound_total;
898         qboolean downloadcsqc;
899         qboolean loadbegun;
900         qboolean loadfinished;
901
902         // quakeworld stuff
903
904         // local copy of the server infostring
905         char qw_serverinfo[MAX_SERVERINFO_STRING];
906
907         // time of last qw "pings" command sent to server while showing scores
908         double last_ping_request;
909
910         // used during connect
911         int qw_servercount;
912
913         // updated from serverinfo
914         int qw_teamplay;
915
916         // unused: indicates whether the player is spectating
917         // use cl.scores[cl.playerentity].qw_spectator instead
918         //qboolean qw_spectator;
919
920         // movement parameters for client prediction
921         float qw_movevars_gravity;
922         float qw_movevars_stopspeed;
923         float qw_movevars_maxspeed; // can change during play
924         float qw_movevars_spectatormaxspeed;
925         float qw_movevars_accelerate;
926         float qw_movevars_airaccelerate;
927         float qw_movevars_wateraccelerate;
928         float qw_movevars_friction;
929         float qw_movevars_waterfriction;
930         float qw_movevars_entgravity; // can change during play
931
932         // models used by qw protocol
933         int qw_modelindex_spike;
934         int qw_modelindex_player;
935         int qw_modelindex_flag;
936         int qw_modelindex_s_explod;
937
938         vec3_t qw_intermission_origin;
939         vec3_t qw_intermission_angles;
940
941         // 255 is the most nails the QW protocol could send
942         int qw_num_nails;
943         vec_t qw_nails[255][6];
944
945         float qw_weaponkick;
946
947         int qw_validsequence;
948
949         int qw_deltasequence[QW_UPDATE_BACKUP];
950
951         // csqc stuff:
952
953         // collision culling data
954         world_t world;
955 }
956 client_state_t;
957
958 //
959 // cvars
960 //
961 extern cvar_t cl_name;
962 extern cvar_t cl_color;
963 extern cvar_t cl_rate;
964 extern cvar_t cl_pmodel;
965 extern cvar_t cl_playermodel;
966 extern cvar_t cl_playerskin;
967
968 extern cvar_t rcon_password;
969 extern cvar_t rcon_address;
970
971 extern cvar_t cl_upspeed;
972 extern cvar_t cl_forwardspeed;
973 extern cvar_t cl_backspeed;
974 extern cvar_t cl_sidespeed;
975
976 extern cvar_t cl_movespeedkey;
977
978 extern cvar_t cl_yawspeed;
979 extern cvar_t cl_pitchspeed;
980
981 extern cvar_t cl_anglespeedkey;
982
983 extern cvar_t cl_autofire;
984
985 extern cvar_t cl_shownet;
986 extern cvar_t cl_nolerp;
987 extern cvar_t cl_nettimesyncmode;
988
989 extern cvar_t cl_pitchdriftspeed;
990 extern cvar_t lookspring;
991 extern cvar_t lookstrafe;
992 extern cvar_t sensitivity;
993
994 extern cvar_t freelook;
995
996 extern cvar_t m_pitch;
997 extern cvar_t m_yaw;
998 extern cvar_t m_forward;
999 extern cvar_t m_side;
1000
1001 extern cvar_t cl_autodemo;
1002 extern cvar_t cl_autodemo_nameformat;
1003
1004 extern cvar_t r_draweffects;
1005
1006 extern cvar_t cl_explosions_alpha_start;
1007 extern cvar_t cl_explosions_alpha_end;
1008 extern cvar_t cl_explosions_size_start;
1009 extern cvar_t cl_explosions_size_end;
1010 extern cvar_t cl_explosions_lifetime;
1011 extern cvar_t cl_stainmaps;
1012 extern cvar_t cl_stainmaps_clearonload;
1013
1014 extern cvar_t cl_prydoncursor;
1015
1016 extern client_state_t cl;
1017
1018 extern void CL_AllocLightFlash (entity_render_t *ent, matrix4x4_t *matrix, float radius, float red, float green, float blue, float decay, float lifetime, int cubemapnum, int style, int shadowenable, vec_t corona, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags);
1019
1020 //=============================================================================
1021
1022 //
1023 // cl_main
1024 //
1025
1026 void CL_Shutdown (void);
1027 void CL_Init (void);
1028
1029 void CL_EstablishConnection(const char *host);
1030
1031 void CL_Disconnect (void);
1032 void CL_Disconnect_f (void);
1033
1034 void CL_UpdateRenderEntity(entity_render_t *ent);
1035 void CL_UpdateEntities(void);
1036
1037 //
1038 // cl_input
1039 //
1040 typedef struct kbutton_s
1041 {
1042         int             down[2];                // key nums holding it down
1043         int             state;                  // low bit is down state
1044 }
1045 kbutton_t;
1046
1047 extern  kbutton_t       in_mlook, in_klook;
1048 extern  kbutton_t       in_strafe;
1049 extern  kbutton_t       in_speed;
1050
1051 void CL_InitInput (void);
1052 void CL_SendMove (void);
1053
1054 void CL_ValidateState(entity_state_t *s);
1055 void CL_MoveLerpEntityStates(entity_t *ent);
1056 void CL_LerpUpdate(entity_t *e);
1057 void CL_ParseTEnt (void);
1058 void CL_NewBeam (int ent, vec3_t start, vec3_t end, model_t *m, int lightning);
1059 void CL_RelinkBeams (void);
1060 void CL_Beam_CalculatePositions (const beam_t *b, vec3_t start, vec3_t end);
1061
1062 void CL_ClearTempEntities (void);
1063 entity_t *CL_NewTempEntity (void);
1064
1065 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate);
1066
1067 void CL_ClearState (void);
1068 void CL_ExpandEntities(int num);
1069 void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allowstarkey, qboolean allowmodel, qboolean quiet);
1070
1071
1072 int  CL_ReadFromServer (void);
1073 void CL_WriteToServer (void);
1074 void CL_Input (void);
1075 extern qboolean cl_ignoremousemove;
1076
1077
1078 float CL_KeyState (kbutton_t *key);
1079 const char *Key_KeynumToString (int keynum);
1080 int Key_StringToKeynum (const char *str);
1081
1082 //
1083 // cl_demo.c
1084 //
1085 void CL_StopPlayback(void);
1086 void CL_ReadDemoMessage(void);
1087 void CL_WriteDemoMessage(void);
1088
1089 void CL_NextDemo(void);
1090 void CL_Stop_f(void);
1091 void CL_Record_f(void);
1092 void CL_PlayDemo_f(void);
1093 void CL_TimeDemo_f(void);
1094
1095 //
1096 // cl_parse.c
1097 //
1098 void CL_Parse_Init(void);
1099 void CL_Parse_Shutdown(void);
1100 void CL_ParseServerMessage(void);
1101 void CL_Parse_DumpPacket(void);
1102 void CL_Parse_ErrorCleanUp(void);
1103 void QW_CL_StartUpload(unsigned char *data, int size);
1104 extern cvar_t qport;
1105
1106 //
1107 // view
1108 //
1109 void V_StartPitchDrift (void);
1110 void V_StopPitchDrift (void);
1111
1112 void V_Init (void);
1113 float V_CalcRoll (vec3_t angles, vec3_t velocity);
1114 void V_UpdateBlends (void);
1115 void V_ParseDamage (void);
1116
1117 //
1118 // cl_part
1119 //
1120
1121 extern cvar_t cl_particles;
1122 extern cvar_t cl_particles_quality;
1123 extern cvar_t cl_particles_size;
1124 extern cvar_t cl_particles_quake;
1125 extern cvar_t cl_particles_blood;
1126 extern cvar_t cl_particles_blood_alpha;
1127 extern cvar_t cl_particles_blood_bloodhack;
1128 extern cvar_t cl_particles_bulletimpacts;
1129 extern cvar_t cl_particles_explosions_smoke;
1130 extern cvar_t cl_particles_explosions_sparks;
1131 extern cvar_t cl_particles_explosions_shell;
1132 extern cvar_t cl_particles_smoke;
1133 extern cvar_t cl_particles_smoke_alpha;
1134 extern cvar_t cl_particles_smoke_alphafade;
1135 extern cvar_t cl_particles_sparks;
1136 extern cvar_t cl_particles_bubbles;
1137 extern cvar_t cl_decals;
1138 extern cvar_t cl_decals_time;
1139 extern cvar_t cl_decals_fadetime;
1140
1141 void CL_Particles_Clear(void);
1142 void CL_Particles_Init(void);
1143 void CL_Particles_Shutdown(void);
1144
1145 typedef enum effectnameindex_s
1146 {
1147         EFFECT_NONE,
1148         EFFECT_TE_GUNSHOT,
1149         EFFECT_TE_GUNSHOTQUAD,
1150         EFFECT_TE_SPIKE,
1151         EFFECT_TE_SPIKEQUAD,
1152         EFFECT_TE_SUPERSPIKE,
1153         EFFECT_TE_SUPERSPIKEQUAD,
1154         EFFECT_TE_WIZSPIKE,
1155         EFFECT_TE_KNIGHTSPIKE,
1156         EFFECT_TE_EXPLOSION,
1157         EFFECT_TE_EXPLOSIONQUAD,
1158         EFFECT_TE_TAREXPLOSION,
1159         EFFECT_TE_TELEPORT,
1160         EFFECT_TE_LAVASPLASH,
1161         EFFECT_TE_SMALLFLASH,
1162         EFFECT_TE_FLAMEJET,
1163         EFFECT_EF_FLAME,
1164         EFFECT_TE_BLOOD,
1165         EFFECT_TE_SPARK,
1166         EFFECT_TE_PLASMABURN,
1167         EFFECT_TE_TEI_G3,
1168         EFFECT_TE_TEI_SMOKE,
1169         EFFECT_TE_TEI_BIGEXPLOSION,
1170         EFFECT_TE_TEI_PLASMAHIT,
1171         EFFECT_EF_STARDUST,
1172         EFFECT_TR_ROCKET,
1173         EFFECT_TR_GRENADE,
1174         EFFECT_TR_BLOOD,
1175         EFFECT_TR_WIZSPIKE,
1176         EFFECT_TR_SLIGHTBLOOD,
1177         EFFECT_TR_KNIGHTSPIKE,
1178         EFFECT_TR_VORESPIKE,
1179         EFFECT_TR_NEHAHRASMOKE,
1180         EFFECT_TR_NEXUIZPLASMA,
1181         EFFECT_TR_GLOWTRAIL,
1182         EFFECT_SVC_PARTICLE,
1183         EFFECT_TOTAL
1184 }
1185 effectnameindex_t;
1186
1187 int CL_ParticleEffectIndexForName(const char *name);
1188 const char *CL_ParticleEffectNameForIndex(int i);
1189 void CL_ParticleEffect(int effectindex, float pcount, const vec3_t originmins, const vec3_t originmaxs, const vec3_t velocitymins, const vec3_t velocitymaxs, entity_t *ent, int palettecolor);
1190 void CL_ParticleTrail(int effectindex, float pcount, const vec3_t originmins, const vec3_t originmaxs, const vec3_t velocitymins, const vec3_t velocitymaxs, entity_t *ent, int palettecolor, qboolean spawndlight, qboolean spawnparticles);
1191 void CL_ParseParticleEffect (void);
1192 void CL_ParticleCube (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, vec_t gravity, vec_t randomvel);
1193 void CL_ParticleRain (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, int type);
1194 void CL_EntityParticles (const entity_t *ent);
1195 void CL_ParticleExplosion (const vec3_t org);
1196 void CL_ParticleExplosion2 (const vec3_t org, int colorStart, int colorLength);
1197 void CL_MoveParticles(void);
1198 void R_MoveExplosions(void);
1199 void R_NewExplosion(const vec3_t org);
1200
1201 void Debug_PolygonBegin(const char *picname, int flags, qboolean draw2d, float linewidth);
1202 void Debug_PolygonVertex(float x, float y, float z, float s, float t, float r, float g, float b, float a);
1203 void Debug_PolygonEnd(void);
1204
1205 #include "cl_screen.h"
1206
1207 extern qboolean sb_showscores;
1208
1209 #define NUMCROSSHAIRS 32
1210 extern cachepic_t *r_crosshairs[NUMCROSSHAIRS+1];
1211
1212 #define FOGTABLEWIDTH 1024
1213 extern int fogtableindex;
1214 #define VERTEXFOGTABLE(dist) (fogtableindex = (int)((dist) * r_refdef.fogtabledistmultiplier), r_refdef.fogtable[bound(0, fogtableindex, FOGTABLEWIDTH - 1)])
1215
1216 typedef struct r_refdef_stats_s
1217 {
1218         int entities;
1219         int entities_surfaces;
1220         int entities_triangles;
1221         int world_leafs;
1222         int world_portals;
1223         int particles;
1224         int meshes;
1225         int meshes_elements;
1226         int lights;
1227         int lights_clears;
1228         int lights_scissored;
1229         int lights_lighttriangles;
1230         int lights_shadowtriangles;
1231         int lights_dynamicshadowtriangles;
1232         int bloom;
1233         int bloom_copypixels;
1234         int bloom_drawpixels;
1235 }
1236 r_refdef_stats_t;
1237
1238 typedef struct r_refdef_s
1239 {
1240         // these fields define the basic rendering information for the world
1241         // but not the view, which could change multiple times in one rendered
1242         // frame (for example when rendering textures for certain effects)
1243
1244         // these are set for water warping before
1245         // frustum_x/frustum_y are calculated
1246         float frustumscale_x, frustumscale_y;
1247
1248         // minimum visible distance (pixels closer than this disappear)
1249         double nearclip;
1250         // maximum visible distance (pixels further than this disappear in 16bpp modes,
1251         // in 32bpp an infinite-farclip matrix is used instead)
1252         double farclip;
1253
1254         // fullscreen color blend
1255         float viewblend[4];
1256
1257         // whether to call S_ExtraUpdate during render to reduce sound chop
1258         qboolean extraupdate;
1259
1260         // client gameworld time for rendering time based effects
1261         double time;
1262
1263         // the world
1264         entity_render_t *worldentity;
1265
1266         // same as worldentity->model
1267         model_t *worldmodel;
1268
1269         // renderable entities (excluding world)
1270         entity_render_t **entities;
1271         int numentities;
1272         int maxentities;
1273
1274         // renderable dynamic lights
1275         rtlight_t lights[MAX_DLIGHTS];
1276         int numlights;
1277
1278         // 8.8bit fixed point intensities for light styles
1279         // controls intensity of dynamic lights and lightmap layers
1280         unsigned short  lightstylevalue[256];   // 8.8 fraction of base light value
1281
1282         vec3_t fogcolor;
1283         vec_t fogrange;
1284         vec_t fograngerecip;
1285         vec_t fogtabledistmultiplier;
1286         float fogtable[FOGTABLEWIDTH];
1287         float fog_density;
1288         float fog_red;
1289         float fog_green;
1290         float fog_blue;
1291         qboolean fogenabled;
1292         qboolean oldgl_fogenable;
1293
1294         qboolean draw2dstage;
1295
1296         // true during envmap command capture
1297         qboolean envmap;
1298
1299         // brightness of world lightmaps and related lighting
1300         // (often reduced when world rtlights are enabled)
1301         float lightmapintensity;
1302         // whether to draw world lights realtime, dlights realtime, and their shadows
1303         qboolean rtworld;
1304         qboolean rtworldshadows;
1305         qboolean rtdlight;
1306         qboolean rtdlightshadows;
1307         float polygonfactor;
1308         float polygonoffset;
1309         float shadowpolygonfactor;
1310         float shadowpolygonoffset;
1311
1312         // rendering stats for r_speeds display
1313         // (these are incremented in many places)
1314         r_refdef_stats_t stats;
1315 }
1316 r_refdef_t;
1317
1318 typedef struct r_view_s
1319 {
1320         // view information (changes multiple times per frame)
1321         // if any of these variables change then r_viewcache must be regenerated
1322         // by calling R_View_Update
1323         // (which also updates viewport, scissor, colormask)
1324
1325         // it is safe and expected to copy this into a structure on the stack and
1326         // call the renderer recursively, then restore from the stack afterward
1327         // (as long as R_View_Update is called)
1328
1329         // eye position information
1330         matrix4x4_t matrix;
1331         vec3_t origin;
1332         vec3_t forward;
1333         vec3_t left;
1334         vec3_t right;
1335         vec3_t up;
1336         mplane_t frustum[5];
1337         float frustum_x, frustum_y;
1338
1339         // screen area to render in
1340         int x;
1341         int y;
1342         int z;
1343         int width;
1344         int height;
1345         int depth;
1346
1347         // which color components to allow (for anaglyph glasses)
1348         int colormask[4];
1349
1350         // global RGB color multiplier for rendering, this is required by HDR
1351         float colorscale;
1352 }
1353 r_view_t;
1354
1355 typedef struct r_viewcache_s
1356 {
1357         // these properties are generated by R_View_Update()
1358
1359         // which entities are currently visible for this viewpoint
1360         // (the used range is 0...r_refdef.numentities)
1361         unsigned char entityvisible[MAX_EDICTS];
1362         // flag arrays used for visibility checking on world model
1363         // (all other entities have no per-surface/per-leaf visibility checks)
1364         // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_clusters
1365         unsigned char world_pvsbits[(32768+7)>>3];
1366         // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_leafs
1367         unsigned char world_leafvisible[32768];
1368         // TODO: dynamic resize according to r_refdef.worldmodel->num_surfaces
1369         unsigned char world_surfacevisible[262144];
1370         // if true, the view is currently in a leaf without pvs data
1371         qboolean world_novis;
1372 }
1373 r_viewcache_t;
1374
1375 extern r_refdef_t r_refdef;
1376 extern r_view_t r_view;
1377 extern r_viewcache_t r_viewcache;
1378
1379 #endif
1380