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