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