]> icculus.org git repositories - divverent/darkplaces.git/blob - client.h
more documentation on B-Splines
[divverent/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
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
33
34 extern int cl_max_entities;
35 extern int cl_max_static_entities;
36 extern int cl_max_temp_entities;
37 extern int cl_max_effects;
38 extern int cl_max_beams;
39
40 typedef struct effect_s
41 {
42         int active;
43         vec3_t origin;
44         float starttime;
45         float framerate;
46         int modelindex;
47         int startframe;
48         int endframe;
49         // these are for interpolation
50         int frame;
51         double frame1time;
52         double frame2time;
53 }
54 cl_effect_t;
55
56 typedef struct
57 {
58         int             entity;
59         // draw this as lightning polygons, or a model?
60         int             lightning;
61         struct model_s  *model;
62         float   endtime;
63         vec3_t  start, end;
64         // if this beam is owned by an entity, this is the beam start relative to
65         // that entity's matrix for per frame start updates
66         vec3_t  relativestart;
67         vec3_t  relativeend;
68         // indicates whether relativestart is valid
69         int     relativestartvalid;
70 }
71 beam_t;
72
73 typedef struct rtlight_s
74 {
75         // shadow volumes are done entirely in model space, so there are no matrices for dealing with them...  they just use the origin 
76
77         // note that the world to light matrices are inversely scaled (divided) by lightradius
78
79         // core properties
80         // matrix for transforming world coordinates to light filter coordinates
81         matrix4x4_t matrix_worldtolight;
82         // based on worldtolight this transforms -1 to +1 to 0 to 1 for purposes
83         // of attenuation texturing in full 3D (Z result often ignored)
84         matrix4x4_t matrix_worldtoattenuationxyz;
85         // this transforms only the Z to S, and T is always 0.5
86         matrix4x4_t matrix_worldtoattenuationz;
87         // typically 1 1 1, can be lower (dim) or higher (overbright)
88         vec3_t color;
89         // size of the light (remove?)
90         vec_t radius;
91         // light filter
92         char cubemapname[64];
93         // whether light should render shadows
94         int shadow;
95         // intensity of corona to render
96         vec_t corona;
97         // light style to monitor for brightness
98         int style;
99         
100         // generated properties
101         // used only for shadow volumes
102         vec3_t shadoworigin;
103         // culling
104         vec3_t cullmins;
105         vec3_t cullmaxs;
106         // culling
107         //vec_t cullradius;
108         // squared cullradius
109         //vec_t cullradius2;
110
111         // lightmap renderer stuff (remove someday!)
112         // the size of the light
113         vec_t lightmap_cullradius;
114         // the size of the light, squared
115         vec_t lightmap_cullradius2;
116         // the brightness of the light
117         vec3_t lightmap_light;
118         // to avoid sudden brightness change at cullradius, subtract this
119         vec_t lightmap_subtract;
120
121         // static light info
122         // true if this light should be compiled as a static light
123         int isstatic;
124         // true if this is a compiled world light, cleared if the light changes
125         int compiled;
126         // premade shadow volumes and lit surfaces to render for world entity
127         shadowmesh_t *static_meshchain_shadow;
128         shadowmesh_t *static_meshchain_light;
129         // used for visibility testing (more exact than bbox)
130         int static_numclusters;
131         int static_numclusterpvsbytes;
132         int *static_clusterlist;
133         qbyte *static_clusterpvs;
134 }
135 rtlight_t;
136
137 typedef struct dlight_s
138 {
139         // destroy light after this time
140         // (dlight only)
141         vec_t die;
142         // the entity that owns this light (can be NULL)
143         // (dlight only)
144         struct entity_render_s *ent;
145         // location
146         // (worldlight: saved to .rtlights file)
147         vec3_t origin;
148         // worldlight orientation
149         // (worldlight only)
150         // (worldlight: saved to .rtlights file)
151         vec3_t angles;
152         // dlight orientation/scaling/location
153         // (dlight only)
154         matrix4x4_t matrix;
155         // color of light
156         // (worldlight: saved to .rtlights file)
157         vec3_t color;
158         // cubemap number to use on this light
159         // (dlight only)
160         int cubemapnum;
161         // cubemap name to use on this light
162         // (worldlight only)
163         // (worldlight: saved to .rtlights file)
164         char cubemapname[64];
165         // make light flash while selected
166         // (worldlight only)
167         int selected;
168         // brightness (not really radius anymore)
169         // (worldlight: saved to .rtlights file)
170         vec_t radius;
171         // drop radius this much each second
172         // (dlight only)
173         vec_t decay;
174         // light style which controls intensity of this light
175         // (worldlight: saved to .rtlights file)
176         int style;
177         // cast shadows
178         // (worldlight: saved to .rtlights file)
179         int shadow;
180         // corona intensity
181         // (worldlight: saved to .rtlights file)
182         vec_t corona;
183         // linked list of world lights
184         // (worldlight only)
185         struct dlight_s *next;
186         // embedded rtlight struct for renderer
187         // (renderer only)      
188         rtlight_t rtlight;
189 }
190 dlight_t;
191
192 typedef struct frameblend_s
193 {
194         int frame;
195         float lerp;
196 }
197 frameblend_t;
198
199 // LordHavoc: this struct is intended for the renderer but some fields are
200 // used by the client.
201 typedef struct entity_render_s
202 {
203         // location
204         vec3_t origin;
205         // orientation
206         vec3_t angles;
207         // transform matrix for model to world
208         matrix4x4_t matrix;
209         // transform matrix for world to model
210         matrix4x4_t inversematrix;
211         // opacity (alpha) of the model
212         float alpha;
213         // size the model is shown
214         float scale;
215
216         // NULL = no model
217         model_t *model;
218         // current uninterpolated animation frame (for things which do not use interpolation)
219         int frame;
220         // entity shirt and pants colors
221         int colormap;
222         // light, particles, etc
223         int effects;
224         // for Alias models
225         int skinnum;
226         // render flags
227         int flags;
228
229         // interpolated animation
230
231         // frame that the model is interpolating from
232         int frame1;
233         // frame that the model is interpolating to
234         int frame2;
235         // interpolation factor, usually computed from frame2time
236         float framelerp;
237         // time frame1 began playing (for framegroup animations)
238         double frame1time;
239         // time frame2 began playing (for framegroup animations)
240         double frame2time;
241
242         // calculated by the renderer (but not persistent)
243
244         // if visframe == r_framecount, it is visible
245         int visframe;
246         // calculated during R_AddModelEntities
247         vec3_t mins, maxs;
248         // 4 frame numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use frame instead
249         frameblend_t frameblend[4];
250
251         // caching results of static light traces (this is semi-persistent)
252         double entlightstime;
253         vec3_t entlightsorigin;
254         int entlightsframe;
255         int numentlights;
256         unsigned short entlights[MAXENTLIGHTS];
257 }
258 entity_render_t;
259
260 typedef struct entity_persistent_s
261 {
262         int linkframe;
263
264         vec3_t trail_origin;
265
266         // particle trail
267         float trail_time;
268
269         // muzzleflash fading
270         float muzzleflash;
271
272         // interpolated movement
273
274         // start time of move
275         float lerpstarttime;
276         // time difference from start to end of move
277         float lerpdeltatime;
278         // the move itself, start and end
279         float oldorigin[3];
280         float oldangles[3];
281         float neworigin[3];
282         float newangles[3];
283 }
284 entity_persistent_t;
285
286 typedef struct entity_s
287 {
288         // baseline state (default values)
289         entity_state_t state_baseline;
290         // previous state (interpolating from this)
291         entity_state_t state_previous;
292         // current state (interpolating to this)
293         entity_state_t state_current;
294
295         // used for regenerating parts of render
296         entity_persistent_t persistent;
297
298         // the only data the renderer should know about
299         entity_render_t render;
300 }
301 entity_t;
302
303 typedef struct
304 {
305         vec3_t  viewangles;
306
307 // intended velocities
308         float   forwardmove;
309         float   sidemove;
310         float   upmove;
311 } usercmd_t;
312
313 typedef struct
314 {
315         int             length;
316         char    map[MAX_STYLESTRING];
317 } lightstyle_t;
318
319 typedef struct
320 {
321         char    name[MAX_SCOREBOARDNAME];
322         int             frags;
323         int             colors; // two 4 bit fields
324 } scoreboard_t;
325
326 typedef struct
327 {
328         int             destcolor[3];
329         int             percent;                // 0-256
330 } cshift_t;
331
332 #define CSHIFT_CONTENTS 0
333 #define CSHIFT_DAMAGE   1
334 #define CSHIFT_BONUS    2
335 #define CSHIFT_POWERUP  3
336 #define CSHIFT_VCSHIFT  4
337 #define NUM_CSHIFTS             5
338
339 #define NAME_LENGTH     64
340
341
342 //
343 // client_state_t should hold all pieces of the client state
344 //
345
346 #define SIGNONS         4                       // signon messages to receive before connected
347
348 #define MAX_DEMOS               8
349 #define MAX_DEMONAME    16
350
351 typedef enum
352 {
353         ca_dedicated,           // a dedicated server with no ability to start a client
354         ca_disconnected,        // full screen console with no connection
355         ca_connected            // valid netcon, talking to a server
356 }
357 cactive_t;
358
359 //
360 // the client_static_t structure is persistent through an arbitrary number
361 // of server connections
362 //
363 typedef struct
364 {
365         cactive_t state;
366
367 // demo loop control
368         // -1 = don't play demos
369         int demonum;
370         // list of demos in loop
371         char demos[MAX_DEMOS][MAX_DEMONAME];
372         // the actively playing demo (set by CL_PlayDemo_f)
373         char demoname[64];
374
375 // demo recording info must be here, because record is started before
376 // entering a map (and clearing client_state_t)
377         qboolean demorecording;
378         qboolean demoplayback;
379         qboolean timedemo;
380         // -1 = use normal cd track
381         int forcetrack;
382         qfile_t *demofile;
383         // to meter out one message a frame
384         int td_lastframe;
385         // host_framecount at start
386         int td_startframe;
387         // realtime at second frame of timedemo (LordHavoc: changed to double)
388         double td_starttime;
389         // LordHavoc: for measuring maxfps
390         double td_minframetime;
391         // LordHavoc: for measuring minfps
392         double td_maxframetime;
393         // LordHavoc: pausedemo
394         qboolean demopaused;
395
396         qboolean connect_trying;
397         int connect_remainingtries;
398         double connect_nextsendtime;
399         lhnetsocket_t *connect_mysocket;
400         lhnetaddress_t connect_address;
401
402 // connection information
403         // 0 to SIGNONS
404         int signon;
405         // network connection
406         netconn_t *netcon;
407         // writing buffer to send to server
408         sizebuf_t message;
409 }
410 client_static_t;
411
412 extern client_static_t  cls;
413
414 //
415 // the client_state_t structure is wiped completely at every
416 // server signon
417 //
418 typedef struct
419 {
420         // true if playing in a local game and no one else is connected
421         int islocalgame;
422
423         // when connecting to the server throw out the first couple move messages
424         // so the player doesn't accidentally do something the first frame
425         int movemessages;
426
427         // send a clc_nop periodically until connected
428         float sendnoptime;
429
430         // last command sent to the server
431         usercmd_t cmd;
432
433 // information for local display
434         // health, etc
435         int stats[MAX_CL_STATS];
436         // inventory bit flags
437         int items;
438         // cl.time of acquiring item, for blinking
439         float item_gettime[32];
440         // cl.time of changing STAT_ACTIVEWEAPON
441         float weapontime;
442         // use pain anim frame if cl.time < this
443         float faceanimtime;
444
445         // color shifts for damage, powerups
446         cshift_t cshifts[NUM_CSHIFTS];
447         // and content types
448         cshift_t prev_cshifts[NUM_CSHIFTS];
449
450 // the client maintains its own idea of view angles, which are
451 // sent to the server each frame.  The server sets punchangle when
452 // the view is temporarily offset, and an angle reset commands at the start
453 // of each level and after teleporting.
454
455         // during demo playback viewangles is lerped between these
456         vec3_t mviewangles[2];
457         // either client controlled, or lerped from demo mviewangles
458         vec3_t viewangles;
459
460         // update by server, used for lean+bob (0 is newest)
461         vec3_t mvelocity[2];
462         // lerped between mvelocity[0] and [1]
463         vec3_t velocity;
464
465         // temporary offset
466         vec3_t punchangle;
467         // LordHavoc: origin view kick
468         vec3_t punchvector;
469
470 // pitch drifting vars
471         float idealpitch;
472         float pitchvel;
473         qboolean nodrift;
474         float driftmove;
475         double laststop;
476
477         float viewheight;
478         // local amount for smoothing stepups
479         //float crouch;
480
481         // sent by server
482         qboolean paused;
483         qboolean onground;
484         qboolean inwater;
485
486         // don't change view angle, full screen, etc
487         int intermission;
488         // latched at intermission start
489         int completed_time;
490
491         // the timestamp of the last two messages
492         double mtime[2];
493
494         // clients view of time, time should be between mtime[0] and mtime[1] to
495         // generate a lerp point for other data, oldtime is the previous frame's
496         // value of time, frametime is the difference between time and oldtime
497         double time, oldtime, frametime;
498
499         // copy of realtime from last recieved message, for net trouble icon
500         float last_received_message;
501
502 // information that is static for the entire time connected to a server
503         struct model_s *model_precache[MAX_MODELS];
504         struct sfx_s *sound_precache[MAX_SOUNDS];
505
506         // for display on solo scoreboard
507         char levelname[40];
508         // cl_entitites[cl.viewentity] = player
509         int viewentity;
510         // the real player entity (normally same as viewentity,
511         // different than viewentity if mod uses chasecam or other tricks)
512         int playerentity;
513         // max players that can be in this game
514         int maxclients;
515         // type of game (deathmatch, coop, singleplayer)
516         int gametype;
517
518 // refresh related state
519
520         // cl_entitites[0].model
521         struct model_s *worldmodel;
522
523         // the gun model
524         entity_t viewent;
525
526         // cd audio
527         int cdtrack, looptrack;
528
529 // frag scoreboard
530
531         // [cl.maxclients]
532         scoreboard_t *scores;
533
534         // LordHavoc: sniping zoom, QC controlled
535         float viewzoom;
536         // for interpolation
537         float viewzoomold, viewzoomnew;
538
539         // protocol version of the server we're connected to
540         int protocol;
541
542         // entity database stuff
543         entity_database_t entitydatabase;
544         entity_database4_t *entitydatabase4;
545 }
546 client_state_t;
547
548 extern mempool_t *cl_scores_mempool;
549
550 //
551 // cvars
552 //
553 extern cvar_t cl_name;
554 extern cvar_t cl_color;
555 extern cvar_t cl_rate;
556 extern cvar_t cl_pmodel;
557
558 extern cvar_t cl_upspeed;
559 extern cvar_t cl_forwardspeed;
560 extern cvar_t cl_backspeed;
561 extern cvar_t cl_sidespeed;
562
563 extern cvar_t cl_movespeedkey;
564
565 extern cvar_t cl_yawspeed;
566 extern cvar_t cl_pitchspeed;
567
568 extern cvar_t cl_anglespeedkey;
569
570 extern cvar_t cl_autofire;
571
572 extern cvar_t cl_shownet;
573 extern cvar_t cl_nolerp;
574
575 extern cvar_t cl_pitchdriftspeed;
576 extern cvar_t lookspring;
577 extern cvar_t lookstrafe;
578 extern cvar_t sensitivity;
579
580 extern cvar_t freelook;
581
582 extern cvar_t m_pitch;
583 extern cvar_t m_yaw;
584 extern cvar_t m_forward;
585 extern cvar_t m_side;
586
587 extern cvar_t r_draweffects;
588
589 extern cvar_t cl_explosions;
590 extern cvar_t cl_explosions_alpha_start;
591 extern cvar_t cl_explosions_alpha_end;
592 extern cvar_t cl_explosions_size_start;
593 extern cvar_t cl_explosions_size_end;
594 extern cvar_t cl_explosions_lifetime;
595 extern cvar_t cl_stainmaps;
596
597 // these are updated by CL_ClearState
598 extern int cl_num_entities;
599 extern int cl_num_static_entities;
600 extern int cl_num_temp_entities;
601 extern int cl_num_brushmodel_entities;
602
603 extern entity_t *cl_entities;
604 extern qbyte *cl_entities_active;
605 extern entity_t *cl_static_entities;
606 extern entity_t *cl_temp_entities;
607 extern entity_render_t **cl_brushmodel_entities;
608 extern cl_effect_t *cl_effects;
609 extern beam_t *cl_beams;
610 extern dlight_t *cl_dlights;
611 extern lightstyle_t *cl_lightstyle;
612
613
614 extern client_state_t cl;
615
616 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);
617 extern void CL_DecayLights (void);
618
619 //=============================================================================
620
621 //
622 // cl_main
623 //
624
625 void CL_Init (void);
626
627 void CL_EstablishConnection(const char *host);
628
629 void CL_Disconnect (void);
630 void CL_Disconnect_f (void);
631
632 void CL_BoundingBoxForEntity(entity_render_t *ent);
633
634 extern cvar_t cl_beams_polygons;
635 extern cvar_t cl_beams_relative;
636 extern cvar_t cl_beams_lightatend;
637
638 //
639 // cl_input
640 //
641 typedef struct
642 {
643         int             down[2];                // key nums holding it down
644         int             state;                  // low bit is down state
645 }
646 kbutton_t;
647
648 extern  kbutton_t       in_mlook, in_klook;
649 extern  kbutton_t       in_strafe;
650 extern  kbutton_t       in_speed;
651
652 void CL_InitInput (void);
653 void CL_SendCmd (usercmd_t *cmd);
654 void CL_SendMove (usercmd_t *cmd);
655
656 void CL_LerpUpdate(entity_t *e);
657 void CL_ParseTEnt (void);
658 void CL_RelinkBeams (void);
659
660 void CL_ClearTempEntities (void);
661 entity_t *CL_NewTempEntity (void);
662
663 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate);
664
665 void CL_ClearState (void);
666
667
668 int  CL_ReadFromServer (void);
669 void CL_WriteToServer (usercmd_t *cmd);
670 void CL_BaseMove (usercmd_t *cmd);
671
672
673 float CL_KeyState (kbutton_t *key);
674 const char *Key_KeynumToString (int keynum);
675
676 //
677 // cl_demo.c
678 //
679 void CL_StopPlayback(void);
680 void CL_ReadDemoMessage(void);
681 void CL_WriteDemoMessage(void);
682
683 void CL_NextDemo(void);
684 void CL_Stop_f(void);
685 void CL_Record_f(void);
686 void CL_PlayDemo_f(void);
687 void CL_TimeDemo_f(void);
688
689 //
690 // cl_parse.c
691 //
692 void CL_Parse_Init(void);
693 void CL_ParseServerMessage(void);
694 void CL_Parse_DumpPacket(void);
695
696 //
697 // view
698 //
699 void V_StartPitchDrift (void);
700 void V_StopPitchDrift (void);
701
702 void V_Init (void);
703 float V_CalcRoll (vec3_t angles, vec3_t velocity);
704 void V_UpdateBlends (void);
705 void V_ParseDamage (void);
706
707
708 //
709 // cl_tent
710 //
711 void CL_InitTEnts (void);
712
713 //
714 // cl_part
715 //
716
717 void CL_Particles_Clear(void);
718 void CL_Particles_Init(void);
719
720 void CL_ParseParticleEffect (void);
721 void CL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count);
722 void CL_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent);
723 void CL_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
724 void CL_SparkShower (vec3_t org, vec3_t dir, int count);
725 void CL_PlasmaBurn (vec3_t org);
726 void CL_BloodPuff (vec3_t org, vec3_t vel, int count);
727 void CL_Stardust (vec3_t mins, vec3_t maxs, int count);
728 void CL_FlameCube (vec3_t mins, vec3_t maxs, int count);
729 void CL_Flames (vec3_t org, vec3_t vel, int count);
730 void CL_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count);
731 void CL_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel);
732 void CL_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type);
733 void CL_EntityParticles (entity_t *ent);
734 void CL_BlobExplosion (vec3_t org);
735 void CL_ParticleExplosion (vec3_t org);
736 void CL_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength);
737 void CL_LavaSplash (vec3_t org);
738 void CL_TeleportSplash (vec3_t org);
739 void CL_BeamParticle (const vec3_t start, const vec3_t end, vec_t radius, float red, float green, float blue, float alpha, float lifetime);
740 void CL_Tei_Smoke(const vec3_t pos, const vec3_t dir, int count);
741 void CL_Tei_PlasmaHit(const vec3_t pos, const vec3_t dir, int count);
742 void CL_MoveParticles(void);
743 void R_MoveExplosions(void);
744 void R_NewExplosion(vec3_t org);
745
746 #include "cl_screen.h"
747
748 typedef struct
749 {
750         // area to render in
751         int x, y, width, height;
752         float fov_x, fov_y;
753
754         // these are set for water warping before
755         // fov_x/fov_y are calculated
756         float fovscale_x, fovscale_y;
757
758         // view transform
759         matrix4x4_t viewentitymatrix;
760
761         // which color components to allow (for anaglyph glasses)
762         int colormask[4];
763
764         // fullscreen color blend
765         float viewblend[4];
766
767         entity_render_t **entities;
768         int numentities;
769         int maxentities;
770
771         qbyte *drawqueue;
772         int drawqueuesize;
773         int maxdrawqueuesize;
774 }
775 refdef_t;
776
777 refdef_t r_refdef;
778
779 extern mempool_t *cl_refdef_mempool;
780
781 #include "cgamevm.h"
782
783 #endif
784