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