]> icculus.org git repositories - divverent/darkplaces.git/blob - client.h
win32 fixes and some MSVC warnings fixed
[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 #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
378 // LordHavoc: raised these from 64 and 128 to 512 and 256
379 #define MAX_TEMP_ENTITIES       512                     // lightning bolts, effects, etc
380 #define MAX_STATIC_ENTITIES     256                     // torches, etc
381
382 extern client_state_t cl;
383
384 // FIXME, allocate dynamically
385 extern  entity_t                cl_entities[MAX_EDICTS];
386 extern  entity_t                cl_static_entities[MAX_STATIC_ENTITIES];
387 extern  lightstyle_t    cl_lightstyle[MAX_LIGHTSTYLES];
388 extern  entity_t                cl_temp_entities[MAX_TEMP_ENTITIES];
389 extern  beam_t                  cl_beams[MAX_BEAMS];
390
391 #include "cl_light.h"
392
393 //=============================================================================
394
395 //
396 // cl_main
397 //
398
399 void CL_Init (void);
400
401 void CL_EstablishConnection (char *host);
402
403 void CL_Disconnect (void);
404 void CL_Disconnect_f (void);
405
406 //
407 // cl_input
408 //
409 typedef struct
410 {
411         int             down[2];                // key nums holding it down
412         int             state;                  // low bit is down state
413 }
414 kbutton_t;
415
416 extern  kbutton_t       in_mlook, in_klook;
417 extern  kbutton_t       in_strafe;
418 extern  kbutton_t       in_speed;
419
420 void CL_InitInput (void);
421 void CL_SendCmd (void);
422 void CL_SendMove (usercmd_t *cmd);
423
424 void CL_LerpUpdate(entity_t *e);
425 void CL_ParseTEnt (void);
426 void CL_UpdateTEnts (void);
427
428 entity_t *CL_NewTempEntity (void);
429
430 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate);
431
432 void CL_ClearState (void);
433
434
435 int  CL_ReadFromServer (void);
436 void CL_WriteToServer (usercmd_t *cmd);
437 void CL_BaseMove (usercmd_t *cmd);
438
439
440 float CL_KeyState (kbutton_t *key);
441 char *Key_KeynumToString (int keynum);
442
443 //
444 // cl_demo.c
445 //
446 void CL_StopPlayback (void);
447 int CL_GetMessage (void);
448
449 void CL_NextDemo (void);
450 void CL_Stop_f (void);
451 void CL_Record_f (void);
452 void CL_PlayDemo_f (void);
453 void CL_TimeDemo_f (void);
454
455 //
456 // cl_parse.c
457 //
458 void CL_Parse_Init(void);
459 void CL_ParseServerMessage(void);
460 void CL_BitProfile_f(void);
461
462 //
463 // view
464 //
465 void V_StartPitchDrift (void);
466 void V_StopPitchDrift (void);
467
468 void V_Init (void);
469 float V_CalcRoll (vec3_t angles, vec3_t velocity);
470 void V_UpdateBlends (void);
471 void V_ParseDamage (void);
472
473
474 //
475 // cl_tent
476 //
477 void CL_InitTEnts (void);
478
479 //
480 // cl_part
481 //
482
483 #define PARTICLE_INVALID 0
484 #define PARTICLE_BILLBOARD 1
485 #define PARTICLE_UPRIGHT_FACING 2
486 #define PARTICLE_ORIENTED_DOUBLESIDED 3
487
488 void CL_Particles_Clear(void);
489 void CL_Particles_Init(void);
490
491 void CL_ParseParticleEffect (void);
492 void CL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count);
493 void CL_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent);
494 void CL_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
495 void CL_SparkShower (vec3_t org, vec3_t dir, int count);
496 void CL_PlasmaBurn (vec3_t org);
497 void CL_BloodPuff (vec3_t org, vec3_t vel, int count);
498 void CL_Stardust (vec3_t mins, vec3_t maxs, int count);
499 void CL_FlameCube (vec3_t mins, vec3_t maxs, int count);
500 void CL_Flames (vec3_t org, vec3_t vel, int count);
501 void CL_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count);
502 void CL_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel);
503 void CL_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type);
504 void CL_EntityParticles (entity_t *ent);
505 void CL_BlobExplosion (vec3_t org);
506 void CL_ParticleExplosion (vec3_t org, int smoke);
507 void CL_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength);
508 void CL_LavaSplash (vec3_t org);
509 void CL_TeleportSplash (vec3_t org);
510 void CL_MoveParticles(void);
511 void R_MoveExplosions(void);
512 void R_NewExplosion(vec3_t org);
513
514 #include "cl_screen.h"
515
516 #define MAX_VISEDICTS (MAX_EDICTS + MAX_STATIC_ENTITIES + MAX_TEMP_ENTITIES)
517
518 typedef struct
519 {
520         // area to render in
521         int x, y, width, height;
522         float fov_x, fov_y;
523
524         // view point
525         vec3_t vieworg;
526         vec3_t viewangles;
527
528         // fullscreen color blend
529         float viewblend[4];
530
531         // weapon model
532         entity_render_t viewent;
533
534         int numentities;
535         entity_render_t **entities;
536
537         qbyte drawqueue[MAX_DRAWQUEUE];
538         int drawqueuesize;
539 }
540 refdef_t;
541
542 refdef_t r_refdef;
543
544 extern mempool_t *cl_refdef_mempool;
545
546 #include "cgamevm.h"
547
548 #endif
549