]> icculus.org git repositories - divverent/darkplaces.git/blob - client.h
Fixed a potential buffer overflow in Con_DebugLog
[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 // LordHavoc: 256 dynamic lights
26 #define MAX_DLIGHTS 256
27 // LordHavoc: this affects the lighting scale of the whole game
28 #define LIGHTOFFSET 1024.0f
29 // max lights shining on one entity
30 #define MAXENTLIGHTS 128
31
32 extern int cl_max_entities;
33 extern int cl_max_static_entities;
34 extern int cl_max_temp_entities;
35 extern int cl_max_effects;
36 extern int cl_max_beams;
37
38 typedef struct effect_s
39 {
40         int active;
41         vec3_t origin;
42         float starttime;
43         float framerate;
44         int modelindex;
45         int startframe;
46         int endframe;
47         // these are for interpolation
48         int frame;
49         double frame1time;
50         double frame2time;
51 }
52 cl_effect_t;
53
54 typedef struct
55 {
56         int             entity;
57         struct model_s  *model;
58         float   endtime;
59         vec3_t  start, end;
60 }
61 beam_t;
62
63 typedef struct
64 {
65         // location
66         vec3_t  origin;
67         // stop lighting after this time
68         float   die;
69         // color of light
70         vec3_t  color;
71         // brightness (not really radius anymore)
72         float   radius;
73         // drop this each second
74         float   decay;
75         // the entity that spawned this light (can be NULL if it will never be replaced)
76         //entity_render_t *ent;
77 }
78 dlight_t;
79
80 typedef struct frameblend_s
81 {
82         int frame;
83         float lerp;
84 }
85 frameblend_t;
86
87 // LordHavoc: disregard the following warning, entlights stuff is semi-persistent...
88 // LordHavoc: nothing in this structure is persistent, it may be overwritten by the client every frame, for persistent data use entity_lerp_t.
89 typedef struct entity_render_s
90 {
91         // location
92         vec3_t origin;
93         // orientation
94         vec3_t angles;
95         // opacity (alpha) of the model
96         float alpha;
97         // size the model is shown
98         float scale;
99
100         // NULL = no model
101         model_t *model;
102         // current uninterpolated animation frame (for things which do not use interpolation)
103         int frame;
104         // entity shirt and pants colors
105         int colormap;
106         // light, particles, etc
107         int effects;
108         // for Alias models
109         int skinnum;
110         // render flags
111         int flags;
112
113         // these are copied from the persistent data
114
115         // frame that the model is interpolating from
116         int frame1;
117         // frame that the model is interpolating to
118         int frame2;
119         // interpolation factor, usually computed from frame2time
120         double framelerp;
121         // time frame1 began playing (for framegroup animations)
122         double frame1time;
123         // time frame2 began playing (for framegroup animations)
124         double frame2time;
125
126         // calculated by the renderer (but not persistent)
127
128         // if visframe == r_framecount, it is visible
129         int visframe;
130         // calculated during R_AddModelEntities
131         vec3_t mins, maxs;
132         // 4 frame numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use frame instead
133         frameblend_t frameblend[4];
134
135         // caching results of static light traces (this is semi-persistent)
136         double entlightstime;
137         vec3_t entlightsorigin;
138         int numentlights;
139         unsigned short entlights[MAXENTLIGHTS];
140 }
141 entity_render_t;
142
143 typedef struct entity_persistent_s
144 {
145         // particles
146
147         // trail rendering
148         vec3_t trail_origin;
149         float trail_time;
150
151         // effects
152
153         // muzzleflash fading
154         float muzzleflash;
155
156         // interpolated movement
157
158         // start time of move
159         float lerpstarttime;
160         // time difference from start to end of move
161         float lerpdeltatime;
162         // the move itself, start and end
163         float oldorigin[3];
164         float oldangles[3];
165         float neworigin[3];
166         float newangles[3];
167
168         // interpolated animation
169
170         // lerp resets when model changes
171         int modelindex;
172         // frame that the model is interpolating from
173         int frame1;
174         // frame that the model is interpolating to
175         int frame2;
176         // interpolation factor, usually computed from frame2time
177         double framelerp;
178         // time frame1 began playing (for framegroup animations)
179         double frame1time;
180         // time frame2 began playing (for framegroup animations)
181         double frame2time;
182 }
183 entity_persistent_t;
184
185 typedef struct entity_s
186 {
187         // baseline state (default values)
188         entity_state_t state_baseline;
189         // previous state (interpolating from this)
190         entity_state_t state_previous;
191         // current state (interpolating to this)
192         entity_state_t state_current;
193
194         // used for regenerating parts of render
195         entity_persistent_t persistent;
196
197         // the only data the renderer should know about
198         entity_render_t render;
199 }
200 entity_t;
201
202 typedef struct
203 {
204         vec3_t  viewangles;
205
206 // intended velocities
207         float   forwardmove;
208         float   sidemove;
209         float   upmove;
210 } usercmd_t;
211
212 typedef struct
213 {
214         int             length;
215         char    map[MAX_STYLESTRING];
216 } lightstyle_t;
217
218 typedef struct
219 {
220         char    name[MAX_SCOREBOARDNAME];
221         float   entertime;
222         int             frags;
223         int             colors; // two 4 bit fields
224 } scoreboard_t;
225
226 typedef struct
227 {
228         int             destcolor[3];
229         int             percent;                // 0-256
230 } cshift_t;
231
232 #define CSHIFT_CONTENTS 0
233 #define CSHIFT_DAMAGE   1
234 #define CSHIFT_BONUS    2
235 #define CSHIFT_POWERUP  3
236 #define NUM_CSHIFTS             4
237
238 #define NAME_LENGTH     64
239
240
241 //
242 // client_state_t should hold all pieces of the client state
243 //
244
245 #define SIGNONS         4                       // signon messages to receive before connected
246
247 #define MAX_MAPSTRING   2048
248 #define MAX_DEMOS               8
249 #define MAX_DEMONAME    16
250
251 typedef enum
252 {
253         ca_dedicated,           // a dedicated server with no ability to start a client
254         ca_disconnected,        // full screen console with no connection
255         ca_connected            // valid netcon, talking to a server
256 }
257 cactive_t;
258
259 //
260 // the client_static_t structure is persistent through an arbitrary number
261 // of server connections
262 //
263 typedef struct
264 {
265         cactive_t state;
266
267 // personalization data sent to server
268         char mapstring[MAX_QPATH];
269         // to restart a level
270         //char spawnparms[MAX_MAPSTRING];
271
272 // demo loop control
273         // -1 = don't play demos
274         int demonum;
275         // list of demos in loop
276         char demos[MAX_DEMOS][MAX_DEMONAME];
277
278 // demo recording info must be here, because record is started before
279 // entering a map (and clearing client_state_t)
280         qboolean demorecording;
281         qboolean demoplayback;
282         qboolean timedemo;
283         // -1 = use normal cd track
284         int forcetrack;
285         QFile *demofile;
286         // to meter out one message a frame
287         int td_lastframe;
288         // host_framecount at start
289         int td_startframe;
290         // realtime at second frame of timedemo (LordHavoc: changed to double)
291         double td_starttime;
292         // LordHavoc: pausedemo
293         qboolean demopaused;
294
295
296 // connection information
297         // 0 to SIGNONS
298         int signon;
299         // network socket
300         struct qsocket_s *netcon;
301         // writing buffer to send to server
302         sizebuf_t message;
303 }
304 client_static_t;
305
306 extern client_static_t  cls;
307
308 //
309 // the client_state_t structure is wiped completely at every
310 // server signon
311 //
312 typedef struct
313 {
314         // when connecting to the server throw out the first couple move messages
315         // so the player doesn't accidentally do something the first frame
316         int movemessages;
317
318         // send a clc_nop periodically until connected
319         float sendnoptime;
320
321         // last command sent to the server
322         usercmd_t cmd;
323
324 // information for local display
325         // health, etc
326         int stats[MAX_CL_STATS];
327         // inventory bit flags
328         int items;
329         // cl.time of acquiring item, for blinking
330         float item_gettime[32];
331         // use pain anim frame if cl.time < this
332         float faceanimtime;
333
334         // color shifts for damage, powerups
335         cshift_t cshifts[NUM_CSHIFTS];
336         // and content types
337         cshift_t prev_cshifts[NUM_CSHIFTS];
338
339 // the client maintains its own idea of view angles, which are
340 // sent to the server each frame.  The server sets punchangle when
341 // the view is temporarily offset, and an angle reset commands at the start
342 // of each level and after teleporting.
343
344         // during demo playback viewangles is lerped between these
345         vec3_t mviewangles[2];
346         // either client controlled, or lerped from demo mviewangles
347         vec3_t viewangles;
348
349         // update by server, used for lean+bob (0 is newest)
350         vec3_t mvelocity[2];
351         // lerped between mvelocity[0] and [1]
352         vec3_t velocity;
353
354         // temporary offset
355         vec3_t punchangle;
356         // LordHavoc: origin view kick
357         vec3_t punchvector;
358
359 // pitch drifting vars
360         float idealpitch;
361         float pitchvel;
362         qboolean nodrift;
363         float driftmove;
364         double laststop;
365
366         float viewheight;
367         // local amount for smoothing stepups
368         //float crouch;
369
370         // sent by server
371         qboolean paused;
372         qboolean onground;
373         qboolean inwater;
374
375         // don't change view angle, full screen, etc
376         int intermission;
377         // latched at intermission start
378         int completed_time;
379
380         // the timestamp of the last two messages
381         double mtime[2];
382
383         // clients view of time, time should be between mtime[0] and mtime[1] to
384         // generate a lerp point for other data, oldtime is the previous frame's
385         // value of time, frametime is the difference between time and oldtime
386         double time, oldtime, frametime;
387
388         // copy of realtime from last recieved message, for net trouble icon
389         float last_received_message;
390
391 // information that is static for the entire time connected to a server
392         struct model_s *model_precache[MAX_MODELS];
393         struct sfx_s *sound_precache[MAX_SOUNDS];
394
395         // for display on solo scoreboard
396         char levelname[40];
397         // cl_entitites[cl.viewentity] = player
398         int viewentity;
399         // the real player entity (normally same as viewentity,
400         // different than viewentity if mod uses chasecam or other tricks)
401         int playerentity;
402         // max players that can be in this game
403         int maxclients;
404         // type of game (deathmatch, coop, singleplayer)
405         int gametype;
406
407 // refresh related state
408
409         // cl_entitites[0].model
410         struct model_s *worldmodel;
411
412         // the gun model
413         entity_t viewent;
414
415         // cd audio
416         int cdtrack, looptrack;
417
418 // frag scoreboard
419
420         // [cl.maxclients]
421         scoreboard_t *scores;
422
423         // used by view code for setting up eye position
424         vec3_t viewentorigin;
425         // LordHavoc: sniping zoom, QC controlled
426         float viewzoom;
427         // for interpolation
428         float viewzoomold, viewzoomnew;
429
430         // entity database stuff
431         vec3_t viewentoriginold, viewentoriginnew;
432         entity_database_t entitydatabase;
433 }
434 client_state_t;
435
436 extern mempool_t *cl_scores_mempool;
437
438 //
439 // cvars
440 //
441 extern cvar_t cl_name;
442 extern cvar_t cl_color;
443 extern cvar_t cl_pmodel;
444
445 extern cvar_t cl_upspeed;
446 extern cvar_t cl_forwardspeed;
447 extern cvar_t cl_backspeed;
448 extern cvar_t cl_sidespeed;
449
450 extern cvar_t cl_movespeedkey;
451
452 extern cvar_t cl_yawspeed;
453 extern cvar_t cl_pitchspeed;
454
455 extern cvar_t cl_anglespeedkey;
456
457 extern cvar_t cl_autofire;
458
459 extern cvar_t cl_shownet;
460 extern cvar_t cl_nolerp;
461
462 extern cvar_t cl_pitchdriftspeed;
463 extern cvar_t lookspring;
464 extern cvar_t lookstrafe;
465 extern cvar_t sensitivity;
466
467 extern cvar_t freelook;
468
469 extern cvar_t m_pitch;
470 extern cvar_t m_yaw;
471 extern cvar_t m_forward;
472 extern cvar_t m_side;
473
474 extern cvar_t r_draweffects;
475
476 extern cvar_t cl_explosions;
477 extern cvar_t cl_stainmaps;
478
479 // these are updated by
480 extern int cl_num_entities;
481 extern int cl_num_static_entities;
482 extern int cl_num_temp_entities;
483 extern int cl_num_brushmodel_entities;
484
485 extern entity_t *cl_entities;
486 extern qbyte *cl_entities_active;
487 extern entity_t *cl_static_entities;
488 extern entity_t *cl_temp_entities;
489 extern entity_render_t **cl_brushmodel_entities;
490 extern cl_effect_t *cl_effects;
491 extern beam_t *cl_beams;
492 extern dlight_t *cl_dlights;
493 extern lightstyle_t *cl_lightstyle;
494
495
496 extern client_state_t cl;
497
498 extern void CL_AllocDlight (entity_render_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime);
499 extern void CL_DecayLights (void);
500
501 //=============================================================================
502
503 //
504 // cl_main
505 //
506
507 void CL_Init (void);
508
509 void CL_EstablishConnection (char *host);
510
511 void CL_Disconnect (void);
512 void CL_Disconnect_f (void);
513
514 //
515 // cl_input
516 //
517 typedef struct
518 {
519         int             down[2];                // key nums holding it down
520         int             state;                  // low bit is down state
521 }
522 kbutton_t;
523
524 extern  kbutton_t       in_mlook, in_klook;
525 extern  kbutton_t       in_strafe;
526 extern  kbutton_t       in_speed;
527
528 void CL_InitInput (void);
529 void CL_SendCmd (void);
530 void CL_SendMove (usercmd_t *cmd);
531
532 void CL_LerpUpdate(entity_t *e);
533 void CL_ParseTEnt (void);
534 void CL_RelinkBeams (void);
535
536 void CL_ClearTempEntities (void);
537 entity_t *CL_NewTempEntity (void);
538
539 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate);
540
541 void CL_ClearState (void);
542
543
544 int  CL_ReadFromServer (void);
545 void CL_WriteToServer (usercmd_t *cmd);
546 void CL_BaseMove (usercmd_t *cmd);
547
548
549 float CL_KeyState (kbutton_t *key);
550 char *Key_KeynumToString (int keynum);
551
552 //
553 // cl_demo.c
554 //
555 void CL_StopPlayback (void);
556 int CL_GetMessage (void);
557
558 void CL_NextDemo (void);
559 void CL_Stop_f (void);
560 void CL_Record_f (void);
561 void CL_PlayDemo_f (void);
562 void CL_TimeDemo_f (void);
563
564 //
565 // cl_parse.c
566 //
567 void CL_Parse_Init(void);
568 void CL_ParseServerMessage(void);
569 void CL_BitProfile_f(void);
570
571 //
572 // view
573 //
574 void V_StartPitchDrift (void);
575 void V_StopPitchDrift (void);
576
577 void V_Init (void);
578 float V_CalcRoll (vec3_t angles, vec3_t velocity);
579 void V_UpdateBlends (void);
580 void V_ParseDamage (void);
581
582
583 //
584 // cl_tent
585 //
586 void CL_InitTEnts (void);
587
588 //
589 // cl_part
590 //
591
592 #define PARTICLE_INVALID 0
593 #define PARTICLE_BILLBOARD 1
594 #define PARTICLE_UPRIGHT_FACING 2
595 #define PARTICLE_ORIENTED_DOUBLESIDED 3
596
597 void CL_Particles_Clear(void);
598 void CL_Particles_Init(void);
599
600 void CL_ParseParticleEffect (void);
601 void CL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count);
602 void CL_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent);
603 void CL_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
604 void CL_SparkShower (vec3_t org, vec3_t dir, int count);
605 void CL_PlasmaBurn (vec3_t org);
606 void CL_BloodPuff (vec3_t org, vec3_t vel, int count);
607 void CL_Stardust (vec3_t mins, vec3_t maxs, int count);
608 void CL_FlameCube (vec3_t mins, vec3_t maxs, int count);
609 void CL_Flames (vec3_t org, vec3_t vel, int count);
610 void CL_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count);
611 void CL_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel);
612 void CL_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type);
613 void CL_EntityParticles (entity_t *ent);
614 void CL_BlobExplosion (vec3_t org);
615 void CL_ParticleExplosion (vec3_t org, int smoke);
616 void CL_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength);
617 void CL_LavaSplash (vec3_t org);
618 void CL_TeleportSplash (vec3_t org);
619 void CL_MoveParticles(void);
620 void R_MoveExplosions(void);
621 void R_NewExplosion(vec3_t org);
622
623 #include "cl_screen.h"
624
625 typedef struct
626 {
627         // area to render in
628         int x, y, width, height;
629         float fov_x, fov_y;
630
631         // view point
632         vec3_t vieworg;
633         vec3_t viewangles;
634
635         // fullscreen color blend
636         float viewblend[4];
637
638         // weapon model
639         entity_render_t viewent;
640
641         entity_render_t **entities;
642         int numentities;
643         int maxentities;
644
645         qbyte *drawqueue;
646         int drawqueuesize;
647         int maxdrawqueuesize;
648 }
649 refdef_t;
650
651 refdef_t r_refdef;
652
653 extern mempool_t *cl_refdef_mempool;
654
655 #include "cgamevm.h"
656
657 #endif
658