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