2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
25 #include "matrixlib.h"
30 #include "cl_particles.h"
32 // NOTE: r_stat_name[] must match this indexing
39 r_stat_entities_surfaces,
40 r_stat_entities_triangles,
43 r_stat_world_surfaces,
44 r_stat_world_triangles,
45 r_stat_lightmapupdates,
46 r_stat_lightmapupdatepixels,
51 r_stat_draws_vertices,
52 r_stat_draws_elements,
55 r_stat_lights_scissored,
56 r_stat_lights_lighttriangles,
57 r_stat_lights_shadowtriangles,
58 r_stat_lights_dynamicshadowtriangles,
59 r_stat_bouncegrid_lights,
60 r_stat_bouncegrid_particles,
61 r_stat_bouncegrid_traces,
62 r_stat_bouncegrid_hits,
63 r_stat_bouncegrid_splats,
64 r_stat_bouncegrid_bounces,
65 r_stat_photoncache_animated,
66 r_stat_photoncache_cached,
67 r_stat_photoncache_traced,
69 r_stat_bloom_copypixels,
70 r_stat_bloom_drawpixels,
71 r_stat_rendertargets_used,
72 r_stat_rendertargets_pixels,
73 r_stat_indexbufferuploadcount,
74 r_stat_indexbufferuploadsize,
75 r_stat_vertexbufferuploadcount,
76 r_stat_vertexbufferuploadsize,
77 r_stat_framedatacurrent,
79 r_stat_bufferdatacurrent_vertex, // R_BUFFERDATA_ types are added to this index
80 r_stat_bufferdatacurrent_index16,
81 r_stat_bufferdatacurrent_index32,
82 r_stat_bufferdatacurrent_uniform,
83 r_stat_bufferdatasize_vertex, // R_BUFFERDATA_ types are added to this index
84 r_stat_bufferdatasize_index16,
85 r_stat_bufferdatasize_index32,
86 r_stat_bufferdatasize_uniform,
87 r_stat_animcache_skeletal_count,
88 r_stat_animcache_skeletal_bones,
89 r_stat_animcache_skeletal_maxbones,
90 r_stat_animcache_shade_count,
91 r_stat_animcache_shade_vertices,
92 r_stat_animcache_shade_maxvertices,
93 r_stat_animcache_shape_count,
94 r_stat_animcache_shape_vertices,
95 r_stat_animcache_shape_maxvertices,
97 r_stat_batch_withgaps,
98 r_stat_batch_surfaces,
99 r_stat_batch_vertices,
100 r_stat_batch_triangles,
101 r_stat_batch_fast_batches,
102 r_stat_batch_fast_surfaces,
103 r_stat_batch_fast_vertices,
104 r_stat_batch_fast_triangles,
105 r_stat_batch_copytriangles_batches,
106 r_stat_batch_copytriangles_surfaces,
107 r_stat_batch_copytriangles_vertices,
108 r_stat_batch_copytriangles_triangles,
109 r_stat_batch_dynamic_batches,
110 r_stat_batch_dynamic_surfaces,
111 r_stat_batch_dynamic_vertices,
112 r_stat_batch_dynamic_triangles,
113 r_stat_batch_dynamicskeletal_batches,
114 r_stat_batch_dynamicskeletal_surfaces,
115 r_stat_batch_dynamicskeletal_vertices,
116 r_stat_batch_dynamicskeletal_triangles,
117 r_stat_batch_dynamic_batches_because_cvar,
118 r_stat_batch_dynamic_surfaces_because_cvar,
119 r_stat_batch_dynamic_vertices_because_cvar,
120 r_stat_batch_dynamic_triangles_because_cvar,
121 r_stat_batch_dynamic_batches_because_lightmapvertex,
122 r_stat_batch_dynamic_surfaces_because_lightmapvertex,
123 r_stat_batch_dynamic_vertices_because_lightmapvertex,
124 r_stat_batch_dynamic_triangles_because_lightmapvertex,
125 r_stat_batch_dynamic_batches_because_deformvertexes_autosprite,
126 r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite,
127 r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite,
128 r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite,
129 r_stat_batch_dynamic_batches_because_deformvertexes_autosprite2,
130 r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite2,
131 r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite2,
132 r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite2,
133 r_stat_batch_dynamic_batches_because_deformvertexes_normal,
134 r_stat_batch_dynamic_surfaces_because_deformvertexes_normal,
135 r_stat_batch_dynamic_vertices_because_deformvertexes_normal,
136 r_stat_batch_dynamic_triangles_because_deformvertexes_normal,
137 r_stat_batch_dynamic_batches_because_deformvertexes_wave,
138 r_stat_batch_dynamic_surfaces_because_deformvertexes_wave,
139 r_stat_batch_dynamic_vertices_because_deformvertexes_wave,
140 r_stat_batch_dynamic_triangles_because_deformvertexes_wave,
141 r_stat_batch_dynamic_batches_because_deformvertexes_bulge,
142 r_stat_batch_dynamic_surfaces_because_deformvertexes_bulge,
143 r_stat_batch_dynamic_vertices_because_deformvertexes_bulge,
144 r_stat_batch_dynamic_triangles_because_deformvertexes_bulge,
145 r_stat_batch_dynamic_batches_because_deformvertexes_move,
146 r_stat_batch_dynamic_surfaces_because_deformvertexes_move,
147 r_stat_batch_dynamic_vertices_because_deformvertexes_move,
148 r_stat_batch_dynamic_triangles_because_deformvertexes_move,
149 r_stat_batch_dynamic_batches_because_tcgen_lightmap,
150 r_stat_batch_dynamic_surfaces_because_tcgen_lightmap,
151 r_stat_batch_dynamic_vertices_because_tcgen_lightmap,
152 r_stat_batch_dynamic_triangles_because_tcgen_lightmap,
153 r_stat_batch_dynamic_batches_because_tcgen_vector,
154 r_stat_batch_dynamic_surfaces_because_tcgen_vector,
155 r_stat_batch_dynamic_vertices_because_tcgen_vector,
156 r_stat_batch_dynamic_triangles_because_tcgen_vector,
157 r_stat_batch_dynamic_batches_because_tcgen_environment,
158 r_stat_batch_dynamic_surfaces_because_tcgen_environment,
159 r_stat_batch_dynamic_vertices_because_tcgen_environment,
160 r_stat_batch_dynamic_triangles_because_tcgen_environment,
161 r_stat_batch_dynamic_batches_because_tcmod_turbulent,
162 r_stat_batch_dynamic_surfaces_because_tcmod_turbulent,
163 r_stat_batch_dynamic_vertices_because_tcmod_turbulent,
164 r_stat_batch_dynamic_triangles_because_tcmod_turbulent,
165 r_stat_batch_dynamic_batches_because_nogaps,
166 r_stat_batch_dynamic_surfaces_because_nogaps,
167 r_stat_batch_dynamic_vertices_because_nogaps,
168 r_stat_batch_dynamic_triangles_because_nogaps,
169 r_stat_batch_dynamic_batches_because_derived,
170 r_stat_batch_dynamic_surfaces_because_derived,
171 r_stat_batch_dynamic_vertices_because_derived,
172 r_stat_batch_dynamic_triangles_because_derived,
173 r_stat_batch_entitycache_count,
174 r_stat_batch_entitycache_surfaces,
175 r_stat_batch_entitycache_vertices,
176 r_stat_batch_entitycache_triangles,
177 r_stat_batch_entityanimate_count,
178 r_stat_batch_entityanimate_surfaces,
179 r_stat_batch_entityanimate_vertices,
180 r_stat_batch_entityanimate_triangles,
181 r_stat_batch_entityskeletal_count,
182 r_stat_batch_entityskeletal_surfaces,
183 r_stat_batch_entityskeletal_vertices,
184 r_stat_batch_entityskeletal_triangles,
185 r_stat_batch_entitystatic_count,
186 r_stat_batch_entitystatic_surfaces,
187 r_stat_batch_entitystatic_vertices,
188 r_stat_batch_entitystatic_triangles,
189 r_stat_batch_entitycustom_count,
190 r_stat_batch_entitycustom_surfaces,
191 r_stat_batch_entitycustom_vertices,
192 r_stat_batch_entitycustom_triangles,
193 r_stat_count // size of array
197 // flags for rtlight rendering
198 #define LIGHTFLAG_NORMALMODE 1
199 #define LIGHTFLAG_REALTIMEMODE 2
201 typedef struct tridecal_s
203 // color and initial alpha value
204 float texcoord2f[3][2];
205 float vertex3f[3][3];
207 float plane[4]; // backface culling
208 // how long this decal has lived so far (the actual fade begins at cl_decals_time)
210 // if >= 0 this indicates the decal should follow an animated triangle
212 // for visibility culling
214 // old decals are killed to obey cl_decals_max
215 unsigned int decalsequence;
219 typedef struct decalsystem_s
222 double lastupdatetime;
231 unsigned short *element3s;
235 typedef struct effect_s
244 // these are for interpolation
251 typedef struct beam_s
254 // draw this as lightning polygons, or a model?
256 struct model_s *model;
262 typedef struct rtlight_particle_s
269 typedef struct rtlight_s
271 // note that the world to light matrices are inversely scaled (divided) by lightradius
274 /// matrix for transforming light filter coordinates to world coordinates
275 matrix4x4_t matrix_lighttoworld;
276 /// matrix for transforming world coordinates to light filter coordinates
277 matrix4x4_t matrix_worldtolight;
278 /// typically 1 1 1, can be lower (dim) or higher (overbright)
280 /// size of the light (remove?)
283 char cubemapname[64];
284 /// light style to monitor for brightness
286 /// whether light should render shadows (see castshadows for whether it actually does this frame)
288 /// intensity of corona to render
290 /// radius scale of corona to render (1.0 means same as light radius)
291 vec_t coronasizescale;
292 /// ambient intensity to render
294 /// diffuse intensity to render
296 /// specular intensity to render
298 /// LIGHTFLAG_* flags
301 // generated properties
302 /// used only for casting shadows
307 /// when r_shadow_culllights_trace is set, this is refreshed by each successful trace.
310 // rendering properties, updated each time a light is rendered
311 // this is rtlight->color * d_lightstylevalue
313 /// used by corona updates, due to occlusion query
314 float corona_visibility;
315 unsigned int corona_queryindex_visiblepixels;
316 unsigned int corona_queryindex_allpixels;
317 /// this is R_GetCubemap(rtlight->cubemapname)
318 rtexture_t *currentcubemap;
319 /// set by R_Shadow_PrepareLight to decide whether R_Shadow_DrawLight should draw it
321 /// set by R_Shadow_PrepareLight to indicate whether R_Shadow_DrawShadowMaps should do anything
323 /// these fields are set by R_Shadow_PrepareLight for later drawing
324 int cached_numlightentities;
325 int cached_numlightentities_noselfshadow;
326 int cached_numshadowentities;
327 int cached_numshadowentities_noselfshadow;
328 int cached_numsurfaces;
329 struct entity_render_s **cached_lightentities;
330 struct entity_render_s **cached_lightentities_noselfshadow;
331 struct entity_render_s **cached_shadowentities;
332 struct entity_render_s **cached_shadowentities_noselfshadow;
333 unsigned char *cached_shadowtrispvs;
334 unsigned char *cached_lighttrispvs;
335 int *cached_surfacelist;
336 // reduced light cullbox from GetLightInfo
337 vec3_t cached_cullmins;
338 vec3_t cached_cullmaxs;
339 // current shadow-caster culling planes based on view
340 // (any geometry outside these planes can not contribute to the visible
341 // shadows in any way, and thus can be culled safely)
342 int cached_numfrustumplanes;
343 mplane_t cached_frustumplanes[5]; // see R_Shadow_ComputeShadowCasterCullingPlanes
345 /// static light info
346 /// true if this light should be compiled as a static light
348 /// true if this is a compiled world light, cleared if the light changes
350 /// the size that this light should have (assuming no scene LOD kicking in to reduce it)
351 int shadowmapsidesize;
352 /// position of this light in the shadowmap atlas
353 int shadowmapatlasposition[2];
354 /// 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)
355 int shadowmapatlassidesize;
356 /// optimized and culled mesh to render for world entity shadows
357 shadowmesh_t *static_meshchain_shadow_shadowmap;
358 /// used for visibility testing (more exact than bbox)
360 int static_numleafpvsbytes;
361 int *static_leaflist;
362 unsigned char *static_leafpvs;
363 /// surfaces seen by light
364 int static_numsurfaces;
365 int *static_surfacelist;
366 /// flag bits indicating which triangles of the world model should cast
367 /// shadows, and which ones should be lit
369 /// this avoids redundantly scanning the triangles in each surface twice
370 /// for whether they should cast shadows, once in culling and once in the
371 /// actual shadowmarklist production.
372 int static_numshadowtrispvsbytes;
373 unsigned char *static_shadowtrispvs;
374 /// this allows the lighting batch code to skip backfaces andother culled
375 /// triangles not relevant for lighting
376 /// (important on big surfaces such as terrain)
377 int static_numlighttrispvsbytes;
378 unsigned char *static_lighttrispvs;
379 /// masks of all shadowmap sides that have any potential static receivers or casters
380 int static_shadowmap_receivers;
381 int static_shadowmap_casters;
382 /// particle-tracing cache for global illumination
383 int particlecache_numparticles;
384 int particlecache_maxparticles;
385 int particlecache_updateparticle;
386 rtlight_particle_t *particlecache_particles;
388 /// bouncegrid light info
389 float bouncegrid_photoncolor[3];
390 float bouncegrid_photons;
392 int bouncegrid_traces;
393 float bouncegrid_effectiveradius;
397 typedef struct dlight_s
399 // destroy light after this time
402 // the entity that owns this light (can be NULL)
404 struct entity_render_s *ent;
406 // (worldlight: saved to .rtlights file)
408 // worldlight orientation
410 // (worldlight: saved to .rtlights file)
412 // dlight orientation/scaling/location
416 // (worldlight: saved to .rtlights file)
418 // cubemap name to use on this light
419 // (worldlight: saved to .rtlights file)
420 char cubemapname[64];
421 // make light flash while selected
424 // brightness (not really radius anymore)
425 // (worldlight: saved to .rtlights file)
427 // drop intensity this much each second
430 // intensity value which is dropped over time
433 // initial values for intensity to modify
437 // light style which controls intensity of this light
438 // (worldlight: saved to .rtlights file)
441 // (worldlight: saved to .rtlights file)
444 // (worldlight: saved to .rtlights file)
446 // radius scale of corona to render (1.0 means same as light radius)
447 // (worldlight: saved to .rtlights file)
448 vec_t coronasizescale;
449 // ambient intensity to render
450 // (worldlight: saved to .rtlights file)
452 // diffuse intensity to render
453 // (worldlight: saved to .rtlights file)
455 // specular intensity to render
456 // (worldlight: saved to .rtlights file)
459 // (worldlight: saved to .rtlights file)
461 // linked list of world lights
463 struct dlight_s *next;
464 // embedded rtlight struct for renderer
470 // this is derived from processing of the framegroupblend array
471 // note: technically each framegroupblend can produce two of these, but that
472 // never happens in practice because no one blends between more than 2
473 // framegroups at once
474 #define MAX_FRAMEBLENDS (MAX_FRAMEGROUPBLENDS * 2)
475 typedef struct frameblend_s
482 // LadyHavoc: this struct is intended for the renderer but some fields are
483 // used by the client.
485 // The renderer should not rely on any changes to this struct to be persistent
486 // across multiple frames because temp entities are wiped every frame, but it
487 // is acceptable to cache things in this struct that are not critical.
489 // For example the r_cullentities_trace code does such caching.
490 typedef struct entity_render_s
496 // transform matrix for model to world
498 // transform matrix for world to model
499 matrix4x4_t inversematrix;
500 // opacity (alpha) of the model
502 // size the model is shown
504 // transparent sorting offset
505 float transparent_offset;
509 // number of the entity represents, or 0 for non-network entities
511 // literal colormap colors for renderer, if both are 0 0 0 it is not colormapped
512 vec3_t colormap_pantscolor;
513 vec3_t colormap_shirtcolor;
514 // light, particles, etc
516 // qw CTF flags and other internal-use-only effect bits
523 // colormod tinting of models
527 // interpolated animation - active framegroups and blend factors
528 framegroupblend_t framegroupblend[MAX_FRAMEGROUPBLENDS];
530 // time of last model change (for shader animations)
533 // calculated by the renderer (but not persistent)
535 // calculated during R_AddModelEntities
537 // subframe numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use subframeblend[0].subframe
538 frameblend_t frameblend[MAX_FRAMEBLENDS];
539 // skeletal animation data (if skeleton.relativetransforms is not NULL, it overrides frameblend)
540 skeleton_t *skeleton;
542 // animation cache (pointers allocated using R_FrameData_Alloc)
543 // ONLY valid during R_RenderView! may be NULL (not cached)
544 float *animcache_vertex3f;
545 r_meshbuffer_t *animcache_vertex3f_vertexbuffer;
546 int animcache_vertex3f_bufferoffset;
547 float *animcache_normal3f;
548 r_meshbuffer_t *animcache_normal3f_vertexbuffer;
549 int animcache_normal3f_bufferoffset;
550 float *animcache_svector3f;
551 r_meshbuffer_t *animcache_svector3f_vertexbuffer;
552 int animcache_svector3f_bufferoffset;
553 float *animcache_tvector3f;
554 r_meshbuffer_t *animcache_tvector3f_vertexbuffer;
555 int animcache_tvector3f_bufferoffset;
556 // gpu-skinning shader needs transforms in a certain format, we have to
557 // upload this to a uniform buffer for the shader to use, and also keep a
558 // backup copy in system memory for the dynamic batch fallback code
559 // if this is not NULL, the other animcache variables are NULL
560 float *animcache_skeletaltransform3x4;
561 r_meshbuffer_t *animcache_skeletaltransform3x4buffer;
562 int animcache_skeletaltransform3x4offset;
563 int animcache_skeletaltransform3x4size;
565 // CL_UpdateEntityShading reads these fields
566 // used only if RENDER_CUSTOMIZEDMODELLIGHT is set
567 vec3_t custommodellight_ambient;
568 vec3_t custommodellight_diffuse;
569 vec3_t custommodellight_lightdir;
570 // CSQC entities get their shading from the root of their attachment chain
571 float custommodellight_origin[3];
573 // derived lighting parameters (CL_UpdateEntityShading)
575 // used by MATERIALFLAG_FULLBRIGHT which is MATERIALFLAG_MODELLIGHT with
576 // this as ambient color, along with MATERIALFLAG_NORTLIGHT
577 float render_fullbright[3];
578 // color tint for the base pass glow textures if any
579 float render_glowmod[3];
580 // MATERIALFLAG_MODELLIGHT uses these parameters
581 float render_modellight_ambient[3];
582 float render_modellight_diffuse[3];
583 float render_modellight_lightdir_world[3];
584 float render_modellight_lightdir_local[3];
585 float render_modellight_specular[3];
586 // lightmap rendering (not MATERIALFLAG_MODELLIGHT)
587 float render_lightmap_ambient[3];
588 float render_lightmap_diffuse[3];
589 float render_lightmap_specular[3];
590 // rtlights use these colors for the materials on this entity
591 float render_rtlight_diffuse[3];
592 float render_rtlight_specular[3];
593 // ignore lightmap and use fixed lighting settings on this entity (e.g. FULLBRIGHT)
594 qbool render_modellight_forced;
595 // do not process per pixel lights on this entity at all (like MATERIALFLAG_NORTLIGHT)
596 qbool render_rtlight_disabled;
597 // use the 3D lightmap from q3bsp on this entity
598 qbool render_lightgrid;
600 // storage of decals on this entity
601 // (note: if allowdecals is set, be sure to call R_DecalSystem_Reset on removal!)
603 decalsystem_t decalsystem;
605 // FIELDS UPDATED BY RENDERER:
606 // last time visible during trace culling
607 double last_trace_visibility;
609 // user wavefunc parameters (from csqc)
610 vec_t userwavefunc_param[Q3WAVEFUNC_USER_COUNT];
614 typedef struct entity_persistent_s
616 vec3_t trail_origin; // previous position for particle trail spawning
617 vec3_t oldorigin; // lerp
618 vec3_t oldangles; // lerp
619 vec3_t neworigin; // lerp
620 vec3_t newangles; // lerp
621 vec_t lerpstarttime; // lerp
622 vec_t lerpdeltatime; // lerp
623 float muzzleflash; // muzzleflash intensity, fades over time
624 float trail_time; // residual error accumulation for particle trail spawning (to keep spacing across frames)
625 qbool trail_allowed; // set to false by teleports, true by update code, prevents bad lerps
629 typedef struct entity_s
631 // baseline state (default values)
632 entity_state_t state_baseline;
633 // previous state (interpolating from this)
634 entity_state_t state_previous;
635 // current state (interpolating to this)
636 entity_state_t state_current;
638 // used for regenerating parts of render
639 entity_persistent_t persistent;
641 // the only data the renderer should know about
642 entity_render_t render;
646 typedef struct usercmd_s
650 // intended velocities
655 vec3_t cursor_screen;
658 vec3_t cursor_impact;
659 vec3_t cursor_normal;
660 vec_t cursor_fraction;
661 int cursor_entitynumber;
663 double time; // time the move is executed for (cl_movement: clienttime, non-cl_movement: receivetime)
664 double receivetime; // time the move was received at
665 double clienttime; // time to which server state the move corresponds to
666 int msec; // for predicted moves
669 unsigned int sequence;
670 qbool applied; // if false we're still accumulating a move
671 qbool predicted; // if true the sequence should be sent as 0
673 // derived properties
680 typedef struct lightstyle_s
683 char map[MAX_STYLESTRING];
686 typedef struct scoreboard_s
688 char name[MAX_SCOREBOARDNAME];
690 int colors; // two 4 bit fields
693 char qw_userinfo[MAX_USERINFO_STRING];
700 char qw_skin[MAX_QPATH];
703 typedef struct cshift_s
706 float percent; // 0-255
707 float alphafade; // (any speed)
710 #define CSHIFT_CONTENTS 0
711 #define CSHIFT_DAMAGE 1
712 #define CSHIFT_BONUS 2
713 #define CSHIFT_POWERUP 3
714 #define CSHIFT_VCSHIFT 4
715 #define NUM_CSHIFTS 5
717 #define NAME_LENGTH 64
721 // client_state_t should hold all pieces of the client state
724 #define SIGNONS 4 // signon messages to receive before connected
726 typedef enum cactive_e
728 ca_uninitialized, // during early startup
729 ca_dedicated, // a dedicated server with no ability to start a client
730 ca_disconnected, // full screen console with no connection
731 ca_connected // valid netcon, talking to a server
735 typedef enum qw_downloadtype_e
745 #define CL_MAX_DOWNLOADACKS 4
747 typedef struct cl_downloadack_s
753 typedef struct cl_soundstats_s
757 int latency_milliseconds;
762 // the client_static_t structure is persistent through an arbitrary number
763 // of server connections
765 typedef struct client_static_s
769 // all client memory allocations go in these pools
770 mempool_t *levelmempool;
771 mempool_t *permanentmempool;
774 // -1 = don't play demos
776 // list of demos in loop
777 char demos[MAX_DEMOS][MAX_DEMONAME];
778 // the actively playing demo (set by CL_PlayDemo_f)
779 char demoname[MAX_QPATH];
781 // demo recording info must be here, because record is started before
782 // entering a map (and clearing client_state_t)
784 fs_offset_t demo_lastcsprogssize;
785 int demo_lastcsprogscrc;
787 qbool demostarting; // set if currently starting a demo, to stop -demo from quitting when switching to another demo
789 // -1 = use normal cd track
792 // realtime at second frame of timedemo (LadyHavoc: changed to double)
794 int td_frames; // total frames parsed
795 double td_onesecondnexttime;
796 double td_onesecondframes;
797 double td_onesecondrealtime;
798 double td_onesecondminfps;
799 double td_onesecondmaxfps;
800 double td_onesecondavgfps;
801 int td_onesecondavgcount;
802 // LadyHavoc: pausedemo
805 // sound mixer statistics for showsound display
806 cl_soundstats_t soundstats;
808 qbool connect_trying;
809 int connect_remainingtries;
810 double connect_nextsendtime;
811 lhnetsocket_t *connect_mysocket;
812 lhnetaddress_t connect_address;
813 lhnetaddress_t rcon_address;
814 // protocol version of the server we're connected to
815 // (kept outside client_state_t because it's used between levels)
816 protocolversion_t protocol;
820 lhnetaddress_t rcon_addresses[MAX_RCONS];
821 char rcon_commands[MAX_RCONS][MAX_INPUTLINE];
822 double rcon_timeout[MAX_RCONS];
825 // connection information
828 // network connection
831 // download information
832 // (note: qw_download variables are also used)
833 cl_downloadack_t dp_downloadack[CL_MAX_DOWNLOADACKS];
835 // input sequence numbers are not reset on level change, only connect
836 unsigned int servermovesequence;
838 // quakeworld stuff below
840 // value of "qport" cvar at time of connection
842 // copied from cls.netcon->qw. variables every time they change, or set by demos (which have no cls.netcon)
843 unsigned int qw_incoming_sequence;
844 unsigned int qw_outgoing_sequence;
846 // current file download buffer (only saved when file is completed)
847 char qw_downloadname[MAX_QPATH];
848 unsigned char *qw_downloadmemory;
849 int qw_downloadmemorycursize;
850 int qw_downloadmemorymaxsize;
851 int qw_downloadnumber;
852 int qw_downloadpercent;
853 qw_downloadtype_t qw_downloadtype;
854 // transfer rate display
855 double qw_downloadspeedtime;
856 int qw_downloadspeedcount;
857 int qw_downloadspeedrate;
858 qbool qw_download_deflate;
860 // current file upload buffer (for uploading screenshots to server)
861 unsigned char *qw_uploaddata;
866 // this normally contains the following keys in quakeworld:
867 // password spectator name team skin topcolor bottomcolor rate noaim msg *ver *ip
868 char userinfo[MAX_USERINFO_STRING];
870 // extra user info for the "connect" command
871 char connect_userinfo[MAX_USERINFO_STRING];
873 #ifdef CONFIG_VIDEO_CAPTURE
874 // video capture stuff
875 capturevideostate_t capturevideo;
881 // ProQuake compatibility stuff
882 int proquake_servermod; // 0 = not proquake, 1 = proquake
883 int proquake_serverversion; // actual proquake server version * 10 (3.40 = 34, etc)
884 int proquake_serverflags; // 0 (PQF_CHEATFREE not supported)
886 // don't write-then-read csprogs.dat (useful for demo playback)
887 unsigned char *caughtcsprogsdata;
888 fs_offset_t caughtcsprogsdatasize;
890 int r_speeds_graph_length;
891 int r_speeds_graph_current;
892 int *r_speeds_graph_data;
895 int r_speeds_graph_datamin[r_stat_count];
896 int r_speeds_graph_datamax[r_stat_count];
900 extern client_static_t cls;
906 qbool drawenginesbar;
910 typedef enum cl_parsingtextmode_e
912 CL_PARSETEXTMODE_NONE,
913 CL_PARSETEXTMODE_PING,
914 CL_PARSETEXTMODE_STATUS,
915 CL_PARSETEXTMODE_STATUS_PLAYERID,
916 CL_PARSETEXTMODE_STATUS_PLAYERIP
918 cl_parsingtextmode_t;
920 typedef struct cl_locnode_s
922 struct cl_locnode_s *next;
928 typedef struct showlmp_s
939 // the client_state_t structure is wiped completely at every
942 typedef struct client_state_s
944 // true if playing in a local game and no one else is connected
947 // send a clc_nop periodically until connected
950 // current input being accumulated by mouse/joystick/etc input
952 // latest moves sent to the server that have not been confirmed yet
953 usercmd_t movecmd[CL_MAX_USERCMDS];
955 // information for local display
957 int stats[MAX_CL_STATS];
958 float *statsf; // points to stats[] array
959 // last known inventory bit flags, for blinking
961 // cl.time of acquiring item, for blinking
962 float item_gettime[32];
963 // last known STAT_ACTIVEWEAPON
965 // cl.time of changing STAT_ACTIVEWEAPON
967 // use pain anim frame if cl.time < this
969 // for stair smoothing
971 double stairsmoothtime;
973 // color shifts for damage, powerups
974 cshift_t cshifts[NUM_CSHIFTS];
976 cshift_t prev_cshifts[NUM_CSHIFTS];
978 // the client maintains its own idea of view angles, which are
979 // sent to the server each frame. The server sets punchangle when
980 // the view is temporarily offset, and an angle reset commands at the start
981 // of each level and after teleporting.
983 // mviewangles is read from demo
984 // viewangles is either client controlled or lerped from mviewangles
985 vec3_t mviewangles[2], viewangles;
986 // update by server, used by qc to do weapon recoil
987 vec3_t mpunchangle[2], punchangle;
988 // update by server, can be used by mods to kick view around
989 vec3_t mpunchvector[2], punchvector;
990 // update by server, used for lean+bob (0 is newest)
991 vec3_t mvelocity[2], velocity;
992 // update by server, can be used by mods for zooming
993 vec_t mviewzoom[2], viewzoom;
994 // if true interpolation the mviewangles and other interpolation of the
995 // player is disabled until the next network packet
996 // this is used primarily by teleporters, and when spectating players
997 // special checking of the old fixangle[1] is used to differentiate
998 // between teleporting and spectating
1001 // client movement simulation
1002 // these fields are only updated by CL_ClientMovement (called by CL_SendMove after parsing each network packet)
1003 // set by CL_ClientMovement_Replay functions
1004 qbool movement_predicted;
1005 // if true the CL_ClientMovement_Replay function will update origin, etc
1006 qbool movement_replay;
1007 // simulated data (this is valid even if cl.movement is false)
1008 vec3_t movement_origin;
1009 vec3_t movement_velocity;
1010 // whether the replay should allow a jump at the first sequence
1011 qbool movement_replay_canjump;
1013 // previous gun angles (for leaning effects)
1014 vec3_t gunangles_prev;
1015 vec3_t gunangles_highpass;
1016 vec3_t gunangles_adjustment_lowpass;
1017 vec3_t gunangles_adjustment_highpass;
1018 // previous gun angles (for leaning effects)
1020 vec3_t gunorg_highpass;
1021 vec3_t gunorg_adjustment_lowpass;
1022 vec3_t gunorg_adjustment_highpass;
1024 // pitch drifting vars
1031 //[515]: added for csqc purposes
1032 float sensitivityscale;
1033 csqc_vidvars_t csqc_vidvars; //[515]: these parms must be set to true by default
1034 qbool csqc_wantsmousemove;
1035 struct model_s *csqc_model_precache[MAX_MODELS];
1037 // local amount for smoothing stepups
1047 double lastongroundtime;
1048 double hitgroundtime;
1050 float bobfall_speed;
1051 float bobfall_swing;
1052 double calcrefdef_prevtime;
1054 // don't change view angle, full screen, etc
1056 // latched at intermission start
1057 double completed_time;
1059 // the timestamp of the last two messages
1062 // clients view of time, time should be between mtime[0] and mtime[1] to
1063 // generate a lerp point for other data, oldtime is the previous frame's
1064 // value of time, frametime is the difference between time and oldtime
1065 // note: cl.time may be beyond cl.mtime[0] if packet loss is occuring, it
1066 // is only forcefully limited when a packet is received
1067 double time, oldtime;
1068 // how long it has been since the previous client frame in real time
1069 // (not game time, for that use cl.time - cl.oldtime)
1070 double realframetime;
1072 // fade var for fading while dead
1075 // motionblur alpha level variable
1076 float motionbluralpha;
1078 // copy of realtime from last recieved message, for net trouble icon
1079 float last_received_message;
1081 // information that is static for the entire time connected to a server
1082 struct model_s *model_precache[MAX_MODELS];
1083 struct sfx_s *sound_precache[MAX_SOUNDS];
1085 // FIXME: this is a lot of memory to be keeping around, this really should be dynamically allocated and freed somehow
1086 char model_name[MAX_MODELS][MAX_QPATH];
1087 char sound_name[MAX_SOUNDS][MAX_QPATH];
1089 // for display on solo scoreboard
1090 char worldmessage[40]; // map title (not related to filename)
1091 // variants of map name
1092 char worldbasename[MAX_QPATH]; // %s
1093 char worldname[MAX_QPATH]; // maps/%s.bsp
1094 char worldnamenoextension[MAX_QPATH]; // maps/%s
1095 // cl_entitites[cl.viewentity] = player
1097 // the real player entity (normally same as viewentity,
1098 // different than viewentity if mod uses chasecam or other tricks)
1099 int realplayerentity;
1100 // this is updated to match cl.viewentity whenever it is in the clients
1101 // range, basically this is used in preference to cl.realplayerentity for
1102 // most purposes because when spectating another player it should show
1103 // their information rather than yours
1105 // max players that can be in this game
1107 // type of game (deathmatch, coop, singleplayer)
1110 // models and sounds used by engine code (particularly cl_parse.c)
1111 dp_model_t *model_bolt;
1112 dp_model_t *model_bolt2;
1113 dp_model_t *model_bolt3;
1114 dp_model_t *model_beam;
1116 sfx_t *sfx_knighthit;
1122 // indicates that the file "sound/misc/talk2.wav" was found (for use by team chat messages)
1123 qbool foundteamchatsound;
1125 // refresh related state
1127 // cl_entitites[0].model
1128 struct model_s *worldmodel;
1134 int cdtrack, looptrack;
1139 scoreboard_t *scores;
1141 // keep track of svc_print parsing state (analyzes ping reports and status reports)
1142 cl_parsingtextmode_t parsingtextmode;
1143 int parsingtextplayerindex;
1144 // set by scoreboard code when sending ping command, this causes the next ping results to be hidden
1145 // (which could eat the wrong ping report if the player issues one
1146 // manually, but they would still see a ping report, just a later one
1147 // caused by the scoreboard code rather than the one they intentionally
1149 int parsingtextexpectingpingforscores;
1151 // entity database stuff
1152 // latest received entity frame numbers
1153 #define LATESTFRAMENUMS 32
1154 int latestframenumsposition;
1155 int latestframenums[LATESTFRAMENUMS];
1156 unsigned int latestsendnums[LATESTFRAMENUMS];
1157 entityframe_database_t *entitydatabase;
1158 entityframe4_database_t *entitydatabase4;
1159 entityframeqw_database_t *entitydatabaseqw;
1161 // keep track of quake entities because they need to be killed if they get stale
1162 int lastquakeentity;
1163 unsigned char isquakeentity[MAX_EDICTS];
1165 // bounding boxes for clientside movement
1166 vec3_t playerstandmins;
1167 vec3_t playerstandmaxs;
1168 vec3_t playercrouchmins;
1169 vec3_t playercrouchmaxs;
1171 // old decals are killed based on this
1172 unsigned int decalsequence;
1175 int max_csqcrenderentities;
1176 int max_static_entities;
1181 int max_brushmodel_entities;
1186 entity_render_t *csqcrenderentities;
1187 unsigned char *entities_active;
1188 entity_t *static_entities;
1189 cl_effect_t *effects;
1192 lightstyle_t *lightstyle;
1193 int *brushmodel_entities;
1194 particle_t *particles;
1195 showlmp_t *showlmps;
1198 int num_static_entities;
1199 int num_brushmodel_entities;
1207 double particles_updatetime;
1208 double decals_updatetime;
1212 // cl_serverextension_download feature
1213 int loadmodel_current;
1214 int downloadmodel_current;
1215 int loadmodel_total;
1216 int loadsound_current;
1217 int downloadsound_current;
1218 int loadsound_total;
1226 // local copy of the server infostring
1227 char qw_serverinfo[MAX_SERVERINFO_STRING];
1229 // time of last qw "pings" command sent to server while showing scores
1230 double last_ping_request;
1232 // used during connect
1235 // updated from serverinfo
1238 // unused: indicates whether the player is spectating
1239 // use cl.scores[cl.playerentity-1].qw_spectator instead
1240 //qbool qw_spectator;
1242 // last time an input packet was sent
1243 double lastpackettime;
1245 // movement parameters for client prediction
1246 unsigned int moveflags;
1247 float movevars_wallfriction;
1248 float movevars_waterfriction;
1249 float movevars_friction;
1250 float movevars_timescale;
1251 float movevars_gravity;
1252 float movevars_stopspeed;
1253 float movevars_maxspeed;
1254 float movevars_spectatormaxspeed;
1255 float movevars_accelerate;
1256 float movevars_airaccelerate;
1257 float movevars_wateraccelerate;
1258 float movevars_entgravity;
1259 float movevars_jumpvelocity;
1260 float movevars_edgefriction;
1261 float movevars_maxairspeed;
1262 float movevars_stepheight;
1263 float movevars_airaccel_qw;
1264 float movevars_airaccel_qw_stretchfactor;
1265 float movevars_airaccel_sideways_friction;
1266 float movevars_airstopaccelerate;
1267 float movevars_airstrafeaccelerate;
1268 float movevars_maxairstrafespeed;
1269 float movevars_airstrafeaccel_qw;
1270 float movevars_aircontrol;
1271 float movevars_aircontrol_power;
1272 float movevars_aircontrol_penalty;
1273 float movevars_warsowbunny_airforwardaccel;
1274 float movevars_warsowbunny_accel;
1275 float movevars_warsowbunny_topspeed;
1276 float movevars_warsowbunny_turnaccel;
1277 float movevars_warsowbunny_backtosideratio;
1278 float movevars_ticrate;
1279 float movevars_airspeedlimit_nonqw;
1281 // models used by qw protocol
1282 int qw_modelindex_spike;
1283 int qw_modelindex_player;
1284 int qw_modelindex_flag;
1285 int qw_modelindex_s_explod;
1287 vec3_t qw_intermission_origin;
1288 vec3_t qw_intermission_angles;
1290 // 255 is the most nails the QW protocol could send
1292 vec_t qw_nails[255][6];
1294 float qw_weaponkick;
1296 unsigned int qw_validsequence;
1298 unsigned int qw_deltasequence[QW_UPDATE_BACKUP];
1301 // server entity number corresponding to a clientside entity
1302 unsigned short csqc_server2csqcentitynumber[MAX_EDICTS];
1304 vec3_t csqc_vieworigin;
1305 vec3_t csqc_viewangles;
1306 vec3_t csqc_vieworiginfromengine;
1307 vec3_t csqc_viewanglesfromengine;
1308 matrix4x4_t csqc_viewmodelmatrixfromengine;
1309 qbool csqc_usecsqclistener;
1310 matrix4x4_t csqc_listenermatrix;
1311 char csqc_printtextbuf[MAX_INPUTLINE];
1313 // collision culling data
1316 // loc file stuff (points and boxes describing locations in the level)
1317 cl_locnode_t *locnodes;
1318 // this is updated to cl.movement_origin whenever health is < 1
1319 // used by %d print in say/say_team messages if cl_locs_enable is on
1320 vec3_t lastdeathorigin;
1322 // processing buffer used by R_BuildLightMap, reallocated as needed,
1323 // freed on each level change
1324 size_t buildlightmapmemorysize;
1325 unsigned char *buildlightmapmemory;
1327 // used by EntityState5_ReadUpdate
1328 skeleton_t *engineskeletonobjects;
1335 extern cvar_t cl_name;
1336 extern cvar_t cl_color;
1337 extern cvar_t cl_rate;
1338 extern cvar_t cl_rate_burstsize;
1339 extern cvar_t cl_pmodel;
1340 extern cvar_t cl_playermodel;
1341 extern cvar_t cl_playerskin;
1343 extern cvar_t rcon_password;
1344 extern cvar_t rcon_address;
1346 extern cvar_t cl_upspeed;
1347 extern cvar_t cl_forwardspeed;
1348 extern cvar_t cl_backspeed;
1349 extern cvar_t cl_sidespeed;
1351 extern cvar_t cl_movespeedkey;
1353 extern cvar_t cl_yawspeed;
1354 extern cvar_t cl_pitchspeed;
1356 extern cvar_t cl_anglespeedkey;
1358 extern cvar_t cl_autofire;
1360 extern cvar_t cl_shownet;
1361 extern cvar_t cl_nolerp;
1362 extern cvar_t cl_nettimesyncfactor;
1363 extern cvar_t cl_nettimesyncboundmode;
1364 extern cvar_t cl_nettimesyncboundtolerance;
1366 extern cvar_t cl_pitchdriftspeed;
1367 extern cvar_t lookspring;
1368 extern cvar_t lookstrafe;
1369 extern cvar_t sensitivity;
1371 extern cvar_t freelook;
1373 extern cvar_t m_pitch;
1374 extern cvar_t m_yaw;
1375 extern cvar_t m_forward;
1376 extern cvar_t m_side;
1378 extern cvar_t cl_autodemo;
1379 extern cvar_t cl_autodemo_nameformat;
1380 extern cvar_t cl_autodemo_delete;
1382 extern cvar_t r_draweffects;
1384 extern cvar_t cl_explosions_alpha_start;
1385 extern cvar_t cl_explosions_alpha_end;
1386 extern cvar_t cl_explosions_size_start;
1387 extern cvar_t cl_explosions_size_end;
1388 extern cvar_t cl_explosions_lifetime;
1389 extern cvar_t cl_stainmaps;
1390 extern cvar_t cl_stainmaps_clearonload;
1392 extern cvar_t cl_prydoncursor;
1393 extern cvar_t cl_prydoncursor_notrace;
1395 extern cvar_t cl_locs_enable;
1397 extern client_state_t cl;
1399 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);
1401 cl_locnode_t *CL_Locs_FindNearest(const vec3_t point);
1402 void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point);
1404 //=============================================================================
1410 double CL_Frame(double time);
1412 void CL_Shutdown (void);
1413 void CL_Init (void);
1415 void CL_EstablishConnection(const char *host, int firstarg);
1417 void CL_Disconnect (void);
1418 void CL_Disconnect_f(cmd_state_t *cmd);
1420 void CL_UpdateRenderEntity(entity_render_t *ent);
1421 void CL_SetEntityColormapColors(entity_render_t *ent, int colormap);
1422 void CL_UpdateViewEntities(void);
1427 typedef struct kbutton_s
1429 int down[2]; // key nums holding it down
1430 int state; // low bit is down state
1434 extern kbutton_t in_mlook, in_klook;
1435 extern kbutton_t in_strafe;
1436 extern kbutton_t in_speed;
1438 void CL_InitInput (void);
1439 void CL_SendMove (void);
1441 void CL_ValidateState(entity_state_t *s);
1442 void CL_MoveLerpEntityStates(entity_t *ent);
1443 void CL_LerpUpdate(entity_t *e);
1444 void CL_ParseTEnt (void);
1445 void CL_NewBeam (int ent, vec3_t start, vec3_t end, dp_model_t *m, int lightning);
1446 void CL_RelinkBeams (void);
1447 void CL_Beam_CalculatePositions (const beam_t *b, vec3_t start, vec3_t end);
1448 void CL_ClientMovement_Replay(void);
1450 void CL_ClearTempEntities (void);
1451 entity_render_t *CL_NewTempEntity (double shadertime);
1453 void CL_Effect(vec3_t org, dp_model_t *model, int startframe, int framecount, float framerate);
1455 void CL_ClearState (void);
1456 void CL_ExpandEntities(int num);
1457 void CL_ExpandCSQCRenderEntities(int num);
1458 void CL_SetInfo(const char *key, const char *value, qbool send, qbool allowstarkey, qbool allowmodel, qbool quiet);
1461 void CL_UpdateWorld (void);
1462 void CL_WriteToServer (void);
1463 void CL_Input (void);
1464 extern int cl_ignoremousemoves;
1467 float CL_KeyState (kbutton_t *key);
1472 /// adds the string as a clc_stringcmd to the client message.
1473 /// (used when there is no reason to generate a local command to do it)
1474 void CL_ForwardToServer (const char *s);
1476 /// adds the current command line as a clc_stringcmd to the client message.
1477 /// things like godmode, noclip, etc, are commands directed to the server,
1478 /// so when they are typed in at the console, they will need to be forwarded.
1479 void CL_ForwardToServer_f (cmd_state_t *cmd);
1480 void CL_InitCommands(void);
1486 void CL_StopPlayback(void);
1487 void CL_ReadDemoMessage(void);
1488 void CL_WriteDemoMessage(sizebuf_t *mesage);
1490 void CL_CutDemo(unsigned char **buf, fs_offset_t *filesize);
1491 void CL_PasteDemo(unsigned char **buf, fs_offset_t *filesize);
1493 void CL_NextDemo(void);
1494 void CL_Stop_f(cmd_state_t *cmd);
1495 void CL_Record_f(cmd_state_t *cmd);
1496 void CL_PlayDemo_f(cmd_state_t *cmd);
1497 void CL_TimeDemo_f(cmd_state_t *cmd);
1499 void CL_Demo_Init(void);
1502 #include "cl_screen.h"
1504 extern qbool sb_showscores;
1506 typedef enum waterlevel_e
1510 WATERLEVEL_SWIMMING,
1511 WATERLEVEL_SUBMERGED
1515 typedef struct cl_clientmovement_state_s
1517 // entity to be ignored for movement
1518 struct prvm_edict_s *self;
1522 // current bounding box (different if crouched vs standing)
1525 // currently on the ground
1527 // currently crouching
1529 // what kind of water (SUPERCONTENTS_LAVA for instance)
1532 waterlevel_t waterlevel;
1533 // weird hacks when jumping out of water
1534 // (this is in seconds and counts down to 0)
1535 float waterjumptime;
1540 cl_clientmovement_state_t;
1541 void CL_ClientMovement_PlayerMove_Frame(cl_clientmovement_state_t *s);
1543 // warpzone prediction hack (CSQC builtin)
1544 void CL_RotateMoves(const matrix4x4_t *m);
1546 typedef enum meshname_e {
1547 MESH_SCENE, // CSQC R_PolygonBegin, potentially also engine particles and debug stuff
1551 extern entity_t cl_meshentities[NUM_MESHENTITIES];
1552 extern dp_model_t cl_meshentitymodels[NUM_MESHENTITIES];
1553 extern const char *cl_meshentitynames[NUM_MESHENTITIES];
1554 #define CL_Mesh_Scene() (&cl_meshentitymodels[MESH_SCENE])
1555 #define CL_Mesh_UI() (&cl_meshentitymodels[MESH_UI])
1556 void CL_MeshEntities_Scene_Clear(void);
1557 void CL_MeshEntities_Scene_AddRenderEntity(void);
1558 void CL_MeshEntities_Scene_FinalizeRenderEntity(void);
1559 void CL_UpdateEntityShading(void);
1561 void CL_NewFrameReceived(int num);
1562 void CL_ParseEntityLump(char *entitystring);
1563 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius);
1564 void CL_RelinkLightFlashes(void);
1565 void CL_Beam_AddPolygons(const beam_t *b);
1566 void CL_UpdateMoveVars(void);
1567 void CL_Locs_Reload_f(cmd_state_t *cmd);