]> icculus.org git repositories - divverent/darkplaces.git/blob - client.h
even better matrix inversion (will test it later), in benchmarks it was slightly...
[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 #include "snd_main.h"
27
28 // LordHavoc: 256 dynamic lights
29 #define MAX_DLIGHTS 256
30
31 /// this is the maximum number of input packets that can be predicted
32 #define CL_MAX_USERCMDS 128
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         double 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 light filter coordinates to world coordinates
73         matrix4x4_t matrix_lighttoworld;
74         /// matrix for transforming world coordinates to light filter coordinates
75         matrix4x4_t matrix_worldtolight;
76         /// typically 1 1 1, can be lower (dim) or higher (overbright)
77         vec3_t color;
78         /// size of the light (remove?)
79         vec_t radius;
80         /// light filter
81         char cubemapname[64];
82         /// light style to monitor for brightness
83         int style;
84         /// whether light should render shadows
85         int shadow;
86         /// intensity of corona to render
87         vec_t corona;
88         /// radius scale of corona to render (1.0 means same as light radius)
89         vec_t coronasizescale;
90         /// ambient intensity to render
91         vec_t ambientscale;
92         /// diffuse intensity to render
93         vec_t diffusescale;
94         /// specular intensity to render
95         vec_t specularscale;
96         /// LIGHTFLAG_* flags
97         int flags;
98
99         // generated properties
100         /// used only for shadow volumes
101         vec3_t shadoworigin;
102         /// culling
103         vec3_t cullmins;
104         vec3_t cullmaxs;
105         // culling
106         //vec_t cullradius;
107         // squared cullradius
108         //vec_t cullradius2;
109
110         // rendering properties, updated each time a light is rendered
111         // this is rtlight->color * d_lightstylevalue
112         vec3_t currentcolor;
113         /// used by corona updates, due to occlusion query
114         float corona_visibility;
115         unsigned int corona_queryindex_visiblepixels;
116         unsigned int corona_queryindex_allpixels;
117         /// this is R_Shadow_Cubemap(rtlight->cubemapname)
118         rtexture_t *currentcubemap;
119
120         /// static light info
121         /// true if this light should be compiled as a static light
122         int isstatic;
123         /// true if this is a compiled world light, cleared if the light changes
124         int compiled;
125         /// the shadowing mode used to compile this light
126         int shadowmode;
127         /// premade shadow volumes to render for world entity
128         shadowmesh_t *static_meshchain_shadow_zpass;
129         shadowmesh_t *static_meshchain_shadow_zfail;
130         shadowmesh_t *static_meshchain_shadow_shadowmap;
131         /// used for visibility testing (more exact than bbox)
132         int static_numleafs;
133         int static_numleafpvsbytes;
134         int *static_leaflist;
135         unsigned char *static_leafpvs;
136         /// surfaces seen by light
137         int static_numsurfaces;
138         int *static_surfacelist;
139         /// flag bits indicating which triangles of the world model should cast
140         /// shadows, and which ones should be lit
141         ///
142         /// this avoids redundantly scanning the triangles in each surface twice
143         /// for whether they should cast shadows, once in culling and once in the
144         /// actual shadowmarklist production.
145         int static_numshadowtrispvsbytes;
146         unsigned char *static_shadowtrispvs;
147         /// this allows the lighting batch code to skip backfaces andother culled
148         /// triangles not relevant for lighting
149         /// (important on big surfaces such as terrain)
150         int static_numlighttrispvsbytes;
151         unsigned char *static_lighttrispvs;
152 }
153 rtlight_t;
154
155 typedef struct dlight_s
156 {
157         // destroy light after this time
158         // (dlight only)
159         vec_t die;
160         // the entity that owns this light (can be NULL)
161         // (dlight only)
162         struct entity_render_s *ent;
163         // location
164         // (worldlight: saved to .rtlights file)
165         vec3_t origin;
166         // worldlight orientation
167         // (worldlight only)
168         // (worldlight: saved to .rtlights file)
169         vec3_t angles;
170         // dlight orientation/scaling/location
171         // (dlight only)
172         matrix4x4_t matrix;
173         // color of light
174         // (worldlight: saved to .rtlights file)
175         vec3_t color;
176         // cubemap name to use on this light
177         // (worldlight: saved to .rtlights file)
178         char cubemapname[64];
179         // make light flash while selected
180         // (worldlight only)
181         int selected;
182         // brightness (not really radius anymore)
183         // (worldlight: saved to .rtlights file)
184         vec_t radius;
185         // drop intensity this much each second
186         // (dlight only)
187         vec_t decay;
188         // intensity value which is dropped over time
189         // (dlight only)
190         vec_t intensity;
191         // initial values for intensity to modify
192         // (dlight only)
193         vec_t initialradius;
194         vec3_t initialcolor;
195         // light style which controls intensity of this light
196         // (worldlight: saved to .rtlights file)
197         int style;
198         // cast shadows
199         // (worldlight: saved to .rtlights file)
200         int shadow;
201         // corona intensity
202         // (worldlight: saved to .rtlights file)
203         vec_t corona;
204         // radius scale of corona to render (1.0 means same as light radius)
205         // (worldlight: saved to .rtlights file)
206         vec_t coronasizescale;
207         // ambient intensity to render
208         // (worldlight: saved to .rtlights file)
209         vec_t ambientscale;
210         // diffuse intensity to render
211         // (worldlight: saved to .rtlights file)
212         vec_t diffusescale;
213         // specular intensity to render
214         // (worldlight: saved to .rtlights file)
215         vec_t specularscale;
216         // LIGHTFLAG_* flags
217         // (worldlight: saved to .rtlights file)
218         int flags;
219         // linked list of world lights
220         // (worldlight only)
221         struct dlight_s *next;
222         // embedded rtlight struct for renderer
223         // (worldlight only)
224         rtlight_t rtlight;
225 }
226 dlight_t;
227
228 #define MAX_FRAMEGROUPBLENDS 4
229 typedef struct framegroupblend_s
230 {
231         // animation number and blend factor
232         // (for most models this is the frame number)
233         int frame;
234         float lerp;
235         // time frame began playing (for framegroup animations)
236         double start;
237 }
238 framegroupblend_t;
239
240 // this is derived from processing of the framegroupblend array
241 // note: technically each framegroupblend can produce two of these, but that
242 // never happens in practice because no one blends between more than 2
243 // framegroups at once
244 #define MAX_FRAMEBLENDS MAX_FRAMEGROUPBLENDS
245 typedef struct frameblend_s
246 {
247         int subframe;
248         float lerp;
249 }
250 frameblend_t;
251
252 // LordHavoc: this struct is intended for the renderer but some fields are
253 // used by the client.
254 //
255 // The renderer should not rely on any changes to this struct to be persistent
256 // across multiple frames because temp entities are wiped every frame, but it
257 // is acceptable to cache things in this struct that are not critical.
258 //
259 // For example the r_cullentities_trace code does such caching.
260 typedef struct entity_render_s
261 {
262         // location
263         //vec3_t origin;
264         // orientation
265         //vec3_t angles;
266         // transform matrix for model to world
267         matrix4x4_t matrix;
268         // transform matrix for world to model
269         matrix4x4_t inversematrix;
270         // opacity (alpha) of the model
271         float alpha;
272         // size the model is shown
273         float scale;
274         // transparent sorting offset
275         float transparent_offset;
276
277         // NULL = no model
278         dp_model_t *model;
279         // number of the entity represents, or 0 for non-network entities
280         int entitynumber;
281         // literal colormap colors for renderer, if both are 0 0 0 it is not colormapped
282         vec3_t colormap_pantscolor;
283         vec3_t colormap_shirtcolor;
284         // light, particles, etc
285         int effects;
286         // qw CTF flags and other internal-use-only effect bits
287         int internaleffects;
288         // for Alias models
289         int skinnum;
290         // render flags
291         int flags;
292
293         // colormod tinting of models
294         float colormod[3];
295         float glowmod[3];
296
297         // interpolated animation - active framegroups and blend factors
298         framegroupblend_t framegroupblend[MAX_FRAMEGROUPBLENDS];
299
300         // time of last model change (for shader animations)
301         double shadertime;
302
303         // calculated by the renderer (but not persistent)
304
305         // calculated during R_AddModelEntities
306         vec3_t mins, maxs;
307         // subframe numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use subframeblend[0].subframe
308         frameblend_t frameblend[MAX_FRAMEBLENDS];
309
310         // animation cache index
311         int animcacheindex;
312
313         // current lighting from map (updated ONLY by client code, not renderer)
314         vec3_t modellight_ambient;
315         vec3_t modellight_diffuse; // q3bsp
316         vec3_t modellight_lightdir; // q3bsp
317
318         // FIELDS UPDATED BY RENDERER:
319         // last time visible during trace culling
320         double last_trace_visibility;
321 }
322 entity_render_t;
323
324 typedef struct entity_persistent_s
325 {
326         vec3_t trail_origin;
327
328         // particle trail
329         float trail_time;
330         qboolean trail_allowed; // set to false by teleports, true by update code, prevents bad lerps
331
332         // muzzleflash fading
333         float muzzleflash;
334
335         // interpolated movement
336
337         // start time of move
338         float lerpstarttime;
339         // time difference from start to end of move
340         float lerpdeltatime;
341         // the move itself, start and end
342         float oldorigin[3];
343         float oldangles[3];
344         float neworigin[3];
345         float newangles[3];
346 }
347 entity_persistent_t;
348
349 typedef struct entity_s
350 {
351         // baseline state (default values)
352         entity_state_t state_baseline;
353         // previous state (interpolating from this)
354         entity_state_t state_previous;
355         // current state (interpolating to this)
356         entity_state_t state_current;
357
358         // used for regenerating parts of render
359         entity_persistent_t persistent;
360
361         // the only data the renderer should know about
362         entity_render_t render;
363 }
364 entity_t;
365
366 typedef struct usercmd_s
367 {
368         vec3_t  viewangles;
369
370 // intended velocities
371         float   forwardmove;
372         float   sidemove;
373         float   upmove;
374
375         vec3_t  cursor_screen;
376         vec3_t  cursor_start;
377         vec3_t  cursor_end;
378         vec3_t  cursor_impact;
379         vec3_t  cursor_normal;
380         vec_t   cursor_fraction;
381         int             cursor_entitynumber;
382
383         double time; // time the move is executed for (cl_movement: clienttime, non-cl_movement: receivetime)
384         double receivetime; // time the move was received at
385         double clienttime; // time to which server state the move corresponds to
386         int msec; // for predicted moves
387         int buttons;
388         int impulse;
389         int sequence;
390         qboolean applied; // if false we're still accumulating a move
391         qboolean predicted; // if true the sequence should be sent as 0
392
393         // derived properties
394         double frametime;
395         qboolean canjump;
396         qboolean jump;
397         qboolean crouch;
398 } usercmd_t;
399
400 typedef struct lightstyle_s
401 {
402         int             length;
403         char    map[MAX_STYLESTRING];
404 } lightstyle_t;
405
406 typedef struct scoreboard_s
407 {
408         char    name[MAX_SCOREBOARDNAME];
409         int             frags;
410         int             colors; // two 4 bit fields
411         // QW fields:
412         int             qw_userid;
413         char    qw_userinfo[MAX_USERINFO_STRING];
414         float   qw_entertime;
415         int             qw_ping;
416         int             qw_packetloss;
417         int             qw_spectator;
418         char    qw_team[8];
419         char    qw_skin[MAX_QPATH];
420 } scoreboard_t;
421
422 typedef struct cshift_s
423 {
424         float   destcolor[3];
425         float   percent;                // 0-255
426         float   alphafade;      // (any speed)
427 } cshift_t;
428
429 #define CSHIFT_CONTENTS 0
430 #define CSHIFT_DAMAGE   1
431 #define CSHIFT_BONUS    2
432 #define CSHIFT_POWERUP  3
433 #define CSHIFT_VCSHIFT  4
434 #define NUM_CSHIFTS             5
435
436 #define NAME_LENGTH     64
437
438
439 //
440 // client_state_t should hold all pieces of the client state
441 //
442
443 #define SIGNONS         4                       // signon messages to receive before connected
444
445 #define MAX_DEMOS               8
446 #define MAX_DEMONAME    16
447
448 typedef enum cactive_e
449 {
450         ca_uninitialized,       // during early startup
451         ca_dedicated,           // a dedicated server with no ability to start a client
452         ca_disconnected,        // full screen console with no connection
453         ca_connected            // valid netcon, talking to a server
454 }
455 cactive_t;
456
457 typedef enum qw_downloadtype_e
458 {
459         dl_none,
460         dl_single,
461         dl_skin,
462         dl_model,
463         dl_sound
464 }
465 qw_downloadtype_t;
466
467 typedef enum capturevideoformat_e
468 {
469         CAPTUREVIDEOFORMAT_AVI_I420,
470         CAPTUREVIDEOFORMAT_OGG_VORBIS_THEORA,
471 }
472 capturevideoformat_t;
473
474 typedef struct capturevideostate_s
475 {
476         double startrealtime;
477         double framerate;
478         int framestep;
479         int framestepframe;
480         qboolean active;
481         qboolean realtime;
482         qboolean error;
483         int soundrate;
484         int soundchannels;
485         int frame;
486         double starttime;
487         double lastfpstime;
488         int lastfpsframe;
489         int soundsampleframe;
490         unsigned char *screenbuffer;
491         unsigned char *outbuffer;
492         char basename[MAX_QPATH];
493         int width, height;
494
495         // precomputed RGB to YUV tables
496         // converts the RGB values to YUV (see cap_avi.c for how to use them)
497         short rgbtoyuvscaletable[3][3][256];
498         unsigned char yuvnormalizetable[3][256];
499
500         // precomputed gamma ramp (only needed if the capturevideo module uses RGB output)
501         // note: to map from these values to RGB24, you have to multiply by 255.0/65535.0, then add 0.5, then cast to integer
502         unsigned short vidramp[256 * 3];
503
504         // stuff to be filled in by the video format module
505         capturevideoformat_t format;
506         const char *formatextension;
507         qfile_t *videofile;
508                 // always use this:
509                 //   cls.capturevideo.videofile = FS_OpenRealFile(va("%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false);
510         void (*endvideo) (void);
511         void (*videoframes) (int num);
512         void (*soundframe) (const portable_sampleframe_t *paintbuffer, size_t length);
513
514         // format specific data
515         void *formatspecific;
516 }
517 capturevideostate_t;
518
519 #define CL_MAX_DOWNLOADACKS 4
520
521 typedef struct cl_downloadack_s
522 {
523         int start, size;
524 }
525 cl_downloadack_t;
526
527 typedef struct cl_soundstats_s
528 {
529         int mixedsounds;
530         int totalsounds;
531         int latency_milliseconds;
532 }
533 cl_soundstats_t;
534
535 //
536 // the client_static_t structure is persistent through an arbitrary number
537 // of server connections
538 //
539 typedef struct client_static_s
540 {
541         cactive_t state;
542
543         // all client memory allocations go in these pools
544         mempool_t *levelmempool;
545         mempool_t *permanentmempool;
546
547 // demo loop control
548         // -1 = don't play demos
549         int demonum;
550         // list of demos in loop
551         char demos[MAX_DEMOS][MAX_DEMONAME];
552         // the actively playing demo (set by CL_PlayDemo_f)
553         char demoname[MAX_QPATH];
554
555 // demo recording info must be here, because record is started before
556 // entering a map (and clearing client_state_t)
557         qboolean demorecording;
558         fs_offset_t demo_lastcsprogssize;
559         int demo_lastcsprogscrc;
560         qboolean demoplayback;
561         qboolean timedemo;
562         // -1 = use normal cd track
563         int forcetrack;
564         qfile_t *demofile;
565         // realtime at second frame of timedemo (LordHavoc: changed to double)
566         double td_starttime;
567         int td_frames; // total frames parsed
568         double td_onesecondnexttime;
569         double td_onesecondframes;
570         double td_onesecondrealtime;
571         double td_onesecondminfps;
572         double td_onesecondmaxfps;
573         double td_onesecondavgfps;
574         int td_onesecondavgcount;
575         // LordHavoc: pausedemo
576         qboolean demopaused;
577
578         // sound mixer statistics for showsound display
579         cl_soundstats_t soundstats;
580
581         qboolean connect_trying;
582         int connect_remainingtries;
583         double connect_nextsendtime;
584         lhnetsocket_t *connect_mysocket;
585         lhnetaddress_t connect_address;
586         // protocol version of the server we're connected to
587         // (kept outside client_state_t because it's used between levels)
588         protocolversion_t protocol;
589
590 #define MAX_RCONS 16
591         int rcon_trying;
592         lhnetaddress_t rcon_addresses[MAX_RCONS];
593         char rcon_commands[MAX_RCONS][MAX_INPUTLINE];
594         double rcon_timeout[MAX_RCONS];
595         int rcon_ringpos;
596
597 // connection information
598         // 0 to SIGNONS
599         int signon;
600         // network connection
601         netconn_t *netcon;
602
603         // download information
604         // (note: qw_download variables are also used)
605         cl_downloadack_t dp_downloadack[CL_MAX_DOWNLOADACKS];
606
607         // input sequence numbers are not reset on level change, only connect
608         int movesequence;
609         int servermovesequence;
610
611         // quakeworld stuff below
612
613         // value of "qport" cvar at time of connection
614         int qw_qport;
615         // copied from cls.netcon->qw. variables every time they change, or set by demos (which have no cls.netcon)
616         int qw_incoming_sequence;
617         int qw_outgoing_sequence;
618
619         // current file download buffer (only saved when file is completed)
620         char qw_downloadname[MAX_QPATH];
621         unsigned char *qw_downloadmemory;
622         int qw_downloadmemorycursize;
623         int qw_downloadmemorymaxsize;
624         int qw_downloadnumber;
625         int qw_downloadpercent;
626         qw_downloadtype_t qw_downloadtype;
627         // transfer rate display
628         double qw_downloadspeedtime;
629         int qw_downloadspeedcount;
630         int qw_downloadspeedrate;
631         qboolean qw_download_deflate;
632
633         // current file upload buffer (for uploading screenshots to server)
634         unsigned char *qw_uploaddata;
635         int qw_uploadsize;
636         int qw_uploadpos;
637
638         // user infostring
639         // this normally contains the following keys in quakeworld:
640         // password spectator name team skin topcolor bottomcolor rate noaim msg *ver *ip
641         char userinfo[MAX_USERINFO_STRING];
642
643         // video capture stuff
644         capturevideostate_t capturevideo;
645 }
646 client_static_t;
647
648 extern client_static_t  cls;
649
650 typedef struct client_movementqueue_s
651 {
652         double time;
653         float frametime;
654         int sequence;
655         float viewangles[3];
656         float move[3];
657         qboolean jump;
658         qboolean crouch;
659         qboolean canjump;
660 }
661 client_movementqueue_t;
662
663 //[515]: csqc
664 typedef struct
665 {
666         qboolean drawworld;
667         qboolean drawenginesbar;
668         qboolean drawcrosshair;
669 }csqc_vidvars_t;
670
671 typedef enum
672 {
673         PARTICLE_BILLBOARD = 0,
674         PARTICLE_SPARK = 1,
675         PARTICLE_ORIENTED_DOUBLESIDED = 2,
676         PARTICLE_VBEAM = 3,
677         PARTICLE_HBEAM = 4,
678         PARTICLE_INVALID = -1
679 }
680 porientation_t;
681
682 typedef enum
683 {
684         PBLEND_ALPHA = 0,
685         PBLEND_ADD = 1,
686         PBLEND_INVMOD = 2,
687         PBLEND_INVALID = -1
688 }
689 pblend_t;
690
691 typedef struct particletype_s
692 {
693         pblend_t blendmode;
694         porientation_t orientation;
695         qboolean lighting;
696 }
697 particletype_t;
698
699 typedef enum
700 {
701         pt_dead, 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
702 }
703 ptype_t;
704
705 typedef struct decal_s
706 {
707         // fields used by rendering:  (44 bytes)
708         unsigned short  typeindex;
709         unsigned short  texnum;
710         vec3_t                  org;
711         vec3_t                  normal;
712         float                   size;
713         float                   alpha; // 0-255
714         unsigned char   color[3];
715         unsigned char   unused1;
716         int                             clusterindex; // cheap culling by pvs
717
718         // fields not used by rendering: (36 bytes in 32bit, 40 bytes in 64bit)
719         float                   time2; // used for decal fade
720         unsigned int    owner; // decal stuck to this entity
721         dp_model_t                      *ownermodel; // model the decal is stuck to (used to make sure the entity is still alive)
722         vec3_t                  relativeorigin; // decal at this location in entity's coordinate space
723         vec3_t                  relativenormal; // decal oriented this way relative to entity's coordinate space
724 }
725 decal_t;
726
727 typedef struct particle_s
728 {
729         // fields used by rendering: (40 bytes)
730         unsigned char   typeindex;
731         pblend_t   blendmode;
732         porientation_t   orientation;
733         unsigned char   texnum;
734         vec3_t                  org;
735         vec3_t                  vel; // velocity of particle, or orientation of decal, or end point of beam
736         float                   size;
737         float                   alpha; // 0-255
738         unsigned char   color[3];
739         unsigned char   qualityreduction; // enables skipping of this particle according to r_refdef.view.qualityreduction
740         float           stretch; // only for sparks
741         int             staincolor;
742         signed char     staintexnum;
743         float           stainsizefactor;
744
745         // fields not used by rendering:  (40 bytes)
746         float                   sizeincrease; // rate of size change per second
747         float                   alphafade; // how much alpha reduces per second
748         float                   time2; // used for snow fluttering and decal fade
749         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)
750         float                   gravity; // how much gravity affects this particle (1.0 = normal gravity, 0.0 = none)
751         float                   airfriction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
752         float                   liquidfriction; // how much liquid friction affects this object (objects with a low mass/size ratio tend to get more liquid friction)
753         float                   delayedcollisions; // time that p->bounce becomes active
754         float                   delayedspawn; // time that particle appears and begins moving
755         float                   die; // time when this particle should be removed, regardless of alpha
756 }
757 particle_t;
758
759 typedef enum cl_parsingtextmode_e
760 {
761         CL_PARSETEXTMODE_NONE,
762         CL_PARSETEXTMODE_PING,
763         CL_PARSETEXTMODE_STATUS,
764         CL_PARSETEXTMODE_STATUS_PLAYERID,
765         CL_PARSETEXTMODE_STATUS_PLAYERIP
766 }
767 cl_parsingtextmode_t;
768
769 typedef struct cl_locnode_s
770 {
771         struct cl_locnode_s *next;
772         char *name;
773         vec3_t mins, maxs;
774 }
775 cl_locnode_t;
776
777 typedef struct showlmp_s
778 {
779         qboolean        isactive;
780         float           x;
781         float           y;
782         char            label[32];
783         char            pic[128];
784 }
785 showlmp_t;
786
787 //
788 // the client_state_t structure is wiped completely at every
789 // server signon
790 //
791 typedef struct client_state_s
792 {
793         // true if playing in a local game and no one else is connected
794         int islocalgame;
795
796         // send a clc_nop periodically until connected
797         float sendnoptime;
798
799         // current input being accumulated by mouse/joystick/etc input
800         usercmd_t cmd;
801         // latest moves sent to the server that have not been confirmed yet
802         usercmd_t movecmd[CL_MAX_USERCMDS];
803
804 // information for local display
805         // health, etc
806         int stats[MAX_CL_STATS];
807         float *statsf; // points to stats[] array
808         // last known inventory bit flags, for blinking
809         int olditems;
810         // cl.time of acquiring item, for blinking
811         float item_gettime[32];
812         // last known STAT_ACTIVEWEAPON
813         int activeweapon;
814         // cl.time of changing STAT_ACTIVEWEAPON
815         float weapontime;
816         // use pain anim frame if cl.time < this
817         float faceanimtime;
818         // for stair smoothing
819         float stairsmoothz;
820         double stairsmoothtime;
821
822         // color shifts for damage, powerups
823         cshift_t cshifts[NUM_CSHIFTS];
824         // and content types
825         cshift_t prev_cshifts[NUM_CSHIFTS];
826
827 // the client maintains its own idea of view angles, which are
828 // sent to the server each frame.  The server sets punchangle when
829 // the view is temporarily offset, and an angle reset commands at the start
830 // of each level and after teleporting.
831
832         // mviewangles is read from demo
833         // viewangles is either client controlled or lerped from mviewangles
834         vec3_t mviewangles[2], viewangles;
835         // update by server, used by qc to do weapon recoil
836         vec3_t mpunchangle[2], punchangle;
837         // update by server, can be used by mods to kick view around
838         vec3_t mpunchvector[2], punchvector;
839         // update by server, used for lean+bob (0 is newest)
840         vec3_t mvelocity[2], velocity;
841         // update by server, can be used by mods for zooming
842         vec_t mviewzoom[2], viewzoom;
843         // if true interpolation the mviewangles and other interpolation of the
844         // player is disabled until the next network packet
845         // this is used primarily by teleporters, and when spectating players
846         // special checking of the old fixangle[1] is used to differentiate
847         // between teleporting and spectating
848         qboolean fixangle[2];
849
850         // client movement simulation
851         // these fields are only updated by CL_ClientMovement (called by CL_SendMove after parsing each network packet)
852         // set by CL_ClientMovement_Replay functions
853         qboolean movement_predicted;
854         // if true the CL_ClientMovement_Replay function will update origin, etc
855         qboolean movement_replay;
856         // simulated data (this is valid even if cl.movement is false)
857         vec3_t movement_origin;
858         vec3_t movement_velocity;
859         // whether the replay should allow a jump at the first sequence
860         qboolean movement_replay_canjump;
861
862 // pitch drifting vars
863         float idealpitch;
864         float pitchvel;
865         qboolean nodrift;
866         float driftmove;
867         double laststop;
868
869 //[515]: added for csqc purposes
870         float sensitivityscale;
871         csqc_vidvars_t csqc_vidvars;    //[515]: these parms must be set to true by default
872         qboolean csqc_wantsmousemove;
873         struct model_s *csqc_model_precache[MAX_MODELS];
874
875         // local amount for smoothing stepups
876         //float crouch;
877
878         // sent by server
879         qboolean paused;
880         qboolean onground;
881         qboolean inwater;
882
883         // used by bob
884         qboolean oldonground;
885         double lastongroundtime;
886         double hitgroundtime;
887
888         // don't change view angle, full screen, etc
889         int intermission;
890         // latched at intermission start
891         double completed_time;
892
893         // the timestamp of the last two messages
894         double mtime[2];
895
896         // clients view of time, time should be between mtime[0] and mtime[1] to
897         // generate a lerp point for other data, oldtime is the previous frame's
898         // value of time, frametime is the difference between time and oldtime
899         // note: cl.time may be beyond cl.mtime[0] if packet loss is occuring, it
900         // is only forcefully limited when a packet is received
901         double time, oldtime;
902         // how long it has been since the previous client frame in real time
903         // (not game time, for that use cl.time - cl.oldtime)
904         double realframetime;
905         
906         // fade var for fading while dead
907         float deathfade;
908
909         // motionblur alpha level variable
910         float motionbluralpha;
911
912         // copy of realtime from last recieved message, for net trouble icon
913         float last_received_message;
914
915 // information that is static for the entire time connected to a server
916         struct model_s *model_precache[MAX_MODELS];
917         struct sfx_s *sound_precache[MAX_SOUNDS];
918
919         // FIXME: this is a lot of memory to be keeping around, this really should be dynamically allocated and freed somehow
920         char model_name[MAX_MODELS][MAX_QPATH];
921         char sound_name[MAX_SOUNDS][MAX_QPATH];
922
923         // for display on solo scoreboard
924         char levelname[40];
925         // cl_entitites[cl.viewentity] = player
926         int viewentity;
927         // the real player entity (normally same as viewentity,
928         // different than viewentity if mod uses chasecam or other tricks)
929         int realplayerentity;
930         // this is updated to match cl.viewentity whenever it is in the clients
931         // range, basically this is used in preference to cl.realplayerentity for
932         // most purposes because when spectating another player it should show
933         // their information rather than yours
934         int playerentity;
935         // max players that can be in this game
936         int maxclients;
937         // type of game (deathmatch, coop, singleplayer)
938         int gametype;
939
940         // models and sounds used by engine code (particularly cl_parse.c)
941         dp_model_t *model_bolt;
942         dp_model_t *model_bolt2;
943         dp_model_t *model_bolt3;
944         dp_model_t *model_beam;
945         sfx_t *sfx_wizhit;
946         sfx_t *sfx_knighthit;
947         sfx_t *sfx_tink1;
948         sfx_t *sfx_ric1;
949         sfx_t *sfx_ric2;
950         sfx_t *sfx_ric3;
951         sfx_t *sfx_r_exp3;
952         // indicates that the file "sound/misc/talk2.wav" was found (for use by team chat messages)
953         qboolean foundtalk2wav;
954
955 // refresh related state
956
957         // cl_entitites[0].model
958         struct model_s *worldmodel;
959
960         // the gun model
961         entity_t viewent;
962
963         // cd audio
964         int cdtrack, looptrack;
965
966 // frag scoreboard
967
968         // [cl.maxclients]
969         scoreboard_t *scores;
970
971         // keep track of svc_print parsing state (analyzes ping reports and status reports)
972         cl_parsingtextmode_t parsingtextmode;
973         int parsingtextplayerindex;
974         // set by scoreboard code when sending ping command, this causes the next ping results to be hidden
975         // (which could eat the wrong ping report if the player issues one
976         //  manually, but they would still see a ping report, just a later one
977         //  caused by the scoreboard code rather than the one they intentionally
978         //  issued)
979         int parsingtextexpectingpingforscores;
980
981         // entity database stuff
982         // latest received entity frame numbers
983 #define LATESTFRAMENUMS 3
984         int latestframenums[LATESTFRAMENUMS];
985         entityframe_database_t *entitydatabase;
986         entityframe4_database_t *entitydatabase4;
987         entityframeqw_database_t *entitydatabaseqw;
988
989         // keep track of quake entities because they need to be killed if they get stale
990         int lastquakeentity;
991         unsigned char isquakeentity[MAX_EDICTS];
992
993         // bounding boxes for clientside movement
994         vec3_t playerstandmins;
995         vec3_t playerstandmaxs;
996         vec3_t playercrouchmins;
997         vec3_t playercrouchmaxs;
998
999         int max_entities;
1000         int max_static_entities;
1001         int max_effects;
1002         int max_beams;
1003         int max_dlights;
1004         int max_lightstyle;
1005         int max_brushmodel_entities;
1006         int max_particles;
1007         int max_decals;
1008         int max_showlmps;
1009
1010         entity_t *entities;
1011         unsigned char *entities_active;
1012         entity_t *static_entities;
1013         cl_effect_t *effects;
1014         beam_t *beams;
1015         dlight_t *dlights;
1016         lightstyle_t *lightstyle;
1017         int *brushmodel_entities;
1018         particle_t *particles;
1019         decal_t *decals;
1020         showlmp_t *showlmps;
1021
1022         int num_entities;
1023         int num_static_entities;
1024         int num_brushmodel_entities;
1025         int num_effects;
1026         int num_beams;
1027         int num_dlights;
1028         int num_particles;
1029         int num_decals;
1030         int num_showlmps;
1031
1032         double particles_updatetime;
1033         double decals_updatetime;
1034         int free_particle;
1035         int free_decal;
1036
1037         // cl_serverextension_download feature
1038         int loadmodel_current;
1039         int downloadmodel_current;
1040         int loadmodel_total;
1041         int loadsound_current;
1042         int downloadsound_current;
1043         int loadsound_total;
1044         qboolean downloadcsqc;
1045         qboolean loadcsqc;
1046         qboolean loadbegun;
1047         qboolean loadfinished;
1048
1049         // quakeworld stuff
1050
1051         // local copy of the server infostring
1052         char qw_serverinfo[MAX_SERVERINFO_STRING];
1053
1054         // time of last qw "pings" command sent to server while showing scores
1055         double last_ping_request;
1056
1057         // used during connect
1058         int qw_servercount;
1059
1060         // updated from serverinfo
1061         int qw_teamplay;
1062
1063         // unused: indicates whether the player is spectating
1064         // use cl.scores[cl.playerentity-1].qw_spectator instead
1065         //qboolean qw_spectator;
1066
1067         // last time an input packet was sent
1068         double lastpackettime;
1069
1070         // movement parameters for client prediction
1071         unsigned int moveflags;
1072         float movevars_wallfriction;
1073         float movevars_waterfriction;
1074         float movevars_friction;
1075         float movevars_timescale;
1076         float movevars_gravity;
1077         float movevars_stopspeed;
1078         float movevars_maxspeed;
1079         float movevars_spectatormaxspeed;
1080         float movevars_accelerate;
1081         float movevars_airaccelerate;
1082         float movevars_wateraccelerate;
1083         float movevars_entgravity;
1084         float movevars_jumpvelocity;
1085         float movevars_edgefriction;
1086         float movevars_maxairspeed;
1087         float movevars_stepheight;
1088         float movevars_airaccel_qw;
1089         float movevars_airaccel_sideways_friction;
1090         float movevars_airstopaccelerate;
1091         float movevars_airstrafeaccelerate;
1092         float movevars_maxairstrafespeed;
1093         float movevars_aircontrol;
1094         float movevars_warsowbunny_airforwardaccel;
1095         float movevars_warsowbunny_accel;
1096         float movevars_warsowbunny_topspeed;
1097         float movevars_warsowbunny_turnaccel;
1098         float movevars_warsowbunny_backtosideratio;
1099         float movevars_ticrate;
1100
1101         // models used by qw protocol
1102         int qw_modelindex_spike;
1103         int qw_modelindex_player;
1104         int qw_modelindex_flag;
1105         int qw_modelindex_s_explod;
1106
1107         vec3_t qw_intermission_origin;
1108         vec3_t qw_intermission_angles;
1109
1110         // 255 is the most nails the QW protocol could send
1111         int qw_num_nails;
1112         vec_t qw_nails[255][6];
1113
1114         float qw_weaponkick;
1115
1116         int qw_validsequence;
1117
1118         int qw_deltasequence[QW_UPDATE_BACKUP];
1119
1120         // csqc stuff:
1121         // server entity number corresponding to a clientside entity
1122         unsigned short csqc_server2csqcentitynumber[MAX_EDICTS];
1123         qboolean csqc_loaded;
1124         vec3_t csqc_origin;
1125         vec3_t csqc_angles;
1126         qboolean csqc_usecsqclistener;
1127         matrix4x4_t csqc_listenermatrix;
1128         char csqc_printtextbuf[MAX_INPUTLINE];
1129
1130         // collision culling data
1131         world_t world;
1132
1133         // loc file stuff (points and boxes describing locations in the level)
1134         cl_locnode_t *locnodes;
1135         // this is updated to cl.movement_origin whenever health is < 1
1136         // used by %d print in say/say_team messages if cl_locs_enable is on
1137         vec3_t lastdeathorigin;
1138
1139         // processing buffer used by R_BuildLightMap, reallocated as needed,
1140         // freed on each level change
1141         size_t buildlightmapmemorysize;
1142         unsigned char *buildlightmapmemory;
1143 }
1144 client_state_t;
1145
1146 //
1147 // cvars
1148 //
1149 extern cvar_t cl_name;
1150 extern cvar_t cl_color;
1151 extern cvar_t cl_rate;
1152 extern cvar_t cl_pmodel;
1153 extern cvar_t cl_playermodel;
1154 extern cvar_t cl_playerskin;
1155
1156 extern cvar_t rcon_password;
1157 extern cvar_t rcon_address;
1158
1159 extern cvar_t cl_upspeed;
1160 extern cvar_t cl_forwardspeed;
1161 extern cvar_t cl_backspeed;
1162 extern cvar_t cl_sidespeed;
1163
1164 extern cvar_t cl_movespeedkey;
1165
1166 extern cvar_t cl_yawspeed;
1167 extern cvar_t cl_pitchspeed;
1168
1169 extern cvar_t cl_anglespeedkey;
1170
1171 extern cvar_t cl_autofire;
1172
1173 extern cvar_t cl_shownet;
1174 extern cvar_t cl_nolerp;
1175 extern cvar_t cl_nettimesyncfactor;
1176 extern cvar_t cl_nettimesyncboundmode;
1177 extern cvar_t cl_nettimesyncboundtolerance;
1178
1179 extern cvar_t cl_pitchdriftspeed;
1180 extern cvar_t lookspring;
1181 extern cvar_t lookstrafe;
1182 extern cvar_t sensitivity;
1183
1184 extern cvar_t freelook;
1185
1186 extern cvar_t m_pitch;
1187 extern cvar_t m_yaw;
1188 extern cvar_t m_forward;
1189 extern cvar_t m_side;
1190
1191 extern cvar_t cl_autodemo;
1192 extern cvar_t cl_autodemo_nameformat;
1193
1194 extern cvar_t r_draweffects;
1195
1196 extern cvar_t cl_explosions_alpha_start;
1197 extern cvar_t cl_explosions_alpha_end;
1198 extern cvar_t cl_explosions_size_start;
1199 extern cvar_t cl_explosions_size_end;
1200 extern cvar_t cl_explosions_lifetime;
1201 extern cvar_t cl_stainmaps;
1202 extern cvar_t cl_stainmaps_clearonload;
1203
1204 extern cvar_t cl_prydoncursor;
1205
1206 extern cvar_t cl_locs_enable;
1207
1208 extern client_state_t cl;
1209
1210 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);
1211
1212 cl_locnode_t *CL_Locs_FindNearest(const vec3_t point);
1213 void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point);
1214
1215 //=============================================================================
1216
1217 //
1218 // cl_main
1219 //
1220
1221 void CL_Shutdown (void);
1222 void CL_Init (void);
1223
1224 void CL_EstablishConnection(const char *host);
1225
1226 void CL_Disconnect (void);
1227 void CL_Disconnect_f (void);
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, dp_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, int modelindex, int startframe, int framecount, float framerate);
1263
1264 void CL_ClearState (void);
1265 void CL_ExpandEntities(int num);
1266 void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allowstarkey, qboolean allowmodel, qboolean quiet);
1267
1268
1269 void CL_UpdateWorld (void);
1270 void CL_WriteToServer (void);
1271 void CL_Input (void);
1272 extern int cl_ignoremousemoves;
1273
1274
1275 float CL_KeyState (kbutton_t *key);
1276 const char *Key_KeynumToString (int keynum);
1277 int Key_StringToKeynum (const char *str);
1278
1279 //
1280 // cl_demo.c
1281 //
1282 void CL_StopPlayback(void);
1283 void CL_ReadDemoMessage(void);
1284 void CL_WriteDemoMessage(sizebuf_t *mesage);
1285
1286 void CL_CutDemo(unsigned char **buf, fs_offset_t *filesize);
1287 void CL_PasteDemo(unsigned char **buf, fs_offset_t *filesize);
1288
1289 void CL_NextDemo(void);
1290 void CL_Stop_f(void);
1291 void CL_Record_f(void);
1292 void CL_PlayDemo_f(void);
1293 void CL_TimeDemo_f(void);
1294
1295 //
1296 // cl_parse.c
1297 //
1298 void CL_Parse_Init(void);
1299 void CL_Parse_Shutdown(void);
1300 void CL_ParseServerMessage(void);
1301 void CL_Parse_DumpPacket(void);
1302 void CL_Parse_ErrorCleanUp(void);
1303 void QW_CL_StartUpload(unsigned char *data, int size);
1304 extern cvar_t qport;
1305 void CL_KeepaliveMessage(qboolean readmessages); // call this during loading of large content
1306
1307 //
1308 // view
1309 //
1310 void V_StartPitchDrift (void);
1311 void V_StopPitchDrift (void);
1312
1313 void V_Init (void);
1314 float V_CalcRoll (vec3_t angles, vec3_t velocity);
1315 void V_UpdateBlends (void);
1316 void V_ParseDamage (void);
1317
1318 //
1319 // cl_part
1320 //
1321
1322 extern cvar_t cl_particles;
1323 extern cvar_t cl_particles_quality;
1324 extern cvar_t cl_particles_size;
1325 extern cvar_t cl_particles_quake;
1326 extern cvar_t cl_particles_blood;
1327 extern cvar_t cl_particles_blood_alpha;
1328 extern cvar_t cl_particles_blood_bloodhack;
1329 extern cvar_t cl_particles_bulletimpacts;
1330 extern cvar_t cl_particles_explosions_sparks;
1331 extern cvar_t cl_particles_explosions_shell;
1332 extern cvar_t cl_particles_rain;
1333 extern cvar_t cl_particles_snow;
1334 extern cvar_t cl_particles_smoke;
1335 extern cvar_t cl_particles_smoke_alpha;
1336 extern cvar_t cl_particles_smoke_alphafade;
1337 extern cvar_t cl_particles_sparks;
1338 extern cvar_t cl_particles_bubbles;
1339 extern cvar_t cl_decals;
1340 extern cvar_t cl_decals_time;
1341 extern cvar_t cl_decals_fadetime;
1342
1343 void CL_Particles_Clear(void);
1344 void CL_Particles_Init(void);
1345 void CL_Particles_Shutdown(void);
1346 particle_t *CL_NewParticle(unsigned short ptypeindex, int pcolor1, int pcolor2, int ptex, float psize, float psizeincrease, float palpha, float palphafade, float pgravity, float pbounce, float px, float py, float pz, float pvx, float pvy, float pvz, float pairfriction, float pliquidfriction, float originjitter, float velocityjitter, qboolean pqualityreduction, float lifetime, float stretch, pblend_t blendmode, porientation_t orientation, int staincolor1, int staincolor2, int staintex);
1347
1348 typedef enum effectnameindex_s
1349 {
1350         EFFECT_NONE,
1351         EFFECT_TE_GUNSHOT,
1352         EFFECT_TE_GUNSHOTQUAD,
1353         EFFECT_TE_SPIKE,
1354         EFFECT_TE_SPIKEQUAD,
1355         EFFECT_TE_SUPERSPIKE,
1356         EFFECT_TE_SUPERSPIKEQUAD,
1357         EFFECT_TE_WIZSPIKE,
1358         EFFECT_TE_KNIGHTSPIKE,
1359         EFFECT_TE_EXPLOSION,
1360         EFFECT_TE_EXPLOSIONQUAD,
1361         EFFECT_TE_TAREXPLOSION,
1362         EFFECT_TE_TELEPORT,
1363         EFFECT_TE_LAVASPLASH,
1364         EFFECT_TE_SMALLFLASH,
1365         EFFECT_TE_FLAMEJET,
1366         EFFECT_EF_FLAME,
1367         EFFECT_TE_BLOOD,
1368         EFFECT_TE_SPARK,
1369         EFFECT_TE_PLASMABURN,
1370         EFFECT_TE_TEI_G3,
1371         EFFECT_TE_TEI_SMOKE,
1372         EFFECT_TE_TEI_BIGEXPLOSION,
1373         EFFECT_TE_TEI_PLASMAHIT,
1374         EFFECT_EF_STARDUST,
1375         EFFECT_TR_ROCKET,
1376         EFFECT_TR_GRENADE,
1377         EFFECT_TR_BLOOD,
1378         EFFECT_TR_WIZSPIKE,
1379         EFFECT_TR_SLIGHTBLOOD,
1380         EFFECT_TR_KNIGHTSPIKE,
1381         EFFECT_TR_VORESPIKE,
1382         EFFECT_TR_NEHAHRASMOKE,
1383         EFFECT_TR_NEXUIZPLASMA,
1384         EFFECT_TR_GLOWTRAIL,
1385         EFFECT_SVC_PARTICLE,
1386         EFFECT_TOTAL
1387 }
1388 effectnameindex_t;
1389
1390 int CL_ParticleEffectIndexForName(const char *name);
1391 const char *CL_ParticleEffectNameForIndex(int i);
1392 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);
1393 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);
1394 void CL_ParseParticleEffect (void);
1395 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);
1396 void CL_ParticleRain (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, int type);
1397 void CL_EntityParticles (const entity_t *ent);
1398 void CL_ParticleExplosion (const vec3_t org);
1399 void CL_ParticleExplosion2 (const vec3_t org, int colorStart, int colorLength);
1400 void R_NewExplosion(const vec3_t org);
1401
1402 void Debug_PolygonBegin(const char *picname, int flags);
1403 void Debug_PolygonVertex(float x, float y, float z, float s, float t, float r, float g, float b, float a);
1404 void Debug_PolygonEnd(void);
1405
1406 #include "cl_screen.h"
1407
1408 extern qboolean sb_showscores;
1409
1410 float FogPoint_World(const vec3_t p);
1411 float FogPoint_Model(const vec3_t p);
1412 float FogForDistance(vec_t dist);
1413
1414 typedef struct r_refdef_stats_s
1415 {
1416         int renders;
1417         int entities;
1418         int entities_surfaces;
1419         int entities_triangles;
1420         int world_leafs;
1421         int world_portals;
1422         int world_surfaces;
1423         int world_triangles;
1424         int lightmapupdates;
1425         int lightmapupdatepixels;
1426         int particles;
1427         int decals;
1428         int meshes;
1429         int meshes_elements;
1430         int lights;
1431         int lights_clears;
1432         int lights_scissored;
1433         int lights_lighttriangles;
1434         int lights_shadowtriangles;
1435         int lights_dynamicshadowtriangles;
1436         int bloom;
1437         int bloom_copypixels;
1438         int bloom_drawpixels;
1439 }
1440 r_refdef_stats_t;
1441
1442 typedef enum r_viewport_type_e
1443 {
1444         R_VIEWPORTTYPE_ORTHO,
1445         R_VIEWPORTTYPE_PERSPECTIVE,
1446         R_VIEWPORTTYPE_PERSPECTIVE_INFINITEFARCLIP,
1447         R_VIEWPORTTYPE_PERSPECTIVECUBESIDE,
1448         R_VIEWPORTTYPE_TOTAL
1449 }
1450 r_viewport_type_t;
1451
1452 typedef struct r_viewport_s
1453 {
1454         double m[16];
1455         matrix4x4_t cameramatrix; // from entity (transforms from camera entity to world)
1456         matrix4x4_t viewmatrix; // actual matrix for rendering (transforms to viewspace)
1457         matrix4x4_t projectmatrix; // actual projection matrix (transforms from viewspace to screen)
1458         int x;
1459         int y;
1460         int z;
1461         int width;
1462         int height;
1463         int depth;
1464         r_viewport_type_t type;
1465 }
1466 r_viewport_t;
1467
1468 typedef struct r_refdef_view_s
1469 {
1470         // view information (changes multiple times per frame)
1471         // if any of these variables change then r_refdef.viewcache must be regenerated
1472         // by calling R_View_Update
1473         // (which also updates viewport, scissor, colormask)
1474
1475         // it is safe and expected to copy this into a structure on the stack and
1476         // call the renderer recursively, then restore from the stack afterward
1477         // (as long as R_View_Update is called)
1478
1479         // eye position information
1480         matrix4x4_t matrix, inverse_matrix;
1481         vec3_t origin;
1482         vec3_t forward;
1483         vec3_t left;
1484         vec3_t right;
1485         vec3_t up;
1486         int numfrustumplanes;
1487         mplane_t frustum[6];
1488         qboolean useclipplane;
1489         qboolean usecustompvs; // uses r_refdef.viewcache.pvsbits as-is rather than computing it
1490         mplane_t clipplane;
1491         float frustum_x, frustum_y;
1492         vec3_t frustumcorner[4];
1493         // if turned off it renders an ortho view
1494         int useperspective;
1495         float ortho_x, ortho_y;
1496
1497         // screen area to render in
1498         int x;
1499         int y;
1500         int z;
1501         int width;
1502         int height;
1503         int depth;
1504         r_viewport_t viewport;
1505
1506         // which color components to allow (for anaglyph glasses)
1507         int colormask[4];
1508
1509         // global RGB color multiplier for rendering, this is required by HDR
1510         float colorscale;
1511
1512         // whether to call R_ClearScreen before rendering stuff
1513         qboolean clear;
1514         // if true, don't clear or do any post process effects (bloom, etc)
1515         qboolean isoverlay;
1516
1517         // whether to draw r_showtris and such, this is only true for the main
1518         // view render, all secondary renders (HDR, mirrors, portals, cameras,
1519         // distortion effects, etc) omit such debugging information
1520         qboolean showdebug;
1521
1522         // these define which values to use in GL_CullFace calls to request frontface or backface culling
1523         int cullface_front;
1524         int cullface_back;
1525
1526         // render quality (0 to 1) - affects r_drawparticles_drawdistance and others
1527         float quality;
1528 }
1529 r_refdef_view_t;
1530
1531 typedef struct r_refdef_viewcache_s
1532 {
1533         // these properties are generated by R_View_Update()
1534
1535         // which entities are currently visible for this viewpoint
1536         // (the used range is 0...r_refdef.scene.numentities)
1537         unsigned char entityvisible[MAX_EDICTS];
1538         // flag arrays used for visibility checking on world model
1539         // (all other entities have no per-surface/per-leaf visibility checks)
1540         // TODO: dynamic resize according to r_refdef.scene.worldmodel->brush.num_clusters
1541         unsigned char world_pvsbits[(32768+7)>>3]; // FIXME: buffer overflow on huge maps
1542         // TODO: dynamic resize according to r_refdef.scene.worldmodel->brush.num_leafs
1543         unsigned char world_leafvisible[32768]; // FIXME: buffer overflow on huge maps
1544         // TODO: dynamic resize according to r_refdef.scene.worldmodel->num_surfaces
1545         unsigned char world_surfacevisible[262144]; // FIXME: buffer overflow on huge maps
1546         // if true, the view is currently in a leaf without pvs data
1547         qboolean world_novis;
1548 }
1549 r_refdef_viewcache_t;
1550
1551 // TODO: really think about which fields should go into scene and which one should stay in refdef [1/7/2008 Black]
1552 // maybe also refactor some of the functions to support different setting sources (ie. fogenabled, etc.) for different scenes
1553 typedef struct r_refdef_scene_s {
1554         // whether to call S_ExtraUpdate during render to reduce sound chop
1555         qboolean extraupdate;
1556
1557         // (client gameworld) time for rendering time based effects
1558         double time;
1559
1560         // the world
1561         entity_render_t *worldentity;
1562
1563         // same as worldentity->model
1564         dp_model_t *worldmodel;
1565
1566         // renderable entities (excluding world)
1567         entity_render_t **entities;
1568         int numentities;
1569         int maxentities;
1570
1571         // field of temporary entities that is reset each (client) frame
1572         entity_render_t *tempentities;
1573         int numtempentities;
1574         int maxtempentities;
1575
1576         // renderable dynamic lights
1577         rtlight_t *lights[MAX_DLIGHTS];
1578         rtlight_t templights[MAX_DLIGHTS];
1579         int numlights;
1580
1581         // intensities for light styles right now, controls rtlights
1582         float rtlightstylevalue[256];   // float fraction of base light value
1583         // 8.8bit fixed point intensities for light styles
1584         // controls intensity lightmap layers
1585         unsigned short lightstylevalue[256];    // 8.8 fraction of base light value
1586
1587         float ambient;
1588
1589         qboolean rtworld;
1590         qboolean rtworldshadows;
1591         qboolean rtdlight;
1592         qboolean rtdlightshadows;
1593 } r_refdef_scene_t;
1594
1595 typedef struct r_refdef_s
1596 {
1597         // these fields define the basic rendering information for the world
1598         // but not the view, which could change multiple times in one rendered
1599         // frame (for example when rendering textures for certain effects)
1600
1601         // these are set for water warping before
1602         // frustum_x/frustum_y are calculated
1603         float frustumscale_x, frustumscale_y;
1604
1605         // current view settings (these get reset a few times during rendering because of water rendering, reflections, etc)
1606         r_refdef_view_t view;
1607         r_refdef_viewcache_t viewcache;
1608
1609         // minimum visible distance (pixels closer than this disappear)
1610         double nearclip;
1611         // maximum visible distance (pixels further than this disappear in 16bpp modes,
1612         // in 32bpp an infinite-farclip matrix is used instead)
1613         double farclip;
1614
1615         // fullscreen color blend
1616         float viewblend[4];
1617
1618         r_refdef_scene_t scene;
1619
1620         vec3_t fogcolor;
1621         vec_t fogrange;
1622         vec_t fograngerecip;
1623         vec_t fogmasktabledistmultiplier;
1624 #define FOGMASKTABLEWIDTH 1024
1625         float fogmasktable[FOGMASKTABLEWIDTH];
1626         float fogmasktable_start, fogmasktable_alpha, fogmasktable_range, fogmasktable_density;
1627         float fog_density;
1628         float fog_red;
1629         float fog_green;
1630         float fog_blue;
1631         float fog_alpha;
1632         float fog_start;
1633         float fog_end;
1634         qboolean fogenabled;
1635         qboolean oldgl_fogenable;
1636
1637         qboolean draw2dstage;
1638
1639         // true during envmap command capture
1640         qboolean envmap;
1641
1642         // brightness of world lightmaps and related lighting
1643         // (often reduced when world rtlights are enabled)
1644         float lightmapintensity;
1645         // whether to draw world lights realtime, dlights realtime, and their shadows
1646         float polygonfactor;
1647         float polygonoffset;
1648         float shadowpolygonfactor;
1649         float shadowpolygonoffset;
1650
1651         // rendering stats for r_speeds display
1652         // (these are incremented in many places)
1653         r_refdef_stats_t stats;
1654 }
1655 r_refdef_t;
1656
1657 extern r_refdef_t r_refdef;
1658
1659 #endif
1660