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"
27 // LordHavoc: 256 dynamic lights
28 #define MAX_DLIGHTS 256
29 // LordHavoc: this affects the lighting scale of the whole game
30 #define LIGHTOFFSET 1024.0f
31 // max lights shining on one entity
32 #define MAXENTLIGHTS 128
34 // flags for rtlight rendering
35 #define LIGHTFLAG_NORMALMODE 1
36 #define LIGHTFLAG_REALTIMEMODE 2
38 extern int cl_max_entities;
39 extern int cl_max_static_entities;
40 extern int cl_max_temp_entities;
41 extern int cl_max_effects;
42 extern int cl_max_beams;
44 typedef struct effect_s
53 // these are for interpolation
63 // draw this as lightning polygons, or a model?
65 struct model_s *model;
68 // if this beam is owned by an entity, this is the beam start relative to
69 // that entity's matrix for per frame start updates
72 // indicates whether relativestart is valid
73 int relativestartvalid;
77 typedef struct rtlight_s
79 // shadow volumes are done entirely in model space, so there are no matrices for dealing with them... they just use the origin
81 // note that the world to light matrices are inversely scaled (divided) by lightradius
84 // matrix for transforming world coordinates to light filter coordinates
85 matrix4x4_t matrix_worldtolight;
86 // typically 1 1 1, can be lower (dim) or higher (overbright)
88 // size of the light (remove?)
92 // light style to monitor for brightness
94 // whether light should render shadows
96 // intensity of corona to render
98 // radius scale of corona to render (1.0 means same as light radius)
99 vec_t coronasizescale;
100 // ambient intensity to render
102 // diffuse intensity to render
104 // specular intensity to render
109 // generated properties
110 // used only for shadow volumes
117 // squared cullradius
120 // rendering properties, updated each time a light is rendered
121 // this is rtlight->color * d_lightstylevalue
123 // this is R_Shadow_Cubemap(rtlight->cubemapname)
124 rtexture_t *currentcubemap;
126 // lightmap renderer stuff (remove someday!)
127 // the size of the light
128 vec_t lightmap_cullradius;
129 // the size of the light, squared
130 vec_t lightmap_cullradius2;
131 // the brightness of the light
132 vec3_t lightmap_light;
133 // to avoid sudden brightness change at cullradius, subtract this
134 vec_t lightmap_subtract;
137 // true if this light should be compiled as a static light
139 // true if this is a compiled world light, cleared if the light changes
141 // premade shadow volumes to render for world entity
142 shadowmesh_t *static_meshchain_shadow;
143 // used for visibility testing (more exact than bbox)
145 int static_numleafpvsbytes;
146 int *static_leaflist;
147 unsigned char *static_leafpvs;
148 // surfaces seen by light
149 int static_numsurfaces;
150 int *static_surfacelist;
154 typedef struct dlight_s
156 // destroy light after this time
159 // the entity that owns this light (can be NULL)
161 struct entity_render_s *ent;
163 // (worldlight: saved to .rtlights file)
165 // worldlight orientation
167 // (worldlight: saved to .rtlights file)
169 // dlight orientation/scaling/location
173 // (worldlight: saved to .rtlights file)
175 // cubemap number to use on this light
178 // cubemap name to use on this light
180 // (worldlight: saved to .rtlights file)
181 char cubemapname[64];
182 // make light flash while selected
185 // brightness (not really radius anymore)
186 // (worldlight: saved to .rtlights file)
188 // drop radius this much each second
191 // light style which controls intensity of this light
192 // (worldlight: saved to .rtlights file)
195 // (worldlight: saved to .rtlights file)
198 // (worldlight: saved to .rtlights file)
200 // radius scale of corona to render (1.0 means same as light radius)
201 // (worldlight: saved to .rtlights file)
202 vec_t coronasizescale;
203 // ambient intensity to render
204 // (worldlight: saved to .rtlights file)
206 // diffuse intensity to render
207 // (worldlight: saved to .rtlights file)
209 // specular intensity to render
210 // (worldlight: saved to .rtlights file)
213 // (worldlight: saved to .rtlights file)
215 // linked list of world lights
217 struct dlight_s *next;
218 // embedded rtlight struct for renderer
224 typedef struct frameblend_s
231 // LordHavoc: this struct is intended for the renderer but some fields are
232 // used by the client.
233 typedef struct entity_render_s
239 // transform matrix for model to world
241 // transform matrix for world to model
242 matrix4x4_t inversematrix;
243 // opacity (alpha) of the model
245 // size the model is shown
250 // current uninterpolated animation frame (for things which do not use interpolation)
252 // entity shirt and pants colors (-1 if not colormapped)
254 // literal colors for renderer
255 vec3_t colormap_pantscolor;
256 vec3_t colormap_shirtcolor;
257 // light, particles, etc
264 // colormod tinting of models
267 // interpolated animation
269 // frame that the model is interpolating from
271 // frame that the model is interpolating to
273 // interpolation factor, usually computed from frame2time
275 // time frame1 began playing (for framegroup animations)
277 // time frame2 began playing (for framegroup animations)
280 // calculated by the renderer (but not persistent)
282 // if visframe == r_framecount, it is visible
284 // calculated during R_AddModelEntities
286 // 4 frame numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use frame instead
287 frameblend_t frameblend[4];
289 // caching results of static light traces (this is semi-persistent)
290 double entlightstime;
291 vec3_t entlightsorigin;
294 unsigned short entlights[MAXENTLIGHTS];
298 typedef struct entity_persistent_s
307 // muzzleflash fading
310 // interpolated movement
312 // start time of move
314 // time difference from start to end of move
316 // the move itself, start and end
324 typedef struct entity_s
326 // baseline state (default values)
327 entity_state_t state_baseline;
328 // previous state (interpolating from this)
329 entity_state_t state_previous;
330 // current state (interpolating to this)
331 entity_state_t state_current;
333 // used for regenerating parts of render
334 entity_persistent_t persistent;
336 // the only data the renderer should know about
337 entity_render_t render;
341 typedef struct usercmd_s
345 // intended velocities
350 vec3_t cursor_screen;
353 vec3_t cursor_impact;
354 vec3_t cursor_normal;
355 vec_t cursor_fraction;
356 int cursor_entitynumber;
365 typedef struct lightstyle_s
368 char map[MAX_STYLESTRING];
371 typedef struct scoreboard_s
373 char name[MAX_SCOREBOARDNAME];
375 int colors; // two 4 bit fields
378 typedef struct cshift_s
381 int percent; // 0-256
384 #define CSHIFT_CONTENTS 0
385 #define CSHIFT_DAMAGE 1
386 #define CSHIFT_BONUS 2
387 #define CSHIFT_POWERUP 3
388 #define CSHIFT_VCSHIFT 4
389 #define NUM_CSHIFTS 5
391 #define NAME_LENGTH 64
395 // client_state_t should hold all pieces of the client state
398 #define SIGNONS 4 // signon messages to receive before connected
401 #define MAX_DEMONAME 16
405 ca_dedicated, // a dedicated server with no ability to start a client
406 ca_disconnected, // full screen console with no connection
407 ca_connected // valid netcon, talking to a server
412 // the client_static_t structure is persistent through an arbitrary number
413 // of server connections
415 typedef struct client_static_s
420 // -1 = don't play demos
422 // list of demos in loop
423 char demos[MAX_DEMOS][MAX_DEMONAME];
424 // the actively playing demo (set by CL_PlayDemo_f)
427 // demo recording info must be here, because record is started before
428 // entering a map (and clearing client_state_t)
429 qboolean demorecording;
430 qboolean demoplayback;
432 // -1 = use normal cd track
435 // to meter out one message a frame
437 // host_framecount at start
439 // realtime at second frame of timedemo (LordHavoc: changed to double)
441 // LordHavoc: for measuring maxfps
442 double td_minframetime;
443 // LordHavoc: for measuring minfps
444 double td_maxframetime;
445 // LordHavoc: pausedemo
448 qboolean connect_trying;
449 int connect_remainingtries;
450 double connect_nextsendtime;
451 lhnetsocket_t *connect_mysocket;
452 lhnetaddress_t connect_address;
454 // connection information
457 // network connection
459 // writing buffer to send to server
461 unsigned char message_buf[1024];
465 extern client_static_t cls;
467 typedef struct client_movementqueue_s
477 client_movementqueue_t;
480 // the client_state_t structure is wiped completely at every
483 typedef struct client_state_s
485 // true if playing in a local game and no one else is connected
488 // when connecting to the server throw out the first couple move messages
489 // so the player doesn't accidentally do something the first frame
492 // send a clc_nop periodically until connected
495 // current input to send to the server
498 // information for local display
500 int stats[MAX_CL_STATS];
501 // last known inventory bit flags, for blinking
503 // cl.time of acquiring item, for blinking
504 float item_gettime[32];
505 // last known STAT_ACTIVEWEAPON
507 // cl.time of changing STAT_ACTIVEWEAPON
509 // use pain anim frame if cl.time < this
512 // color shifts for damage, powerups
513 cshift_t cshifts[NUM_CSHIFTS];
515 cshift_t prev_cshifts[NUM_CSHIFTS];
517 // the client maintains its own idea of view angles, which are
518 // sent to the server each frame. The server sets punchangle when
519 // the view is temporarily offset, and an angle reset commands at the start
520 // of each level and after teleporting.
522 // mviewangles is read from demo
523 // viewangles is either client controlled or lerped from mviewangles
524 vec3_t mviewangles[2], viewangles;
525 // update by server, used by qc to do weapon recoil
526 vec3_t mpunchangle[2], punchangle;
527 // update by server, can be used by mods to kick view around
528 vec3_t mpunchvector[2], punchvector;
529 // update by server, used for lean+bob (0 is newest)
530 vec3_t mvelocity[2], velocity;
531 // update by server, can be used by mods for zooming
532 vec_t mviewzoom[2], viewzoom;
534 // client movement simulation
535 // these fields are only updated by CL_ClientMovement (called by CL_SendMove after parsing each network packet)
537 // indicates the queue has been updated and should be replayed
538 qboolean movement_replay;
539 // simulated data (this is valid even if cl.movement is false)
540 vec3_t movement_origin;
541 vec3_t movement_oldorigin;
542 vec3_t movement_velocity;
543 // queue of proposed moves
544 int movement_numqueue;
545 client_movementqueue_t movement_queue[64];
547 int servermovesequence;
549 // pitch drifting vars
556 // local amount for smoothing stepups
565 qboolean oldonground;
566 double lastongroundtime;
567 double hitgroundtime;
569 // don't change view angle, full screen, etc
571 // latched at intermission start
574 // the timestamp of the last two messages
577 // clients view of time, time should be between mtime[0] and mtime[1] to
578 // generate a lerp point for other data, oldtime is the previous frame's
579 // value of time, frametime is the difference between time and oldtime
580 double time, oldtime, frametime;
582 // copy of realtime from last recieved message, for net trouble icon
583 float last_received_message;
585 // information that is static for the entire time connected to a server
586 struct model_s *model_precache[MAX_MODELS];
587 struct sfx_s *sound_precache[MAX_SOUNDS];
589 // for display on solo scoreboard
591 // cl_entitites[cl.viewentity] = player
593 // the real player entity (normally same as viewentity,
594 // different than viewentity if mod uses chasecam or other tricks)
596 // max players that can be in this game
598 // type of game (deathmatch, coop, singleplayer)
601 // models and sounds used by engine code (particularly cl_parse.c)
603 model_t *model_bolt2;
604 model_t *model_bolt3;
607 sfx_t *sfx_knighthit;
614 // refresh related state
616 // cl_entitites[0].model
617 struct model_s *worldmodel;
623 int cdtrack, looptrack;
628 scoreboard_t *scores;
630 // protocol version of the server we're connected to
631 protocolversion_t protocol;
633 // entity database stuff
634 // latest received entity frame numbers
635 #define LATESTFRAMENUMS 3
636 int latestframenums[LATESTFRAMENUMS];
637 entityframe_database_t *entitydatabase;
638 entityframe4_database_t *entitydatabase4;
645 extern cvar_t cl_name;
646 extern cvar_t cl_color;
647 extern cvar_t cl_rate;
648 extern cvar_t cl_pmodel;
649 extern cvar_t cl_playermodel;
650 extern cvar_t cl_playerskin;
652 extern cvar_t cl_upspeed;
653 extern cvar_t cl_forwardspeed;
654 extern cvar_t cl_backspeed;
655 extern cvar_t cl_sidespeed;
657 extern cvar_t cl_movespeedkey;
659 extern cvar_t cl_yawspeed;
660 extern cvar_t cl_pitchspeed;
662 extern cvar_t cl_anglespeedkey;
664 extern cvar_t cl_autofire;
666 extern cvar_t cl_shownet;
667 extern cvar_t cl_nolerp;
669 extern cvar_t cl_pitchdriftspeed;
670 extern cvar_t lookspring;
671 extern cvar_t lookstrafe;
672 extern cvar_t sensitivity;
674 extern cvar_t freelook;
676 extern cvar_t m_pitch;
678 extern cvar_t m_forward;
679 extern cvar_t m_side;
681 extern cvar_t r_draweffects;
683 extern cvar_t cl_explosions_alpha_start;
684 extern cvar_t cl_explosions_alpha_end;
685 extern cvar_t cl_explosions_size_start;
686 extern cvar_t cl_explosions_size_end;
687 extern cvar_t cl_explosions_lifetime;
688 extern cvar_t cl_stainmaps;
689 extern cvar_t cl_stainmaps_clearonload;
691 extern cvar_t cl_prydoncursor;
693 extern vec3_t cl_playerstandmins;
694 extern vec3_t cl_playerstandmaxs;
695 extern vec3_t cl_playercrouchmins;
696 extern vec3_t cl_playercrouchmaxs;
698 // these are updated by CL_ClearState
699 extern int cl_num_entities;
700 extern int cl_num_static_entities;
701 extern int cl_num_temp_entities;
702 extern int cl_num_brushmodel_entities;
704 extern mempool_t *cl_mempool;
705 extern entity_t *cl_entities;
706 extern unsigned char *cl_entities_active;
707 extern entity_t *cl_static_entities;
708 extern entity_t *cl_temp_entities;
709 extern int *cl_brushmodel_entities;
710 extern cl_effect_t *cl_effects;
711 extern beam_t *cl_beams;
712 extern dlight_t *cl_dlights;
713 extern lightstyle_t *cl_lightstyle;
716 extern client_state_t cl;
718 extern void CL_AllocDlight (entity_render_t *ent, matrix4x4_t *matrix, float radius, float red, float green, float blue, float decay, float lifetime, int cubemapnum, int style, int shadowenable, vec_t corona, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags);
720 //=============================================================================
726 void CL_Shutdown (void);
729 void CL_EstablishConnection(const char *host);
731 void CL_Disconnect (void);
732 void CL_Disconnect_f (void);
734 void CL_BoundingBoxForEntity(entity_render_t *ent);
736 extern cvar_t cl_beams_polygons;
737 extern cvar_t cl_beams_relative;
738 extern cvar_t cl_beams_lightatend;
743 typedef struct kbutton_s
745 int down[2]; // key nums holding it down
746 int state; // low bit is down state
750 extern kbutton_t in_mlook, in_klook;
751 extern kbutton_t in_strafe;
752 extern kbutton_t in_speed;
754 void CL_InitInput (void);
755 void CL_SendCmd (void);
756 void CL_SendMove (void);
758 void CL_ValidateState(entity_state_t *s);
759 void CL_MoveLerpEntityStates(entity_t *ent);
760 void CL_LerpUpdate(entity_t *e);
761 void CL_ParseTEnt (void);
762 void CL_RelinkBeams (void);
764 void CL_ClearTempEntities (void);
765 entity_t *CL_NewTempEntity (void);
767 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate);
769 void CL_ClearState (void);
770 void CL_ExpandEntities(int num);
773 int CL_ReadFromServer (void);
774 void CL_WriteToServer (void);
776 extern qboolean cl_ignoremousemove;
779 float CL_KeyState (kbutton_t *key);
780 const char *Key_KeynumToString (int keynum);
781 int Key_StringToKeynum (const char *str);
786 void CL_StopPlayback(void);
787 void CL_ReadDemoMessage(void);
788 void CL_WriteDemoMessage(void);
790 void CL_NextDemo(void);
791 void CL_Stop_f(void);
792 void CL_Record_f(void);
793 void CL_PlayDemo_f(void);
794 void CL_TimeDemo_f(void);
799 void CL_Parse_Init(void);
800 void CL_Parse_Shutdown(void);
801 void CL_ParseServerMessage(void);
802 void CL_Parse_DumpPacket(void);
807 void V_StartPitchDrift (void);
808 void V_StopPitchDrift (void);
811 float V_CalcRoll (vec3_t angles, vec3_t velocity);
812 void V_UpdateBlends (void);
813 void V_ParseDamage (void);
819 extern cvar_t cl_particles;
820 extern cvar_t cl_particles_quality;
821 extern cvar_t cl_particles_size;
822 extern cvar_t cl_particles_quake;
823 extern cvar_t cl_particles_bloodshowers;
824 extern cvar_t cl_particles_blood;
825 extern cvar_t cl_particles_blood_alpha;
826 extern cvar_t cl_particles_blood_bloodhack;
827 extern cvar_t cl_particles_bulletimpacts;
828 extern cvar_t cl_particles_explosions_bubbles;
829 extern cvar_t cl_particles_explosions_smoke;
830 extern cvar_t cl_particles_explosions_sparks;
831 extern cvar_t cl_particles_explosions_shell;
832 extern cvar_t cl_particles_smoke;
833 extern cvar_t cl_particles_smoke_alpha;
834 extern cvar_t cl_particles_smoke_alphafade;
835 extern cvar_t cl_particles_sparks;
836 extern cvar_t cl_particles_bubbles;
837 extern cvar_t cl_decals;
838 extern cvar_t cl_decals_time;
839 extern cvar_t cl_decals_fadetime;
841 void CL_Particles_Clear(void);
842 void CL_Particles_Init(void);
843 void CL_Particles_Shutdown(void);
845 void CL_ParseParticleEffect (void);
846 void CL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count);
847 void CL_RocketTrail (vec3_t start, vec3_t end, int type, int color, entity_t *ent);
848 void CL_SparkShower (vec3_t org, vec3_t dir, int count, vec_t gravityscale);
849 void CL_Smoke (vec3_t org, vec3_t dir, int count);
850 void CL_BulletMark (vec3_t org);
851 void CL_PlasmaBurn (vec3_t org);
852 void CL_BloodPuff (vec3_t org, vec3_t vel, int count);
853 void CL_Stardust (vec3_t mins, vec3_t maxs, int count);
854 void CL_FlameCube (vec3_t mins, vec3_t maxs, int count);
855 void CL_Flames (vec3_t org, vec3_t vel, int count);
856 void CL_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count);
857 void CL_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel);
858 void CL_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type);
859 void CL_EntityParticles (entity_t *ent);
860 void CL_BlobExplosion (vec3_t org);
861 void CL_ParticleExplosion (vec3_t org);
862 void CL_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength);
863 void CL_LavaSplash (vec3_t org);
864 void CL_TeleportSplash (vec3_t org);
865 void CL_BeamParticle (const vec3_t start, const vec3_t end, vec_t radius, float red, float green, float blue, float alpha, float lifetime);
866 void CL_Tei_Smoke(const vec3_t pos, const vec3_t dir, int count);
867 void CL_Tei_PlasmaHit(const vec3_t pos, const vec3_t dir, int count);
868 void CL_MoveParticles(void);
869 void R_MoveExplosions(void);
870 void R_NewExplosion(vec3_t org);
872 #include "cl_screen.h"
874 typedef struct refdef_s
877 int x, y, width, height;
878 float frustum_x, frustum_y;
880 // these are set for water warping before
881 // frustum_x/frustum_y are calculated
882 float frustumscale_x, frustumscale_y;
885 matrix4x4_t viewentitymatrix;
887 // which color components to allow (for anaglyph glasses)
890 // fullscreen color blend
893 // whether to call S_ExtraUpdate during render to reduce sound chop
894 qboolean extraupdate;
896 // client gameworld time for rendering time based effects
900 entity_render_t *worldentity;
902 // same as worldentity->model
905 // renderable entities (excluding world)
906 entity_render_t **entities;
910 // renderable dynamic lights
911 dlight_t *lights[MAX_DLIGHTS];
914 // 8.8bit fixed point intensities for light styles
915 // controls intensity of dynamic lights and lightmap layers
916 unsigned short lightstylevalue[256]; // 8.8 fraction of base light value
918 // 2D art drawing queue
919 // TODO: get rid of this
920 unsigned char *drawqueue;
922 int maxdrawqueuesize;
926 extern refdef_t r_refdef;