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