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