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