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