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