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