]> git.xonotic.org Git - xonotic/darkplaces.git/blob - client.h
client: Add view.h. Move view prototypes to it.
[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 #include "view.h"
28
29 // NOTE: r_stat_name[] must match this indexing
30 typedef enum r_stat_e
31 {
32         r_stat_timedelta,
33         r_stat_quality,
34         r_stat_renders,
35         r_stat_entities,
36         r_stat_entities_surfaces,
37         r_stat_entities_triangles,
38         r_stat_world_leafs,
39         r_stat_world_portals,
40         r_stat_world_surfaces,
41         r_stat_world_triangles,
42         r_stat_lightmapupdates,
43         r_stat_lightmapupdatepixels,
44         r_stat_particles,
45         r_stat_drawndecals,
46         r_stat_totaldecals,
47         r_stat_draws,
48         r_stat_draws_vertices,
49         r_stat_draws_elements,
50         r_stat_lights,
51         r_stat_lights_clears,
52         r_stat_lights_scissored,
53         r_stat_lights_lighttriangles,
54         r_stat_lights_shadowtriangles,
55         r_stat_lights_dynamicshadowtriangles,
56         r_stat_bouncegrid_lights,
57         r_stat_bouncegrid_particles,
58         r_stat_bouncegrid_traces,
59         r_stat_bouncegrid_hits,
60         r_stat_bouncegrid_splats,
61         r_stat_bouncegrid_bounces,
62         r_stat_photoncache_animated,
63         r_stat_photoncache_cached,
64         r_stat_photoncache_traced,
65         r_stat_bloom,
66         r_stat_bloom_copypixels,
67         r_stat_bloom_drawpixels,
68         r_stat_rendertargets_used,
69         r_stat_rendertargets_pixels,
70         r_stat_indexbufferuploadcount,
71         r_stat_indexbufferuploadsize,
72         r_stat_vertexbufferuploadcount,
73         r_stat_vertexbufferuploadsize,
74         r_stat_framedatacurrent,
75         r_stat_framedatasize,
76         r_stat_bufferdatacurrent_vertex, // R_BUFFERDATA_ types are added to this index
77         r_stat_bufferdatacurrent_index16,
78         r_stat_bufferdatacurrent_index32,
79         r_stat_bufferdatacurrent_uniform,
80         r_stat_bufferdatasize_vertex, // R_BUFFERDATA_ types are added to this index
81         r_stat_bufferdatasize_index16,
82         r_stat_bufferdatasize_index32,
83         r_stat_bufferdatasize_uniform,
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_nogaps,
163         r_stat_batch_dynamic_surfaces_because_nogaps,
164         r_stat_batch_dynamic_vertices_because_nogaps,
165         r_stat_batch_dynamic_triangles_because_nogaps,
166         r_stat_batch_dynamic_batches_because_derived,
167         r_stat_batch_dynamic_surfaces_because_derived,
168         r_stat_batch_dynamic_vertices_because_derived,
169         r_stat_batch_dynamic_triangles_because_derived,
170         r_stat_batch_entitycache_count,
171         r_stat_batch_entitycache_surfaces,
172         r_stat_batch_entitycache_vertices,
173         r_stat_batch_entitycache_triangles,
174         r_stat_batch_entityanimate_count,
175         r_stat_batch_entityanimate_surfaces,
176         r_stat_batch_entityanimate_vertices,
177         r_stat_batch_entityanimate_triangles,
178         r_stat_batch_entityskeletal_count,
179         r_stat_batch_entityskeletal_surfaces,
180         r_stat_batch_entityskeletal_vertices,
181         r_stat_batch_entityskeletal_triangles,
182         r_stat_batch_entitystatic_count,
183         r_stat_batch_entitystatic_surfaces,
184         r_stat_batch_entitystatic_vertices,
185         r_stat_batch_entitystatic_triangles,
186         r_stat_batch_entitycustom_count,
187         r_stat_batch_entitycustom_surfaces,
188         r_stat_batch_entitycustom_vertices,
189         r_stat_batch_entitycustom_triangles,
190         r_stat_count // size of array
191 }
192 r_stat_t;
193
194 // flags for rtlight rendering
195 #define LIGHTFLAG_NORMALMODE 1
196 #define LIGHTFLAG_REALTIMEMODE 2
197
198 typedef struct tridecal_s
199 {
200         // color and initial alpha value
201         float                   texcoord2f[3][2];
202         float                   vertex3f[3][3];
203         float                   color4f[3][4];
204         float                   plane[4]; // backface culling
205         // how long this decal has lived so far (the actual fade begins at cl_decals_time)
206         float                   lived;
207         // if >= 0 this indicates the decal should follow an animated triangle
208         int                             triangleindex;
209         // for visibility culling
210         int                             surfaceindex;
211         // old decals are killed to obey cl_decals_max
212         unsigned int    decalsequence;
213 }
214 tridecal_t;
215
216 typedef struct decalsystem_s
217 {
218         dp_model_t *model;
219         double lastupdatetime;
220         int maxdecals;
221         int freedecal;
222         int numdecals;
223         tridecal_t *decals;
224         float *vertex3f;
225         float *texcoord2f;
226         float *color4f;
227         int *element3i;
228         unsigned short *element3s;
229 }
230 decalsystem_t;
231
232 typedef struct effect_s
233 {
234         int active;
235         vec3_t origin;
236         double starttime;
237         float framerate;
238         dp_model_t *model;
239         int startframe;
240         int endframe;
241         // these are for interpolation
242         int frame;
243         double frame1time;
244         double frame2time;
245 }
246 cl_effect_t;
247
248 typedef struct beam_s
249 {
250         int             entity;
251         // draw this as lightning polygons, or a model?
252         int             lightning;
253         struct model_s  *model;
254         float   endtime;
255         vec3_t  start, end;
256 }
257 beam_t;
258
259 typedef struct rtlight_particle_s
260 {
261         float origin[3];
262         float color[3];
263 }
264 rtlight_particle_t;
265
266 typedef struct rtlight_s
267 {
268         // note that the world to light matrices are inversely scaled (divided) by lightradius
269
270         // core properties
271         /// matrix for transforming light filter coordinates to world coordinates
272         matrix4x4_t matrix_lighttoworld;
273         /// matrix for transforming world coordinates to light filter coordinates
274         matrix4x4_t matrix_worldtolight;
275         /// typically 1 1 1, can be lower (dim) or higher (overbright)
276         vec3_t color;
277         /// size of the light (remove?)
278         vec_t radius;
279         /// light filter
280         char cubemapname[64];
281         /// light style to monitor for brightness
282         int style;
283         /// whether light should render shadows (see castshadows for whether it actually does this frame)
284         int shadow;
285         /// intensity of corona to render
286         vec_t corona;
287         /// radius scale of corona to render (1.0 means same as light radius)
288         vec_t coronasizescale;
289         /// ambient intensity to render
290         vec_t ambientscale;
291         /// diffuse intensity to render
292         vec_t diffusescale;
293         /// specular intensity to render
294         vec_t specularscale;
295         /// LIGHTFLAG_* flags
296         int flags;
297
298         // generated properties
299         /// used only for casting shadows
300         vec3_t shadoworigin;
301         /// culling
302         vec3_t cullmins;
303         vec3_t cullmaxs;
304         /// when r_shadow_culllights_trace is set, this is refreshed by each successful trace.
305         double trace_timer;
306
307         // rendering properties, updated each time a light is rendered
308         // this is rtlight->color * d_lightstylevalue
309         vec3_t currentcolor;
310         /// used by corona updates, due to occlusion query
311         float corona_visibility;
312         unsigned int corona_queryindex_visiblepixels;
313         unsigned int corona_queryindex_allpixels;
314         /// this is R_GetCubemap(rtlight->cubemapname)
315         rtexture_t *currentcubemap;
316         /// set by R_Shadow_PrepareLight to decide whether R_Shadow_DrawLight should draw it
317         qbool draw;
318         /// set by R_Shadow_PrepareLight to indicate whether R_Shadow_DrawShadowMaps should do anything
319         qbool castshadows;
320         /// these fields are set by R_Shadow_PrepareLight for later drawing
321         int cached_numlightentities;
322         int cached_numlightentities_noselfshadow;
323         int cached_numshadowentities;
324         int cached_numshadowentities_noselfshadow;
325         int cached_numsurfaces;
326         struct entity_render_s **cached_lightentities;
327         struct entity_render_s **cached_lightentities_noselfshadow;
328         struct entity_render_s **cached_shadowentities;
329         struct entity_render_s **cached_shadowentities_noselfshadow;
330         unsigned char *cached_shadowtrispvs;
331         unsigned char *cached_lighttrispvs;
332         int *cached_surfacelist;
333         // reduced light cullbox from GetLightInfo
334         vec3_t cached_cullmins;
335         vec3_t cached_cullmaxs;
336         // current shadow-caster culling planes based on view
337         // (any geometry outside these planes can not contribute to the visible
338         //  shadows in any way, and thus can be culled safely)
339         int cached_numfrustumplanes;
340         mplane_t cached_frustumplanes[5]; // see R_Shadow_ComputeShadowCasterCullingPlanes
341
342         /// static light info
343         /// true if this light should be compiled as a static light
344         int isstatic;
345         /// true if this is a compiled world light, cleared if the light changes
346         int compiled;
347         /// the size that this light should have (assuming no scene LOD kicking in to reduce it)
348         int shadowmapsidesize;
349         /// position of this light in the shadowmap atlas
350         int shadowmapatlasposition[2];
351         /// 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)
352         int shadowmapatlassidesize;
353         /// optimized and culled mesh to render for world entity shadows
354         shadowmesh_t *static_meshchain_shadow_shadowmap;
355         /// used for visibility testing (more exact than bbox)
356         int static_numleafs;
357         int static_numleafpvsbytes;
358         int *static_leaflist;
359         unsigned char *static_leafpvs;
360         /// surfaces seen by light
361         int static_numsurfaces;
362         int *static_surfacelist;
363         /// flag bits indicating which triangles of the world model should cast
364         /// shadows, and which ones should be lit
365         ///
366         /// this avoids redundantly scanning the triangles in each surface twice
367         /// for whether they should cast shadows, once in culling and once in the
368         /// actual shadowmarklist production.
369         int static_numshadowtrispvsbytes;
370         unsigned char *static_shadowtrispvs;
371         /// this allows the lighting batch code to skip backfaces andother culled
372         /// triangles not relevant for lighting
373         /// (important on big surfaces such as terrain)
374         int static_numlighttrispvsbytes;
375         unsigned char *static_lighttrispvs;
376         /// masks of all shadowmap sides that have any potential static receivers or casters
377         int static_shadowmap_receivers;
378         int static_shadowmap_casters;
379         /// particle-tracing cache for global illumination
380         int particlecache_numparticles;
381         int particlecache_maxparticles;
382         int particlecache_updateparticle;
383         rtlight_particle_t *particlecache_particles;
384
385         /// bouncegrid light info
386         float bouncegrid_photoncolor[3];
387         float bouncegrid_photons;
388         int bouncegrid_hits;
389         int bouncegrid_traces;
390         float bouncegrid_effectiveradius;
391 }
392 rtlight_t;
393
394 typedef struct dlight_s
395 {
396         // destroy light after this time
397         // (dlight only)
398         vec_t die;
399         // the entity that owns this light (can be NULL)
400         // (dlight only)
401         struct entity_render_s *ent;
402         // location
403         // (worldlight: saved to .rtlights file)
404         vec3_t origin;
405         // worldlight orientation
406         // (worldlight only)
407         // (worldlight: saved to .rtlights file)
408         vec3_t angles;
409         // dlight orientation/scaling/location
410         // (dlight only)
411         matrix4x4_t matrix;
412         // color of light
413         // (worldlight: saved to .rtlights file)
414         vec3_t color;
415         // cubemap name to use on this light
416         // (worldlight: saved to .rtlights file)
417         char cubemapname[64];
418         // make light flash while selected
419         // (worldlight only)
420         int selected;
421         // brightness (not really radius anymore)
422         // (worldlight: saved to .rtlights file)
423         vec_t radius;
424         // drop intensity this much each second
425         // (dlight only)
426         vec_t decay;
427         // intensity value which is dropped over time
428         // (dlight only)
429         vec_t intensity;
430         // initial values for intensity to modify
431         // (dlight only)
432         vec_t initialradius;
433         vec3_t initialcolor;
434         // light style which controls intensity of this light
435         // (worldlight: saved to .rtlights file)
436         int style;
437         // cast shadows
438         // (worldlight: saved to .rtlights file)
439         int shadow;
440         // corona intensity
441         // (worldlight: saved to .rtlights file)
442         vec_t corona;
443         // radius scale of corona to render (1.0 means same as light radius)
444         // (worldlight: saved to .rtlights file)
445         vec_t coronasizescale;
446         // ambient intensity to render
447         // (worldlight: saved to .rtlights file)
448         vec_t ambientscale;
449         // diffuse intensity to render
450         // (worldlight: saved to .rtlights file)
451         vec_t diffusescale;
452         // specular intensity to render
453         // (worldlight: saved to .rtlights file)
454         vec_t specularscale;
455         // LIGHTFLAG_* flags
456         // (worldlight: saved to .rtlights file)
457         int flags;
458         // linked list of world lights
459         // (worldlight only)
460         struct dlight_s *next;
461         // embedded rtlight struct for renderer
462         // (worldlight only)
463         rtlight_t rtlight;
464 }
465 dlight_t;
466
467 // this is derived from processing of the framegroupblend array
468 // note: technically each framegroupblend can produce two of these, but that
469 // never happens in practice because no one blends between more than 2
470 // framegroups at once
471 #define MAX_FRAMEBLENDS (MAX_FRAMEGROUPBLENDS * 2)
472 typedef struct frameblend_s
473 {
474         int subframe;
475         float lerp;
476 }
477 frameblend_t;
478
479 // LadyHavoc: this struct is intended for the renderer but some fields are
480 // used by the client.
481 //
482 // The renderer should not rely on any changes to this struct to be persistent
483 // across multiple frames because temp entities are wiped every frame, but it
484 // is acceptable to cache things in this struct that are not critical.
485 //
486 // For example the r_cullentities_trace code does such caching.
487 typedef struct entity_render_s
488 {
489         // location
490         //vec3_t origin;
491         // orientation
492         //vec3_t angles;
493         // transform matrix for model to world
494         matrix4x4_t matrix;
495         // transform matrix for world to model
496         matrix4x4_t inversematrix;
497         // opacity (alpha) of the model
498         float alpha;
499         // size the model is shown
500         float scale;
501         // transparent sorting offset
502         float transparent_offset;
503
504         // NULL = no model
505         dp_model_t *model;
506         // number of the entity represents, or 0 for non-network entities
507         int entitynumber;
508         // literal colormap colors for renderer, if both are 0 0 0 it is not colormapped
509         vec3_t colormap_pantscolor;
510         vec3_t colormap_shirtcolor;
511         // light, particles, etc
512         int effects;
513         // qw CTF flags and other internal-use-only effect bits
514         int internaleffects;
515         // for Alias models
516         int skinnum;
517         // render flags
518         int flags;
519
520         // colormod tinting of models
521         float colormod[3];
522         float glowmod[3];
523
524         // interpolated animation - active framegroups and blend factors
525         framegroupblend_t framegroupblend[MAX_FRAMEGROUPBLENDS];
526
527         // time of last model change (for shader animations)
528         double shadertime;
529
530         // calculated by the renderer (but not persistent)
531
532         // calculated during R_AddModelEntities
533         vec3_t mins, maxs;
534         // subframe numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use subframeblend[0].subframe
535         frameblend_t frameblend[MAX_FRAMEBLENDS];
536         // skeletal animation data (if skeleton.relativetransforms is not NULL, it overrides frameblend)
537         skeleton_t *skeleton;
538
539         // animation cache (pointers allocated using R_FrameData_Alloc)
540         // ONLY valid during R_RenderView!  may be NULL (not cached)
541         float          *animcache_vertex3f;
542         r_meshbuffer_t *animcache_vertex3f_vertexbuffer;
543         int             animcache_vertex3f_bufferoffset;
544         float          *animcache_normal3f;
545         r_meshbuffer_t *animcache_normal3f_vertexbuffer;
546         int             animcache_normal3f_bufferoffset;
547         float          *animcache_svector3f;
548         r_meshbuffer_t *animcache_svector3f_vertexbuffer;
549         int             animcache_svector3f_bufferoffset;
550         float          *animcache_tvector3f;
551         r_meshbuffer_t *animcache_tvector3f_vertexbuffer;
552         int             animcache_tvector3f_bufferoffset;
553         // gpu-skinning shader needs transforms in a certain format, we have to
554         // upload this to a uniform buffer for the shader to use, and also keep a
555         // backup copy in system memory for the dynamic batch fallback code
556         // if this is not NULL, the other animcache variables are NULL
557         float *animcache_skeletaltransform3x4;
558         r_meshbuffer_t *animcache_skeletaltransform3x4buffer;
559         int animcache_skeletaltransform3x4offset;
560         int animcache_skeletaltransform3x4size;
561
562         // CL_UpdateEntityShading reads these fields
563         // used only if RENDER_CUSTOMIZEDMODELLIGHT is set
564         vec3_t custommodellight_ambient;
565         vec3_t custommodellight_diffuse;
566         vec3_t custommodellight_lightdir;
567         // CSQC entities get their shading from the root of their attachment chain
568         float custommodellight_origin[3];
569
570         // derived lighting parameters (CL_UpdateEntityShading)
571
572         // used by MATERIALFLAG_FULLBRIGHT which is MATERIALFLAG_MODELLIGHT with
573         // this as ambient color, along with MATERIALFLAG_NORTLIGHT
574         float render_fullbright[3];
575         // color tint for the base pass glow textures if any
576         float render_glowmod[3];
577         // MATERIALFLAG_MODELLIGHT uses these parameters
578         float render_modellight_ambient[3];
579         float render_modellight_diffuse[3];
580         float render_modellight_lightdir_world[3];
581         float render_modellight_lightdir_local[3];
582         float render_modellight_specular[3];
583         // lightmap rendering (not MATERIALFLAG_MODELLIGHT)
584         float render_lightmap_ambient[3];
585         float render_lightmap_diffuse[3];
586         float render_lightmap_specular[3];
587         // rtlights use these colors for the materials on this entity
588         float render_rtlight_diffuse[3];
589         float render_rtlight_specular[3];
590         // ignore lightmap and use fixed lighting settings on this entity (e.g. FULLBRIGHT)
591         qbool render_modellight_forced;
592         // do not process per pixel lights on this entity at all (like MATERIALFLAG_NORTLIGHT)
593         qbool render_rtlight_disabled;
594         // use the 3D lightmap from q3bsp on this entity
595         qbool render_lightgrid;
596
597         // storage of decals on this entity
598         // (note: if allowdecals is set, be sure to call R_DecalSystem_Reset on removal!)
599         int allowdecals;
600         decalsystem_t decalsystem;
601
602         // FIELDS UPDATED BY RENDERER:
603         // last time visible during trace culling
604         double last_trace_visibility;
605
606         // user wavefunc parameters (from csqc)
607         vec_t userwavefunc_param[Q3WAVEFUNC_USER_COUNT];
608 }
609 entity_render_t;
610
611 typedef struct entity_persistent_s
612 {
613         vec3_t trail_origin; // previous position for particle trail spawning
614         vec3_t oldorigin; // lerp
615         vec3_t oldangles; // lerp
616         vec3_t neworigin; // lerp
617         vec3_t newangles; // lerp
618         vec_t lerpstarttime; // lerp
619         vec_t lerpdeltatime; // lerp
620         float muzzleflash; // muzzleflash intensity, fades over time
621         float trail_time; // residual error accumulation for particle trail spawning (to keep spacing across frames)
622         qbool trail_allowed; // set to false by teleports, true by update code, prevents bad lerps
623 }
624 entity_persistent_t;
625
626 typedef struct entity_s
627 {
628         // baseline state (default values)
629         entity_state_t state_baseline;
630         // previous state (interpolating from this)
631         entity_state_t state_previous;
632         // current state (interpolating to this)
633         entity_state_t state_current;
634
635         // used for regenerating parts of render
636         entity_persistent_t persistent;
637
638         // the only data the renderer should know about
639         entity_render_t render;
640 }
641 entity_t;
642
643 typedef struct usercmd_s
644 {
645         vec3_t  viewangles;
646
647 // intended velocities
648         float   forwardmove;
649         float   sidemove;
650         float   upmove;
651
652         vec3_t  cursor_screen;
653         vec3_t  cursor_start;
654         vec3_t  cursor_end;
655         vec3_t  cursor_impact;
656         vec3_t  cursor_normal;
657         vec_t   cursor_fraction;
658         int             cursor_entitynumber;
659
660         double time; // time the move is executed for (cl_movement: clienttime, non-cl_movement: receivetime)
661         double receivetime; // time the move was received at
662         double clienttime; // time to which server state the move corresponds to
663         int msec; // for predicted moves
664         int buttons;
665         int impulse;
666         unsigned int sequence;
667         qbool applied; // if false we're still accumulating a move
668         qbool predicted; // if true the sequence should be sent as 0
669
670         // derived properties
671         double frametime;
672         qbool canjump;
673         qbool jump;
674         qbool crouch;
675 } usercmd_t;
676
677 typedef struct lightstyle_s
678 {
679         int             length;
680         char    map[MAX_STYLESTRING];
681 } lightstyle_t;
682
683 typedef struct scoreboard_s
684 {
685         char    name[MAX_SCOREBOARDNAME];
686         int             frags;
687         int             colors; // two 4 bit fields
688         // QW fields:
689         int             qw_userid;
690         char    qw_userinfo[MAX_USERINFO_STRING];
691         float   qw_entertime;
692         int             qw_ping;
693         int             qw_packetloss;
694         int             qw_movementloss;
695         int             qw_spectator;
696         char    qw_team[8];
697         char    qw_skin[MAX_QPATH];
698 } scoreboard_t;
699
700 typedef struct cshift_s
701 {
702         float   destcolor[3];
703         float   percent;                // 0-255
704         float   alphafade;      // (any speed)
705 } cshift_t;
706
707 #define CSHIFT_CONTENTS 0
708 #define CSHIFT_DAMAGE   1
709 #define CSHIFT_BONUS    2
710 #define CSHIFT_POWERUP  3
711 #define CSHIFT_VCSHIFT  4
712 #define NUM_CSHIFTS             5
713
714 #define NAME_LENGTH     64
715
716
717 //
718 // client_state_t should hold all pieces of the client state
719 //
720
721 #define SIGNONS         4                       // signon messages to receive before connected
722
723 typedef enum cactive_e
724 {
725         ca_uninitialized,       // during early startup
726         ca_dedicated,           // a dedicated server with no ability to start a client
727         ca_disconnected,        // full screen console with no connection
728         ca_connected            // valid netcon, talking to a server
729 }
730 cactive_t;
731
732 typedef enum qw_downloadtype_e
733 {
734         dl_none,
735         dl_single,
736         dl_skin,
737         dl_model,
738         dl_sound
739 }
740 qw_downloadtype_t;
741
742 #ifdef CONFIG_VIDEO_CAPTURE
743 typedef enum capturevideoformat_e
744 {
745         CAPTUREVIDEOFORMAT_AVI_I420,
746         CAPTUREVIDEOFORMAT_OGG_VORBIS_THEORA
747 }
748 capturevideoformat_t;
749
750 typedef struct capturevideostate_s
751 {
752         double startrealtime;
753         double framerate;
754         int framestep;
755         int framestepframe;
756         qbool active;
757         qbool realtime;
758         qbool error;
759         int soundrate;
760         int soundchannels;
761         int frame;
762         double starttime;
763         double lastfpstime;
764         int lastfpsframe;
765         int soundsampleframe;
766         unsigned char *screenbuffer;
767         unsigned char *outbuffer;
768         char basename[MAX_QPATH];
769         int width, height;
770
771         // precomputed RGB to YUV tables
772         // converts the RGB values to YUV (see cap_avi.c for how to use them)
773         short rgbtoyuvscaletable[3][3][256];
774         unsigned char yuvnormalizetable[3][256];
775
776         // precomputed gamma ramp (only needed if the capturevideo module uses RGB output)
777         // 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
778         unsigned short vidramp[256 * 3];
779
780         // stuff to be filled in by the video format module
781         capturevideoformat_t format;
782         const char *formatextension;
783         qfile_t *videofile;
784                 // always use this:
785                 //   cls.capturevideo.videofile = FS_OpenRealFile(va(vabuf, sizeof(vabuf), "%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false);
786         void (*endvideo) (void);
787         void (*videoframes) (int num);
788         void (*soundframe) (const portable_sampleframe_t *paintbuffer, size_t length);
789
790         // format specific data
791         void *formatspecific;
792 }
793 capturevideostate_t;
794 #endif
795
796 #define CL_MAX_DOWNLOADACKS 4
797
798 typedef struct cl_downloadack_s
799 {
800         int start, size;
801 }
802 cl_downloadack_t;
803
804 typedef struct cl_soundstats_s
805 {
806         int mixedsounds;
807         int totalsounds;
808         int latency_milliseconds;
809 }
810 cl_soundstats_t;
811
812 //
813 // the client_static_t structure is persistent through an arbitrary number
814 // of server connections
815 //
816 typedef struct client_static_s
817 {
818         cactive_t state;
819
820         // all client memory allocations go in these pools
821         mempool_t *levelmempool;
822         mempool_t *permanentmempool;
823
824 // demo loop control
825         // -1 = don't play demos
826         int demonum;
827         // list of demos in loop
828         char demos[MAX_DEMOS][MAX_DEMONAME];
829         // the actively playing demo (set by CL_PlayDemo_f)
830         char demoname[MAX_QPATH];
831
832 // demo recording info must be here, because record is started before
833 // entering a map (and clearing client_state_t)
834         qbool demorecording;
835         fs_offset_t demo_lastcsprogssize;
836         int demo_lastcsprogscrc;
837         qbool demoplayback;
838         qbool demostarting; // set if currently starting a demo, to stop -demo from quitting when switching to another demo
839         qbool timedemo;
840         // -1 = use normal cd track
841         int forcetrack;
842         qfile_t *demofile;
843         // realtime at second frame of timedemo (LadyHavoc: changed to double)
844         double td_starttime;
845         int td_frames; // total frames parsed
846         double td_onesecondnexttime;
847         double td_onesecondframes;
848         double td_onesecondrealtime;
849         double td_onesecondminfps;
850         double td_onesecondmaxfps;
851         double td_onesecondavgfps;
852         int td_onesecondavgcount;
853         // LadyHavoc: pausedemo
854         qbool demopaused;
855
856         // sound mixer statistics for showsound display
857         cl_soundstats_t soundstats;
858
859         qbool connect_trying;
860         int connect_remainingtries;
861         double connect_nextsendtime;
862         lhnetsocket_t *connect_mysocket;
863         lhnetaddress_t connect_address;
864         lhnetaddress_t rcon_address;
865         // protocol version of the server we're connected to
866         // (kept outside client_state_t because it's used between levels)
867         protocolversion_t protocol;
868
869 #define MAX_RCONS 16
870         int rcon_trying;
871         lhnetaddress_t rcon_addresses[MAX_RCONS];
872         char rcon_commands[MAX_RCONS][MAX_INPUTLINE];
873         double rcon_timeout[MAX_RCONS];
874         int rcon_ringpos;
875
876 // connection information
877         // 0 to SIGNONS
878         int signon;
879         // network connection
880         netconn_t *netcon;
881
882         // download information
883         // (note: qw_download variables are also used)
884         cl_downloadack_t dp_downloadack[CL_MAX_DOWNLOADACKS];
885
886         // input sequence numbers are not reset on level change, only connect
887         unsigned int servermovesequence;
888
889         // quakeworld stuff below
890
891         // value of "qport" cvar at time of connection
892         int qw_qport;
893         // copied from cls.netcon->qw. variables every time they change, or set by demos (which have no cls.netcon)
894         unsigned int qw_incoming_sequence;
895         unsigned int qw_outgoing_sequence;
896
897         // current file download buffer (only saved when file is completed)
898         char qw_downloadname[MAX_QPATH];
899         unsigned char *qw_downloadmemory;
900         int qw_downloadmemorycursize;
901         int qw_downloadmemorymaxsize;
902         int qw_downloadnumber;
903         int qw_downloadpercent;
904         qw_downloadtype_t qw_downloadtype;
905         // transfer rate display
906         double qw_downloadspeedtime;
907         int qw_downloadspeedcount;
908         int qw_downloadspeedrate;
909         qbool qw_download_deflate;
910
911         // current file upload buffer (for uploading screenshots to server)
912         unsigned char *qw_uploaddata;
913         int qw_uploadsize;
914         int qw_uploadpos;
915
916         // user infostring
917         // this normally contains the following keys in quakeworld:
918         // password spectator name team skin topcolor bottomcolor rate noaim msg *ver *ip
919         char userinfo[MAX_USERINFO_STRING];
920
921         // extra user info for the "connect" command
922         char connect_userinfo[MAX_USERINFO_STRING];
923
924 #ifdef CONFIG_VIDEO_CAPTURE
925         // video capture stuff
926         capturevideostate_t capturevideo;
927 #endif
928
929         // crypto channel
930         crypto_t crypto;
931
932         // ProQuake compatibility stuff
933         int proquake_servermod; // 0 = not proquake, 1 = proquake
934         int proquake_serverversion; // actual proquake server version * 10 (3.40 = 34, etc)
935         int proquake_serverflags; // 0 (PQF_CHEATFREE not supported)
936
937         // don't write-then-read csprogs.dat (useful for demo playback)
938         unsigned char *caughtcsprogsdata;
939         fs_offset_t caughtcsprogsdatasize;
940
941         int r_speeds_graph_length;
942         int r_speeds_graph_current;
943         int *r_speeds_graph_data;
944
945         // graph scales
946         int r_speeds_graph_datamin[r_stat_count];
947         int r_speeds_graph_datamax[r_stat_count];
948 }
949 client_static_t;
950
951 extern client_static_t  cls;
952
953 //[515]: csqc
954 typedef struct
955 {
956         qbool drawworld;
957         qbool drawenginesbar;
958         qbool drawcrosshair;
959 }csqc_vidvars_t;
960
961 typedef enum
962 {
963         PARTICLE_BILLBOARD = 0,
964         PARTICLE_SPARK = 1,
965         PARTICLE_ORIENTED_DOUBLESIDED = 2,
966         PARTICLE_VBEAM = 3,
967         PARTICLE_HBEAM = 4,
968         PARTICLE_INVALID = -1
969 }
970 porientation_t;
971
972 typedef enum
973 {
974         PBLEND_ALPHA = 0,
975         PBLEND_ADD = 1,
976         PBLEND_INVMOD = 2,
977         PBLEND_INVALID = -1
978 }
979 pblend_t;
980
981 typedef struct particletype_s
982 {
983         pblend_t blendmode;
984         porientation_t orientation;
985         qbool lighting;
986 }
987 particletype_t;
988
989 typedef enum ptype_e
990 {
991         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
992 }
993 ptype_t;
994
995 typedef struct particle_s
996 {
997         // for faster batch rendering, particles are rendered in groups by effect (resulting in less perfect sorting but far less state changes)
998
999         // fields used by rendering: (48 bytes)
1000         vec3_t          sortorigin; // sort by this group origin, not particle org
1001         vec3_t          org;
1002         vec3_t          vel; // velocity of particle, or orientation of decal, or end point of beam
1003         float           size;
1004         float           alpha; // 0-255
1005         float           stretch; // only for sparks
1006
1007         // fields not used by rendering:  (44 bytes)
1008         float           stainsize;
1009         float           stainalpha;
1010         float           sizeincrease; // rate of size change per second
1011         float           alphafade; // how much alpha reduces per second
1012         float           time2; // used for snow fluttering and decal fade
1013         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)
1014         float           gravity; // how much gravity affects this particle (1.0 = normal gravity, 0.0 = none)
1015         float           airfriction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
1016         float           liquidfriction; // how much liquid friction affects this object (objects with a low mass/size ratio tend to get more liquid friction)
1017 //      float           delayedcollisions; // time that p->bounce becomes active
1018         float           delayedspawn; // time that particle appears and begins moving
1019         float           die; // time when this particle should be removed, regardless of alpha
1020
1021         // short variables grouped to save memory (4 bytes)
1022         short                   angle; // base rotation of particle
1023         short                   spin; // geometry rotation speed around the particle center normal
1024
1025         // byte variables grouped to save memory (12 bytes)
1026         unsigned char   color[3];
1027         unsigned char   qualityreduction; // enables skipping of this particle according to r_refdef.view.qualityreduction
1028         unsigned char   typeindex;
1029         unsigned char   blendmode;
1030         unsigned char   orientation;
1031         unsigned char   texnum;
1032         unsigned char   staincolor[3];
1033         signed char     staintexnum;
1034 }
1035 particle_t;
1036
1037 typedef enum cl_parsingtextmode_e
1038 {
1039         CL_PARSETEXTMODE_NONE,
1040         CL_PARSETEXTMODE_PING,
1041         CL_PARSETEXTMODE_STATUS,
1042         CL_PARSETEXTMODE_STATUS_PLAYERID,
1043         CL_PARSETEXTMODE_STATUS_PLAYERIP
1044 }
1045 cl_parsingtextmode_t;
1046
1047 typedef struct cl_locnode_s
1048 {
1049         struct cl_locnode_s *next;
1050         char *name;
1051         vec3_t mins, maxs;
1052 }
1053 cl_locnode_t;
1054
1055 typedef struct showlmp_s
1056 {
1057         qbool   isactive;
1058         float           x;
1059         float           y;
1060         char            label[32];
1061         char            pic[128];
1062 }
1063 showlmp_t;
1064
1065 //
1066 // the client_state_t structure is wiped completely at every
1067 // server signon
1068 //
1069 typedef struct client_state_s
1070 {
1071         // true if playing in a local game and no one else is connected
1072         int islocalgame;
1073
1074         // send a clc_nop periodically until connected
1075         float sendnoptime;
1076
1077         // current input being accumulated by mouse/joystick/etc input
1078         usercmd_t cmd;
1079         // latest moves sent to the server that have not been confirmed yet
1080         usercmd_t movecmd[CL_MAX_USERCMDS];
1081
1082 // information for local display
1083         // health, etc
1084         int stats[MAX_CL_STATS];
1085         float *statsf; // points to stats[] array
1086         // last known inventory bit flags, for blinking
1087         int olditems;
1088         // cl.time of acquiring item, for blinking
1089         float item_gettime[32];
1090         // last known STAT_ACTIVEWEAPON
1091         int activeweapon;
1092         // cl.time of changing STAT_ACTIVEWEAPON
1093         float weapontime;
1094         // use pain anim frame if cl.time < this
1095         float faceanimtime;
1096         // for stair smoothing
1097         float stairsmoothz;
1098         double stairsmoothtime;
1099
1100         // color shifts for damage, powerups
1101         cshift_t cshifts[NUM_CSHIFTS];
1102         // and content types
1103         cshift_t prev_cshifts[NUM_CSHIFTS];
1104
1105 // the client maintains its own idea of view angles, which are
1106 // sent to the server each frame.  The server sets punchangle when
1107 // the view is temporarily offset, and an angle reset commands at the start
1108 // of each level and after teleporting.
1109
1110         // mviewangles is read from demo
1111         // viewangles is either client controlled or lerped from mviewangles
1112         vec3_t mviewangles[2], viewangles;
1113         // update by server, used by qc to do weapon recoil
1114         vec3_t mpunchangle[2], punchangle;
1115         // update by server, can be used by mods to kick view around
1116         vec3_t mpunchvector[2], punchvector;
1117         // update by server, used for lean+bob (0 is newest)
1118         vec3_t mvelocity[2], velocity;
1119         // update by server, can be used by mods for zooming
1120         vec_t mviewzoom[2], viewzoom;
1121         // if true interpolation the mviewangles and other interpolation of the
1122         // player is disabled until the next network packet
1123         // this is used primarily by teleporters, and when spectating players
1124         // special checking of the old fixangle[1] is used to differentiate
1125         // between teleporting and spectating
1126         qbool fixangle[2];
1127
1128         // client movement simulation
1129         // these fields are only updated by CL_ClientMovement (called by CL_SendMove after parsing each network packet)
1130         // set by CL_ClientMovement_Replay functions
1131         qbool movement_predicted;
1132         // if true the CL_ClientMovement_Replay function will update origin, etc
1133         qbool movement_replay;
1134         // simulated data (this is valid even if cl.movement is false)
1135         vec3_t movement_origin;
1136         vec3_t movement_velocity;
1137         // whether the replay should allow a jump at the first sequence
1138         qbool movement_replay_canjump;
1139
1140         // previous gun angles (for leaning effects)
1141         vec3_t gunangles_prev;
1142         vec3_t gunangles_highpass;
1143         vec3_t gunangles_adjustment_lowpass;
1144         vec3_t gunangles_adjustment_highpass;
1145         // previous gun angles (for leaning effects)
1146         vec3_t gunorg_prev;
1147         vec3_t gunorg_highpass;
1148         vec3_t gunorg_adjustment_lowpass;
1149         vec3_t gunorg_adjustment_highpass;
1150
1151 // pitch drifting vars
1152         float idealpitch;
1153         float pitchvel;
1154         qbool nodrift;
1155         float driftmove;
1156         double laststop;
1157
1158 //[515]: added for csqc purposes
1159         float sensitivityscale;
1160         csqc_vidvars_t csqc_vidvars;    //[515]: these parms must be set to true by default
1161         qbool csqc_wantsmousemove;
1162         struct model_s *csqc_model_precache[MAX_MODELS];
1163
1164         // local amount for smoothing stepups
1165         //float crouch;
1166
1167         // sent by server
1168         qbool paused;
1169         qbool onground;
1170         qbool inwater;
1171
1172         // used by bob
1173         qbool oldonground;
1174         double lastongroundtime;
1175         double hitgroundtime;
1176         float bob2_smooth;
1177         float bobfall_speed;
1178         float bobfall_swing;
1179         double calcrefdef_prevtime;
1180
1181         // don't change view angle, full screen, etc
1182         int intermission;
1183         // latched at intermission start
1184         double completed_time;
1185
1186         // the timestamp of the last two messages
1187         double mtime[2];
1188
1189         // clients view of time, time should be between mtime[0] and mtime[1] to
1190         // generate a lerp point for other data, oldtime is the previous frame's
1191         // value of time, frametime is the difference between time and oldtime
1192         // note: cl.time may be beyond cl.mtime[0] if packet loss is occuring, it
1193         // is only forcefully limited when a packet is received
1194         double time, oldtime;
1195         // how long it has been since the previous client frame in real time
1196         // (not game time, for that use cl.time - cl.oldtime)
1197         double realframetime;
1198         
1199         // fade var for fading while dead
1200         float deathfade;
1201
1202         // motionblur alpha level variable
1203         float motionbluralpha;
1204
1205         // copy of realtime from last recieved message, for net trouble icon
1206         float last_received_message;
1207
1208 // information that is static for the entire time connected to a server
1209         struct model_s *model_precache[MAX_MODELS];
1210         struct sfx_s *sound_precache[MAX_SOUNDS];
1211
1212         // FIXME: this is a lot of memory to be keeping around, this really should be dynamically allocated and freed somehow
1213         char model_name[MAX_MODELS][MAX_QPATH];
1214         char sound_name[MAX_SOUNDS][MAX_QPATH];
1215
1216         // for display on solo scoreboard
1217         char worldmessage[40]; // map title (not related to filename)
1218         // variants of map name
1219         char worldbasename[MAX_QPATH]; // %s
1220         char worldname[MAX_QPATH]; // maps/%s.bsp
1221         char worldnamenoextension[MAX_QPATH]; // maps/%s
1222         // cl_entitites[cl.viewentity] = player
1223         int viewentity;
1224         // the real player entity (normally same as viewentity,
1225         // different than viewentity if mod uses chasecam or other tricks)
1226         int realplayerentity;
1227         // this is updated to match cl.viewentity whenever it is in the clients
1228         // range, basically this is used in preference to cl.realplayerentity for
1229         // most purposes because when spectating another player it should show
1230         // their information rather than yours
1231         int playerentity;
1232         // max players that can be in this game
1233         int maxclients;
1234         // type of game (deathmatch, coop, singleplayer)
1235         int gametype;
1236
1237         // models and sounds used by engine code (particularly cl_parse.c)
1238         dp_model_t *model_bolt;
1239         dp_model_t *model_bolt2;
1240         dp_model_t *model_bolt3;
1241         dp_model_t *model_beam;
1242         sfx_t *sfx_wizhit;
1243         sfx_t *sfx_knighthit;
1244         sfx_t *sfx_tink1;
1245         sfx_t *sfx_ric1;
1246         sfx_t *sfx_ric2;
1247         sfx_t *sfx_ric3;
1248         sfx_t *sfx_r_exp3;
1249         // indicates that the file "sound/misc/talk2.wav" was found (for use by team chat messages)
1250         qbool foundteamchatsound;
1251
1252 // refresh related state
1253
1254         // cl_entitites[0].model
1255         struct model_s *worldmodel;
1256
1257         // the gun model
1258         entity_t viewent;
1259
1260         // cd audio
1261         int cdtrack, looptrack;
1262
1263 // frag scoreboard
1264
1265         // [cl.maxclients]
1266         scoreboard_t *scores;
1267
1268         // keep track of svc_print parsing state (analyzes ping reports and status reports)
1269         cl_parsingtextmode_t parsingtextmode;
1270         int parsingtextplayerindex;
1271         // set by scoreboard code when sending ping command, this causes the next ping results to be hidden
1272         // (which could eat the wrong ping report if the player issues one
1273         //  manually, but they would still see a ping report, just a later one
1274         //  caused by the scoreboard code rather than the one they intentionally
1275         //  issued)
1276         int parsingtextexpectingpingforscores;
1277
1278         // entity database stuff
1279         // latest received entity frame numbers
1280 #define LATESTFRAMENUMS 32
1281         int latestframenumsposition;
1282         int latestframenums[LATESTFRAMENUMS];
1283         unsigned int latestsendnums[LATESTFRAMENUMS];
1284         entityframe_database_t *entitydatabase;
1285         entityframe4_database_t *entitydatabase4;
1286         entityframeqw_database_t *entitydatabaseqw;
1287
1288         // keep track of quake entities because they need to be killed if they get stale
1289         int lastquakeentity;
1290         unsigned char isquakeentity[MAX_EDICTS];
1291
1292         // bounding boxes for clientside movement
1293         vec3_t playerstandmins;
1294         vec3_t playerstandmaxs;
1295         vec3_t playercrouchmins;
1296         vec3_t playercrouchmaxs;
1297
1298         // old decals are killed based on this
1299         unsigned int decalsequence;
1300
1301         int max_entities;
1302         int max_csqcrenderentities;
1303         int max_static_entities;
1304         int max_effects;
1305         int max_beams;
1306         int max_dlights;
1307         int max_lightstyle;
1308         int max_brushmodel_entities;
1309         int max_particles;
1310         int max_showlmps;
1311
1312         entity_t *entities;
1313         entity_render_t *csqcrenderentities;
1314         unsigned char *entities_active;
1315         entity_t *static_entities;
1316         cl_effect_t *effects;
1317         beam_t *beams;
1318         dlight_t *dlights;
1319         lightstyle_t *lightstyle;
1320         int *brushmodel_entities;
1321         particle_t *particles;
1322         showlmp_t *showlmps;
1323
1324         int num_entities;
1325         int num_static_entities;
1326         int num_brushmodel_entities;
1327         int num_effects;
1328         int num_beams;
1329         int num_dlights;
1330         int num_particles;
1331         int num_decals;
1332         int num_showlmps;
1333
1334         double particles_updatetime;
1335         double decals_updatetime;
1336         int free_particle;
1337         int free_decal;
1338
1339         // cl_serverextension_download feature
1340         int loadmodel_current;
1341         int downloadmodel_current;
1342         int loadmodel_total;
1343         int loadsound_current;
1344         int downloadsound_current;
1345         int loadsound_total;
1346         qbool downloadcsqc;
1347         qbool loadcsqc;
1348         qbool loadbegun;
1349         qbool loadfinished;
1350
1351         // quakeworld stuff
1352
1353         // local copy of the server infostring
1354         char qw_serverinfo[MAX_SERVERINFO_STRING];
1355
1356         // time of last qw "pings" command sent to server while showing scores
1357         double last_ping_request;
1358
1359         // used during connect
1360         int qw_servercount;
1361
1362         // updated from serverinfo
1363         int qw_teamplay;
1364
1365         // unused: indicates whether the player is spectating
1366         // use cl.scores[cl.playerentity-1].qw_spectator instead
1367         //qbool qw_spectator;
1368
1369         // last time an input packet was sent
1370         double lastpackettime;
1371
1372         // movement parameters for client prediction
1373         unsigned int moveflags;
1374         float movevars_wallfriction;
1375         float movevars_waterfriction;
1376         float movevars_friction;
1377         float movevars_timescale;
1378         float movevars_gravity;
1379         float movevars_stopspeed;
1380         float movevars_maxspeed;
1381         float movevars_spectatormaxspeed;
1382         float movevars_accelerate;
1383         float movevars_airaccelerate;
1384         float movevars_wateraccelerate;
1385         float movevars_entgravity;
1386         float movevars_jumpvelocity;
1387         float movevars_edgefriction;
1388         float movevars_maxairspeed;
1389         float movevars_stepheight;
1390         float movevars_airaccel_qw;
1391         float movevars_airaccel_qw_stretchfactor;
1392         float movevars_airaccel_sideways_friction;
1393         float movevars_airstopaccelerate;
1394         float movevars_airstrafeaccelerate;
1395         float movevars_maxairstrafespeed;
1396         float movevars_airstrafeaccel_qw;
1397         float movevars_aircontrol;
1398         float movevars_aircontrol_power;
1399         float movevars_aircontrol_penalty;
1400         float movevars_warsowbunny_airforwardaccel;
1401         float movevars_warsowbunny_accel;
1402         float movevars_warsowbunny_topspeed;
1403         float movevars_warsowbunny_turnaccel;
1404         float movevars_warsowbunny_backtosideratio;
1405         float movevars_ticrate;
1406         float movevars_airspeedlimit_nonqw;
1407
1408         // models used by qw protocol
1409         int qw_modelindex_spike;
1410         int qw_modelindex_player;
1411         int qw_modelindex_flag;
1412         int qw_modelindex_s_explod;
1413
1414         vec3_t qw_intermission_origin;
1415         vec3_t qw_intermission_angles;
1416
1417         // 255 is the most nails the QW protocol could send
1418         int qw_num_nails;
1419         vec_t qw_nails[255][6];
1420
1421         float qw_weaponkick;
1422
1423         unsigned int qw_validsequence;
1424
1425         unsigned int qw_deltasequence[QW_UPDATE_BACKUP];
1426
1427         // csqc stuff:
1428         // server entity number corresponding to a clientside entity
1429         unsigned short csqc_server2csqcentitynumber[MAX_EDICTS];
1430         qbool csqc_loaded;
1431         vec3_t csqc_vieworigin;
1432         vec3_t csqc_viewangles;
1433         vec3_t csqc_vieworiginfromengine;
1434         vec3_t csqc_viewanglesfromengine;
1435         matrix4x4_t csqc_viewmodelmatrixfromengine;
1436         qbool csqc_usecsqclistener;
1437         matrix4x4_t csqc_listenermatrix;
1438         char csqc_printtextbuf[MAX_INPUTLINE];
1439
1440         // collision culling data
1441         world_t world;
1442
1443         // loc file stuff (points and boxes describing locations in the level)
1444         cl_locnode_t *locnodes;
1445         // this is updated to cl.movement_origin whenever health is < 1
1446         // used by %d print in say/say_team messages if cl_locs_enable is on
1447         vec3_t lastdeathorigin;
1448
1449         // processing buffer used by R_BuildLightMap, reallocated as needed,
1450         // freed on each level change
1451         size_t buildlightmapmemorysize;
1452         unsigned char *buildlightmapmemory;
1453
1454         // used by EntityState5_ReadUpdate
1455         skeleton_t *engineskeletonobjects;
1456 }
1457 client_state_t;
1458
1459 //
1460 // cvars
1461 //
1462 extern cvar_t cl_name;
1463 extern cvar_t cl_color;
1464 extern cvar_t cl_rate;
1465 extern cvar_t cl_rate_burstsize;
1466 extern cvar_t cl_pmodel;
1467 extern cvar_t cl_playermodel;
1468 extern cvar_t cl_playerskin;
1469
1470 extern cvar_t rcon_password;
1471 extern cvar_t rcon_address;
1472
1473 extern cvar_t cl_upspeed;
1474 extern cvar_t cl_forwardspeed;
1475 extern cvar_t cl_backspeed;
1476 extern cvar_t cl_sidespeed;
1477
1478 extern cvar_t cl_movespeedkey;
1479
1480 extern cvar_t cl_yawspeed;
1481 extern cvar_t cl_pitchspeed;
1482
1483 extern cvar_t cl_anglespeedkey;
1484
1485 extern cvar_t cl_autofire;
1486
1487 extern cvar_t cl_shownet;
1488 extern cvar_t cl_nolerp;
1489 extern cvar_t cl_nettimesyncfactor;
1490 extern cvar_t cl_nettimesyncboundmode;
1491 extern cvar_t cl_nettimesyncboundtolerance;
1492
1493 extern cvar_t cl_pitchdriftspeed;
1494 extern cvar_t lookspring;
1495 extern cvar_t lookstrafe;
1496 extern cvar_t sensitivity;
1497
1498 extern cvar_t freelook;
1499
1500 extern cvar_t m_pitch;
1501 extern cvar_t m_yaw;
1502 extern cvar_t m_forward;
1503 extern cvar_t m_side;
1504
1505 extern cvar_t cl_autodemo;
1506 extern cvar_t cl_autodemo_nameformat;
1507 extern cvar_t cl_autodemo_delete;
1508
1509 extern cvar_t r_draweffects;
1510
1511 extern cvar_t cl_explosions_alpha_start;
1512 extern cvar_t cl_explosions_alpha_end;
1513 extern cvar_t cl_explosions_size_start;
1514 extern cvar_t cl_explosions_size_end;
1515 extern cvar_t cl_explosions_lifetime;
1516 extern cvar_t cl_stainmaps;
1517 extern cvar_t cl_stainmaps_clearonload;
1518
1519 extern cvar_t cl_prydoncursor;
1520 extern cvar_t cl_prydoncursor_notrace;
1521
1522 extern cvar_t cl_locs_enable;
1523
1524 extern client_state_t cl;
1525
1526 extern void CL_AllocLightFlash (entity_render_t *ent, matrix4x4_t *matrix, float radius, float red, float green, float blue, float decay, float lifetime, char *cubemapname, int style, int shadowenable, vec_t corona, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags);
1527
1528 cl_locnode_t *CL_Locs_FindNearest(const vec3_t point);
1529 void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point);
1530
1531 //=============================================================================
1532
1533 //
1534 // cl_main
1535 //
1536
1537 double CL_Frame(double time);
1538
1539 void CL_Shutdown (void);
1540 void CL_Init (void);
1541
1542 void CL_EstablishConnection(const char *host, int firstarg);
1543
1544 void CL_Disconnect (void);
1545 void CL_Disconnect_f(cmd_state_t *cmd);
1546
1547 void CL_UpdateRenderEntity(entity_render_t *ent);
1548 void CL_SetEntityColormapColors(entity_render_t *ent, int colormap);
1549 void CL_UpdateViewEntities(void);
1550
1551 //
1552 // cl_input
1553 //
1554 typedef struct kbutton_s
1555 {
1556         int             down[2];                // key nums holding it down
1557         int             state;                  // low bit is down state
1558 }
1559 kbutton_t;
1560
1561 extern  kbutton_t       in_mlook, in_klook;
1562 extern  kbutton_t       in_strafe;
1563 extern  kbutton_t       in_speed;
1564
1565 void CL_InitInput (void);
1566 void CL_SendMove (void);
1567
1568 void CL_ValidateState(entity_state_t *s);
1569 void CL_MoveLerpEntityStates(entity_t *ent);
1570 void CL_LerpUpdate(entity_t *e);
1571 void CL_ParseTEnt (void);
1572 void CL_NewBeam (int ent, vec3_t start, vec3_t end, dp_model_t *m, int lightning);
1573 void CL_RelinkBeams (void);
1574 void CL_Beam_CalculatePositions (const beam_t *b, vec3_t start, vec3_t end);
1575 void CL_ClientMovement_Replay(void);
1576
1577 void CL_ClearTempEntities (void);
1578 entity_render_t *CL_NewTempEntity (double shadertime);
1579
1580 void CL_Effect(vec3_t org, dp_model_t *model, int startframe, int framecount, float framerate);
1581
1582 void CL_ClearState (void);
1583 void CL_ExpandEntities(int num);
1584 void CL_ExpandCSQCRenderEntities(int num);
1585 void CL_SetInfo(const char *key, const char *value, qbool send, qbool allowstarkey, qbool allowmodel, qbool quiet);
1586
1587
1588 void CL_UpdateWorld (void);
1589 void CL_WriteToServer (void);
1590 void CL_Input (void);
1591 extern int cl_ignoremousemoves;
1592
1593
1594 float CL_KeyState (kbutton_t *key);
1595 const char *Key_KeynumToString (int keynum, char *buf, size_t buflength);
1596 int Key_StringToKeynum (const char *str);
1597
1598 //
1599 // cl_cmd.c
1600 //
1601 /// adds the string as a clc_stringcmd to the client message.
1602 /// (used when there is no reason to generate a local command to do it)
1603 void CL_ForwardToServer (const char *s);
1604
1605 /// adds the current command line as a clc_stringcmd to the client message.
1606 /// things like godmode, noclip, etc, are commands directed to the server,
1607 /// so when they are typed in at the console, they will need to be forwarded.
1608 void CL_ForwardToServer_f (cmd_state_t *cmd);
1609 void CL_InitCommands(void);
1610
1611
1612 //
1613 // cl_demo.c
1614 //
1615 void CL_StopPlayback(void);
1616 void CL_ReadDemoMessage(void);
1617 void CL_WriteDemoMessage(sizebuf_t *mesage);
1618
1619 void CL_CutDemo(unsigned char **buf, fs_offset_t *filesize);
1620 void CL_PasteDemo(unsigned char **buf, fs_offset_t *filesize);
1621
1622 void CL_NextDemo(void);
1623 void CL_Stop_f(cmd_state_t *cmd);
1624 void CL_Record_f(cmd_state_t *cmd);
1625 void CL_PlayDemo_f(cmd_state_t *cmd);
1626 void CL_TimeDemo_f(cmd_state_t *cmd);
1627
1628 void CL_Demo_Init(void);
1629
1630 //
1631 // cl_parse.c
1632 //
1633 void CL_Parse_Init(void);
1634 void CL_Parse_Shutdown(void);
1635 void CL_ParseServerMessage(void);
1636 void CL_Parse_DumpPacket(void);
1637 void CL_Parse_ErrorCleanUp(void);
1638 void QW_CL_StartUpload(unsigned char *data, int size);
1639 extern cvar_t qport;
1640 void CL_KeepaliveMessage(qbool readmessages); // call this during loading of large content
1641
1642 //
1643 // cl_part
1644 //
1645
1646 extern cvar_t cl_particles;
1647 extern cvar_t cl_particles_quality;
1648 extern cvar_t cl_particles_size;
1649 extern cvar_t cl_particles_quake;
1650 extern cvar_t cl_particles_blood;
1651 extern cvar_t cl_particles_blood_alpha;
1652 extern cvar_t cl_particles_blood_decal_alpha;
1653 extern cvar_t cl_particles_blood_decal_scalemin;
1654 extern cvar_t cl_particles_blood_decal_scalemax;
1655 extern cvar_t cl_particles_blood_bloodhack;
1656 extern cvar_t cl_particles_bulletimpacts;
1657 extern cvar_t cl_particles_explosions_sparks;
1658 extern cvar_t cl_particles_explosions_shell;
1659 extern cvar_t cl_particles_rain;
1660 extern cvar_t cl_particles_snow;
1661 extern cvar_t cl_particles_smoke;
1662 extern cvar_t cl_particles_smoke_alpha;
1663 extern cvar_t cl_particles_smoke_alphafade;
1664 extern cvar_t cl_particles_sparks;
1665 extern cvar_t cl_particles_bubbles;
1666 extern cvar_t cl_decals;
1667 extern cvar_t cl_decals_time;
1668 extern cvar_t cl_decals_fadetime;
1669
1670 void CL_Particles_Clear(void);
1671 void CL_Particles_Init(void);
1672 void CL_Particles_Shutdown(void);
1673 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, qbool 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]);
1674
1675 typedef enum effectnameindex_s
1676 {
1677         EFFECT_NONE,
1678         EFFECT_TE_GUNSHOT,
1679         EFFECT_TE_GUNSHOTQUAD,
1680         EFFECT_TE_SPIKE,
1681         EFFECT_TE_SPIKEQUAD,
1682         EFFECT_TE_SUPERSPIKE,
1683         EFFECT_TE_SUPERSPIKEQUAD,
1684         EFFECT_TE_WIZSPIKE,
1685         EFFECT_TE_KNIGHTSPIKE,
1686         EFFECT_TE_EXPLOSION,
1687         EFFECT_TE_EXPLOSIONQUAD,
1688         EFFECT_TE_TAREXPLOSION,
1689         EFFECT_TE_TELEPORT,
1690         EFFECT_TE_LAVASPLASH,
1691         EFFECT_TE_SMALLFLASH,
1692         EFFECT_TE_FLAMEJET,
1693         EFFECT_EF_FLAME,
1694         EFFECT_TE_BLOOD,
1695         EFFECT_TE_SPARK,
1696         EFFECT_TE_PLASMABURN,
1697         EFFECT_TE_TEI_G3,
1698         EFFECT_TE_TEI_SMOKE,
1699         EFFECT_TE_TEI_BIGEXPLOSION,
1700         EFFECT_TE_TEI_PLASMAHIT,
1701         EFFECT_EF_STARDUST,
1702         EFFECT_TR_ROCKET,
1703         EFFECT_TR_GRENADE,
1704         EFFECT_TR_BLOOD,
1705         EFFECT_TR_WIZSPIKE,
1706         EFFECT_TR_SLIGHTBLOOD,
1707         EFFECT_TR_KNIGHTSPIKE,
1708         EFFECT_TR_VORESPIKE,
1709         EFFECT_TR_NEHAHRASMOKE,
1710         EFFECT_TR_NEXUIZPLASMA,
1711         EFFECT_TR_GLOWTRAIL,
1712         EFFECT_SVC_PARTICLE,
1713         EFFECT_TOTAL
1714 }
1715 effectnameindex_t;
1716
1717 int CL_ParticleEffectIndexForName(const char *name);
1718 const char *CL_ParticleEffectNameForIndex(int i);
1719 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);
1720 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, qbool spawndlight, qbool spawnparticles, float tintmins[4], float tintmaxs[4], float fade);
1721 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, qbool spawndlight, qbool spawnparticles, float tintmins[4], float tintmaxs[4], float fade);
1722 void CL_ParseParticleEffect (void);
1723 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);
1724 void CL_ParticleRain (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, int type);
1725 void CL_EntityParticles (const entity_t *ent);
1726 void CL_ParticleExplosion (const vec3_t org);
1727 void CL_ParticleExplosion2 (const vec3_t org, int colorStart, int colorLength);
1728
1729 #include "cl_screen.h"
1730
1731 extern qbool sb_showscores;
1732
1733 typedef enum waterlevel_e
1734 {
1735         WATERLEVEL_NONE,
1736         WATERLEVEL_WETFEET,
1737         WATERLEVEL_SWIMMING,
1738         WATERLEVEL_SUBMERGED
1739 }
1740 waterlevel_t;
1741
1742 typedef struct cl_clientmovement_state_s
1743 {
1744         // entity to be ignored for movement
1745         struct prvm_edict_s *self;
1746         // position
1747         vec3_t origin;
1748         vec3_t velocity;
1749         // current bounding box (different if crouched vs standing)
1750         vec3_t mins;
1751         vec3_t maxs;
1752         // currently on the ground
1753         qbool onground;
1754         // currently crouching
1755         qbool crouched;
1756         // what kind of water (SUPERCONTENTS_LAVA for instance)
1757         int watertype;
1758         // how deep
1759         waterlevel_t waterlevel;
1760         // weird hacks when jumping out of water
1761         // (this is in seconds and counts down to 0)
1762         float waterjumptime;
1763
1764         // user command
1765         usercmd_t cmd;
1766 }
1767 cl_clientmovement_state_t;
1768 void CL_ClientMovement_PlayerMove_Frame(cl_clientmovement_state_t *s);
1769
1770 // warpzone prediction hack (CSQC builtin)
1771 void CL_RotateMoves(const matrix4x4_t *m);
1772
1773 typedef enum meshname_e {
1774         MESH_SCENE, // CSQC R_PolygonBegin, potentially also engine particles and debug stuff
1775         MESH_UI,
1776         NUM_MESHENTITIES,
1777 } meshname_t;
1778 extern entity_t cl_meshentities[NUM_MESHENTITIES];
1779 extern dp_model_t cl_meshentitymodels[NUM_MESHENTITIES];
1780 extern const char *cl_meshentitynames[NUM_MESHENTITIES];
1781 #define CL_Mesh_Scene() (&cl_meshentitymodels[MESH_SCENE])
1782 #define CL_Mesh_UI() (&cl_meshentitymodels[MESH_UI])
1783 void CL_MeshEntities_Scene_Clear(void);
1784 void CL_MeshEntities_Scene_AddRenderEntity(void);
1785 void CL_MeshEntities_Scene_FinalizeRenderEntity(void);
1786 void CL_UpdateEntityShading(void);
1787
1788 void CL_NewFrameReceived(int num);
1789 void CL_ParseEntityLump(char *entitystring);
1790 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius);
1791 void CL_RelinkLightFlashes(void);
1792 void CL_Beam_AddPolygons(const beam_t *b);
1793 void CL_UpdateMoveVars(void);
1794 void SCR_CaptureVideo_SoundFrame(const portable_sampleframe_t *paintbuffer, size_t length);
1795 void CL_Locs_Reload_f(cmd_state_t *cmd);
1796
1797 #endif
1798