]> icculus.org git repositories - divverent/darkplaces.git/blob - client.h
slight simplification of fog layer in alias skins
[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         float   die;
79         // color of light
80         vec3_t  color;
81         // brightness (not really radius anymore)
82         float   radius;
83         // drop this each second
84         float   decay;
85         // the entity that owns this light (can be NULL)
86         struct entity_render_s *ent;
87 }
88 dlight_t;
89
90 typedef struct frameblend_s
91 {
92         int frame;
93         float lerp;
94 }
95 frameblend_t;
96
97 // LordHavoc: disregard the following warning, entlights stuff is semi-persistent...
98 // LordHavoc: nothing in this structure is persistent, it may be overwritten by the client every frame, for persistent data use entity_lerp_t.
99 typedef struct entity_render_s
100 {
101         // location
102         vec3_t origin;
103         // orientation
104         vec3_t angles;
105         // transform matrix for model to world
106         matrix4x4_t matrix;
107         // transform matrix for world to model
108         matrix4x4_t inversematrix;
109         // opacity (alpha) of the model
110         float alpha;
111         // size the model is shown
112         float scale;
113
114         // NULL = no model
115         model_t *model;
116         // current uninterpolated animation frame (for things which do not use interpolation)
117         int frame;
118         // entity shirt and pants colors
119         int colormap;
120         // light, particles, etc
121         int effects;
122         // for Alias models
123         int skinnum;
124         // render flags
125         int flags;
126
127         // these are copied from the persistent data
128
129         // frame that the model is interpolating from
130         int frame1;
131         // frame that the model is interpolating to
132         int frame2;
133         // interpolation factor, usually computed from frame2time
134         double framelerp;
135         // time frame1 began playing (for framegroup animations)
136         double frame1time;
137         // time frame2 began playing (for framegroup animations)
138         double frame2time;
139
140         // calculated by the renderer (but not persistent)
141
142         // if visframe == r_framecount, it is visible
143         int visframe;
144         // calculated during R_AddModelEntities
145         vec3_t mins, maxs;
146         // 4 frame numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use frame instead
147         frameblend_t frameblend[4];
148
149         // caching results of static light traces (this is semi-persistent)
150         double entlightstime;
151         vec3_t entlightsorigin;
152         int entlightsframe;
153         int numentlights;
154         unsigned short entlights[MAXENTLIGHTS];
155 }
156 entity_render_t;
157
158 typedef struct entity_persistent_s
159 {
160         // particles
161
162         // trail rendering
163         vec3_t trail_origin;
164         float trail_time;
165
166         // effects
167
168         // muzzleflash fading
169         float muzzleflash;
170
171         // interpolated movement
172
173         // start time of move
174         float lerpstarttime;
175         // time difference from start to end of move
176         float lerpdeltatime;
177         // the move itself, start and end
178         float oldorigin[3];
179         float oldangles[3];
180         float neworigin[3];
181         float newangles[3];
182
183         // interpolated animation
184
185         // lerp resets when model changes
186         int modelindex;
187         // frame that the model is interpolating from
188         int frame1;
189         // frame that the model is interpolating to
190         int frame2;
191         // interpolation factor, usually computed from frame2time
192         double framelerp;
193         // time frame1 began playing (for framegroup animations)
194         double frame1time;
195         // time frame2 began playing (for framegroup animations)
196         double frame2time;
197 }
198 entity_persistent_t;
199
200 typedef struct entity_s
201 {
202         // baseline state (default values)
203         entity_state_t state_baseline;
204         // previous state (interpolating from this)
205         entity_state_t state_previous;
206         // current state (interpolating to this)
207         entity_state_t state_current;
208
209         // used for regenerating parts of render
210         entity_persistent_t persistent;
211
212         // the only data the renderer should know about
213         entity_render_t render;
214 }
215 entity_t;
216
217 typedef struct
218 {
219         vec3_t  viewangles;
220
221 // intended velocities
222         float   forwardmove;
223         float   sidemove;
224         float   upmove;
225 } usercmd_t;
226
227 typedef struct
228 {
229         int             length;
230         char    map[MAX_STYLESTRING];
231 } lightstyle_t;
232
233 typedef struct
234 {
235         char    name[MAX_SCOREBOARDNAME];
236         int             frags;
237         int             colors; // two 4 bit fields
238 } scoreboard_t;
239
240 typedef struct
241 {
242         int             destcolor[3];
243         int             percent;                // 0-256
244 } cshift_t;
245
246 #define CSHIFT_CONTENTS 0
247 #define CSHIFT_DAMAGE   1
248 #define CSHIFT_BONUS    2
249 #define CSHIFT_POWERUP  3
250 #define NUM_CSHIFTS             4
251
252 #define NAME_LENGTH     64
253
254
255 //
256 // client_state_t should hold all pieces of the client state
257 //
258
259 #define SIGNONS         4                       // signon messages to receive before connected
260
261 #define MAX_DEMOS               8
262 #define MAX_DEMONAME    16
263
264 typedef enum
265 {
266         ca_dedicated,           // a dedicated server with no ability to start a client
267         ca_disconnected,        // full screen console with no connection
268         ca_connected            // valid netcon, talking to a server
269 }
270 cactive_t;
271
272 //
273 // the client_static_t structure is persistent through an arbitrary number
274 // of server connections
275 //
276 typedef struct
277 {
278         cactive_t state;
279
280 // demo loop control
281         // -1 = don't play demos
282         int demonum;
283         // list of demos in loop
284         char demos[MAX_DEMOS][MAX_DEMONAME];
285
286 // demo recording info must be here, because record is started before
287 // entering a map (and clearing client_state_t)
288         qboolean demorecording;
289         qboolean demoplayback;
290         qboolean timedemo;
291         // -1 = use normal cd track
292         int forcetrack;
293         qfile_t *demofile;
294         // to meter out one message a frame
295         int td_lastframe;
296         // host_framecount at start
297         int td_startframe;
298         // realtime at second frame of timedemo (LordHavoc: changed to double)
299         double td_starttime;
300         // LordHavoc: pausedemo
301         qboolean demopaused;
302
303         qboolean connect_trying;
304         int connect_remainingtries;
305         double connect_nextsendtime;
306         lhnetsocket_t *connect_mysocket;
307         lhnetaddress_t connect_address;
308
309 // connection information
310         // 0 to SIGNONS
311         int signon;
312         // network connection
313         netconn_t *netcon;
314         // writing buffer to send to server
315         sizebuf_t message;
316 }
317 client_static_t;
318
319 extern client_static_t  cls;
320
321 //
322 // the client_state_t structure is wiped completely at every
323 // server signon
324 //
325 typedef struct
326 {
327         // when connecting to the server throw out the first couple move messages
328         // so the player doesn't accidentally do something the first frame
329         int movemessages;
330
331         // send a clc_nop periodically until connected
332         float sendnoptime;
333
334         // last command sent to the server
335         usercmd_t cmd;
336
337 // information for local display
338         // health, etc
339         int stats[MAX_CL_STATS];
340         // inventory bit flags
341         int items;
342         // cl.time of acquiring item, for blinking
343         float item_gettime[32];
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         // entity database stuff
442         entity_database_t entitydatabase;
443 }
444 client_state_t;
445
446 extern mempool_t *cl_scores_mempool;
447
448 //
449 // cvars
450 //
451 extern cvar_t cl_name;
452 extern cvar_t cl_color;
453 extern cvar_t cl_pmodel;
454
455 extern cvar_t cl_upspeed;
456 extern cvar_t cl_forwardspeed;
457 extern cvar_t cl_backspeed;
458 extern cvar_t cl_sidespeed;
459
460 extern cvar_t cl_movespeedkey;
461
462 extern cvar_t cl_yawspeed;
463 extern cvar_t cl_pitchspeed;
464
465 extern cvar_t cl_anglespeedkey;
466
467 extern cvar_t cl_autofire;
468
469 extern cvar_t cl_shownet;
470 extern cvar_t cl_nolerp;
471
472 extern cvar_t cl_pitchdriftspeed;
473 extern cvar_t lookspring;
474 extern cvar_t lookstrafe;
475 extern cvar_t sensitivity;
476
477 extern cvar_t freelook;
478
479 extern cvar_t m_pitch;
480 extern cvar_t m_yaw;
481 extern cvar_t m_forward;
482 extern cvar_t m_side;
483
484 extern cvar_t r_draweffects;
485
486 extern cvar_t cl_explosions;
487 extern cvar_t cl_stainmaps;
488
489 // these are updated by CL_ClearState
490 extern int cl_num_entities;
491 extern int cl_num_static_entities;
492 extern int cl_num_temp_entities;
493 extern int cl_num_brushmodel_entities;
494
495 extern entity_t *cl_entities;
496 extern qbyte *cl_entities_active;
497 extern entity_t *cl_static_entities;
498 extern entity_t *cl_temp_entities;
499 extern entity_render_t **cl_brushmodel_entities;
500 extern cl_effect_t *cl_effects;
501 extern beam_t *cl_beams;
502 extern dlight_t *cl_dlights;
503 extern lightstyle_t *cl_lightstyle;
504
505
506 extern client_state_t cl;
507
508 extern void CL_AllocDlight (entity_render_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime);
509 extern void CL_DecayLights (void);
510
511 //=============================================================================
512
513 //
514 // cl_main
515 //
516
517 void CL_Init (void);
518
519 void CL_EstablishConnection(const char *host);
520
521 void CL_Disconnect (void);
522 void CL_Disconnect_f (void);
523
524 void CL_BoundingBoxForEntity(entity_render_t *ent);
525
526 //
527 // cl_input
528 //
529 typedef struct
530 {
531         int             down[2];                // key nums holding it down
532         int             state;                  // low bit is down state
533 }
534 kbutton_t;
535
536 extern  kbutton_t       in_mlook, in_klook;
537 extern  kbutton_t       in_strafe;
538 extern  kbutton_t       in_speed;
539
540 void CL_InitInput (void);
541 void CL_SendCmd (void);
542 void CL_SendMove (usercmd_t *cmd);
543
544 void CL_LerpUpdate(entity_t *e);
545 void CL_ParseTEnt (void);
546 void CL_RelinkBeams (void);
547
548 void CL_ClearTempEntities (void);
549 entity_t *CL_NewTempEntity (void);
550
551 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate);
552
553 void CL_ClearState (void);
554
555
556 int  CL_ReadFromServer (void);
557 void CL_WriteToServer (usercmd_t *cmd);
558 void CL_BaseMove (usercmd_t *cmd);
559
560
561 float CL_KeyState (kbutton_t *key);
562 char *Key_KeynumToString (int keynum);
563
564 //
565 // cl_demo.c
566 //
567 void CL_StopPlayback(void);
568 void CL_ReadDemoMessage(void);
569 void CL_WriteDemoMessage(void);
570
571 void CL_NextDemo(void);
572 void CL_Stop_f(void);
573 void CL_Record_f(void);
574 void CL_PlayDemo_f(void);
575 void CL_TimeDemo_f(void);
576
577 //
578 // cl_parse.c
579 //
580 void CL_Parse_Init(void);
581 void CL_ParseServerMessage(void);
582 void CL_Parse_DumpPacket(void);
583
584 //
585 // view
586 //
587 void V_StartPitchDrift (void);
588 void V_StopPitchDrift (void);
589
590 void V_Init (void);
591 float V_CalcRoll (vec3_t angles, vec3_t velocity);
592 void V_UpdateBlends (void);
593 void V_ParseDamage (void);
594
595
596 //
597 // cl_tent
598 //
599 void CL_InitTEnts (void);
600
601 //
602 // cl_part
603 //
604
605 void CL_Particles_Clear(void);
606 void CL_Particles_Init(void);
607
608 void CL_ParseParticleEffect (void);
609 void CL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count);
610 void CL_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent);
611 void CL_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
612 void CL_SparkShower (vec3_t org, vec3_t dir, int count);
613 void CL_PlasmaBurn (vec3_t org);
614 void CL_BloodPuff (vec3_t org, vec3_t vel, int count);
615 void CL_Stardust (vec3_t mins, vec3_t maxs, int count);
616 void CL_FlameCube (vec3_t mins, vec3_t maxs, int count);
617 void CL_Flames (vec3_t org, vec3_t vel, int count);
618 void CL_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count);
619 void CL_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel);
620 void CL_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type);
621 void CL_EntityParticles (entity_t *ent);
622 void CL_BlobExplosion (vec3_t org);
623 void CL_ParticleExplosion (vec3_t org);
624 void CL_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength);
625 void CL_LavaSplash (vec3_t org);
626 void CL_TeleportSplash (vec3_t org);
627 void CL_BeamParticle (const vec3_t start, const vec3_t end, vec_t radius, float red, float green, float blue, float alpha, float lifetime);
628 void CL_Tei_Smoke(const vec3_t pos, const vec3_t dir, int count);
629 void CL_Tei_PlasmaHit(const vec3_t pos, const vec3_t dir, int count);
630 void CL_MoveParticles(void);
631 void R_MoveExplosions(void);
632 void R_NewExplosion(vec3_t org);
633
634 #include "cl_screen.h"
635
636 typedef struct
637 {
638         // area to render in
639         int x, y, width, height;
640         float fov_x, fov_y;
641
642         // view point
643         vec3_t vieworg;
644         vec3_t viewangles;
645
646         // fullscreen color blend
647         float viewblend[4];
648
649         entity_render_t **entities;
650         int numentities;
651         int maxentities;
652
653         qbyte *drawqueue;
654         int drawqueuesize;
655         int maxdrawqueuesize;
656 }
657 refdef_t;
658
659 refdef_t r_refdef;
660
661 extern mempool_t *cl_refdef_mempool;
662
663 #include "cgamevm.h"
664
665 void Host_PerformSpawnServerAndLoadGame(void);
666
667 #endif
668