]> git.xonotic.org Git - xonotic/darkplaces.git/blob - client.h
Implement GPU-side corona fading
[xonotic/darkplaces.git] / client.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // client.h
21
22 #ifndef CLIENT_H
23 #define CLIENT_H
24
25 #include "matrixlib.h"
26 #include "snd_main.h"
27
28 // NOTE: r_stat_name[] must match this indexing
29 typedef enum r_stat_e
30 {
31         r_stat_timedelta,
32         r_stat_quality,
33         r_stat_renders,
34         r_stat_entities,
35         r_stat_entities_surfaces,
36         r_stat_entities_triangles,
37         r_stat_world_leafs,
38         r_stat_world_portals,
39         r_stat_world_surfaces,
40         r_stat_world_triangles,
41         r_stat_lightmapupdates,
42         r_stat_lightmapupdatepixels,
43         r_stat_particles,
44         r_stat_drawndecals,
45         r_stat_totaldecals,
46         r_stat_draws,
47         r_stat_draws_vertices,
48         r_stat_draws_elements,
49         r_stat_lights,
50         r_stat_lights_clears,
51         r_stat_lights_scissored,
52         r_stat_lights_lighttriangles,
53         r_stat_lights_shadowtriangles,
54         r_stat_lights_dynamicshadowtriangles,
55         r_stat_bouncegrid_lights,
56         r_stat_bouncegrid_particles,
57         r_stat_bouncegrid_traces,
58         r_stat_bouncegrid_hits,
59         r_stat_bouncegrid_splats,
60         r_stat_bouncegrid_bounces,
61         r_stat_photoncache_animated,
62         r_stat_photoncache_cached,
63         r_stat_photoncache_traced,
64         r_stat_bloom,
65         r_stat_bloom_copypixels,
66         r_stat_bloom_drawpixels,
67         r_stat_indexbufferuploadcount,
68         r_stat_indexbufferuploadsize,
69         r_stat_vertexbufferuploadcount,
70         r_stat_vertexbufferuploadsize,
71         r_stat_framedatacurrent,
72         r_stat_framedatasize,
73         r_stat_bufferdatacurrent_vertex, // R_BUFFERDATA_ types are added to this index
74         r_stat_bufferdatacurrent_index16,
75         r_stat_bufferdatacurrent_index32,
76         r_stat_bufferdatacurrent_uniform,
77         r_stat_bufferdatasize_vertex, // R_BUFFERDATA_ types are added to this index
78         r_stat_bufferdatasize_index16,
79         r_stat_bufferdatasize_index32,
80         r_stat_bufferdatasize_uniform,
81         r_stat_animcache_vertexmesh_count,
82         r_stat_animcache_vertexmesh_vertices,
83         r_stat_animcache_vertexmesh_maxvertices,
84         r_stat_animcache_skeletal_count,
85         r_stat_animcache_skeletal_bones,
86         r_stat_animcache_skeletal_maxbones,
87         r_stat_animcache_shade_count,
88         r_stat_animcache_shade_vertices,
89         r_stat_animcache_shade_maxvertices,
90         r_stat_animcache_shape_count,
91         r_stat_animcache_shape_vertices,
92         r_stat_animcache_shape_maxvertices,
93         r_stat_batch_batches,
94         r_stat_batch_withgaps,
95         r_stat_batch_surfaces,
96         r_stat_batch_vertices,
97         r_stat_batch_triangles,
98         r_stat_batch_fast_batches,
99         r_stat_batch_fast_surfaces,
100         r_stat_batch_fast_vertices,
101         r_stat_batch_fast_triangles,
102         r_stat_batch_copytriangles_batches,
103         r_stat_batch_copytriangles_surfaces,
104         r_stat_batch_copytriangles_vertices,
105         r_stat_batch_copytriangles_triangles,
106         r_stat_batch_dynamic_batches,
107         r_stat_batch_dynamic_surfaces,
108         r_stat_batch_dynamic_vertices,
109         r_stat_batch_dynamic_triangles,
110         r_stat_batch_dynamicskeletal_batches,
111         r_stat_batch_dynamicskeletal_surfaces,
112         r_stat_batch_dynamicskeletal_vertices,
113         r_stat_batch_dynamicskeletal_triangles,
114         r_stat_batch_dynamic_batches_because_cvar,
115         r_stat_batch_dynamic_surfaces_because_cvar,
116         r_stat_batch_dynamic_vertices_because_cvar,
117         r_stat_batch_dynamic_triangles_because_cvar,
118         r_stat_batch_dynamic_batches_because_lightmapvertex,
119         r_stat_batch_dynamic_surfaces_because_lightmapvertex,
120         r_stat_batch_dynamic_vertices_because_lightmapvertex,
121         r_stat_batch_dynamic_triangles_because_lightmapvertex,
122         r_stat_batch_dynamic_batches_because_deformvertexes_autosprite,
123         r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite,
124         r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite,
125         r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite,
126         r_stat_batch_dynamic_batches_because_deformvertexes_autosprite2,
127         r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite2,
128         r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite2,
129         r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite2,
130         r_stat_batch_dynamic_batches_because_deformvertexes_normal,
131         r_stat_batch_dynamic_surfaces_because_deformvertexes_normal,
132         r_stat_batch_dynamic_vertices_because_deformvertexes_normal,
133         r_stat_batch_dynamic_triangles_because_deformvertexes_normal,
134         r_stat_batch_dynamic_batches_because_deformvertexes_wave,
135         r_stat_batch_dynamic_surfaces_because_deformvertexes_wave,
136         r_stat_batch_dynamic_vertices_because_deformvertexes_wave,
137         r_stat_batch_dynamic_triangles_because_deformvertexes_wave,
138         r_stat_batch_dynamic_batches_because_deformvertexes_bulge,
139         r_stat_batch_dynamic_surfaces_because_deformvertexes_bulge,
140         r_stat_batch_dynamic_vertices_because_deformvertexes_bulge,
141         r_stat_batch_dynamic_triangles_because_deformvertexes_bulge,
142         r_stat_batch_dynamic_batches_because_deformvertexes_move,
143         r_stat_batch_dynamic_surfaces_because_deformvertexes_move,
144         r_stat_batch_dynamic_vertices_because_deformvertexes_move,
145         r_stat_batch_dynamic_triangles_because_deformvertexes_move,
146         r_stat_batch_dynamic_batches_because_tcgen_lightmap,
147         r_stat_batch_dynamic_surfaces_because_tcgen_lightmap,
148         r_stat_batch_dynamic_vertices_because_tcgen_lightmap,
149         r_stat_batch_dynamic_triangles_because_tcgen_lightmap,
150         r_stat_batch_dynamic_batches_because_tcgen_vector,
151         r_stat_batch_dynamic_surfaces_because_tcgen_vector,
152         r_stat_batch_dynamic_vertices_because_tcgen_vector,
153         r_stat_batch_dynamic_triangles_because_tcgen_vector,
154         r_stat_batch_dynamic_batches_because_tcgen_environment,
155         r_stat_batch_dynamic_surfaces_because_tcgen_environment,
156         r_stat_batch_dynamic_vertices_because_tcgen_environment,
157         r_stat_batch_dynamic_triangles_because_tcgen_environment,
158         r_stat_batch_dynamic_batches_because_tcmod_turbulent,
159         r_stat_batch_dynamic_surfaces_because_tcmod_turbulent,
160         r_stat_batch_dynamic_vertices_because_tcmod_turbulent,
161         r_stat_batch_dynamic_triangles_because_tcmod_turbulent,
162         r_stat_batch_dynamic_batches_because_interleavedarrays,
163         r_stat_batch_dynamic_surfaces_because_interleavedarrays,
164         r_stat_batch_dynamic_vertices_because_interleavedarrays,
165         r_stat_batch_dynamic_triangles_because_interleavedarrays,
166         r_stat_batch_dynamic_batches_because_nogaps,
167         r_stat_batch_dynamic_surfaces_because_nogaps,
168         r_stat_batch_dynamic_vertices_because_nogaps,
169         r_stat_batch_dynamic_triangles_because_nogaps,
170         r_stat_batch_dynamic_batches_because_derived,
171         r_stat_batch_dynamic_surfaces_because_derived,
172         r_stat_batch_dynamic_vertices_because_derived,
173         r_stat_batch_dynamic_triangles_because_derived,
174         r_stat_batch_entitycache_count,
175         r_stat_batch_entitycache_surfaces,
176         r_stat_batch_entitycache_vertices,
177         r_stat_batch_entitycache_triangles,
178         r_stat_batch_entityanimate_count,
179         r_stat_batch_entityanimate_surfaces,
180         r_stat_batch_entityanimate_vertices,
181         r_stat_batch_entityanimate_triangles,
182         r_stat_batch_entityskeletal_count,
183         r_stat_batch_entityskeletal_surfaces,
184         r_stat_batch_entityskeletal_vertices,
185         r_stat_batch_entityskeletal_triangles,
186         r_stat_batch_entitystatic_count,
187         r_stat_batch_entitystatic_surfaces,
188         r_stat_batch_entitystatic_vertices,
189         r_stat_batch_entitystatic_triangles,
190         r_stat_batch_entitycustom_count,
191         r_stat_batch_entitycustom_surfaces,
192         r_stat_batch_entitycustom_vertices,
193         r_stat_batch_entitycustom_triangles,
194         r_stat_count // size of array
195 }
196 r_stat_t;
197
198 // flags for rtlight rendering
199 #define LIGHTFLAG_NORMALMODE 1
200 #define LIGHTFLAG_REALTIMEMODE 2
201
202 typedef struct tridecal_s
203 {
204         // color and initial alpha value
205         float                   texcoord2f[3][2];
206         float                   vertex3f[3][3];
207         float                   color4f[3][4];
208         float                   plane[4]; // backface culling
209         // how long this decal has lived so far (the actual fade begins at cl_decals_time)
210         float                   lived;
211         // if >= 0 this indicates the decal should follow an animated triangle
212         int                             triangleindex;
213         // for visibility culling
214         int                             surfaceindex;
215         // old decals are killed to obey cl_decals_max
216         int                             decalsequence;
217 }
218 tridecal_t;
219
220 typedef struct decalsystem_s
221 {
222         dp_model_t *model;
223         double lastupdatetime;
224         int maxdecals;
225         int freedecal;
226         int numdecals;
227         tridecal_t *decals;
228         float *vertex3f;
229         float *texcoord2f;
230         float *color4f;
231         int *element3i;
232         unsigned short *element3s;
233 }
234 decalsystem_t;
235
236 typedef struct effect_s
237 {
238         int active;
239         vec3_t origin;
240         double starttime;
241         float framerate;
242         int modelindex;
243         int startframe;
244         int endframe;
245         // these are for interpolation
246         int frame;
247         double frame1time;
248         double frame2time;
249 }
250 cl_effect_t;
251
252 typedef struct beam_s
253 {
254         int             entity;
255         // draw this as lightning polygons, or a model?
256         int             lightning;
257         struct model_s  *model;
258         float   endtime;
259         vec3_t  start, end;
260 }
261 beam_t;
262
263 typedef struct rtlight_particle_s
264 {
265         float origin[3];
266         float color[3];
267 }
268 rtlight_particle_t;
269
270 typedef struct rtlight_s
271 {
272         // shadow volumes are done entirely in model space, so there are no matrices for dealing with them...  they just use the origin
273
274         // note that the world to light matrices are inversely scaled (divided) by lightradius
275
276         // core properties
277         /// matrix for transforming light filter coordinates to world coordinates
278         matrix4x4_t matrix_lighttoworld;
279         /// matrix for transforming world coordinates to light filter coordinates
280         matrix4x4_t matrix_worldtolight;
281         /// typically 1 1 1, can be lower (dim) or higher (overbright)
282         vec3_t color;
283         /// size of the light (remove?)
284         vec_t radius;
285         /// light filter
286         char cubemapname[64];
287         /// light style to monitor for brightness
288         int style;
289         /// whether light should render shadows
290         int shadow;
291         /// intensity of corona to render
292         vec_t corona;
293         /// radius scale of corona to render (1.0 means same as light radius)
294         vec_t coronasizescale;
295         /// ambient intensity to render
296         vec_t ambientscale;
297         /// diffuse intensity to render
298         vec_t diffusescale;
299         /// specular intensity to render
300         vec_t specularscale;
301         /// LIGHTFLAG_* flags
302         int flags;
303
304         // generated properties
305         /// used only for shadow volumes
306         vec3_t shadoworigin;
307         /// culling
308         vec3_t cullmins;
309         vec3_t cullmaxs;
310         // culling
311         //vec_t cullradius;
312         // squared cullradius
313         //vec_t cullradius2;
314
315         // rendering properties, updated each time a light is rendered
316         // this is rtlight->color * d_lightstylevalue
317         vec3_t currentcolor;
318         /// used by corona updates, due to occlusion query
319         float corona_visibility;
320         unsigned int occlusion_buf;
321         unsigned int corona_queryindex_visiblepixels;
322         unsigned int corona_queryindex_allpixels;
323         /// this is R_GetCubemap(rtlight->cubemapname)
324         rtexture_t *currentcubemap;
325         /// set by R_Shadow_PrepareLight to decide whether R_Shadow_DrawLight should draw it
326         qboolean draw;
327         /// these fields are set by R_Shadow_PrepareLight for later drawing
328         int cached_numlightentities;
329         int cached_numlightentities_noselfshadow;
330         int cached_numshadowentities;
331         int cached_numshadowentities_noselfshadow;
332         int cached_numsurfaces;
333         struct entity_render_s **cached_lightentities;
334         struct entity_render_s **cached_lightentities_noselfshadow;
335         struct entity_render_s **cached_shadowentities;
336         struct entity_render_s **cached_shadowentities_noselfshadow;
337         unsigned char *cached_shadowtrispvs;
338         unsigned char *cached_lighttrispvs;
339         int *cached_surfacelist;
340         // reduced light cullbox from GetLightInfo
341         vec3_t cached_cullmins;
342         vec3_t cached_cullmaxs;
343         // current shadow-caster culling planes based on view
344         // (any geometry outside these planes can not contribute to the visible
345         //  shadows in any way, and thus can be culled safely)
346         int cached_numfrustumplanes;
347         mplane_t cached_frustumplanes[5]; // see R_Shadow_ComputeShadowCasterCullingPlanes
348
349         /// static light info
350         /// true if this light should be compiled as a static light
351         int isstatic;
352         /// true if this is a compiled world light, cleared if the light changes
353         int compiled;
354         /// the shadowing mode used to compile this light
355         int shadowmode;
356         /// premade shadow volumes to render for world entity
357         shadowmesh_t *static_meshchain_shadow_zpass;
358         shadowmesh_t *static_meshchain_shadow_zfail;
359         shadowmesh_t *static_meshchain_shadow_shadowmap;
360         /// used for visibility testing (more exact than bbox)
361         int static_numleafs;
362         int static_numleafpvsbytes;
363         int *static_leaflist;
364         unsigned char *static_leafpvs;
365         /// surfaces seen by light
366         int static_numsurfaces;
367         int *static_surfacelist;
368         /// flag bits indicating which triangles of the world model should cast
369         /// shadows, and which ones should be lit
370         ///
371         /// this avoids redundantly scanning the triangles in each surface twice
372         /// for whether they should cast shadows, once in culling and once in the
373         /// actual shadowmarklist production.
374         int static_numshadowtrispvsbytes;
375         unsigned char *static_shadowtrispvs;
376         /// this allows the lighting batch code to skip backfaces andother culled
377         /// triangles not relevant for lighting
378         /// (important on big surfaces such as terrain)
379         int static_numlighttrispvsbytes;
380         unsigned char *static_lighttrispvs;
381         /// masks of all shadowmap sides that have any potential static receivers or casters
382         int static_shadowmap_receivers;
383         int static_shadowmap_casters;
384         /// particle-tracing cache for global illumination
385         int particlecache_numparticles;
386         int particlecache_maxparticles;
387         int particlecache_updateparticle;
388         rtlight_particle_t *particlecache_particles;
389
390         /// bouncegrid light info
391         float photoncolor[3];
392         float photons;
393 }
394 rtlight_t;
395
396 typedef struct dlight_s
397 {
398         // destroy light after this time
399         // (dlight only)
400         vec_t die;
401         // the entity that owns this light (can be NULL)
402         // (dlight only)
403         struct entity_render_s *ent;
404         // location
405         // (worldlight: saved to .rtlights file)
406         vec3_t origin;
407         // worldlight orientation
408         // (worldlight only)
409         // (worldlight: saved to .rtlights file)
410         vec3_t angles;
411         // dlight orientation/scaling/location
412         // (dlight only)
413         matrix4x4_t matrix;
414         // color of light
415         // (worldlight: saved to .rtlights file)
416         vec3_t color;
417         // cubemap name to use on this light
418         // (worldlight: saved to .rtlights file)
419         char cubemapname[64];
420         // make light flash while selected
421         // (worldlight only)
422         int selected;
423         // brightness (not really radius anymore)
424         // (worldlight: saved to .rtlights file)
425         vec_t radius;
426         // drop intensity this much each second
427         // (dlight only)
428         vec_t decay;
429         // intensity value which is dropped over time
430         // (dlight only)
431         vec_t intensity;
432         // initial values for intensity to modify
433         // (dlight only)
434         vec_t initialradius;
435         vec3_t initialcolor;
436         // light style which controls intensity of this light
437         // (worldlight: saved to .rtlights file)
438         int style;
439         // cast shadows
440         // (worldlight: saved to .rtlights file)
441         int shadow;
442         // corona intensity
443         // (worldlight: saved to .rtlights file)
444         vec_t corona;
445         // radius scale of corona to render (1.0 means same as light radius)
446         // (worldlight: saved to .rtlights file)
447         vec_t coronasizescale;
448         // ambient intensity to render
449         // (worldlight: saved to .rtlights file)
450         vec_t ambientscale;
451         // diffuse intensity to render
452         // (worldlight: saved to .rtlights file)
453         vec_t diffusescale;
454         // specular intensity to render
455         // (worldlight: saved to .rtlights file)
456         vec_t specularscale;
457         // LIGHTFLAG_* flags
458         // (worldlight: saved to .rtlights file)
459         int flags;
460         // linked list of world lights
461         // (worldlight only)
462         struct dlight_s *next;
463         // embedded rtlight struct for renderer
464         // (worldlight only)
465         rtlight_t rtlight;
466 }
467 dlight_t;
468
469 // this is derived from processing of the framegroupblend array
470 // note: technically each framegroupblend can produce two of these, but that
471 // never happens in practice because no one blends between more than 2
472 // framegroups at once
473 #define MAX_FRAMEBLENDS (MAX_FRAMEGROUPBLENDS * 2)
474 typedef struct frameblend_s
475 {
476         int subframe;
477         float lerp;
478 }
479 frameblend_t;
480
481 // LordHavoc: this struct is intended for the renderer but some fields are
482 // used by the client.
483 //
484 // The renderer should not rely on any changes to this struct to be persistent
485 // across multiple frames because temp entities are wiped every frame, but it
486 // is acceptable to cache things in this struct that are not critical.
487 //
488 // For example the r_cullentities_trace code does such caching.
489 typedef struct entity_render_s
490 {
491         // location
492         //vec3_t origin;
493         // orientation
494         //vec3_t angles;
495         // transform matrix for model to world
496         matrix4x4_t matrix;
497         // transform matrix for world to model
498         matrix4x4_t inversematrix;
499         // opacity (alpha) of the model
500         float alpha;
501         // size the model is shown
502         float scale;
503         // transparent sorting offset
504         float transparent_offset;
505
506         // NULL = no model
507         dp_model_t *model;
508         // number of the entity represents, or 0 for non-network entities
509         int entitynumber;
510         // literal colormap colors for renderer, if both are 0 0 0 it is not colormapped
511         vec3_t colormap_pantscolor;
512         vec3_t colormap_shirtcolor;
513         // light, particles, etc
514         int effects;
515         // qw CTF flags and other internal-use-only effect bits
516         int internaleffects;
517         // for Alias models
518         int skinnum;
519         // render flags
520         int flags;
521
522         // colormod tinting of models
523         float colormod[3];
524         float glowmod[3];
525
526         // interpolated animation - active framegroups and blend factors
527         framegroupblend_t framegroupblend[MAX_FRAMEGROUPBLENDS];
528
529         // time of last model change (for shader animations)
530         double shadertime;
531
532         // calculated by the renderer (but not persistent)
533
534         // calculated during R_AddModelEntities
535         vec3_t mins, maxs;
536         // subframe numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use subframeblend[0].subframe
537         frameblend_t frameblend[MAX_FRAMEBLENDS];
538         // skeletal animation data (if skeleton.relativetransforms is not NULL, it overrides frameblend)
539         skeleton_t *skeleton;
540
541         // animation cache (pointers allocated using R_FrameData_Alloc)
542         // ONLY valid during R_RenderView!  may be NULL (not cached)
543         float          *animcache_vertex3f;
544         r_meshbuffer_t *animcache_vertex3f_vertexbuffer;
545         int             animcache_vertex3f_bufferoffset;
546         float          *animcache_normal3f;
547         r_meshbuffer_t *animcache_normal3f_vertexbuffer;
548         int             animcache_normal3f_bufferoffset;
549         float          *animcache_svector3f;
550         r_meshbuffer_t *animcache_svector3f_vertexbuffer;
551         int             animcache_svector3f_bufferoffset;
552         float          *animcache_tvector3f;
553         r_meshbuffer_t *animcache_tvector3f_vertexbuffer;
554         int             animcache_tvector3f_bufferoffset;
555         // interleaved arrays for rendering and dynamic vertex buffers for them
556         r_vertexmesh_t *animcache_vertexmesh;
557         r_meshbuffer_t *animcache_vertexmesh_vertexbuffer;
558         int             animcache_vertexmesh_bufferoffset;
559         // gpu-skinning shader needs transforms in a certain format, we have to
560         // upload this to a uniform buffer for the shader to use, and also keep a
561         // backup copy in system memory for the dynamic batch fallback code
562         // if this is not NULL, the other animcache variables are NULL
563         float *animcache_skeletaltransform3x4;
564         r_meshbuffer_t *animcache_skeletaltransform3x4buffer;
565         int animcache_skeletaltransform3x4offset;
566         int animcache_skeletaltransform3x4size;
567
568         // current lighting from map (updated ONLY by client code, not renderer)
569         vec3_t modellight_ambient;
570         vec3_t modellight_diffuse; // q3bsp
571         vec3_t modellight_lightdir; // q3bsp
572
573         // storage of decals on this entity
574         // (note: if allowdecals is set, be sure to call R_DecalSystem_Reset on removal!)
575         int allowdecals;
576         decalsystem_t decalsystem;
577
578         // FIELDS UPDATED BY RENDERER:
579         // last time visible during trace culling
580         double last_trace_visibility;
581
582         // user wavefunc parameters (from csqc)
583         vec_t userwavefunc_param[Q3WAVEFUNC_USER_COUNT];
584 }
585 entity_render_t;
586
587 typedef struct entity_persistent_s
588 {
589         vec3_t trail_origin; // previous position for particle trail spawning
590         vec3_t oldorigin; // lerp
591         vec3_t oldangles; // lerp
592         vec3_t neworigin; // lerp
593         vec3_t newangles; // lerp
594         vec_t lerpstarttime; // lerp
595         vec_t lerpdeltatime; // lerp
596         float muzzleflash; // muzzleflash intensity, fades over time
597         float trail_time; // residual error accumulation for particle trail spawning (to keep spacing across frames)
598         qboolean trail_allowed; // set to false by teleports, true by update code, prevents bad lerps
599 }
600 entity_persistent_t;
601
602 typedef struct entity_s
603 {
604         // baseline state (default values)
605         entity_state_t state_baseline;
606         // previous state (interpolating from this)
607         entity_state_t state_previous;
608         // current state (interpolating to this)
609         entity_state_t state_current;
610
611         // used for regenerating parts of render
612         entity_persistent_t persistent;
613
614         // the only data the renderer should know about
615         entity_render_t render;
616 }
617 entity_t;
618
619 typedef struct usercmd_s
620 {
621         vec3_t  viewangles;
622
623 // intended velocities
624         float   forwardmove;
625         float   sidemove;
626         float   upmove;
627
628         vec3_t  cursor_screen;
629         vec3_t  cursor_start;
630         vec3_t  cursor_end;
631         vec3_t  cursor_impact;
632         vec3_t  cursor_normal;
633         vec_t   cursor_fraction;
634         int             cursor_entitynumber;
635
636         double time; // time the move is executed for (cl_movement: clienttime, non-cl_movement: receivetime)
637         double receivetime; // time the move was received at
638         double clienttime; // time to which server state the move corresponds to
639         int msec; // for predicted moves
640         int buttons;
641         int impulse;
642         int sequence;
643         qboolean applied; // if false we're still accumulating a move
644         qboolean predicted; // if true the sequence should be sent as 0
645
646         // derived properties
647         double frametime;
648         qboolean canjump;
649         qboolean jump;
650         qboolean crouch;
651 } usercmd_t;
652
653 typedef struct lightstyle_s
654 {
655         int             length;
656         char    map[MAX_STYLESTRING];
657 } lightstyle_t;
658
659 typedef struct scoreboard_s
660 {
661         char    name[MAX_SCOREBOARDNAME];
662         int             frags;
663         int             colors; // two 4 bit fields
664         // QW fields:
665         int             qw_userid;
666         char    qw_userinfo[MAX_USERINFO_STRING];
667         float   qw_entertime;
668         int             qw_ping;
669         int             qw_packetloss;
670         int             qw_movementloss;
671         int             qw_spectator;
672         char    qw_team[8];
673         char    qw_skin[MAX_QPATH];
674 } scoreboard_t;
675
676 typedef struct cshift_s
677 {
678         float   destcolor[3];
679         float   percent;                // 0-255
680         float   alphafade;      // (any speed)
681 } cshift_t;
682
683 #define CSHIFT_CONTENTS 0
684 #define CSHIFT_DAMAGE   1
685 #define CSHIFT_BONUS    2
686 #define CSHIFT_POWERUP  3
687 #define CSHIFT_VCSHIFT  4
688 #define NUM_CSHIFTS             5
689
690 #define NAME_LENGTH     64
691
692
693 //
694 // client_state_t should hold all pieces of the client state
695 //
696
697 #define SIGNONS         4                       // signon messages to receive before connected
698
699 typedef enum cactive_e
700 {
701         ca_uninitialized,       // during early startup
702         ca_dedicated,           // a dedicated server with no ability to start a client
703         ca_disconnected,        // full screen console with no connection
704         ca_connected            // valid netcon, talking to a server
705 }
706 cactive_t;
707
708 typedef enum qw_downloadtype_e
709 {
710         dl_none,
711         dl_single,
712         dl_skin,
713         dl_model,
714         dl_sound
715 }
716 qw_downloadtype_t;
717
718 typedef enum capturevideoformat_e
719 {
720         CAPTUREVIDEOFORMAT_AVI_I420,
721         CAPTUREVIDEOFORMAT_OGG_VORBIS_THEORA
722 }
723 capturevideoformat_t;
724
725 typedef struct capturevideostate_s
726 {
727         double startrealtime;
728         double framerate;
729         int framestep;
730         int framestepframe;
731         qboolean active;
732         qboolean realtime;
733         qboolean error;
734         int soundrate;
735         int soundchannels;
736         int frame;
737         double starttime;
738         double lastfpstime;
739         int lastfpsframe;
740         int soundsampleframe;
741         unsigned char *screenbuffer;
742         unsigned char *outbuffer;
743         char basename[MAX_QPATH];
744         int width, height;
745
746         // precomputed RGB to YUV tables
747         // converts the RGB values to YUV (see cap_avi.c for how to use them)
748         short rgbtoyuvscaletable[3][3][256];
749         unsigned char yuvnormalizetable[3][256];
750
751         // precomputed gamma ramp (only needed if the capturevideo module uses RGB output)
752         // note: to map from these values to RGB24, you have to multiply by 255.0/65535.0, then add 0.5, then cast to integer
753         unsigned short vidramp[256 * 3];
754
755         // stuff to be filled in by the video format module
756         capturevideoformat_t format;
757         const char *formatextension;
758         qfile_t *videofile;
759                 // always use this:
760                 //   cls.capturevideo.videofile = FS_OpenRealFile(va(vabuf, sizeof(vabuf), "%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false);
761         void (*endvideo) (void);
762         void (*videoframes) (int num);
763         void (*soundframe) (const portable_sampleframe_t *paintbuffer, size_t length);
764
765         // format specific data
766         void *formatspecific;
767 }
768 capturevideostate_t;
769
770 #define CL_MAX_DOWNLOADACKS 4
771
772 typedef struct cl_downloadack_s
773 {
774         int start, size;
775 }
776 cl_downloadack_t;
777
778 typedef struct cl_soundstats_s
779 {
780         int mixedsounds;
781         int totalsounds;
782         int latency_milliseconds;
783 }
784 cl_soundstats_t;
785
786 //
787 // the client_static_t structure is persistent through an arbitrary number
788 // of server connections
789 //
790 typedef struct client_static_s
791 {
792         cactive_t state;
793
794         // all client memory allocations go in these pools
795         mempool_t *levelmempool;
796         mempool_t *permanentmempool;
797
798 // demo loop control
799         // -1 = don't play demos
800         int demonum;
801         // list of demos in loop
802         char demos[MAX_DEMOS][MAX_DEMONAME];
803         // the actively playing demo (set by CL_PlayDemo_f)
804         char demoname[MAX_QPATH];
805
806 // demo recording info must be here, because record is started before
807 // entering a map (and clearing client_state_t)
808         qboolean demorecording;
809         fs_offset_t demo_lastcsprogssize;
810         int demo_lastcsprogscrc;
811         qboolean demoplayback;
812         qboolean demostarting; // set if currently starting a demo, to stop -demo from quitting when switching to another demo
813         qboolean timedemo;
814         // -1 = use normal cd track
815         int forcetrack;
816         qfile_t *demofile;
817         // realtime at second frame of timedemo (LordHavoc: changed to double)
818         double td_starttime;
819         int td_frames; // total frames parsed
820         double td_onesecondnexttime;
821         double td_onesecondframes;
822         double td_onesecondrealtime;
823         double td_onesecondminfps;
824         double td_onesecondmaxfps;
825         double td_onesecondavgfps;
826         int td_onesecondavgcount;
827         // LordHavoc: pausedemo
828         qboolean demopaused;
829
830         // sound mixer statistics for showsound display
831         cl_soundstats_t soundstats;
832
833         qboolean connect_trying;
834         int connect_remainingtries;
835         double connect_nextsendtime;
836         lhnetsocket_t *connect_mysocket;
837         lhnetaddress_t connect_address;
838         // protocol version of the server we're connected to
839         // (kept outside client_state_t because it's used between levels)
840         protocolversion_t protocol;
841
842 #define MAX_RCONS 16
843         int rcon_trying;
844         lhnetaddress_t rcon_addresses[MAX_RCONS];
845         char rcon_commands[MAX_RCONS][MAX_INPUTLINE];
846         double rcon_timeout[MAX_RCONS];
847         int rcon_ringpos;
848
849 // connection information
850         // 0 to SIGNONS
851         int signon;
852         // network connection
853         netconn_t *netcon;
854
855         // download information
856         // (note: qw_download variables are also used)
857         cl_downloadack_t dp_downloadack[CL_MAX_DOWNLOADACKS];
858
859         // input sequence numbers are not reset on level change, only connect
860         int movesequence;
861         int servermovesequence;
862
863         // quakeworld stuff below
864
865         // value of "qport" cvar at time of connection
866         int qw_qport;
867         // copied from cls.netcon->qw. variables every time they change, or set by demos (which have no cls.netcon)
868         int qw_incoming_sequence;
869         int qw_outgoing_sequence;
870
871         // current file download buffer (only saved when file is completed)
872         char qw_downloadname[MAX_QPATH];
873         unsigned char *qw_downloadmemory;
874         int qw_downloadmemorycursize;
875         int qw_downloadmemorymaxsize;
876         int qw_downloadnumber;
877         int qw_downloadpercent;
878         qw_downloadtype_t qw_downloadtype;
879         // transfer rate display
880         double qw_downloadspeedtime;
881         int qw_downloadspeedcount;
882         int qw_downloadspeedrate;
883         qboolean qw_download_deflate;
884
885         // current file upload buffer (for uploading screenshots to server)
886         unsigned char *qw_uploaddata;
887         int qw_uploadsize;
888         int qw_uploadpos;
889
890         // user infostring
891         // this normally contains the following keys in quakeworld:
892         // password spectator name team skin topcolor bottomcolor rate noaim msg *ver *ip
893         char userinfo[MAX_USERINFO_STRING];
894
895         // extra user info for the "connect" command
896         char connect_userinfo[MAX_USERINFO_STRING];
897
898         // video capture stuff
899         capturevideostate_t capturevideo;
900
901         // crypto channel
902         crypto_t crypto;
903
904         // ProQuake compatibility stuff
905         int proquake_servermod; // 0 = not proquake, 1 = proquake
906         int proquake_serverversion; // actual proquake server version * 10 (3.40 = 34, etc)
907         int proquake_serverflags; // 0 (PQF_CHEATFREE not supported)
908
909         // don't write-then-read csprogs.dat (useful for demo playback)
910         unsigned char *caughtcsprogsdata;
911         fs_offset_t caughtcsprogsdatasize;
912
913         int r_speeds_graph_length;
914         int r_speeds_graph_current;
915         int *r_speeds_graph_data;
916
917         // graph scales
918         int r_speeds_graph_datamin[r_stat_count];
919         int r_speeds_graph_datamax[r_stat_count];
920 }
921 client_static_t;
922
923 extern client_static_t  cls;
924
925 typedef struct client_movementqueue_s
926 {
927         double time;
928         float frametime;
929         int sequence;
930         float viewangles[3];
931         float move[3];
932         qboolean jump;
933         qboolean crouch;
934         qboolean canjump;
935 }
936 client_movementqueue_t;
937
938 //[515]: csqc
939 typedef struct
940 {
941         qboolean drawworld;
942         qboolean drawenginesbar;
943         qboolean drawcrosshair;
944 }csqc_vidvars_t;
945
946 typedef enum
947 {
948         PARTICLE_BILLBOARD = 0,
949         PARTICLE_SPARK = 1,
950         PARTICLE_ORIENTED_DOUBLESIDED = 2,
951         PARTICLE_VBEAM = 3,
952         PARTICLE_HBEAM = 4,
953         PARTICLE_INVALID = -1
954 }
955 porientation_t;
956
957 typedef enum
958 {
959         PBLEND_ALPHA = 0,
960         PBLEND_ADD = 1,
961         PBLEND_INVMOD = 2,
962         PBLEND_INVALID = -1
963 }
964 pblend_t;
965
966 typedef struct particletype_s
967 {
968         pblend_t blendmode;
969         porientation_t orientation;
970         qboolean lighting;
971 }
972 particletype_t;
973
974 typedef enum ptype_e
975 {
976         pt_dead, pt_alphastatic, pt_static, pt_spark, pt_beam, pt_rain, pt_raindecal, pt_snow, pt_bubble, pt_blood, pt_smoke, pt_decal, pt_entityparticle, pt_total
977 }
978 ptype_t;
979
980 typedef struct decal_s
981 {
982         // fields used by rendering:  (44 bytes)
983         unsigned short  typeindex;
984         unsigned short  texnum;
985         int                             decalsequence;
986         vec3_t                  org;
987         vec3_t                  normal;
988         float                   size;
989         float                   alpha; // 0-255
990         unsigned char   color[3];
991         unsigned char   unused1;
992         int                             clusterindex; // cheap culling by pvs
993
994         // fields not used by rendering: (36 bytes in 32bit, 40 bytes in 64bit)
995         float                   time2; // used for decal fade
996         unsigned int    owner; // decal stuck to this entity
997         dp_model_t                      *ownermodel; // model the decal is stuck to (used to make sure the entity is still alive)
998         vec3_t                  relativeorigin; // decal at this location in entity's coordinate space
999         vec3_t                  relativenormal; // decal oriented this way relative to entity's coordinate space
1000 }
1001 decal_t;
1002
1003 typedef struct particle_s
1004 {
1005         // for faster batch rendering, particles are rendered in groups by effect (resulting in less perfect sorting but far less state changes)
1006
1007         // fields used by rendering: (48 bytes)
1008         vec3_t          sortorigin; // sort by this group origin, not particle org
1009         vec3_t          org;
1010         vec3_t          vel; // velocity of particle, or orientation of decal, or end point of beam
1011         float           size;
1012         float           alpha; // 0-255
1013         float           stretch; // only for sparks
1014
1015         // fields not used by rendering:  (44 bytes)
1016         float           stainsize;
1017         float           stainalpha;
1018         float           sizeincrease; // rate of size change per second
1019         float           alphafade; // how much alpha reduces per second
1020         float           time2; // used for snow fluttering and decal fade
1021         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)
1022         float           gravity; // how much gravity affects this particle (1.0 = normal gravity, 0.0 = none)
1023         float           airfriction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
1024         float           liquidfriction; // how much liquid friction affects this object (objects with a low mass/size ratio tend to get more liquid friction)
1025 //      float           delayedcollisions; // time that p->bounce becomes active
1026         float           delayedspawn; // time that particle appears and begins moving
1027         float           die; // time when this particle should be removed, regardless of alpha
1028
1029         // short variables grouped to save memory (4 bytes)
1030         short                   angle; // base rotation of particle
1031         short                   spin; // geometry rotation speed around the particle center normal
1032
1033         // byte variables grouped to save memory (12 bytes)
1034         unsigned char   color[3];
1035         unsigned char   qualityreduction; // enables skipping of this particle according to r_refdef.view.qualityreduction
1036         unsigned char   typeindex;
1037         unsigned char   blendmode;
1038         unsigned char   orientation;
1039         unsigned char   texnum;
1040         unsigned char   staincolor[3];
1041         signed char     staintexnum;
1042 }
1043 particle_t;
1044
1045 typedef enum cl_parsingtextmode_e
1046 {
1047         CL_PARSETEXTMODE_NONE,
1048         CL_PARSETEXTMODE_PING,
1049         CL_PARSETEXTMODE_STATUS,
1050         CL_PARSETEXTMODE_STATUS_PLAYERID,
1051         CL_PARSETEXTMODE_STATUS_PLAYERIP
1052 }
1053 cl_parsingtextmode_t;
1054
1055 typedef struct cl_locnode_s
1056 {
1057         struct cl_locnode_s *next;
1058         char *name;
1059         vec3_t mins, maxs;
1060 }
1061 cl_locnode_t;
1062
1063 typedef struct showlmp_s
1064 {
1065         qboolean        isactive;
1066         float           x;
1067         float           y;
1068         char            label[32];
1069         char            pic[128];
1070 }
1071 showlmp_t;
1072
1073 //
1074 // the client_state_t structure is wiped completely at every
1075 // server signon
1076 //
1077 typedef struct client_state_s
1078 {
1079         // true if playing in a local game and no one else is connected
1080         int islocalgame;
1081
1082         // send a clc_nop periodically until connected
1083         float sendnoptime;
1084
1085         // current input being accumulated by mouse/joystick/etc input
1086         usercmd_t cmd;
1087         // latest moves sent to the server that have not been confirmed yet
1088         usercmd_t movecmd[CL_MAX_USERCMDS];
1089
1090 // information for local display
1091         // health, etc
1092         int stats[MAX_CL_STATS];
1093         float *statsf; // points to stats[] array
1094         // last known inventory bit flags, for blinking
1095         int olditems;
1096         // cl.time of acquiring item, for blinking
1097         float item_gettime[32];
1098         // last known STAT_ACTIVEWEAPON
1099         int activeweapon;
1100         // cl.time of changing STAT_ACTIVEWEAPON
1101         float weapontime;
1102         // use pain anim frame if cl.time < this
1103         float faceanimtime;
1104         // for stair smoothing
1105         float stairsmoothz;
1106         double stairsmoothtime;
1107
1108         // color shifts for damage, powerups
1109         cshift_t cshifts[NUM_CSHIFTS];
1110         // and content types
1111         cshift_t prev_cshifts[NUM_CSHIFTS];
1112
1113 // the client maintains its own idea of view angles, which are
1114 // sent to the server each frame.  The server sets punchangle when
1115 // the view is temporarily offset, and an angle reset commands at the start
1116 // of each level and after teleporting.
1117
1118         // mviewangles is read from demo
1119         // viewangles is either client controlled or lerped from mviewangles
1120         vec3_t mviewangles[2], viewangles;
1121         // update by server, used by qc to do weapon recoil
1122         vec3_t mpunchangle[2], punchangle;
1123         // update by server, can be used by mods to kick view around
1124         vec3_t mpunchvector[2], punchvector;
1125         // update by server, used for lean+bob (0 is newest)
1126         vec3_t mvelocity[2], velocity;
1127         // update by server, can be used by mods for zooming
1128         vec_t mviewzoom[2], viewzoom;
1129         // if true interpolation the mviewangles and other interpolation of the
1130         // player is disabled until the next network packet
1131         // this is used primarily by teleporters, and when spectating players
1132         // special checking of the old fixangle[1] is used to differentiate
1133         // between teleporting and spectating
1134         qboolean fixangle[2];
1135
1136         // client movement simulation
1137         // these fields are only updated by CL_ClientMovement (called by CL_SendMove after parsing each network packet)
1138         // set by CL_ClientMovement_Replay functions
1139         qboolean movement_predicted;
1140         // if true the CL_ClientMovement_Replay function will update origin, etc
1141         qboolean movement_replay;
1142         // simulated data (this is valid even if cl.movement is false)
1143         vec3_t movement_origin;
1144         vec3_t movement_velocity;
1145         // whether the replay should allow a jump at the first sequence
1146         qboolean movement_replay_canjump;
1147
1148         // previous gun angles (for leaning effects)
1149         vec3_t gunangles_prev;
1150         vec3_t gunangles_highpass;
1151         vec3_t gunangles_adjustment_lowpass;
1152         vec3_t gunangles_adjustment_highpass;
1153         // previous gun angles (for leaning effects)
1154         vec3_t gunorg_prev;
1155         vec3_t gunorg_highpass;
1156         vec3_t gunorg_adjustment_lowpass;
1157         vec3_t gunorg_adjustment_highpass;
1158
1159 // pitch drifting vars
1160         float idealpitch;
1161         float pitchvel;
1162         qboolean nodrift;
1163         float driftmove;
1164         double laststop;
1165
1166 //[515]: added for csqc purposes
1167         float sensitivityscale;
1168         csqc_vidvars_t csqc_vidvars;    //[515]: these parms must be set to true by default
1169         qboolean csqc_wantsmousemove;
1170         qboolean csqc_paused; // vortex: int because could be flags
1171         struct model_s *csqc_model_precache[MAX_MODELS];
1172
1173         // local amount for smoothing stepups
1174         //float crouch;
1175
1176         // sent by server
1177         qboolean paused;
1178         qboolean onground;
1179         qboolean inwater;
1180
1181         // used by bob
1182         qboolean oldonground;
1183         double lastongroundtime;
1184         double hitgroundtime;
1185         float bob2_smooth;
1186         float bobfall_speed;
1187         float bobfall_swing;
1188         double calcrefdef_prevtime;
1189
1190         // don't change view angle, full screen, etc
1191         int intermission;
1192         // latched at intermission start
1193         double completed_time;
1194
1195         // the timestamp of the last two messages
1196         double mtime[2];
1197
1198         // clients view of time, time should be between mtime[0] and mtime[1] to
1199         // generate a lerp point for other data, oldtime is the previous frame's
1200         // value of time, frametime is the difference between time and oldtime
1201         // note: cl.time may be beyond cl.mtime[0] if packet loss is occuring, it
1202         // is only forcefully limited when a packet is received
1203         double time, oldtime;
1204         // how long it has been since the previous client frame in real time
1205         // (not game time, for that use cl.time - cl.oldtime)
1206         double realframetime;
1207         
1208         // fade var for fading while dead
1209         float deathfade;
1210
1211         // motionblur alpha level variable
1212         float motionbluralpha;
1213
1214         // copy of realtime from last recieved message, for net trouble icon
1215         float last_received_message;
1216
1217 // information that is static for the entire time connected to a server
1218         struct model_s *model_precache[MAX_MODELS];
1219         struct sfx_s *sound_precache[MAX_SOUNDS];
1220
1221         // FIXME: this is a lot of memory to be keeping around, this really should be dynamically allocated and freed somehow
1222         char model_name[MAX_MODELS][MAX_QPATH];
1223         char sound_name[MAX_SOUNDS][MAX_QPATH];
1224
1225         // for display on solo scoreboard
1226         char worldmessage[40]; // map title (not related to filename)
1227         // variants of map name
1228         char worldbasename[MAX_QPATH]; // %s
1229         char worldname[MAX_QPATH]; // maps/%s.bsp
1230         char worldnamenoextension[MAX_QPATH]; // maps/%s
1231         // cl_entitites[cl.viewentity] = player
1232         int viewentity;
1233         // the real player entity (normally same as viewentity,
1234         // different than viewentity if mod uses chasecam or other tricks)
1235         int realplayerentity;
1236         // this is updated to match cl.viewentity whenever it is in the clients
1237         // range, basically this is used in preference to cl.realplayerentity for
1238         // most purposes because when spectating another player it should show
1239         // their information rather than yours
1240         int playerentity;
1241         // max players that can be in this game
1242         int maxclients;
1243         // type of game (deathmatch, coop, singleplayer)
1244         int gametype;
1245
1246         // models and sounds used by engine code (particularly cl_parse.c)
1247         dp_model_t *model_bolt;
1248         dp_model_t *model_bolt2;
1249         dp_model_t *model_bolt3;
1250         dp_model_t *model_beam;
1251         sfx_t *sfx_wizhit;
1252         sfx_t *sfx_knighthit;
1253         sfx_t *sfx_tink1;
1254         sfx_t *sfx_ric1;
1255         sfx_t *sfx_ric2;
1256         sfx_t *sfx_ric3;
1257         sfx_t *sfx_r_exp3;
1258         // indicates that the file "sound/misc/talk2.wav" was found (for use by team chat messages)
1259         qboolean foundtalk2wav;
1260
1261 // refresh related state
1262
1263         // cl_entitites[0].model
1264         struct model_s *worldmodel;
1265
1266         // the gun model
1267         entity_t viewent;
1268
1269         // cd audio
1270         int cdtrack, looptrack;
1271
1272 // frag scoreboard
1273
1274         // [cl.maxclients]
1275         scoreboard_t *scores;
1276
1277         // keep track of svc_print parsing state (analyzes ping reports and status reports)
1278         cl_parsingtextmode_t parsingtextmode;
1279         int parsingtextplayerindex;
1280         // set by scoreboard code when sending ping command, this causes the next ping results to be hidden
1281         // (which could eat the wrong ping report if the player issues one
1282         //  manually, but they would still see a ping report, just a later one
1283         //  caused by the scoreboard code rather than the one they intentionally
1284         //  issued)
1285         int parsingtextexpectingpingforscores;
1286
1287         // entity database stuff
1288         // latest received entity frame numbers
1289 #define LATESTFRAMENUMS 32
1290         int latestframenumsposition;
1291         int latestframenums[LATESTFRAMENUMS];
1292         int latestsendnums[LATESTFRAMENUMS];
1293         entityframe_database_t *entitydatabase;
1294         entityframe4_database_t *entitydatabase4;
1295         entityframeqw_database_t *entitydatabaseqw;
1296
1297         // keep track of quake entities because they need to be killed if they get stale
1298         int lastquakeentity;
1299         unsigned char isquakeentity[MAX_EDICTS];
1300
1301         // bounding boxes for clientside movement
1302         vec3_t playerstandmins;
1303         vec3_t playerstandmaxs;
1304         vec3_t playercrouchmins;
1305         vec3_t playercrouchmaxs;
1306
1307         // old decals are killed based on this
1308         int decalsequence;
1309
1310         int max_entities;
1311         int max_csqcrenderentities;
1312         int max_static_entities;
1313         int max_effects;
1314         int max_beams;
1315         int max_dlights;
1316         int max_lightstyle;
1317         int max_brushmodel_entities;
1318         int max_particles;
1319         int max_decals;
1320         int max_showlmps;
1321
1322         entity_t *entities;
1323         entity_render_t *csqcrenderentities;
1324         unsigned char *entities_active;
1325         entity_t *static_entities;
1326         cl_effect_t *effects;
1327         beam_t *beams;
1328         dlight_t *dlights;
1329         lightstyle_t *lightstyle;
1330         int *brushmodel_entities;
1331         particle_t *particles;
1332         decal_t *decals;
1333         showlmp_t *showlmps;
1334
1335         int num_entities;
1336         int num_static_entities;
1337         int num_brushmodel_entities;
1338         int num_effects;
1339         int num_beams;
1340         int num_dlights;
1341         int num_particles;
1342         int num_decals;
1343         int num_showlmps;
1344
1345         double particles_updatetime;
1346         double decals_updatetime;
1347         int free_particle;
1348         int free_decal;
1349
1350         // cl_serverextension_download feature
1351         int loadmodel_current;
1352         int downloadmodel_current;
1353         int loadmodel_total;
1354         int loadsound_current;
1355         int downloadsound_current;
1356         int loadsound_total;
1357         qboolean downloadcsqc;
1358         qboolean loadcsqc;
1359         qboolean loadbegun;
1360         qboolean loadfinished;
1361
1362         // quakeworld stuff
1363
1364         // local copy of the server infostring
1365         char qw_serverinfo[MAX_SERVERINFO_STRING];
1366
1367         // time of last qw "pings" command sent to server while showing scores
1368         double last_ping_request;
1369
1370         // used during connect
1371         int qw_servercount;
1372
1373         // updated from serverinfo
1374         int qw_teamplay;
1375
1376         // unused: indicates whether the player is spectating
1377         // use cl.scores[cl.playerentity-1].qw_spectator instead
1378         //qboolean qw_spectator;
1379
1380         // last time an input packet was sent
1381         double lastpackettime;
1382
1383         // movement parameters for client prediction
1384         unsigned int moveflags;
1385         float movevars_wallfriction;
1386         float movevars_waterfriction;
1387         float movevars_friction;
1388         float movevars_timescale;
1389         float movevars_gravity;
1390         float movevars_stopspeed;
1391         float movevars_maxspeed;
1392         float movevars_spectatormaxspeed;
1393         float movevars_accelerate;
1394         float movevars_airaccelerate;
1395         float movevars_wateraccelerate;
1396         float movevars_entgravity;
1397         float movevars_jumpvelocity;
1398         float movevars_edgefriction;
1399         float movevars_maxairspeed;
1400         float movevars_stepheight;
1401         float movevars_airaccel_qw;
1402         float movevars_airaccel_qw_stretchfactor;
1403         float movevars_airaccel_sideways_friction;
1404         float movevars_airstopaccelerate;
1405         float movevars_airstrafeaccelerate;
1406         float movevars_maxairstrafespeed;
1407         float movevars_airstrafeaccel_qw;
1408         float movevars_aircontrol;
1409         float movevars_aircontrol_power;
1410         float movevars_aircontrol_penalty;
1411         float movevars_warsowbunny_airforwardaccel;
1412         float movevars_warsowbunny_accel;
1413         float movevars_warsowbunny_topspeed;
1414         float movevars_warsowbunny_turnaccel;
1415         float movevars_warsowbunny_backtosideratio;
1416         float movevars_ticrate;
1417         float movevars_airspeedlimit_nonqw;
1418
1419         // models used by qw protocol
1420         int qw_modelindex_spike;
1421         int qw_modelindex_player;
1422         int qw_modelindex_flag;
1423         int qw_modelindex_s_explod;
1424
1425         vec3_t qw_intermission_origin;
1426         vec3_t qw_intermission_angles;
1427
1428         // 255 is the most nails the QW protocol could send
1429         int qw_num_nails;
1430         vec_t qw_nails[255][6];
1431
1432         float qw_weaponkick;
1433
1434         int qw_validsequence;
1435
1436         int qw_deltasequence[QW_UPDATE_BACKUP];
1437
1438         // csqc stuff:
1439         // server entity number corresponding to a clientside entity
1440         unsigned short csqc_server2csqcentitynumber[MAX_EDICTS];
1441         qboolean csqc_loaded;
1442         vec3_t csqc_vieworigin;
1443         vec3_t csqc_viewangles;
1444         vec3_t csqc_vieworiginfromengine;
1445         vec3_t csqc_viewanglesfromengine;
1446         matrix4x4_t csqc_viewmodelmatrixfromengine;
1447         qboolean csqc_usecsqclistener;
1448         matrix4x4_t csqc_listenermatrix;
1449         char csqc_printtextbuf[MAX_INPUTLINE];
1450
1451         // collision culling data
1452         world_t world;
1453
1454         // loc file stuff (points and boxes describing locations in the level)
1455         cl_locnode_t *locnodes;
1456         // this is updated to cl.movement_origin whenever health is < 1
1457         // used by %d print in say/say_team messages if cl_locs_enable is on
1458         vec3_t lastdeathorigin;
1459
1460         // processing buffer used by R_BuildLightMap, reallocated as needed,
1461         // freed on each level change
1462         size_t buildlightmapmemorysize;
1463         unsigned char *buildlightmapmemory;
1464
1465         // used by EntityState5_ReadUpdate
1466         skeleton_t *engineskeletonobjects;
1467 }
1468 client_state_t;
1469
1470 //
1471 // cvars
1472 //
1473 extern cvar_t cl_name;
1474 extern cvar_t cl_color;
1475 extern cvar_t cl_rate;
1476 extern cvar_t cl_rate_burstsize;
1477 extern cvar_t cl_pmodel;
1478 extern cvar_t cl_playermodel;
1479 extern cvar_t cl_playerskin;
1480
1481 extern cvar_t rcon_password;
1482 extern cvar_t rcon_address;
1483
1484 extern cvar_t cl_upspeed;
1485 extern cvar_t cl_forwardspeed;
1486 extern cvar_t cl_backspeed;
1487 extern cvar_t cl_sidespeed;
1488
1489 extern cvar_t cl_movespeedkey;
1490
1491 extern cvar_t cl_yawspeed;
1492 extern cvar_t cl_pitchspeed;
1493
1494 extern cvar_t cl_anglespeedkey;
1495
1496 extern cvar_t cl_autofire;
1497
1498 extern cvar_t cl_shownet;
1499 extern cvar_t cl_nolerp;
1500 extern cvar_t cl_nettimesyncfactor;
1501 extern cvar_t cl_nettimesyncboundmode;
1502 extern cvar_t cl_nettimesyncboundtolerance;
1503
1504 extern cvar_t cl_pitchdriftspeed;
1505 extern cvar_t lookspring;
1506 extern cvar_t lookstrafe;
1507 extern cvar_t sensitivity;
1508
1509 extern cvar_t freelook;
1510
1511 extern cvar_t m_pitch;
1512 extern cvar_t m_yaw;
1513 extern cvar_t m_forward;
1514 extern cvar_t m_side;
1515
1516 extern cvar_t cl_autodemo;
1517 extern cvar_t cl_autodemo_nameformat;
1518 extern cvar_t cl_autodemo_delete;
1519
1520 extern cvar_t r_draweffects;
1521
1522 extern cvar_t cl_explosions_alpha_start;
1523 extern cvar_t cl_explosions_alpha_end;
1524 extern cvar_t cl_explosions_size_start;
1525 extern cvar_t cl_explosions_size_end;
1526 extern cvar_t cl_explosions_lifetime;
1527 extern cvar_t cl_stainmaps;
1528 extern cvar_t cl_stainmaps_clearonload;
1529
1530 extern cvar_t cl_prydoncursor;
1531 extern cvar_t cl_prydoncursor_notrace;
1532
1533 extern cvar_t cl_locs_enable;
1534
1535 extern client_state_t cl;
1536
1537 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);
1538
1539 cl_locnode_t *CL_Locs_FindNearest(const vec3_t point);
1540 void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point);
1541
1542 //=============================================================================
1543
1544 //
1545 // cl_main
1546 //
1547
1548 void CL_Shutdown (void);
1549 void CL_Init (void);
1550
1551 void CL_EstablishConnection(const char *host, int firstarg);
1552
1553 void CL_Disconnect (void);
1554 void CL_Disconnect_f (void);
1555
1556 void CL_UpdateRenderEntity(entity_render_t *ent);
1557 void CL_SetEntityColormapColors(entity_render_t *ent, int colormap);
1558 void CL_UpdateViewEntities(void);
1559
1560 //
1561 // cl_input
1562 //
1563 typedef struct kbutton_s
1564 {
1565         int             down[2];                // key nums holding it down
1566         int             state;                  // low bit is down state
1567 }
1568 kbutton_t;
1569
1570 extern  kbutton_t       in_mlook, in_klook;
1571 extern  kbutton_t       in_strafe;
1572 extern  kbutton_t       in_speed;
1573
1574 void CL_InitInput (void);
1575 void CL_SendMove (void);
1576
1577 void CL_ValidateState(entity_state_t *s);
1578 void CL_MoveLerpEntityStates(entity_t *ent);
1579 void CL_LerpUpdate(entity_t *e);
1580 void CL_ParseTEnt (void);
1581 void CL_NewBeam (int ent, vec3_t start, vec3_t end, dp_model_t *m, int lightning);
1582 void CL_RelinkBeams (void);
1583 void CL_Beam_CalculatePositions (const beam_t *b, vec3_t start, vec3_t end);
1584 void CL_ClientMovement_Replay(void);
1585
1586 void CL_ClearTempEntities (void);
1587 entity_render_t *CL_NewTempEntity (double shadertime);
1588
1589 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate);
1590
1591 void CL_ClearState (void);
1592 void CL_ExpandEntities(int num);
1593 void CL_ExpandCSQCRenderEntities(int num);
1594 void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allowstarkey, qboolean allowmodel, qboolean quiet);
1595
1596
1597 void CL_UpdateWorld (void);
1598 void CL_WriteToServer (void);
1599 void CL_Input (void);
1600 extern int cl_ignoremousemoves;
1601
1602
1603 float CL_KeyState (kbutton_t *key);
1604 const char *Key_KeynumToString (int keynum, char *buf, size_t buflength);
1605 int Key_StringToKeynum (const char *str);
1606
1607 //
1608 // cl_demo.c
1609 //
1610 void CL_StopPlayback(void);
1611 void CL_ReadDemoMessage(void);
1612 void CL_WriteDemoMessage(sizebuf_t *mesage);
1613
1614 void CL_CutDemo(unsigned char **buf, fs_offset_t *filesize);
1615 void CL_PasteDemo(unsigned char **buf, fs_offset_t *filesize);
1616
1617 void CL_NextDemo(void);
1618 void CL_Stop_f(void);
1619 void CL_Record_f(void);
1620 void CL_PlayDemo_f(void);
1621 void CL_TimeDemo_f(void);
1622
1623 //
1624 // cl_parse.c
1625 //
1626 void CL_Parse_Init(void);
1627 void CL_Parse_Shutdown(void);
1628 void CL_ParseServerMessage(void);
1629 void CL_Parse_DumpPacket(void);
1630 void CL_Parse_ErrorCleanUp(void);
1631 void QW_CL_StartUpload(unsigned char *data, int size);
1632 extern cvar_t qport;
1633 void CL_KeepaliveMessage(qboolean readmessages); // call this during loading of large content
1634
1635 //
1636 // view
1637 //
1638 void V_StartPitchDrift (void);
1639 void V_StopPitchDrift (void);
1640
1641 void V_Init (void);
1642 float V_CalcRoll (const vec3_t angles, const vec3_t velocity);
1643 void V_UpdateBlends (void);
1644 void V_ParseDamage (void);
1645
1646 //
1647 // cl_part
1648 //
1649
1650 extern cvar_t cl_particles;
1651 extern cvar_t cl_particles_quality;
1652 extern cvar_t cl_particles_size;
1653 extern cvar_t cl_particles_quake;
1654 extern cvar_t cl_particles_blood;
1655 extern cvar_t cl_particles_blood_alpha;
1656 extern cvar_t cl_particles_blood_decal_alpha;
1657 extern cvar_t cl_particles_blood_decal_scalemin;
1658 extern cvar_t cl_particles_blood_decal_scalemax;
1659 extern cvar_t cl_particles_blood_bloodhack;
1660 extern cvar_t cl_particles_bulletimpacts;
1661 extern cvar_t cl_particles_explosions_sparks;
1662 extern cvar_t cl_particles_explosions_shell;
1663 extern cvar_t cl_particles_rain;
1664 extern cvar_t cl_particles_snow;
1665 extern cvar_t cl_particles_smoke;
1666 extern cvar_t cl_particles_smoke_alpha;
1667 extern cvar_t cl_particles_smoke_alphafade;
1668 extern cvar_t cl_particles_sparks;
1669 extern cvar_t cl_particles_bubbles;
1670 extern cvar_t cl_decals;
1671 extern cvar_t cl_decals_time;
1672 extern cvar_t cl_decals_fadetime;
1673
1674 void CL_Particles_Clear(void);
1675 void CL_Particles_Init(void);
1676 void CL_Particles_Shutdown(void);
1677 particle_t *CL_NewParticle(const vec3_t sortorigin, unsigned short ptypeindex, int pcolor1, int pcolor2, int ptex, float psize, float psizeincrease, float palpha, float palphafade, float pgravity, float pbounce, float px, float py, float pz, float pvx, float pvy, float pvz, float pairfriction, float pliquidfriction, float originjitter, float velocityjitter, qboolean pqualityreduction, float lifetime, float stretch, pblend_t blendmode, porientation_t orientation, int staincolor1, int staincolor2, int staintex, float stainalpha, float stainsize, float angle, float spin, float tint[4]);
1678
1679 typedef enum effectnameindex_s
1680 {
1681         EFFECT_NONE,
1682         EFFECT_TE_GUNSHOT,
1683         EFFECT_TE_GUNSHOTQUAD,
1684         EFFECT_TE_SPIKE,
1685         EFFECT_TE_SPIKEQUAD,
1686         EFFECT_TE_SUPERSPIKE,
1687         EFFECT_TE_SUPERSPIKEQUAD,
1688         EFFECT_TE_WIZSPIKE,
1689         EFFECT_TE_KNIGHTSPIKE,
1690         EFFECT_TE_EXPLOSION,
1691         EFFECT_TE_EXPLOSIONQUAD,
1692         EFFECT_TE_TAREXPLOSION,
1693         EFFECT_TE_TELEPORT,
1694         EFFECT_TE_LAVASPLASH,
1695         EFFECT_TE_SMALLFLASH,
1696         EFFECT_TE_FLAMEJET,
1697         EFFECT_EF_FLAME,
1698         EFFECT_TE_BLOOD,
1699         EFFECT_TE_SPARK,
1700         EFFECT_TE_PLASMABURN,
1701         EFFECT_TE_TEI_G3,
1702         EFFECT_TE_TEI_SMOKE,
1703         EFFECT_TE_TEI_BIGEXPLOSION,
1704         EFFECT_TE_TEI_PLASMAHIT,
1705         EFFECT_EF_STARDUST,
1706         EFFECT_TR_ROCKET,
1707         EFFECT_TR_GRENADE,
1708         EFFECT_TR_BLOOD,
1709         EFFECT_TR_WIZSPIKE,
1710         EFFECT_TR_SLIGHTBLOOD,
1711         EFFECT_TR_KNIGHTSPIKE,
1712         EFFECT_TR_VORESPIKE,
1713         EFFECT_TR_NEHAHRASMOKE,
1714         EFFECT_TR_NEXUIZPLASMA,
1715         EFFECT_TR_GLOWTRAIL,
1716         EFFECT_SVC_PARTICLE,
1717         EFFECT_TOTAL
1718 }
1719 effectnameindex_t;
1720
1721 int CL_ParticleEffectIndexForName(const char *name);
1722 const char *CL_ParticleEffectNameForIndex(int i);
1723 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);
1724 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, float tintmins[4], float tintmaxs[4], float fade);
1725 void CL_ParticleBox(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, float tintmins[4], float tintmaxs[4], float fade);
1726 void CL_ParseParticleEffect (void);
1727 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);
1728 void CL_ParticleRain (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, int type);
1729 void CL_EntityParticles (const entity_t *ent);
1730 void CL_ParticleExplosion (const vec3_t org);
1731 void CL_ParticleExplosion2 (const vec3_t org, int colorStart, int colorLength);
1732 void R_NewExplosion(const vec3_t org);
1733
1734 void Debug_PolygonBegin(const char *picname, int flags);
1735 void Debug_PolygonVertex(float x, float y, float z, float s, float t, float r, float g, float b, float a);
1736 void Debug_PolygonEnd(void);
1737
1738 #include "cl_screen.h"
1739
1740 extern qboolean sb_showscores;
1741
1742 float RSurf_FogVertex(const vec3_t p);
1743 float RSurf_FogPoint(const vec3_t p);
1744
1745 typedef enum r_viewport_type_e
1746 {
1747         R_VIEWPORTTYPE_ORTHO,
1748         R_VIEWPORTTYPE_PERSPECTIVE,
1749         R_VIEWPORTTYPE_PERSPECTIVE_INFINITEFARCLIP,
1750         R_VIEWPORTTYPE_PERSPECTIVECUBESIDE,
1751         R_VIEWPORTTYPE_TOTAL
1752 }
1753 r_viewport_type_t;
1754
1755 typedef struct r_viewport_s
1756 {
1757         matrix4x4_t cameramatrix; // from entity (transforms from camera entity to world)
1758         matrix4x4_t viewmatrix; // actual matrix for rendering (transforms to viewspace)
1759         matrix4x4_t projectmatrix; // actual projection matrix (transforms from viewspace to screen)
1760         int x;
1761         int y;
1762         int z;
1763         int width;
1764         int height;
1765         int depth;
1766         r_viewport_type_t type;
1767         float screentodepth[2]; // used by deferred renderer to calculate linear depth from device depth coordinates
1768 }
1769 r_viewport_t;
1770
1771 typedef struct r_refdef_view_s
1772 {
1773         // view information (changes multiple times per frame)
1774         // if any of these variables change then r_refdef.viewcache must be regenerated
1775         // by calling R_View_Update
1776         // (which also updates viewport, scissor, colormask)
1777
1778         // it is safe and expected to copy this into a structure on the stack and
1779         // call the renderer recursively, then restore from the stack afterward
1780         // (as long as R_View_Update is called)
1781
1782         // eye position information
1783         matrix4x4_t matrix, inverse_matrix;
1784         vec3_t origin;
1785         vec3_t forward;
1786         vec3_t left;
1787         vec3_t right;
1788         vec3_t up;
1789         int numfrustumplanes;
1790         mplane_t frustum[6];
1791         qboolean useclipplane;
1792         qboolean usecustompvs; // uses r_refdef.viewcache.pvsbits as-is rather than computing it
1793         mplane_t clipplane;
1794         float frustum_x, frustum_y;
1795         vec3_t frustumcorner[4];
1796         // if turned off it renders an ortho view
1797         int useperspective;
1798         float ortho_x, ortho_y;
1799
1800         // screen area to render in
1801         int x;
1802         int y;
1803         int z;
1804         int width;
1805         int height;
1806         int depth;
1807         r_viewport_t viewport; // note: if r_viewscale is used, the viewport.width and viewport.height may be less than width and height
1808
1809         // which color components to allow (for anaglyph glasses)
1810         int colormask[4];
1811
1812         // global RGB color multiplier for rendering
1813         float colorscale;
1814
1815         // whether to call R_ClearScreen before rendering stuff
1816         qboolean clear;
1817         // if true, don't clear or do any post process effects (bloom, etc)
1818         qboolean isoverlay;
1819         // if true, this is the MAIN view (which is, after CSQC, copied into the scene for use e.g. by r_speeds 1, showtex, prydon cursor)
1820         qboolean ismain;
1821
1822         // whether to draw r_showtris and such, this is only true for the main
1823         // view render, all secondary renders (mirrors, portals, cameras,
1824         // distortion effects, etc) omit such debugging information
1825         qboolean showdebug;
1826
1827         // these define which values to use in GL_CullFace calls to request frontface or backface culling
1828         int cullface_front;
1829         int cullface_back;
1830
1831         // render quality (0 to 1) - affects r_drawparticles_drawdistance and others
1832         float quality;
1833 }
1834 r_refdef_view_t;
1835
1836 typedef struct r_refdef_viewcache_s
1837 {
1838         // updated by gl_main_newmap()
1839         int maxentities;
1840         int world_numclusters;
1841         int world_numclusterbytes;
1842         int world_numleafs;
1843         int world_numsurfaces;
1844
1845         // these properties are generated by R_View_Update()
1846
1847         // which entities are currently visible for this viewpoint
1848         // (the used range is 0...r_refdef.scene.numentities)
1849         unsigned char *entityvisible;
1850
1851         // flag arrays used for visibility checking on world model
1852         // (all other entities have no per-surface/per-leaf visibility checks)
1853         unsigned char *world_pvsbits;
1854         unsigned char *world_leafvisible;
1855         unsigned char *world_surfacevisible;
1856         // if true, the view is currently in a leaf without pvs data
1857         qboolean world_novis;
1858 }
1859 r_refdef_viewcache_t;
1860
1861 // TODO: really think about which fields should go into scene and which one should stay in refdef [1/7/2008 Black]
1862 // maybe also refactor some of the functions to support different setting sources (ie. fogenabled, etc.) for different scenes
1863 typedef struct r_refdef_scene_s {
1864         // whether to call S_ExtraUpdate during render to reduce sound chop
1865         qboolean extraupdate;
1866
1867         // (client gameworld) time for rendering time based effects
1868         double time;
1869
1870         // the world
1871         entity_render_t *worldentity;
1872
1873         // same as worldentity->model
1874         dp_model_t *worldmodel;
1875
1876         // renderable entities (excluding world)
1877         entity_render_t **entities;
1878         int numentities;
1879         int maxentities;
1880
1881         // field of temporary entities that is reset each (client) frame
1882         entity_render_t *tempentities;
1883         int numtempentities;
1884         int maxtempentities;
1885         qboolean expandtempentities;
1886
1887         // renderable dynamic lights
1888         rtlight_t *lights[MAX_DLIGHTS];
1889         rtlight_t templights[MAX_DLIGHTS];
1890         int numlights;
1891
1892         // intensities for light styles right now, controls rtlights
1893         float rtlightstylevalue[MAX_LIGHTSTYLES];       // float fraction of base light value
1894         // 8.8bit fixed point intensities for light styles
1895         // controls intensity lightmap layers
1896         unsigned short lightstylevalue[MAX_LIGHTSTYLES];        // 8.8 fraction of base light value
1897
1898         float ambient;
1899
1900         qboolean rtworld;
1901         qboolean rtworldshadows;
1902         qboolean rtdlight;
1903         qboolean rtdlightshadows;
1904 } r_refdef_scene_t;
1905
1906 typedef struct r_refdef_s
1907 {
1908         // these fields define the basic rendering information for the world
1909         // but not the view, which could change multiple times in one rendered
1910         // frame (for example when rendering textures for certain effects)
1911
1912         // these are set for water warping before
1913         // frustum_x/frustum_y are calculated
1914         float frustumscale_x, frustumscale_y;
1915
1916         // current view settings (these get reset a few times during rendering because of water rendering, reflections, etc)
1917         r_refdef_view_t view;
1918         r_refdef_viewcache_t viewcache;
1919
1920         // minimum visible distance (pixels closer than this disappear)
1921         double nearclip;
1922         // maximum visible distance (pixels further than this disappear in 16bpp modes,
1923         // in 32bpp an infinite-farclip matrix is used instead)
1924         double farclip;
1925
1926         // fullscreen color blend
1927         float viewblend[4];
1928
1929         r_refdef_scene_t scene;
1930
1931         float fogplane[4];
1932         float fogplaneviewdist;
1933         qboolean fogplaneviewabove;
1934         float fogheightfade;
1935         float fogcolor[3];
1936         float fogrange;
1937         float fograngerecip;
1938         float fogmasktabledistmultiplier;
1939 #define FOGMASKTABLEWIDTH 1024
1940         float fogmasktable[FOGMASKTABLEWIDTH];
1941         float fogmasktable_start, fogmasktable_alpha, fogmasktable_range, fogmasktable_density;
1942         float fog_density;
1943         float fog_red;
1944         float fog_green;
1945         float fog_blue;
1946         float fog_alpha;
1947         float fog_start;
1948         float fog_end;
1949         float fog_height;
1950         float fog_fadedepth;
1951         qboolean fogenabled;
1952         qboolean oldgl_fogenable;
1953
1954         // new flexible texture height fog (overrides normal fog)
1955         char fog_height_texturename[64]; // note: must be 64 for the sscanf code
1956         unsigned char *fog_height_table1d;
1957         unsigned char *fog_height_table2d;
1958         int fog_height_tablesize; // enable
1959         float fog_height_tablescale;
1960         float fog_height_texcoordscale;
1961         char fogheighttexturename[64]; // detects changes to active fog height texture
1962
1963         int draw2dstage; // 0 = no, 1 = yes, other value = needs setting up again
1964
1965         // true during envmap command capture
1966         qboolean envmap;
1967
1968         // brightness of world lightmaps and related lighting
1969         // (often reduced when world rtlights are enabled)
1970         float lightmapintensity;
1971         // whether to draw world lights realtime, dlights realtime, and their shadows
1972         float polygonfactor;
1973         float polygonoffset;
1974         float shadowpolygonfactor;
1975         float shadowpolygonoffset;
1976
1977         // how long R_RenderView took on the previous frame
1978         double lastdrawscreentime;
1979
1980         // rendering stats for r_speeds display
1981         // (these are incremented in many places)
1982         int stats[r_stat_count];
1983 }
1984 r_refdef_t;
1985
1986 extern r_refdef_t r_refdef;
1987
1988 typedef enum waterlevel_e
1989 {
1990         WATERLEVEL_NONE,
1991         WATERLEVEL_WETFEET,
1992         WATERLEVEL_SWIMMING,
1993         WATERLEVEL_SUBMERGED
1994 }
1995 waterlevel_t;
1996
1997 typedef struct cl_clientmovement_state_s
1998 {
1999         // entity to be ignored for movement
2000         struct prvm_edict_s *self;
2001         // position
2002         vec3_t origin;
2003         vec3_t velocity;
2004         // current bounding box (different if crouched vs standing)
2005         vec3_t mins;
2006         vec3_t maxs;
2007         // currently on the ground
2008         qboolean onground;
2009         // currently crouching
2010         qboolean crouched;
2011         // what kind of water (SUPERCONTENTS_LAVA for instance)
2012         int watertype;
2013         // how deep
2014         waterlevel_t waterlevel;
2015         // weird hacks when jumping out of water
2016         // (this is in seconds and counts down to 0)
2017         float waterjumptime;
2018
2019         // user command
2020         usercmd_t cmd;
2021 }
2022 cl_clientmovement_state_t;
2023 void CL_ClientMovement_PlayerMove_Frame(cl_clientmovement_state_t *s);
2024
2025 // warpzone prediction hack (CSQC builtin)
2026 void CL_RotateMoves(const matrix4x4_t *m);
2027
2028 void CL_NewFrameReceived(int num);
2029 void CL_ParseEntityLump(char *entitystring);
2030 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius);
2031 void CL_RelinkLightFlashes(void);
2032 void Sbar_ShowFPS(void);
2033 void Sbar_ShowFPS_Update(void);
2034 void Host_SaveConfig(void);
2035 void Host_LoadConfig_f(void);
2036 void CL_UpdateMoveVars(void);
2037 void SCR_CaptureVideo_SoundFrame(const portable_sampleframe_t *paintbuffer, size_t length);
2038 void V_DriftPitch(void);
2039 void V_FadeViewFlashs(void);
2040 void V_CalcViewBlend(void);
2041 void V_CalcRefdefUsing (const matrix4x4_t *entrendermatrix, const vec3_t clviewangles, qboolean teleported, qboolean clonground, qboolean clcmdjump, float clstatsviewheight, qboolean cldead, qboolean clintermission, const vec3_t clvelocity);
2042 void V_CalcRefdef(void);
2043 void CL_Locs_Reload_f(void);
2044
2045 #endif
2046