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