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