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