]> icculus.org git repositories - divverent/darkplaces.git/blob - client.h
minor speed increase in surface shaders, by splitting out surfaces with and without...
[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 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         float           sendnoptime;    // send a clc_nop periodically until connected
202         usercmd_t       cmd;                    // last command sent to the server
203
204 // information for local display
205         int                     stats[MAX_CL_STATS];    // health, etc
206         int                     items;                  // inventory bit flags
207         float           item_gettime[32];       // cl.time of acquiring item, for blinking
208         float           faceanimtime;   // use anim frame if cl.time < this
209
210         cshift_t        cshifts[NUM_CSHIFTS];   // color shifts for damage, powerups
211         cshift_t        prev_cshifts[NUM_CSHIFTS];      // and content types
212
213 // the client maintains its own idea of view angles, which are
214 // sent to the server each frame.  The server sets punchangle when
215 // the view is temporarliy offset, and an angle reset commands at the start
216 // of each level and after teleporting.
217         vec3_t          mviewangles[2]; // during demo playback viewangles is lerped
218                                                                 // between these
219         vec3_t          viewangles;
220
221         vec3_t          mvelocity[2];   // update by server, used for lean+bob
222                                                                 // (0 is newest)
223         vec3_t          velocity;               // lerped between mvelocity[0] and [1]
224
225         vec3_t          punchangle;             // temporary offset
226         vec3_t          punchvector;    // LordHavoc: origin view kick
227
228 // pitch drifting vars
229         float           idealpitch;
230         float           pitchvel;
231         qboolean        nodrift;
232         float           driftmove;
233         double          laststop;
234
235         float           viewheight;
236         float           crouch;                 // local amount for smoothing stepups
237
238         qboolean        paused;                 // send over by server
239         qboolean        onground;
240         qboolean        inwater;
241
242         int                     intermission;   // don't change view angle, full screen, etc
243         int                     completed_time; // latched at intermission start
244
245         double          mtime[2];               // the timestamp of last two messages
246         double          time;                   // clients view of time, should be between
247                                                                 // servertime and oldservertime to generate
248                                                                 // a lerp point for other data
249         double          oldtime;                // previous cl.time, time-oldtime is used
250                                                                 // to decay light values and smooth step ups
251
252         double          frametime;
253
254
255         float           last_received_message;  // (realtime) for net trouble icon
256
257 //
258 // information that is static for the entire time connected to a server
259 //
260         struct model_s          *model_precache[MAX_MODELS];
261         struct sfx_s            *sound_precache[MAX_SOUNDS];
262
263         char            levelname[40];  // for display on solo scoreboard
264         int                     viewentity;             // cl_entitites[cl.viewentity] = player
265         int                     maxclients;
266         int                     gametype;
267
268 // refresh related state
269         struct model_s  *worldmodel;    // cl_entitites[0].model
270 //      int                     num_entities;   // held in cl_entities array
271         int                     num_statics;    // held in cl_staticentities array
272         entity_t        viewent;                        // the gun model
273
274         int                     cdtrack, looptrack;     // cd audio
275
276 // frag scoreboard
277         scoreboard_t    *scores;                // [cl.maxclients]
278
279         vec3_t          viewentorigin;
280         float           viewzoom;                       // LordHavoc: sniping zoom, QC controlled
281         float           viewzoomold, viewzoomnew; // for interpolation
282
283         // entity database stuff
284         vec3_t          viewentoriginold, viewentoriginnew;
285         entity_database_t entitydatabase;
286 }
287 client_state_t;
288
289 extern mempool_t *cl_scores_mempool;
290
291 //
292 // cvars
293 //
294 extern cvar_t cl_name;
295 extern cvar_t cl_color;
296 extern cvar_t cl_pmodel;
297
298 extern cvar_t cl_upspeed;
299 extern cvar_t cl_forwardspeed;
300 extern cvar_t cl_backspeed;
301 extern cvar_t cl_sidespeed;
302
303 extern cvar_t cl_movespeedkey;
304
305 extern cvar_t cl_yawspeed;
306 extern cvar_t cl_pitchspeed;
307
308 extern cvar_t cl_anglespeedkey;
309
310 extern cvar_t cl_autofire;
311
312 extern cvar_t cl_shownet;
313 extern cvar_t cl_nolerp;
314
315 extern cvar_t cl_pitchdriftspeed;
316 extern cvar_t lookspring;
317 extern cvar_t lookstrafe;
318 extern cvar_t sensitivity;
319
320 extern cvar_t freelook;
321
322 extern cvar_t m_pitch;
323 extern cvar_t m_yaw;
324 extern cvar_t m_forward;
325 extern cvar_t m_side;
326
327
328 // LordHavoc: raised these from 64 and 128 to 512 and 256
329 #define MAX_TEMP_ENTITIES       512                     // lightning bolts, effects, etc
330 #define MAX_STATIC_ENTITIES     256                     // torches, etc
331
332 extern client_state_t cl;
333
334 // FIXME, allocate dynamically
335 extern  entity_t                cl_entities[MAX_EDICTS];
336 extern  entity_t                cl_static_entities[MAX_STATIC_ENTITIES];
337 extern  lightstyle_t    cl_lightstyle[MAX_LIGHTSTYLES];
338 extern  entity_t                cl_temp_entities[MAX_TEMP_ENTITIES];
339 extern  beam_t                  cl_beams[MAX_BEAMS];
340
341 #include "cl_light.h"
342
343 //=============================================================================
344
345 //
346 // cl_main
347 //
348
349 void CL_Init (void);
350
351 void CL_EstablishConnection (char *host);
352
353 void CL_Disconnect (void);
354 void CL_Disconnect_f (void);
355
356 //
357 // cl_input
358 //
359 typedef struct
360 {
361         int             down[2];                // key nums holding it down
362         int             state;                  // low bit is down state
363 }
364 kbutton_t;
365
366 extern  kbutton_t       in_mlook, in_klook;
367 extern  kbutton_t       in_strafe;
368 extern  kbutton_t       in_speed;
369
370 void CL_InitInput (void);
371 void CL_SendCmd (void);
372 void CL_SendMove (usercmd_t *cmd);
373
374 void CL_LerpUpdate(entity_t *e);
375 void CL_ParseTEnt (void);
376 void CL_UpdateTEnts (void);
377
378 entity_t *CL_NewTempEntity (void);
379
380 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate);
381
382 void CL_ClearState (void);
383
384
385 int  CL_ReadFromServer (void);
386 void CL_WriteToServer (usercmd_t *cmd);
387 void CL_BaseMove (usercmd_t *cmd);
388
389
390 float CL_KeyState (kbutton_t *key);
391 char *Key_KeynumToString (int keynum);
392
393 //
394 // cl_demo.c
395 //
396 void CL_StopPlayback (void);
397 int CL_GetMessage (void);
398
399 void CL_NextDemo (void);
400 void CL_Stop_f (void);
401 void CL_Record_f (void);
402 void CL_PlayDemo_f (void);
403 void CL_TimeDemo_f (void);
404
405 //
406 // cl_parse.c
407 //
408 void CL_Parse_Init(void);
409 void CL_ParseServerMessage(void);
410 void CL_BitProfile_f(void);
411
412 //
413 // view
414 //
415 void V_StartPitchDrift (void);
416 void V_StopPitchDrift (void);
417
418 void V_Init (void);
419 float V_CalcRoll (vec3_t angles, vec3_t velocity);
420 void V_UpdateBlends (void);
421 void V_ParseDamage (void);
422
423
424 //
425 // cl_tent
426 //
427 void CL_InitTEnts (void);
428
429 //
430 // cl_part
431 //
432
433 #define PARTICLE_INVALID 0
434 #define PARTICLE_BILLBOARD 1
435 #define PARTICLE_UPRIGHT_FACING 2
436 #define PARTICLE_ORIENTED_DOUBLESIDED 3
437
438 /*
439 typedef struct renderparticle_s
440 {
441         int tex;
442         int orientation;
443         int additive;
444         int dynlight;
445         float scalex;
446         float scaley;
447         float org[3];
448         float dir[3];
449         float color[4];
450 }
451 renderparticle_t;
452 */
453
454 void CL_Particles_Clear(void);
455 void CL_Particles_Init(void);
456
457 void CL_ParseParticleEffect (void);
458 void CL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count);
459 void CL_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent);
460 void CL_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
461 void CL_SparkShower (vec3_t org, vec3_t dir, int count);
462 void CL_PlasmaBurn (vec3_t org);
463 void CL_BloodPuff (vec3_t org, vec3_t vel, int count);
464 void CL_Stardust (vec3_t mins, vec3_t maxs, int count);
465 void CL_FlameCube (vec3_t mins, vec3_t maxs, int count);
466 void CL_Flames (vec3_t org, vec3_t vel, int count);
467 void CL_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count);
468 void CL_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel);
469 void CL_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type);
470 void CL_EntityParticles (entity_t *ent);
471 void CL_BlobExplosion (vec3_t org);
472 void CL_ParticleExplosion (vec3_t org, int smoke);
473 void CL_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength);
474 void CL_LavaSplash (vec3_t org);
475 void CL_TeleportSplash (vec3_t org);
476 void CL_MoveParticles(void);
477 void R_MoveExplosions(void);
478 void R_NewExplosion(vec3_t org);
479
480 // if contents is not zero, it will impact on content changes
481 // (leafs matching contents are considered empty, others are solid)
482 extern int traceline_endcontents; // set by TraceLine
483 // need to call this sometime before using TraceLine with hitbmodels
484 void TraceLine_ScanForBModels(void);
485 float TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels);
486
487 #include "cl_screen.h"
488
489 #define MAX_VISEDICTS (MAX_EDICTS + MAX_STATIC_ENTITIES + MAX_TEMP_ENTITIES)
490
491 typedef struct
492 {
493         // area to render in
494         int x, y, width, height;
495         float fov_x, fov_y;
496
497         // view point
498         vec3_t vieworg;
499         vec3_t viewangles;
500
501         // fullscreen color blend
502         float viewblend[4];
503
504         // weapon model
505         entity_render_t viewent;
506
507         int numentities;
508         entity_render_t **entities;
509
510         //int numparticles;
511         //struct renderparticle_s *particles;
512
513         qbyte drawqueue[MAX_DRAWQUEUE];
514         int drawqueuesize;
515 }
516 refdef_t;
517
518 refdef_t r_refdef;
519
520 extern mempool_t *cl_refdef_mempool;
521
522 #include "cgamevm.h"