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