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