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