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