1 /* 2 Copyright (C) 1997-2001 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 -- primary header for client 21 22 //define PARANOID // speed sapping error checking 23 24 #include <math.h> 25 #include <string.h> 26 #include <stdarg.h> 27 #include <stdio.h> 28 #include <stdlib.h> 29 30 #include "ref.h" 31 32 #include "vid.h" 33 #include "screen.h" 34 #include "sound.h" 35 #include "input.h" 36 #include "keys.h" 37 #include "console.h" 38 #include "cdaudio.h" 39 40 #define random() ((rand () & 0x7fff) / ((float)0x7fff)) 41 #define crandom() (2.0 * (random() - 0.5)) 42 43 //============================================================================= 44 45 vec3_t clientOrg; //lerped org of client for server->client side effects 46 47 #include "particles.h" 48 49 int color8red (int color8); 50 int color8green (int color8); 51 int color8blue (int color8); 52 53 typedef struct 54 { 55 qboolean valid; // cleared if delta parsing was invalid 56 int serverframe; 57 int servertime; // server time the message is valid for (in msec) 58 int deltaframe; 59 byte areabits[MAX_MAP_AREAS/8]; // portalarea visibility bits 60 player_state_t playerstate; 61 int num_entities; 62 int parse_entities; // non-masked index into cl_parse_entities array 63 } frame_t; 64 65 typedef struct 66 { 67 entity_state_t baseline; // delta from this if not from a previous frame 68 entity_state_t current; 69 entity_state_t prev; // will always be valid, but might just be a copy of current 70 71 int serverframe; // if not current, this ent isn't in the frame 72 73 int trailcount; // for diminishing grenade trails 74 vec3_t lerp_origin; // for trails (variable hz) 75 76 int fly_stoptime; 77 } centity_t; 78 79 #define MAX_CLIENTWEAPONMODELS 20 // PGM -- upped from 16 to fit the chainfist vwep 80 81 typedef struct 82 { 83 char name[MAX_QPATH]; 84 char cinfo[MAX_QPATH]; 85 struct image_s *skin; 86 struct image_s *icon; 87 char iconname[MAX_QPATH]; 88 struct model_s *model; 89 struct model_s *weaponmodel[MAX_CLIENTWEAPONMODELS]; 90 } clientinfo_t; 91 92 extern char cl_weaponmodels[MAX_CLIENTWEAPONMODELS][MAX_QPATH]; 93 extern int num_cl_weaponmodels; 94 95 #define CMD_BACKUP 64 // allow a lot of command backups for very fast systems 96 97 // 98 // the client_state_t structure is wiped completely at every 99 // server map change 100 // 101 typedef struct 102 { 103 int timeoutcount; 104 105 int timedemo_frames; 106 int timedemo_start; 107 108 qboolean refresh_prepped; // false if on new level or new ref dll 109 qboolean sound_prepped; // ambient sounds can start 110 qboolean force_refdef; // vid has changed, so we can't use a paused refdef 111 112 int parse_entities; // index (not anded off) into cl_parse_entities[] 113 114 usercmd_t cmd; 115 usercmd_t cmds[CMD_BACKUP]; // each mesage will send several old cmds 116 int cmd_time[CMD_BACKUP]; // time sent, for calculating pings 117 short predicted_origins[CMD_BACKUP][3]; // for debug comparing against server 118 119 float predicted_step; // for stair up smoothing 120 unsigned predicted_step_time; 121 122 vec3_t predicted_origin; // generated by CL_PredictMovement 123 vec3_t predicted_angles; 124 vec3_t prediction_error; 125 126 frame_t frame; // received from server 127 int surpressCount; // number of messages rate supressed 128 frame_t frames[UPDATE_BACKUP]; 129 130 // the client maintains its own idea of view angles, which are 131 // sent to the server each frame. It is cleared to 0 upon entering each level. 132 // the server sends a delta each frame which is added to the locally 133 // tracked view angles to account for standing on rotating objects, 134 // and teleport direction changes 135 vec3_t viewangles; 136 137 int time; // this is the time value that the client 138 // is rendering at. always <= cls.realtime 139 float lerpfrac; // between oldframe and frame 140 141 refdef_t refdef; 142 143 vec3_t v_forward, v_right, v_up; // set when refdef.angles is set 144 145 // 146 // transient data from server 147 // 148 char layout[1024]; // general 2D overlay 149 int inventory[MAX_ITEMS]; 150 151 // 152 // non-gameserver infornamtion 153 // FIXME: move this cinematic stuff into the cin_t structure 154 FILE *cinematic_file; 155 int cinematictime; // cls.realtime for first cinematic frame 156 int cinematicframe; 157 char cinematicpalette[768]; 158 qboolean cinematicpalette_active; 159 160 // 161 // server state information 162 // 163 qboolean attractloop; // running the attract loop, any key will menu 164 int servercount; // server identification for prespawns 165 char gamedir[MAX_QPATH]; 166 int playernum; 167 168 char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH]; 169 170 // 171 // locally derived information from server state 172 // 173 struct model_s *model_draw[MAX_MODELS]; 174 struct cmodel_s *model_clip[MAX_MODELS]; 175 176 struct sfx_s *sound_precache[MAX_SOUNDS]; 177 struct image_s *image_precache[MAX_IMAGES]; 178 179 clientinfo_t clientinfo[MAX_CLIENTS]; 180 clientinfo_t baseclientinfo; 181 182 int particletime; 183 } client_state_t; 184 185 extern client_state_t cl; 186 187 /* 188 ================================================================== 189 190 the client_static_t structure is persistant through an arbitrary number 191 of server connections 192 193 ================================================================== 194 */ 195 196 typedef enum { 197 ca_uninitialized, 198 ca_disconnected, // not talking to a server 199 ca_connecting, // sending request packets to the server 200 ca_connected, // netchan_t established, waiting for svc_serverdata 201 ca_active // game views should be displayed 202 } connstate_t; 203 204 typedef enum { 205 dl_none, 206 dl_model, 207 dl_sound, 208 dl_skin, 209 dl_single 210 } dltype_t; // download type 211 212 typedef enum {key_game, key_console, key_message, key_menu} keydest_t; 213 214 typedef struct 215 { 216 connstate_t state; 217 keydest_t key_dest; 218 219 qboolean consoleActive; 220 221 int framecount; 222 int realtime; // always increasing, no clamping, etc 223 float frametime; // seconds since last frame 224 225 // screen rendering information 226 float disable_screen; // showing loading plaque between levels 227 // or changing rendering dlls 228 // if time gets > 30 seconds ahead, break it 229 int disable_servercount; // when we receive a frame and cl.servercount 230 // > cls.disable_servercount, clear disable_screen 231 232 // connection information 233 char servername[MAX_OSPATH]; // name of server from original connect 234 float connect_time; // for connection retransmits 235 236 int quakePort; // a 16 bit value that allows quake servers 237 // to work around address translating routers 238 netchan_t netchan; 239 int serverProtocol; // in case we are doing some kind of version hack 240 241 int challenge; // from the server to use for connecting 242 243 FILE *download; // file transfer from server 244 char downloadtempname[MAX_OSPATH]; 245 char downloadname[MAX_OSPATH]; 246 int downloadnumber; 247 dltype_t downloadtype; 248 int downloadpercent; 249 250 // demo recording info must be here, so it isn't cleared on level change 251 qboolean demorecording; 252 qboolean demowaiting; // don't record until a non-delta message is received 253 FILE *demofile; 254 } client_static_t; 255 256 extern client_static_t cls; 257 258 //============================================================================= 259 260 // 261 // cvars 262 // 263 extern cvar_t *cl_stereo_separation; 264 extern cvar_t *cl_stereo; 265 266 extern cvar_t *cl_gun; 267 extern cvar_t *cl_add_blend; 268 extern cvar_t *cl_add_lights; 269 extern cvar_t *cl_add_particles; 270 extern cvar_t *cl_add_entities; 271 extern cvar_t *cl_predict; 272 extern cvar_t *cl_blood; 273 extern cvar_t *cl_explosion; 274 extern cvar_t *cl_explosion_scale; 275 extern cvar_t *cl_footsteps; 276 extern cvar_t *cl_noskins; 277 extern cvar_t *cl_autoskins; 278 279 //psychospaz stuff 280 //railgun 281 extern cvar_t *cl_railred; 282 extern cvar_t *cl_railgreen; 283 extern cvar_t *cl_railblue; 284 extern cvar_t *cl_railtype; 285 286 extern cvar_t *r_particle; 287 extern cvar_t *r_decals; 288 extern cvar_t *con_font_size; 289 290 //3dcam 291 extern cvar_t *cl_3dcam; 292 extern cvar_t *cl_3dcam_angle; 293 extern cvar_t *cl_3dcam_chase; 294 extern cvar_t *cl_3dcam_dist; 295 extern cvar_t *cl_3dcam_alpha; 296 extern cvar_t *cl_3dcam_adjust; 297 298 extern cvar_t *cl_hudres; 299 300 extern cvar_t *cl_upspeed; 301 extern cvar_t *cl_forwardspeed; 302 extern cvar_t *cl_sidespeed; 303 304 extern cvar_t *cl_yawspeed; 305 extern cvar_t *cl_pitchspeed; 306 307 extern cvar_t *cl_run; 308 309 extern cvar_t *cl_anglespeedkey; 310 311 extern cvar_t *cl_shownet; 312 extern cvar_t *cl_showmiss; 313 extern cvar_t *cl_showclamp; 314 315 extern cvar_t *lookspring; 316 extern cvar_t *lookstrafe; 317 extern cvar_t *sensitivity; 318 extern cvar_t *menu_sensitivity; 319 extern cvar_t *menu_rotate; 320 321 extern cvar_t *m_pitch; 322 extern cvar_t *m_yaw; 323 extern cvar_t *m_forward; 324 extern cvar_t *m_side; 325 326 extern cvar_t *freelook; 327 328 extern cvar_t *cl_lightlevel; // FIXME HACK 329 330 extern cvar_t *cl_paused; 331 extern cvar_t *cl_timedemo; 332 333 extern cvar_t *cl_vwep; 334 335 typedef struct 336 { 337 int key; // so entities can reuse same entry 338 vec3_t color; 339 vec3_t origin; 340 float radius; 341 float die; // stop lighting after this time 342 float decay; // drop this each second 343 float minlight; // don't add when contributing less 344 } cdlight_t; 345 346 extern centity_t cl_entities[MAX_EDICTS]; 347 extern cdlight_t cl_dlights[MAX_DLIGHTS]; 348 349 // the cl_parse_entities must be large enough to hold UPDATE_BACKUP frames of 350 // entities, so that when a delta compressed message arives from the server 351 // it can be un-deltad from the original 352 #define MAX_PARSE_ENTITIES 1024 353 extern entity_state_t cl_parse_entities[MAX_PARSE_ENTITIES]; 354 355 //============================================================================= 356 357 extern netadr_t net_from; 358 extern sizebuf_t net_message; 359 360 char *unformattedString ( const char *string); 361 362 void DrawString( int x, int y, const char *string, int alpha ); 363 void DrawAltString( int x, int y, const char *string, int alpha ); // toggle high bit 364 qboolean CL_CheckOrDownloadFile (char *filename); 365 qboolean CL_CheckOrDownloadImage (char *base, char *suffix); 366 367 void CL_AddNetgraph (void); 368 369 //ROGUE 370 typedef struct cl_sustain 371 { 372 int id; 373 int type; 374 int endtime; 375 int nextthink; 376 int thinkinterval; 377 vec3_t org; 378 vec3_t dir; 379 int color; 380 int count; 381 int magnitude; 382 void (*think)(struct cl_sustain *self); 383 } cl_sustain_t; 384 385 #define MAX_SUSTAINS 32 386 void CL_ParticleSteamEffect2(cl_sustain_t *self); 387 388 void CL_TeleporterParticles (entity_state_t *ent); 389 void CL_ParticleEffect (vec3_t org, vec3_t dir, int color, int count); 390 void CL_ParticleEffect2 (vec3_t org, vec3_t dir, int color, int count); 391 void CL_ParticleEffect3 (vec3_t org, vec3_t dir, int color, int count); 392 void CL_ParticleEffectSplash (vec3_t org, vec3_t dir, int color, int count); 393 void CL_ParticleWaterEffectSplash (vec3_t org, vec3_t dir, int color, int count, int r); 394 395 qboolean modType (char *name); 396 397 //================================================= 398 399 // ======== 400 // PGM 401 typedef struct 402 { 403 qboolean isactive; 404 405 vec3_t lightcol; 406 float light; 407 float lightvel; 408 } cplight_t; 409 410 #define P_LIGHTS_MAX 8 411 412 void SetParticleImages (void); 413 414 typedef struct particle_s 415 { 416 struct particle_s *next; 417 418 cplight_t lights[P_LIGHTS_MAX]; 419 420 float start; 421 float time; 422 423 vec3_t org; 424 vec3_t vel; 425 vec3_t accel; 426 427 428 vec3_t color; 429 vec3_t colorvel; 430 431 int blendfunc_src; 432 int blendfunc_dst; 433 434 float alpha; 435 float alphavel; 436 437 float size; 438 float sizevel; 439 440 vec3_t angle; 441 442 int image; 443 int flags; 444 445 vec3_t oldorg; 446 float temp; 447 int src_ent; 448 int dst_ent; 449 450 int decalnum; 451 decalpolys_t decal[MAX_DECAL_FRAGMENTS]; 452 453 struct particle_s *link; 454 455 void (*think)(struct particle_s *p, vec3_t org, vec3_t angle, float *alpha, float *size, int *image, float *time); 456 qboolean thinknext; 457 } cparticle_t; 458 459 #define PARTICLE_GRAVITY 150 460 #define BLASTER_PARTICLE_COLOR 0xe0 461 // PMM 462 #define INSTANT_PARTICLE -10000.0 463 // PGM 464 // ======== 465 466 void CL_ClearEffects (void); 467 void CL_ClearTEnts (void); 468 void CL_BlasterTrail (vec3_t start, vec3_t end); 469 void CL_QuadTrail (vec3_t start, vec3_t end); 470 void CL_RailTrail (vec3_t start, vec3_t end); 471 void CL_BubbleTrail (vec3_t start, vec3_t end); 472 void CL_FlagTrail (vec3_t start, vec3_t end, qboolean isred); 473 474 // RAFAEL 475 void CL_IonripperTrail (vec3_t start, vec3_t end); 476 477 //psychospaz -- client side clipping 478 void ClipCam (vec3_t start, vec3_t end, vec3_t newpos); 479 480 void vectoangles2 (vec3_t value1, vec3_t angles); 481 482 // ======== 483 // PGM 484 void CL_BlasterParticles2 (vec3_t org, vec3_t dir, unsigned int color); 485 void CL_BlasterTrail2 (vec3_t start, vec3_t end); 486 void CL_DebugTrail (vec3_t start, vec3_t end); 487 void CL_Flashlight (int ent, vec3_t pos); 488 void CL_ForceWall (vec3_t start, vec3_t end, int color); 489 void CL_FlameEffects (centity_t *ent, vec3_t origin); 490 void CL_GenericParticleEffect (vec3_t org, vec3_t dir, int color, int count, int numcolors, int dirspread, float alphavel); 491 void CL_BubbleTrail2 (vec3_t start, vec3_t end, int dist); 492 void CL_Heatbeam (vec3_t start, vec3_t end); 493 void CL_ParticleSteamEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude); 494 void CL_TrackerTrail (vec3_t start, vec3_t end); 495 void CL_Tracker_Explode(vec3_t origin); 496 void CL_TagTrail (vec3_t start, vec3_t end, int color8); 497 void CL_ColorFlash (vec3_t pos, int ent, int intensity, float r, float g, float b); 498 void CL_Tracker_Shell(vec3_t origin); 499 void CL_MonsterPlasma_Shell(vec3_t origin); 500 void CL_ColorExplosionParticles (vec3_t org, int color, int run); 501 void CL_ParticleSmokeEffect (vec3_t org, vec3_t dir, float size, float alpha); 502 void CL_Widowbeamout (cl_sustain_t *self); 503 void CL_Nukeblast (cl_sustain_t *self); 504 void CL_WidowSplash (vec3_t org); 505 // PGM 506 // ======== 507 508 int CL_ParseEntityBits (unsigned *bits); 509 void CL_ParseDelta (entity_state_t *from, entity_state_t *to, int number, int bits); 510 void CL_ParseFrame (void); 511 512 void CL_ParseTEnt (void); 513 void CL_ParseConfigString (void); 514 void CL_ParseMuzzleFlash (void); 515 void CL_ParseMuzzleFlash2 (void); 516 void SmokeAndFlash(vec3_t origin); 517 518 void CL_SetLightstyle (int i); 519 520 void CL_RunParticles (void); 521 void CL_RunDLights (void); 522 void CL_RunLightStyles (void); 523 524 void CL_AddEntities (void); 525 void CL_AddDLights (void); 526 void CL_AddHeatDLights (void); 527 void CL_AddTEnts (void); 528 void CL_AddLightStyles (void); 529 530 //================================================= 531 532 void CL_PrepRefresh (); 533 void CL_RegisterSounds (void); 534 535 void CL_Quit_f (void); 536 537 void IN_Accumulate (void); 538 539 void CL_ParseLayout (void); 540 541 542 // 543 // cl_main 544 // 545 extern refexport_t re; // interface to refresh .dll 546 547 void CL_Init (void); 548 549 void CL_FixUpGender(void); 550 void CL_Disconnect (void); 551 void CL_Disconnect_f (void); 552 void CL_GetChallengePacket (void); 553 void CL_PingServers_f (void); 554 void CL_Snd_Restart_f (void); 555 void CL_RequestNextDownload (void); 556 557 // 558 // cl_input 559 // 560 typedef struct 561 { 562 int down[2]; // key nums holding it down 563 unsigned downtime; // msec timestamp 564 unsigned msec; // msec down this frame 565 int state; 566 } kbutton_t; 567 568 extern kbutton_t in_mlook, in_klook; 569 extern kbutton_t in_strafe; 570 extern kbutton_t in_speed; 571 572 void CL_InitInput (void); 573 void CL_SendCmd (void); 574 void CL_SendMove (usercmd_t *cmd); 575 576 void CL_ClearState (void); 577 578 void CL_ReadPackets (void); 579 580 int CL_ReadFromServer (void); 581 void CL_WriteToServer (usercmd_t *cmd); 582 void CL_BaseMove (usercmd_t *cmd); 583 584 void IN_CenterView (void); 585 586 float CL_KeyState (kbutton_t *key); 587 char *Key_KeynumToString (int keynum); 588 589 // 590 // cl_demo.c 591 // 592 void CL_WriteDemoMessage (void); 593 void CL_Stop_f (void); 594 void CL_Record_f (void); 595 596 // 597 // cl_parse.c 598 // 599 extern char *svc_strings[256]; 600 601 void CL_ParseServerMessage (void); 602 void CL_LoadClientinfo (clientinfo_t *ci, char *s); 603 void SHOWNET(char *s); 604 void CL_ParseClientinfo (int player); 605 void CL_DefaultClientinfo (int player); 606 void CL_Download_f (void); 607 608 // 609 // cl_view.c 610 // 611 extern int gun_frame; 612 extern struct model_s *gun_model; 613 614 qboolean loadingMessage; 615 char loadingMessages[5][96]; 616 float loadingPercent; 617 618 void V_Init (void); 619 void V_RenderView( float stereo_separation ); 620 void V_AddEntity (entity_t *ent); 621 void V_AddParticle (vec3_t org, vec3_t angle, vec3_t color, float alpha, int alpha_src, int alpha_dst, float size, int image, int flags, decalpolys_t *decal); 622 void V_AddLight (vec3_t org, float intensity, float r, float g, float b); 623 void V_AddSpotLight (vec3_t org, vec3_t direction, float intensity, float r, float g, float b); 624 void V_AddLightStyle (int style, float r, float g, float b); 625 626 // 627 // cl_tent.c 628 // 629 void CL_RegisterTEntSounds (void); 630 void CL_RegisterTEntModels (void); 631 void CL_SmokeAndFlash(vec3_t origin); 632 633 634 // 635 // cl_pred.c 636 // 637 void CL_InitPrediction (void); 638 void CL_PredictMove (void); 639 void CL_CheckPredictionError (void); 640 641 // 642 // cl_fx.c 643 // 644 cdlight_t *CL_AllocDlight (int key); 645 void CL_BigTeleportParticles (vec3_t org); 646 void CL_RocketTrail (vec3_t start, vec3_t end, centity_t *old, entity_t *ent); 647 void CL_DiminishingTrail (vec3_t start, vec3_t end, centity_t *old, int flags, entity_t *ent); 648 void CL_FlyEffect (centity_t *ent, vec3_t origin); 649 void CL_BfgParticles (entity_t *ent); 650 void CL_AddParticles (void); 651 void CL_EntityEvent (entity_state_t *ent); 652 // RAFAEL 653 void CL_TrapParticles (entity_t *ent); 654 655 // 656 // menus 657 // 658 void M_Init (void); 659 void M_Keydown (int key); 660 void M_Draw (void); 661 void M_Menu_Main_f (void); 662 void M_ForceMenuOff (void); 663 void M_AddToServerList (netadr_t adr, char *info); 664 665 // 666 // cl_inv.c 667 // 668 void CL_ParseInventory (void); 669 void CL_KeyInventory (int key); 670 void CL_DrawInventory (void); 671 672 // 673 // cl_pred.c 674 // 675 void CL_PredictMovement (void); 676 677 #if id386 678 void x86_TimerStart( void ); 679 void x86_TimerStop( void ); 680 void x86_TimerInit( unsigned long smallest, unsigned longest ); 681 unsigned long *x86_TimerGetHistogram( void ); 682 #endif 683 684