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