Add -Wshadow cflag and eliminate its warnings, including with g++
[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_world[3];
580         float render_modellight_lightdir_local[3];
581         float render_modellight_specular[3];
582         // lightmap rendering (not MATERIALFLAG_MODELLIGHT)
583         float render_lightmap_ambient[3];
584         float render_lightmap_diffuse[3];
585         float render_lightmap_specular[3];
586         // rtlights use these colors for the materials on this entity
587         float render_rtlight_diffuse[3];
588         float render_rtlight_specular[3];
589         // ignore lightmap and use fixed lighting settings on this entity (e.g. FULLBRIGHT)
590         qboolean render_modellight_forced;
591         // do not process per pixel lights on this entity at all (like MATERIALFLAG_NORTLIGHT)
592         qboolean render_rtlight_disabled;
593         // use the 3D lightmap from q3bsp on this entity
594         qboolean render_lightgrid;
595
596         // storage of decals on this entity
597         // (note: if allowdecals is set, be sure to call R_DecalSystem_Reset on removal!)
598         int allowdecals;
599         decalsystem_t decalsystem;
600
601         // FIELDS UPDATED BY RENDERER:
602         // last time visible during trace culling
603         double last_trace_visibility;
604
605         // user wavefunc parameters (from csqc)
606         vec_t userwavefunc_param[Q3WAVEFUNC_USER_COUNT];
607 }
608 entity_render_t;
609
610 typedef struct entity_persistent_s
611 {
612         vec3_t trail_origin; // previous position for particle trail spawning
613         vec3_t oldorigin; // lerp
614         vec3_t oldangles; // lerp
615         vec3_t neworigin; // lerp
616         vec3_t newangles; // lerp
617         vec_t lerpstarttime; // lerp
618         vec_t lerpdeltatime; // lerp
619         float muzzleflash; // muzzleflash intensity, fades over time
620         float trail_time; // residual error accumulation for particle trail spawning (to keep spacing across frames)
621         qboolean trail_allowed; // set to false by teleports, true by update code, prevents bad lerps
622 }
623 entity_persistent_t;
624
625 typedef struct entity_s
626 {
627         // baseline state (default values)
628         entity_state_t state_baseline;
629         // previous state (interpolating from this)
630         entity_state_t state_previous;
631         // current state (interpolating to this)
632         entity_state_t state_current;
633
634         // used for regenerating parts of render
635         entity_persistent_t persistent;
636
637         // the only data the renderer should know about
638         entity_render_t render;
639 }
640 entity_t;
641
642 typedef struct usercmd_s
643 {
644         vec3_t  viewangles;
645
646 // intended velocities
647         float   forwardmove;
648         float   sidemove;
649         float   upmove;
650
651         vec3_t  cursor_screen;
652         vec3_t  cursor_start;
653         vec3_t  cursor_end;
654         vec3_t  cursor_impact;
655         vec3_t  cursor_normal;
656         vec_t   cursor_fraction;
657         int             cursor_entitynumber;
658
659         double time; // time the move is executed for (cl_movement: clienttime, non-cl_movement: receivetime)
660         double receivetime; // time the move was received at
661         double clienttime; // time to which server state the move corresponds to
662         int msec; // for predicted moves
663         int buttons;
664         int impulse;
665         unsigned int sequence;
666         qboolean applied; // if false we're still accumulating a move
667         qboolean predicted; // if true the sequence should be sent as 0
668
669         // derived properties
670         double frametime;
671         qboolean canjump;
672         qboolean jump;
673         qboolean crouch;
674 } usercmd_t;
675
676 typedef struct lightstyle_s
677 {
678         int             length;
679         char    map[MAX_STYLESTRING];
680 } lightstyle_t;
681
682 typedef struct scoreboard_s
683 {
684         char    name[MAX_SCOREBOARDNAME];
685         int             frags;
686         int             colors; // two 4 bit fields
687         // QW fields:
688         int             qw_userid;
689         char    qw_userinfo[MAX_USERINFO_STRING];
690         float   qw_entertime;
691         int             qw_ping;
692         int             qw_packetloss;
693         int             qw_movementloss;
694         int             qw_spectator;
695         char    qw_team[8];
696         char    qw_skin[MAX_QPATH];
697 } scoreboard_t;
698
699 typedef struct cshift_s
700 {
701         float   destcolor[3];
702         float   percent;                // 0-255
703         float   alphafade;      // (any speed)
704 } cshift_t;
705
706 #define CSHIFT_CONTENTS 0
707 #define CSHIFT_DAMAGE   1
708 #define CSHIFT_BONUS    2
709 #define CSHIFT_POWERUP  3
710 #define CSHIFT_VCSHIFT  4
711 #define NUM_CSHIFTS             5
712
713 #define NAME_LENGTH     64
714
715
716 //
717 // client_state_t should hold all pieces of the client state
718 //
719
720 #define SIGNONS         4                       // signon messages to receive before connected
721
722 typedef enum cactive_e
723 {
724         ca_uninitialized,       // during early startup
725         ca_dedicated,           // a dedicated server with no ability to start a client
726         ca_disconnected,        // full screen console with no connection
727         ca_connected            // valid netcon, talking to a server
728 }
729 cactive_t;
730
731 typedef enum qw_downloadtype_e
732 {
733         dl_none,
734         dl_single,
735         dl_skin,
736         dl_model,
737         dl_sound
738 }
739 qw_downloadtype_t;
740
741 #ifdef CONFIG_VIDEO_CAPTURE
742 typedef enum capturevideoformat_e
743 {
744         CAPTUREVIDEOFORMAT_AVI_I420,
745         CAPTUREVIDEOFORMAT_OGG_VORBIS_THEORA
746 }
747 capturevideoformat_t;
748
749 typedef struct capturevideostate_s
750 {
751         double startrealtime;
752         double framerate;
753         int framestep;
754         int framestepframe;
755         qboolean active;
756         qboolean realtime;
757         qboolean error;
758         int soundrate;
759         int soundchannels;
760         int frame;
761         double starttime;
762         double lastfpstime;
763         int lastfpsframe;
764         int soundsampleframe;
765         unsigned char *screenbuffer;
766         unsigned char *outbuffer;
767         char basename[MAX_QPATH];
768         int width, height;
769
770         // precomputed RGB to YUV tables
771         // converts the RGB values to YUV (see cap_avi.c for how to use them)
772         short rgbtoyuvscaletable[3][3][256];
773         unsigned char yuvnormalizetable[3][256];
774
775         // precomputed gamma ramp (only needed if the capturevideo module uses RGB output)
776         // 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
777         unsigned short vidramp[256 * 3];
778
779         // stuff to be filled in by the video format module
780         capturevideoformat_t format;
781         const char *formatextension;
782         qfile_t *videofile;
783                 // always use this:
784                 //   cls.capturevideo.videofile = FS_OpenRealFile(va(vabuf, sizeof(vabuf), "%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false);
785         void (*endvideo) (void);
786         void (*videoframes) (int num);
787         void (*soundframe) (const portable_sampleframe_t *paintbuffer, size_t length);
788
789         // format specific data
790         void *formatspecific;
791 }
792 capturevideostate_t;
793 #endif
794
795 #define CL_MAX_DOWNLOADACKS 4
796
797 typedef struct cl_downloadack_s
798 {
799         int start, size;
800 }
801 cl_downloadack_t;
802
803 typedef struct cl_soundstats_s
804 {
805         int mixedsounds;
806         int totalsounds;
807         int latency_milliseconds;
808 }
809 cl_soundstats_t;
810
811 //
812 // the client_static_t structure is persistent through an arbitrary number
813 // of server connections
814 //
815 typedef struct client_static_s
816 {
817         cactive_t state;
818
819         // all client memory allocations go in these pools
820         mempool_t *levelmempool;
821         mempool_t *permanentmempool;
822
823 // demo loop control
824         // -1 = don't play demos
825         int demonum;
826         // list of demos in loop
827         char demos[MAX_DEMOS][MAX_DEMONAME];
828         // the actively playing demo (set by CL_PlayDemo_f)
829         char demoname[MAX_QPATH];
830
831 // demo recording info must be here, because record is started before
832 // entering a map (and clearing client_state_t)
833         qboolean demorecording;
834         fs_offset_t demo_lastcsprogssize;
835         int demo_lastcsprogscrc;
836         qboolean demoplayback;
837         qboolean demostarting; // set if currently starting a demo, to stop -demo from quitting when switching to another demo
838         qboolean timedemo;
839         // -1 = use normal cd track
840         int forcetrack;
841         qfile_t *demofile;
842         // realtime at second frame of timedemo (LadyHavoc: changed to double)
843         double td_starttime;
844         int td_frames; // total frames parsed
845         double td_onesecondnexttime;
846         double td_onesecondframes;
847         double td_onesecondrealtime;
848         double td_onesecondminfps;
849         double td_onesecondmaxfps;
850         double td_onesecondavgfps;
851         int td_onesecondavgcount;
852         // LadyHavoc: pausedemo
853         qboolean demopaused;
854
855         // sound mixer statistics for showsound display
856         cl_soundstats_t soundstats;
857
858         qboolean connect_trying;
859         int connect_remainingtries;
860         double connect_nextsendtime;
861         lhnetsocket_t *connect_mysocket;
862         lhnetaddress_t connect_address;
863         lhnetaddress_t rcon_address;
864         // protocol version of the server we're connected to
865         // (kept outside client_state_t because it's used between levels)
866         protocolversion_t protocol;
867
868 #define MAX_RCONS 16
869         int rcon_trying;
870         lhnetaddress_t rcon_addresses[MAX_RCONS];
871         char rcon_commands[MAX_RCONS][MAX_INPUTLINE];
872         double rcon_timeout[MAX_RCONS];
873         int rcon_ringpos;
874
875 // connection information
876         // 0 to SIGNONS
877         int signon;
878         // network connection
879         netconn_t *netcon;
880
881         // download information
882         // (note: qw_download variables are also used)
883         cl_downloadack_t dp_downloadack[CL_MAX_DOWNLOADACKS];
884
885         // input sequence numbers are not reset on level change, only connect
886         unsigned int servermovesequence;
887
888         // quakeworld stuff below
889
890         // value of "qport" cvar at time of connection
891         int qw_qport;
892         // copied from cls.netcon->qw. variables every time they change, or set by demos (which have no cls.netcon)
893         unsigned int qw_incoming_sequence;
894         unsigned int qw_outgoing_sequence;
895
896         // current file download buffer (only saved when file is completed)
897         char qw_downloadname[MAX_QPATH];
898         unsigned char *qw_downloadmemory;
899         int qw_downloadmemorycursize;
900         int qw_downloadmemorymaxsize;
901         int qw_downloadnumber;
902         int qw_downloadpercent;
903         qw_downloadtype_t qw_downloadtype;
904         // transfer rate display
905         double qw_downloadspeedtime;
906         int qw_downloadspeedcount;
907         int qw_downloadspeedrate;
908         qboolean qw_download_deflate;
909
910         // current file upload buffer (for uploading screenshots to server)
911         unsigned char *qw_uploaddata;
912         int qw_uploadsize;
913         int qw_uploadpos;
914
915         // user infostring
916         // this normally contains the following keys in quakeworld:
917         // password spectator name team skin topcolor bottomcolor rate noaim msg *ver *ip
918         char userinfo[MAX_USERINFO_STRING];
919
920         // extra user info for the "connect" command
921         char connect_userinfo[MAX_USERINFO_STRING];
922
923 #ifdef CONFIG_VIDEO_CAPTURE
924         // video capture stuff
925         capturevideostate_t capturevideo;
926 #endif
927
928         // crypto channel
929         crypto_t crypto;
930
931         // ProQuake compatibility stuff
932         int proquake_servermod; // 0 = not proquake, 1 = proquake
933         int proquake_serverversion; // actual proquake server version * 10 (3.40 = 34, etc)
934         int proquake_serverflags; // 0 (PQF_CHEATFREE not supported)
935
936         // don't write-then-read csprogs.dat (useful for demo playback)
937         unsigned char *caughtcsprogsdata;
938         fs_offset_t caughtcsprogsdatasize;
939
940         int r_speeds_graph_length;
941         int r_speeds_graph_current;
942         int *r_speeds_graph_data;
943
944         // graph scales
945         int r_speeds_graph_datamin[r_stat_count];
946         int r_speeds_graph_datamax[r_stat_count];
947 }
948 client_static_t;
949
950 extern client_static_t  cls;
951
952 //[515]: csqc
953 typedef struct
954 {
955         qboolean drawworld;
956         qboolean drawenginesbar;
957         qboolean drawcrosshair;
958 }csqc_vidvars_t;
959
960 typedef enum
961 {
962         PARTICLE_BILLBOARD = 0,
963         PARTICLE_SPARK = 1,
964         PARTICLE_ORIENTED_DOUBLESIDED = 2,
965         PARTICLE_VBEAM = 3,
966         PARTICLE_HBEAM = 4,
967         PARTICLE_INVALID = -1
968 }
969 porientation_t;
970
971 typedef enum
972 {
973         PBLEND_ALPHA = 0,
974         PBLEND_ADD = 1,
975         PBLEND_INVMOD = 2,
976         PBLEND_INVALID = -1
977 }
978 pblend_t;
979
980 typedef struct particletype_s
981 {
982         pblend_t blendmode;
983         porientation_t orientation;
984         qboolean lighting;
985 }
986 particletype_t;
987
988 typedef enum ptype_e
989 {
990         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
991 }
992 ptype_t;
993
994 typedef struct particle_s
995 {
996         // for faster batch rendering, particles are rendered in groups by effect (resulting in less perfect sorting but far less state changes)
997
998         // fields used by rendering: (48 bytes)
999         vec3_t          sortorigin; // sort by this group origin, not particle org
1000         vec3_t          org;
1001         vec3_t          vel; // velocity of particle, or orientation of decal, or end point of beam
1002         float           size;
1003         float           alpha; // 0-255
1004         float           stretch; // only for sparks
1005
1006         // fields not used by rendering:  (44 bytes)
1007         float           stainsize;
1008         float           stainalpha;
1009         float           sizeincrease; // rate of size change per second
1010         float           alphafade; // how much alpha reduces per second
1011         float           time2; // used for snow fluttering and decal fade
1012         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)
1013         float           gravity; // how much gravity affects this particle (1.0 = normal gravity, 0.0 = none)
1014         float           airfriction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
1015         float           liquidfriction; // how much liquid friction affects this object (objects with a low mass/size ratio tend to get more liquid friction)
1016 //      float           delayedcollisions; // time that p->bounce becomes active
1017         float           delayedspawn; // time that particle appears and begins moving
1018         float           die; // time when this particle should be removed, regardless of alpha
1019
1020         // short variables grouped to save memory (4 bytes)
1021         short                   angle; // base rotation of particle
1022         short                   spin; // geometry rotation speed around the particle center normal
1023
1024         // byte variables grouped to save memory (12 bytes)
1025         unsigned char   color[3];
1026         unsigned char   qualityreduction; // enables skipping of this particle according to r_refdef.view.qualityreduction
1027         unsigned char   typeindex;
1028         unsigned char   blendmode;
1029         unsigned char   orientation;
1030         unsigned char   texnum;
1031         unsigned char   staincolor[3];
1032         signed char     staintexnum;
1033 }
1034 particle_t;
1035
1036 typedef enum cl_parsingtextmode_e
1037 {
1038         CL_PARSETEXTMODE_NONE,
1039         CL_PARSETEXTMODE_PING,
1040         CL_PARSETEXTMODE_STATUS,
1041         CL_PARSETEXTMODE_STATUS_PLAYERID,
1042         CL_PARSETEXTMODE_STATUS_PLAYERIP
1043 }
1044 cl_parsingtextmode_t;
1045
1046 typedef struct cl_locnode_s
1047 {
1048         struct cl_locnode_s *next;
1049         char *name;
1050         vec3_t mins, maxs;
1051 }
1052 cl_locnode_t;
1053
1054 typedef struct showlmp_s
1055 {
1056         qboolean        isactive;
1057         float           x;
1058         float           y;
1059         char            label[32];
1060         char            pic[128];
1061 }
1062 showlmp_t;
1063
1064 //
1065 // the client_state_t structure is wiped completely at every
1066 // server signon
1067 //
1068 typedef struct client_state_s
1069 {
1070         // true if playing in a local game and no one else is connected
1071         int islocalgame;
1072
1073         // send a clc_nop periodically until connected
1074         float sendnoptime;
1075
1076         // current input being accumulated by mouse/joystick/etc input
1077         usercmd_t cmd;
1078         // latest moves sent to the server that have not been confirmed yet
1079         usercmd_t movecmd[CL_MAX_USERCMDS];
1080
1081 // information for local display
1082         // health, etc
1083         int stats[MAX_CL_STATS];
1084         float *statsf; // points to stats[] array
1085         // last known inventory bit flags, for blinking
1086         int olditems;
1087         // cl.time of acquiring item, for blinking
1088         float item_gettime[32];
1089         // last known STAT_ACTIVEWEAPON
1090         int activeweapon;
1091         // cl.time of changing STAT_ACTIVEWEAPON
1092         float weapontime;
1093         // use pain anim frame if cl.time < this
1094         float faceanimtime;
1095         // for stair smoothing
1096         float stairsmoothz;
1097         double stairsmoothtime;
1098
1099         // color shifts for damage, powerups
1100         cshift_t cshifts[NUM_CSHIFTS];
1101         // and content types
1102         cshift_t prev_cshifts[NUM_CSHIFTS];
1103
1104 // the client maintains its own idea of view angles, which are
1105 // sent to the server each frame.  The server sets punchangle when
1106 // the view is temporarily offset, and an angle reset commands at the start
1107 // of each level and after teleporting.
1108
1109         // mviewangles is read from demo
1110         // viewangles is either client controlled or lerped from mviewangles
1111         vec3_t mviewangles[2], viewangles;
1112         // update by server, used by qc to do weapon recoil
1113         vec3_t mpunchangle[2], punchangle;
1114         // update by server, can be used by mods to kick view around
1115         vec3_t mpunchvector[2], punchvector;
1116         // update by server, used for lean+bob (0 is newest)
1117         vec3_t mvelocity[2], velocity;
1118         // update by server, can be used by mods for zooming
1119         vec_t mviewzoom[2], viewzoom;
1120         // if true interpolation the mviewangles and other interpolation of the
1121         // player is disabled until the next network packet
1122         // this is used primarily by teleporters, and when spectating players
1123         // special checking of the old fixangle[1] is used to differentiate
1124         // between teleporting and spectating
1125         qboolean fixangle[2];
1126
1127         // client movement simulation
1128         // these fields are only updated by CL_ClientMovement (called by CL_SendMove after parsing each network packet)
1129         // set by CL_ClientMovement_Replay functions
1130         qboolean movement_predicted;
1131         // if true the CL_ClientMovement_Replay function will update origin, etc
1132         qboolean movement_replay;
1133         // simulated data (this is valid even if cl.movement is false)
1134         vec3_t movement_origin;
1135         vec3_t movement_velocity;
1136         // whether the replay should allow a jump at the first sequence
1137         qboolean movement_replay_canjump;
1138
1139         // previous gun angles (for leaning effects)
1140         vec3_t gunangles_prev;
1141         vec3_t gunangles_highpass;
1142         vec3_t gunangles_adjustment_lowpass;
1143         vec3_t gunangles_adjustment_highpass;
1144         // previous gun angles (for leaning effects)
1145         vec3_t gunorg_prev;
1146         vec3_t gunorg_highpass;
1147         vec3_t gunorg_adjustment_lowpass;
1148         vec3_t gunorg_adjustment_highpass;
1149
1150 // pitch drifting vars
1151         float idealpitch;
1152         float pitchvel;
1153         qboolean nodrift;
1154         float driftmove;
1155         double laststop;
1156
1157 //[515]: added for csqc purposes
1158         float sensitivityscale;
1159         csqc_vidvars_t csqc_vidvars;    //[515]: these parms must be set to true by default
1160         qboolean csqc_wantsmousemove;
1161         qboolean csqc_paused; // vortex: int because could be flags
1162         struct model_s *csqc_model_precache[MAX_MODELS];
1163
1164         // local amount for smoothing stepups
1165         //float crouch;
1166
1167         // sent by server
1168         qboolean paused;
1169         qboolean onground;
1170         qboolean inwater;
1171
1172         // used by bob
1173         qboolean oldonground;
1174         double lastongroundtime;
1175         double hitgroundtime;
1176         float bob2_smooth;
1177         float bobfall_speed;
1178         float bobfall_swing;
1179         double calcrefdef_prevtime;
1180
1181         // don't change view angle, full screen, etc
1182         int intermission;
1183         // latched at intermission start
1184         double completed_time;
1185
1186         // the timestamp of the last two messages
1187         double mtime[2];
1188
1189         // clients view of time, time should be between mtime[0] and mtime[1] to
1190         // generate a lerp point for other data, oldtime is the previous frame's
1191         // value of time, frametime is the difference between time and oldtime
1192         // note: cl.time may be beyond cl.mtime[0] if packet loss is occuring, it
1193         // is only forcefully limited when a packet is received
1194         double time, oldtime;
1195         // how long it has been since the previous client frame in real time
1196         // (not game time, for that use cl.time - cl.oldtime)
1197         double realframetime;
1198         
1199         // fade var for fading while dead
1200         float deathfade;
1201
1202         // motionblur alpha level variable
1203         float motionbluralpha;
1204
1205         // copy of realtime from last recieved message, for net trouble icon
1206         float last_received_message;
1207
1208 // information that is static for the entire time connected to a server
1209         struct model_s *model_precache[MAX_MODELS];
1210         struct sfx_s *sound_precache[MAX_SOUNDS];
1211
1212         // FIXME: this is a lot of memory to be keeping around, this really should be dynamically allocated and freed somehow
1213         char model_name[MAX_MODELS][MAX_QPATH];
1214         char sound_name[MAX_SOUNDS][MAX_QPATH];
1215
1216         // for display on solo scoreboard
1217         char worldmessage[40]; // map title (not related to filename)
1218         // variants of map name
1219         char worldbasename[MAX_QPATH]; // %s
1220         char worldname[MAX_QPATH]; // maps/%s.bsp
1221         char worldnamenoextension[MAX_QPATH]; // maps/%s
1222         // cl_entitites[cl.viewentity] = player
1223         int viewentity;
1224         // the real player entity (normally same as viewentity,
1225         // different than viewentity if mod uses chasecam or other tricks)
1226         int realplayerentity;
1227         // this is updated to match cl.viewentity whenever it is in the clients
1228         // range, basically this is used in preference to cl.realplayerentity for
1229         // most purposes because when spectating another player it should show
1230         // their information rather than yours
1231         int playerentity;
1232         // max players that can be in this game
1233         int maxclients;
1234         // type of game (deathmatch, coop, singleplayer)
1235         int gametype;
1236
1237         // models and sounds used by engine code (particularly cl_parse.c)
1238         dp_model_t *model_bolt;
1239         dp_model_t *model_bolt2;
1240         dp_model_t *model_bolt3;
1241         dp_model_t *model_beam;
1242         sfx_t *sfx_wizhit;
1243         sfx_t *sfx_knighthit;
1244         sfx_t *sfx_tink1;
1245         sfx_t *sfx_ric1;
1246         sfx_t *sfx_ric2;
1247         sfx_t *sfx_ric3;
1248         sfx_t *sfx_r_exp3;
1249         // indicates that the file "sound/misc/talk2.wav" was found (for use by team chat messages)
1250         qboolean foundteamchatsound;
1251
1252 // refresh related state
1253
1254         // cl_entitites[0].model
1255         struct model_s *worldmodel;
1256
1257         // the gun model
1258         entity_t viewent;
1259
1260         // cd audio
1261         int cdtrack, looptrack;
1262
1263 // frag scoreboard
1264
1265         // [cl.maxclients]
1266         scoreboard_t *scores;
1267
1268         // keep track of svc_print parsing state (analyzes ping reports and status reports)
1269         cl_parsingtextmode_t parsingtextmode;
1270         int parsingtextplayerindex;
1271         // set by scoreboard code when sending ping command, this causes the next ping results to be hidden
1272         // (which could eat the wrong ping report if the player issues one
1273         //  manually, but they would still see a ping report, just a later one
1274         //  caused by the scoreboard code rather than the one they intentionally
1275         //  issued)
1276         int parsingtextexpectingpingforscores;
1277
1278         // entity database stuff
1279         // latest received entity frame numbers
1280 #define LATESTFRAMENUMS 32
1281         int latestframenumsposition;
1282         int latestframenums[LATESTFRAMENUMS];
1283         unsigned int latestsendnums[LATESTFRAMENUMS];
1284         entityframe_database_t *entitydatabase;
1285         entityframe4_database_t *entitydatabase4;
1286         entityframeqw_database_t *entitydatabaseqw;
1287
1288         // keep track of quake entities because they need to be killed if they get stale
1289         int lastquakeentity;
1290         unsigned char isquakeentity[MAX_EDICTS];
1291
1292         // bounding boxes for clientside movement
1293         vec3_t playerstandmins;
1294         vec3_t playerstandmaxs;
1295         vec3_t playercrouchmins;
1296         vec3_t playercrouchmaxs;
1297
1298         // old decals are killed based on this
1299         unsigned int decalsequence;
1300
1301         int max_entities;
1302         int max_csqcrenderentities;
1303         int max_static_entities;
1304         int max_effects;
1305         int max_beams;
1306         int max_dlights;
1307         int max_lightstyle;
1308         int max_brushmodel_entities;
1309         int max_particles;
1310         int max_showlmps;
1311
1312         entity_t *entities;
1313         entity_render_t *csqcrenderentities;
1314         unsigned char *entities_active;
1315         entity_t *static_entities;
1316         cl_effect_t *effects;
1317         beam_t *beams;
1318         dlight_t *dlights;
1319         lightstyle_t *lightstyle;
1320         int *brushmodel_entities;
1321         particle_t *particles;
1322         showlmp_t *showlmps;
1323
1324         int num_entities;
1325         int num_static_entities;
1326         int num_brushmodel_entities;
1327         int num_effects;
1328         int num_beams;
1329         int num_dlights;
1330         int num_particles;
1331         int num_decals;
1332         int num_showlmps;
1333
1334         double particles_updatetime;
1335         double decals_updatetime;
1336         int free_particle;
1337         int free_decal;
1338
1339         // cl_serverextension_download feature
1340         int loadmodel_current;
1341         int downloadmodel_current;
1342         int loadmodel_total;
1343         int loadsound_current;
1344         int downloadsound_current;
1345         int loadsound_total;
1346         qboolean downloadcsqc;
1347         qboolean loadcsqc;
1348         qboolean loadbegun;
1349         qboolean loadfinished;
1350
1351         // quakeworld stuff
1352
1353         // local copy of the server infostring
1354         char qw_serverinfo[MAX_SERVERINFO_STRING];
1355
1356         // time of last qw "pings" command sent to server while showing scores
1357         double last_ping_request;
1358
1359         // used during connect
1360         int qw_servercount;
1361
1362         // updated from serverinfo
1363         int qw_teamplay;
1364
1365         // unused: indicates whether the player is spectating
1366         // use cl.scores[cl.playerentity-1].qw_spectator instead
1367         //qboolean qw_spectator;
1368
1369         // last time an input packet was sent
1370         double lastpackettime;
1371
1372         // movement parameters for client prediction
1373         unsigned int moveflags;
1374         float movevars_wallfriction;
1375         float movevars_waterfriction;
1376         float movevars_friction;
1377         float movevars_timescale;
1378         float movevars_gravity;
1379         float movevars_stopspeed;
1380         float movevars_maxspeed;
1381         float movevars_spectatormaxspeed;
1382         float movevars_accelerate;
1383         float movevars_airaccelerate;
1384         float movevars_wateraccelerate;
1385         float movevars_entgravity;
1386         float movevars_jumpvelocity;
1387         float movevars_edgefriction;
1388         float movevars_maxairspeed;
1389         float movevars_stepheight;
1390         float movevars_airaccel_qw;
1391         float movevars_airaccel_qw_stretchfactor;
1392         float movevars_airaccel_sideways_friction;
1393         float movevars_airstopaccelerate;
1394         float movevars_airstrafeaccelerate;
1395         float movevars_maxairstrafespeed;
1396         float movevars_airstrafeaccel_qw;
1397         float movevars_aircontrol;
1398         float movevars_aircontrol_power;
1399         float movevars_aircontrol_penalty;
1400         float movevars_warsowbunny_airforwardaccel;
1401         float movevars_warsowbunny_accel;
1402         float movevars_warsowbunny_topspeed;
1403         float movevars_warsowbunny_turnaccel;
1404         float movevars_warsowbunny_backtosideratio;
1405         float movevars_ticrate;
1406         float movevars_airspeedlimit_nonqw;
1407
1408         // models used by qw protocol
1409         int qw_modelindex_spike;
1410         int qw_modelindex_player;
1411         int qw_modelindex_flag;
1412         int qw_modelindex_s_explod;
1413
1414         vec3_t qw_intermission_origin;
1415         vec3_t qw_intermission_angles;
1416
1417         // 255 is the most nails the QW protocol could send
1418         int qw_num_nails;
1419         vec_t qw_nails[255][6];
1420
1421         float qw_weaponkick;
1422
1423         unsigned int qw_validsequence;
1424
1425         unsigned int qw_deltasequence[QW_UPDATE_BACKUP];
1426
1427         // csqc stuff:
1428         // server entity number corresponding to a clientside entity
1429         unsigned short csqc_server2csqcentitynumber[MAX_EDICTS];
1430         qboolean csqc_loaded;
1431         vec3_t csqc_vieworigin;
1432         vec3_t csqc_viewangles;
1433         vec3_t csqc_vieworiginfromengine;
1434         vec3_t csqc_viewanglesfromengine;
1435         matrix4x4_t csqc_viewmodelmatrixfromengine;
1436         qboolean csqc_usecsqclistener;
1437         matrix4x4_t csqc_listenermatrix;
1438         char csqc_printtextbuf[MAX_INPUTLINE];
1439
1440         // collision culling data
1441         world_t world;
1442
1443         // loc file stuff (points and boxes describing locations in the level)
1444         cl_locnode_t *locnodes;
1445         // this is updated to cl.movement_origin whenever health is < 1
1446         // used by %d print in say/say_team messages if cl_locs_enable is on
1447         vec3_t lastdeathorigin;
1448
1449         // processing buffer used by R_BuildLightMap, reallocated as needed,
1450         // freed on each level change
1451         size_t buildlightmapmemorysize;
1452         unsigned char *buildlightmapmemory;
1453
1454         // used by EntityState5_ReadUpdate
1455         skeleton_t *engineskeletonobjects;
1456 }
1457 client_state_t;
1458
1459 //
1460 // cvars
1461 //
1462 extern cvar_t cl_name;
1463 extern cvar_t cl_color;
1464 extern cvar_t cl_rate;
1465 extern cvar_t cl_rate_burstsize;
1466 extern cvar_t cl_pmodel;
1467 extern cvar_t cl_playermodel;
1468 extern cvar_t cl_playerskin;
1469
1470 extern cvar_t rcon_password;
1471 extern cvar_t rcon_address;
1472
1473 extern cvar_t cl_upspeed;
1474 extern cvar_t cl_forwardspeed;
1475 extern cvar_t cl_backspeed;
1476 extern cvar_t cl_sidespeed;
1477
1478 extern cvar_t cl_movespeedkey;
1479
1480 extern cvar_t cl_yawspeed;
1481 extern cvar_t cl_pitchspeed;
1482
1483 extern cvar_t cl_anglespeedkey;
1484
1485 extern cvar_t cl_autofire;
1486
1487 extern cvar_t cl_shownet;
1488 extern cvar_t cl_nolerp;
1489 extern cvar_t cl_nettimesyncfactor;
1490 extern cvar_t cl_nettimesyncboundmode;
1491 extern cvar_t cl_nettimesyncboundtolerance;
1492
1493 extern cvar_t cl_pitchdriftspeed;
1494 extern cvar_t lookspring;
1495 extern cvar_t lookstrafe;
1496 extern cvar_t sensitivity;
1497
1498 extern cvar_t freelook;
1499
1500 extern cvar_t m_pitch;
1501 extern cvar_t m_yaw;
1502 extern cvar_t m_forward;
1503 extern cvar_t m_side;
1504
1505 extern cvar_t cl_autodemo;
1506 extern cvar_t cl_autodemo_nameformat;
1507 extern cvar_t cl_autodemo_delete;
1508
1509 extern cvar_t r_draweffects;
1510
1511 extern cvar_t cl_explosions_alpha_start;
1512 extern cvar_t cl_explosions_alpha_end;
1513 extern cvar_t cl_explosions_size_start;
1514 extern cvar_t cl_explosions_size_end;
1515 extern cvar_t cl_explosions_lifetime;
1516 extern cvar_t cl_stainmaps;
1517 extern cvar_t cl_stainmaps_clearonload;
1518
1519 extern cvar_t cl_prydoncursor;
1520 extern cvar_t cl_prydoncursor_notrace;
1521
1522 extern cvar_t cl_locs_enable;
1523
1524 extern client_state_t cl;
1525
1526 extern void CL_AllocLightFlash (entity_render_t *ent, matrix4x4_t *matrix, float radius, float red, float green, float blue, float decay, float lifetime, char *cubemapname, int style, int shadowenable, vec_t corona, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags);
1527
1528 cl_locnode_t *CL_Locs_FindNearest(const vec3_t point);
1529 void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point);
1530
1531 //=============================================================================
1532
1533 //
1534 // cl_main
1535 //
1536
1537 void CL_Shutdown (void);
1538 void CL_Init (void);
1539
1540 void CL_EstablishConnection(const char *host, int firstarg);
1541
1542 void CL_Disconnect (void);
1543 void CL_Disconnect_f(cmd_state_t *cmd);
1544
1545 void CL_UpdateRenderEntity(entity_render_t *ent);
1546 void CL_SetEntityColormapColors(entity_render_t *ent, int colormap);
1547 void CL_UpdateViewEntities(void);
1548
1549 //
1550 // cl_input
1551 //
1552 typedef struct kbutton_s
1553 {
1554         int             down[2];                // key nums holding it down
1555         int             state;                  // low bit is down state
1556 }
1557 kbutton_t;
1558
1559 extern  kbutton_t       in_mlook, in_klook;
1560 extern  kbutton_t       in_strafe;
1561 extern  kbutton_t       in_speed;
1562
1563 void CL_InitInput (void);
1564 void CL_SendMove (void);
1565
1566 void CL_ValidateState(entity_state_t *s);
1567 void CL_MoveLerpEntityStates(entity_t *ent);
1568 void CL_LerpUpdate(entity_t *e);
1569 void CL_ParseTEnt (void);
1570 void CL_NewBeam (int ent, vec3_t start, vec3_t end, dp_model_t *m, int lightning);
1571 void CL_RelinkBeams (void);
1572 void CL_Beam_CalculatePositions (const beam_t *b, vec3_t start, vec3_t end);
1573 void CL_ClientMovement_Replay(void);
1574
1575 void CL_ClearTempEntities (void);
1576 entity_render_t *CL_NewTempEntity (double shadertime);
1577
1578 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate);
1579
1580 void CL_ClearState (void);
1581 void CL_ExpandEntities(int num);
1582 void CL_ExpandCSQCRenderEntities(int num);
1583 void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allowstarkey, qboolean allowmodel, qboolean quiet);
1584
1585
1586 void CL_UpdateWorld (void);
1587 void CL_WriteToServer (void);
1588 void CL_Input (void);
1589 extern int cl_ignoremousemoves;
1590
1591
1592 float CL_KeyState (kbutton_t *key);
1593 const char *Key_KeynumToString (int keynum, char *buf, size_t buflength);
1594 int Key_StringToKeynum (const char *str);
1595
1596 //
1597 // cl_demo.c
1598 //
1599 void CL_StopPlayback(void);
1600 void CL_ReadDemoMessage(void);
1601 void CL_WriteDemoMessage(sizebuf_t *mesage);
1602
1603 void CL_CutDemo(unsigned char **buf, fs_offset_t *filesize);
1604 void CL_PasteDemo(unsigned char **buf, fs_offset_t *filesize);
1605
1606 void CL_NextDemo(void);
1607 void CL_Stop_f(cmd_state_t *cmd);
1608 void CL_Record_f(cmd_state_t *cmd);
1609 void CL_PlayDemo_f(cmd_state_t *cmd);
1610 void CL_TimeDemo_f(cmd_state_t *cmd);
1611
1612 void CL_Demo_Init(void);
1613
1614 //
1615 // cl_parse.c
1616 //
1617 void CL_Parse_Init(void);
1618 void CL_Parse_Shutdown(void);
1619 void CL_ParseServerMessage(void);
1620 void CL_Parse_DumpPacket(void);
1621 void CL_Parse_ErrorCleanUp(void);
1622 void QW_CL_StartUpload(unsigned char *data, int size);
1623 extern cvar_t qport;
1624 void CL_KeepaliveMessage(qboolean readmessages); // call this during loading of large content
1625
1626 //
1627 // view
1628 //
1629 void V_StartPitchDrift_f(cmd_state_t *cmd);
1630 void V_StopPitchDrift (void);
1631
1632 void V_Init (void);
1633 float V_CalcRoll (const vec3_t angles, const vec3_t velocity);
1634 void V_UpdateBlends (void);
1635 void V_ParseDamage (void);
1636
1637 //
1638 // cl_part
1639 //
1640
1641 extern cvar_t cl_particles;
1642 extern cvar_t cl_particles_quality;
1643 extern cvar_t cl_particles_size;
1644 extern cvar_t cl_particles_quake;
1645 extern cvar_t cl_particles_blood;
1646 extern cvar_t cl_particles_blood_alpha;
1647 extern cvar_t cl_particles_blood_decal_alpha;
1648 extern cvar_t cl_particles_blood_decal_scalemin;
1649 extern cvar_t cl_particles_blood_decal_scalemax;
1650 extern cvar_t cl_particles_blood_bloodhack;
1651 extern cvar_t cl_particles_bulletimpacts;
1652 extern cvar_t cl_particles_explosions_sparks;
1653 extern cvar_t cl_particles_explosions_shell;
1654 extern cvar_t cl_particles_rain;
1655 extern cvar_t cl_particles_snow;
1656 extern cvar_t cl_particles_smoke;
1657 extern cvar_t cl_particles_smoke_alpha;
1658 extern cvar_t cl_particles_smoke_alphafade;
1659 extern cvar_t cl_particles_sparks;
1660 extern cvar_t cl_particles_bubbles;
1661 extern cvar_t cl_decals;
1662 extern cvar_t cl_decals_time;
1663 extern cvar_t cl_decals_fadetime;
1664
1665 void CL_Particles_Clear(void);
1666 void CL_Particles_Init(void);
1667 void CL_Particles_Shutdown(void);
1668 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]);
1669
1670 typedef enum effectnameindex_s
1671 {
1672         EFFECT_NONE,
1673         EFFECT_TE_GUNSHOT,
1674         EFFECT_TE_GUNSHOTQUAD,
1675         EFFECT_TE_SPIKE,
1676         EFFECT_TE_SPIKEQUAD,
1677         EFFECT_TE_SUPERSPIKE,
1678         EFFECT_TE_SUPERSPIKEQUAD,
1679         EFFECT_TE_WIZSPIKE,
1680         EFFECT_TE_KNIGHTSPIKE,
1681         EFFECT_TE_EXPLOSION,
1682         EFFECT_TE_EXPLOSIONQUAD,
1683         EFFECT_TE_TAREXPLOSION,
1684         EFFECT_TE_TELEPORT,
1685         EFFECT_TE_LAVASPLASH,
1686         EFFECT_TE_SMALLFLASH,
1687         EFFECT_TE_FLAMEJET,
1688         EFFECT_EF_FLAME,
1689         EFFECT_TE_BLOOD,
1690         EFFECT_TE_SPARK,
1691         EFFECT_TE_PLASMABURN,
1692         EFFECT_TE_TEI_G3,
1693         EFFECT_TE_TEI_SMOKE,
1694         EFFECT_TE_TEI_BIGEXPLOSION,
1695         EFFECT_TE_TEI_PLASMAHIT,
1696         EFFECT_EF_STARDUST,
1697         EFFECT_TR_ROCKET,
1698         EFFECT_TR_GRENADE,
1699         EFFECT_TR_BLOOD,
1700         EFFECT_TR_WIZSPIKE,
1701         EFFECT_TR_SLIGHTBLOOD,
1702         EFFECT_TR_KNIGHTSPIKE,
1703         EFFECT_TR_VORESPIKE,
1704         EFFECT_TR_NEHAHRASMOKE,
1705         EFFECT_TR_NEXUIZPLASMA,
1706         EFFECT_TR_GLOWTRAIL,
1707         EFFECT_SVC_PARTICLE,
1708         EFFECT_TOTAL
1709 }
1710 effectnameindex_t;
1711
1712 int CL_ParticleEffectIndexForName(const char *name);
1713 const char *CL_ParticleEffectNameForIndex(int i);
1714 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);
1715 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);
1716 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);
1717 void CL_ParseParticleEffect (void);
1718 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);
1719 void CL_ParticleRain (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, int type);
1720 void CL_EntityParticles (const entity_t *ent);
1721 void CL_ParticleExplosion (const vec3_t org);
1722 void CL_ParticleExplosion2 (const vec3_t org, int colorStart, int colorLength);
1723 void R_NewExplosion(const vec3_t org);
1724
1725 #include "cl_screen.h"
1726
1727 extern qboolean sb_showscores;
1728
1729 float RSurf_FogVertex(const vec3_t p);
1730 float RSurf_FogPoint(const vec3_t p);
1731
1732 typedef enum r_viewport_type_e
1733 {
1734         R_VIEWPORTTYPE_ORTHO,
1735         R_VIEWPORTTYPE_PERSPECTIVE,
1736         R_VIEWPORTTYPE_PERSPECTIVE_INFINITEFARCLIP,
1737         R_VIEWPORTTYPE_PERSPECTIVECUBESIDE,
1738         R_VIEWPORTTYPE_TOTAL
1739 }
1740 r_viewport_type_t;
1741
1742 typedef struct r_viewport_s
1743 {
1744         matrix4x4_t cameramatrix; // from entity (transforms from camera entity to world)
1745         matrix4x4_t viewmatrix; // actual matrix for rendering (transforms to viewspace)
1746         matrix4x4_t projectmatrix; // actual projection matrix (transforms from viewspace to screen)
1747         int x;
1748         int y;
1749         int z;
1750         int width;
1751         int height;
1752         int depth;
1753         r_viewport_type_t type;
1754         float screentodepth[2]; // used by deferred renderer to calculate linear depth from device depth coordinates
1755 }
1756 r_viewport_t;
1757
1758 typedef struct r_refdef_view_s
1759 {
1760         // view information (changes multiple times per frame)
1761         // if any of these variables change then r_refdef.viewcache must be regenerated
1762         // by calling R_View_Update
1763         // (which also updates viewport, scissor, colormask)
1764
1765         // it is safe and expected to copy this into a structure on the stack and
1766         // call the renderer recursively, then restore from the stack afterward
1767         // (as long as R_View_Update is called)
1768
1769         // eye position information
1770         matrix4x4_t matrix, inverse_matrix;
1771         vec3_t origin;
1772         vec3_t forward;
1773         vec3_t left;
1774         vec3_t right;
1775         vec3_t up;
1776         int numfrustumplanes;
1777         mplane_t frustum[6];
1778         qboolean useclipplane;
1779         qboolean usecustompvs; // uses r_refdef.viewcache.pvsbits as-is rather than computing it
1780         mplane_t clipplane;
1781         float frustum_x, frustum_y;
1782         vec3_t frustumcorner[4];
1783         // if turned off it renders an ortho view
1784         int useperspective;
1785         // allows visibility culling based on the view origin (e.g. pvs and R_CanSeeBox)
1786         // this is turned off by:
1787         // r_trippy
1788         // !r_refdef.view.useperspective
1789         // (sometimes) r_refdef.view.useclipplane
1790         int usevieworiginculling;
1791         float ortho_x, ortho_y;
1792
1793         // screen area to render in
1794         int x;
1795         int y;
1796         int z;
1797         int width;
1798         int height;
1799         int depth;
1800         r_viewport_t viewport; // note: if r_viewscale is used, the viewport.width and viewport.height may be less than width and height
1801
1802         // which color components to allow (for anaglyph glasses)
1803         int colormask[4];
1804
1805         // global RGB color multiplier for rendering
1806         float colorscale;
1807
1808         // whether to call R_ClearScreen before rendering stuff
1809         qboolean clear;
1810         // if true, don't clear or do any post process effects (bloom, etc)
1811         qboolean isoverlay;
1812         // 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)
1813         qboolean ismain;
1814
1815         // whether to draw r_showtris and such, this is only true for the main
1816         // view render, all secondary renders (mirrors, portals, cameras,
1817         // distortion effects, etc) omit such debugging information
1818         qboolean showdebug;
1819
1820         // these define which values to use in GL_CullFace calls to request frontface or backface culling
1821         int cullface_front;
1822         int cullface_back;
1823
1824         // render quality (0 to 1) - affects r_drawparticles_drawdistance and others
1825         float quality;
1826 }
1827 r_refdef_view_t;
1828
1829 typedef struct r_refdef_viewcache_s
1830 {
1831         // updated by gl_main_newmap()
1832         int maxentities;
1833         int world_numclusters;
1834         int world_numclusterbytes;
1835         int world_numleafs;
1836         int world_numsurfaces;
1837
1838         // these properties are generated by R_View_Update()
1839
1840         // which entities are currently visible for this viewpoint
1841         // (the used range is 0...r_refdef.scene.numentities)
1842         unsigned char *entityvisible;
1843
1844         // flag arrays used for visibility checking on world model
1845         // (all other entities have no per-surface/per-leaf visibility checks)
1846         unsigned char *world_pvsbits;
1847         unsigned char *world_leafvisible;
1848         unsigned char *world_surfacevisible;
1849         // if true, the view is currently in a leaf without pvs data
1850         qboolean world_novis;
1851 }
1852 r_refdef_viewcache_t;
1853
1854 // TODO: really think about which fields should go into scene and which one should stay in refdef [1/7/2008 Black]
1855 // maybe also refactor some of the functions to support different setting sources (ie. fogenabled, etc.) for different scenes
1856 typedef struct r_refdef_scene_s {
1857         // whether to call S_ExtraUpdate during render to reduce sound chop
1858         qboolean extraupdate;
1859
1860         // (client gameworld) time for rendering time based effects
1861         double time;
1862
1863         // the world
1864         entity_render_t *worldentity;
1865
1866         // same as worldentity->model
1867         dp_model_t *worldmodel;
1868
1869         // renderable entities (excluding world)
1870         entity_render_t **entities;
1871         int numentities;
1872         int maxentities;
1873
1874         // field of temporary entities that is reset each (client) frame
1875         entity_render_t *tempentities;
1876         int numtempentities;
1877         int maxtempentities;
1878         qboolean expandtempentities;
1879
1880         // renderable dynamic lights
1881         rtlight_t *lights[MAX_DLIGHTS];
1882         rtlight_t templights[MAX_DLIGHTS];
1883         int numlights;
1884
1885         // intensities for light styles right now, controls rtlights
1886         float rtlightstylevalue[MAX_LIGHTSTYLES];       // float fraction of base light value
1887         // 8.8bit fixed point intensities for light styles
1888         // controls intensity lightmap layers
1889         unsigned short lightstylevalue[MAX_LIGHTSTYLES];        // 8.8 fraction of base light value
1890
1891         // adds brightness to the whole scene, separate from lightmapintensity
1892         // see CL_UpdateEntityShading
1893         float ambientintensity;
1894         // brightness of lightmap and modellight lighting on materials
1895         // see CL_UpdateEntityShading
1896         float lightmapintensity;
1897
1898         qboolean rtworld;
1899         qboolean rtworldshadows;
1900         qboolean rtdlight;
1901         qboolean rtdlightshadows;
1902 } r_refdef_scene_t;
1903
1904 typedef struct r_refdef_s
1905 {
1906         // these fields define the basic rendering information for the world
1907         // but not the view, which could change multiple times in one rendered
1908         // frame (for example when rendering textures for certain effects)
1909
1910         // these are set for water warping before
1911         // frustum_x/frustum_y are calculated
1912         float frustumscale_x, frustumscale_y;
1913
1914         // current view settings (these get reset a few times during rendering because of water rendering, reflections, etc)
1915         r_refdef_view_t view;
1916         r_refdef_viewcache_t viewcache;
1917
1918         // minimum visible distance (pixels closer than this disappear)
1919         double nearclip;
1920         // maximum visible distance (pixels further than this disappear in 16bpp modes,
1921         // in 32bpp an infinite-farclip matrix is used instead)
1922         double farclip;
1923
1924         // fullscreen color blend
1925         float viewblend[4];
1926
1927         r_refdef_scene_t scene;
1928
1929         float fogplane[4];
1930         float fogplaneviewdist;
1931         qboolean fogplaneviewabove;
1932         float fogheightfade;
1933         float fogcolor[3];
1934         float fogrange;
1935         float fograngerecip;
1936         float fogmasktabledistmultiplier;
1937 #define FOGMASKTABLEWIDTH 1024
1938         float fogmasktable[FOGMASKTABLEWIDTH];
1939         float fogmasktable_start, fogmasktable_alpha, fogmasktable_range, fogmasktable_density;
1940         float fog_density;
1941         float fog_red;
1942         float fog_green;
1943         float fog_blue;
1944         float fog_alpha;
1945         float fog_start;
1946         float fog_end;
1947         float fog_height;
1948         float fog_fadedepth;
1949         qboolean fogenabled;
1950         qboolean oldgl_fogenable;
1951
1952         // new flexible texture height fog (overrides normal fog)
1953         char fog_height_texturename[64]; // note: must be 64 for the sscanf code
1954         unsigned char *fog_height_table1d;
1955         unsigned char *fog_height_table2d;
1956         int fog_height_tablesize; // enable
1957         float fog_height_tablescale;
1958         float fog_height_texcoordscale;
1959         char fogheighttexturename[64]; // detects changes to active fog height texture
1960
1961         int draw2dstage; // 0 = no, 1 = yes, other value = needs setting up again
1962
1963         // true during envmap command capture
1964         qboolean envmap;
1965
1966         // whether to draw world lights realtime, dlights realtime, and their shadows
1967         float polygonfactor;
1968         float polygonoffset;
1969
1970         // how long R_RenderView took on the previous frame
1971         double lastdrawscreentime;
1972
1973         // rendering stats for r_speeds display
1974         // (these are incremented in many places)
1975         int stats[r_stat_count];
1976 }
1977 r_refdef_t;
1978
1979 extern r_refdef_t r_refdef;
1980
1981 typedef enum waterlevel_e
1982 {
1983         WATERLEVEL_NONE,
1984         WATERLEVEL_WETFEET,
1985         WATERLEVEL_SWIMMING,
1986         WATERLEVEL_SUBMERGED
1987 }
1988 waterlevel_t;
1989
1990 typedef struct cl_clientmovement_state_s
1991 {
1992         // entity to be ignored for movement
1993         struct prvm_edict_s *self;
1994         // position
1995         vec3_t origin;
1996         vec3_t velocity;
1997         // current bounding box (different if crouched vs standing)
1998         vec3_t mins;
1999         vec3_t maxs;
2000         // currently on the ground
2001         qboolean onground;
2002         // currently crouching
2003         qboolean crouched;
2004         // what kind of water (SUPERCONTENTS_LAVA for instance)
2005         int watertype;
2006         // how deep
2007         waterlevel_t waterlevel;
2008         // weird hacks when jumping out of water
2009         // (this is in seconds and counts down to 0)
2010         float waterjumptime;
2011
2012         // user command
2013         usercmd_t cmd;
2014 }
2015 cl_clientmovement_state_t;
2016 void CL_ClientMovement_PlayerMove_Frame(cl_clientmovement_state_t *s);
2017
2018 // warpzone prediction hack (CSQC builtin)
2019 void CL_RotateMoves(const matrix4x4_t *m);
2020
2021 typedef enum meshname_e {
2022         MESH_SCENE, // CSQC R_PolygonBegin, potentially also engine particles and debug stuff
2023         MESH_UI,
2024         NUM_MESHENTITIES,
2025 } meshname_t;
2026 extern entity_t cl_meshentities[NUM_MESHENTITIES];
2027 extern dp_model_t cl_meshentitymodels[NUM_MESHENTITIES];
2028 extern const char *cl_meshentitynames[NUM_MESHENTITIES];
2029 #define CL_Mesh_Scene() (&cl_meshentitymodels[MESH_SCENE])
2030 #define CL_Mesh_UI() (&cl_meshentitymodels[MESH_UI])
2031 void CL_MeshEntities_Scene_Clear(void);
2032 void CL_MeshEntities_Scene_AddRenderEntity(void);
2033 void CL_MeshEntities_Scene_FinalizeRenderEntity(void);
2034 void CL_UpdateEntityShading(void);
2035
2036 void CL_NewFrameReceived(int num);
2037 void CL_ParseEntityLump(char *entitystring);
2038 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius);
2039 void CL_RelinkLightFlashes(void);
2040 void CL_Beam_AddPolygons(const beam_t *b);
2041 void Sbar_ShowFPS(void);
2042 void Sbar_ShowFPS_Update(void);
2043 void Host_SaveConfig(void);
2044 void Host_LoadConfig_f(cmd_state_t *cmd);
2045 void CL_UpdateMoveVars(void);
2046 void SCR_CaptureVideo_SoundFrame(const portable_sampleframe_t *paintbuffer, size_t length);
2047 void V_DriftPitch(void);
2048 void V_FadeViewFlashs(void);
2049 void V_CalcViewBlend(void);
2050 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);
2051 void V_CalcRefdef(void);
2052 void V_MakeViewIsometric(void);
2053 void V_MakeViewIsometric(void);
2054 void V_StartPitchDrift(void);
2055 void CL_Locs_Reload_f(cmd_state_t *cmd);
2056
2057 #endif
2058