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 21 #ifndef CLIENT_H 22 #define CLIENT_H 23 24 #include "net.h" 25 #include "protocol.h" 26 #include "render.h" 27 #include "sound.h" 28 #include "vid.h" 29 #include "zone.h" 30 31 // 32 // client_state_t should hold all pieces of the client state 33 // 34 35 typedef struct { 36 char name[16]; 37 qboolean failedload; // the name isn't a valid skin 38 cache_user_t cache; 39 } skin_t; 40 41 #define MAX_DLIGHTS 32 42 typedef struct { 43 int key; // so entities can reuse same entry 44 vec3_t origin; 45 float radius; 46 float die; // stop lighting after this time 47 float decay; // drop this each second 48 float minlight; // don't add when contributing less 49 const float *color; 50 } dlight_t; 51 52 typedef struct { 53 int length; 54 char map[MAX_STYLESTRING]; 55 } lightstyle_t; 56 57 // player_state_t is the information needed by a player entity 58 // to do move prediction and to generate a drawable entity 59 typedef struct { 60 int messagenum; // all player's won't be updated each frame 61 62 double state_time; // not the same as the packet time, 63 // because player commands come asyncronously 64 usercmd_t command; // last command for prediction 65 66 vec3_t origin; 67 vec3_t viewangles; // only for demos, not from server 68 vec3_t velocity; 69 int weaponframe; 70 71 int modelindex; 72 int frame; 73 int skinnum; 74 int effects; 75 76 int flags; // dead, gib, etc 77 78 float waterjumptime; 79 int onground; // -1 = in air, else pmove entity number 80 int oldbuttons; 81 } player_state_t; 82 83 84 #define MAX_SCOREBOARDNAME 16 85 typedef struct player_info_s { 86 int userid; 87 char userinfo[MAX_INFO_STRING]; 88 89 // scoreboard information 90 char name[MAX_SCOREBOARDNAME]; 91 float entertime; 92 int frags; 93 int ping; 94 byte pl; 95 96 // skin information 97 byte topcolor; 98 byte bottomcolor; 99 byte _topcolor; 100 byte _bottomcolor; 101 102 int spectator; 103 byte translations[VID_GRADES * 256]; 104 skin_t *skin; 105 } player_info_t; 106 107 108 typedef struct { 109 // generated on client side 110 usercmd_t cmd; // cmd that generated the frame 111 double senttime; // time cmd was sent off 112 int delta_sequence; // sequence number to delta from, 113 // -1 = full update 114 115 // received from server 116 double receivedtime; // time message was received, or -1 117 player_state_t playerstate[MAX_CLIENTS]; // message received that reflects 118 // performing the usercmd 119 packet_entities_t packet_entities; 120 qboolean invalid; // set if the packet_entities delta was invalid 121 } frame_t; 122 123 124 typedef struct { 125 int destcolor[3]; 126 int percent; // 0-256 127 double time; 128 int initialpct; 129 } cshift_t; 130 131 #define CSHIFT_CONTENTS 0 132 #define CSHIFT_DAMAGE 1 133 #define CSHIFT_BONUS 2 134 #define CSHIFT_POWERUP 3 135 136 #define NUM_CSHIFTS 4 137 138 #define MAX_EFRAGS 512 139 #define MAX_DEMOS 8 140 #define MAX_DEMONAME 16 141 142 typedef enum { 143 ca_disconnected, // full screen console with no connection 144 ca_demostart, // starting up a demo 145 ca_connected, // netchan_t established, waiting for svc_serverdata 146 ca_onserver, // processing data lists, donwloading, etc 147 ca_active, // everything is in, so frames can be rendered 148 ENSURE_INT_CACTIVE = 0x70000000 149 } cactive_t; 150 151 typedef enum { 152 dl_none, 153 dl_model, 154 dl_sound, 155 dl_skin, 156 dl_single, 157 ENSURE_INT_DLTYPE = 0x70000000 158 } dltype_t; // download type 159 160 // 161 // the client_static_t structure is persistant through an arbitrary number 162 // of server connections 163 // 164 typedef struct { 165 // connection information 166 cactive_t state; 167 168 // network stuff 169 netchan_t netchan; 170 171 // private userinfo for sending to masterless servers 172 char userinfo[MAX_INFO_STRING]; 173 174 char servername[MAX_OSPATH]; // name of server from original connect 175 176 int qport; 177 178 FILE *download; // file transfer from server 179 char downloadtempname[MAX_OSPATH]; 180 char downloadname[MAX_OSPATH]; 181 int downloadnumber; 182 dltype_t downloadtype; 183 int downloadpercent; 184 185 // demo loop control 186 int demonum; // -1 = don't play demos 187 char demos[MAX_DEMOS][MAX_DEMONAME]; // when not playing 188 189 // demo recording info must be here, because record is started before 190 // entering a map (and clearing client_state_t) 191 qboolean demorecording; 192 qboolean demoplayback; 193 qboolean timedemo; 194 FILE *demofile; 195 float td_lastframe; // to meter out one message a frame 196 int td_startframe; // host_framecount at start 197 float td_starttime; // realtime at second frame of timedemo 198 199 int challenge; 200 201 float latency; // rolling average 202 } client_static_t; 203 204 extern client_static_t cls; 205 206 // 207 // the client_state_t structure is wiped completely at every 208 // server signon 209 // 210 typedef struct { 211 int servercount; // server identification for prespawns 212 213 char serverinfo[MAX_SERVERINFO_STRING]; 214 215 int parsecount; // server message counter 216 int validsequence; // this is the sequence number of the last good 217 // packetentity_t we got. If this is 0, we can't 218 // render a frame yet 219 int movemessages; // since connecting to this server 220 // throw out the first couple, so the player 221 // doesn't accidentally do something the 222 // first frame 223 224 int spectator; 225 226 double last_ping_request; // while showing scoreboard 227 double last_servermessage; 228 229 // sentcmds[cl.netchan.outgoing_sequence & UPDATE_MASK] = cmd 230 frame_t frames[UPDATE_BACKUP]; 231 232 // information for local display 233 int stats[MAX_CL_STATS]; // health, etc 234 float item_gettime[32]; // cl.time of aquiring item, for blinking 235 float faceanimtime; // use anim frame if cl.time < this 236 237 cshift_t cshifts[NUM_CSHIFTS]; // color shifts for damage, powerups 238 cshift_t prev_cshifts[NUM_CSHIFTS]; // and content types 239 240 // the client maintains its own idea of view angles, which are 241 // sent to the server each frame. And only reset at level change 242 // and teleport times 243 vec3_t viewangles; 244 245 // the client simulates or interpolates movement to get these values 246 double time; // this is the time value that the client 247 // is rendering at. allways <= realtime 248 vec3_t simorg; 249 vec3_t simvel; 250 vec3_t simangles; 251 252 // pitch drifting vars 253 float pitchvel; 254 qboolean nodrift; 255 float driftmove; 256 double laststop; 257 258 259 float crouch; // local amount for smoothing stepups 260 261 qboolean paused; // send over by server 262 263 float punchangle; // temporar yview kick from weapon firing 264 265 int intermission; // don't change view angle, full screen, etc 266 int completed_time; // latched ffrom time at intermission start 267 268 // 269 // information that is static for the entire time connected to a server 270 // 271 char model_name[MAX_MODELS][MAX_QPATH]; 272 char sound_name[MAX_SOUNDS][MAX_QPATH]; 273 274 struct model_s *model_precache[MAX_MODELS]; 275 struct sfx_s *sound_precache[MAX_SOUNDS]; 276 277 char levelname[40]; // for display on solo scoreboard 278 int playernum; 279 280 // refresh related state 281 struct model_s *worldmodel; // cl_entitites[0].model 282 struct efrag_s *free_efrags; 283 int num_entities; // stored bottom up in cl_entities array 284 int num_statics; // stored top down in cl_entitiers 285 286 int cdtrack; // cd audio 287 288 entity_t viewent; // weapon model 289 290 // all player information 291 player_info_t players[MAX_CLIENTS]; 292 } client_state_t; 293 294 295 // 296 // cvars 297 // 298 extern cvar_t cl_warncmd; 299 extern cvar_t cl_upspeed; 300 extern cvar_t cl_forwardspeed; 301 extern cvar_t cl_backspeed; 302 extern cvar_t cl_sidespeed; 303 304 extern cvar_t cl_movespeedkey; 305 306 extern cvar_t cl_yawspeed; 307 extern cvar_t cl_pitchspeed; 308 309 extern cvar_t cl_anglespeedkey; 310 311 extern cvar_t cl_shownet; 312 extern cvar_t cl_sbar; 313 extern cvar_t cl_hudswap; 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 m_pitch; 321 extern cvar_t m_yaw; 322 extern cvar_t m_forward; 323 extern cvar_t m_side; 324 325 extern cvar_t name; 326 327 extern cvar_t cl_predict_players; 328 extern cvar_t cl_predict_players2; 329 extern cvar_t cl_solid_players; 330 331 extern int cl_spikeindex, cl_playerindex, cl_flagindex; 332 extern int parsecountmod; 333 extern double parsecounttime; 334 335 extern vec3_t player_mins; 336 extern vec3_t player_maxs; 337 338 entity_t *CL_NewTempEntity(void); 339 340 #define MAX_STATIC_ENTITIES 128 // torches, etc 341 342 extern client_state_t cl; 343 344 // FIXME, allocate dynamically 345 extern entity_state_t cl_baselines[MAX_EDICTS]; 346 extern efrag_t cl_efrags[MAX_EFRAGS]; 347 extern entity_t cl_static_entities[MAX_STATIC_ENTITIES]; 348 extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; 349 extern dlight_t cl_dlights[MAX_DLIGHTS]; 350 351 //============================================================================= 352 353 354 // 355 // cl_main 356 // 357 dlight_t *CL_AllocDlight(int key); 358 359 /* The standard dynamic light colors */ 360 enum { 361 DLIGHT_FLASH = 0, 362 DLIGHT_BLUE = 1, 363 DLIGHT_RED = 2, 364 DLIGHT_PURPLE = 3 365 }; 366 extern float dl_colors[4][4]; /* Use enums to reference the colors */ 367 368 void CL_DecayLights(void); 369 void CL_RunParticles(void); 370 371 void CL_Init(void); 372 void Host_WriteConfiguration(void); 373 374 void CL_EstablishConnection(char *host); 375 376 void CL_Disconnect(void); 377 void CL_Disconnect_f(void); 378 void CL_NextDemo(void); 379 qboolean CL_DemoBehind(void); 380 381 void CL_BeginServerConnect(void); 382 383 #define MAX_VISEDICTS 256 384 extern int cl_numvisedicts; 385 extern entity_t cl_visedicts[]; 386 387 extern int fps_count; 388 extern int minimum_memory; 389 390 // 391 // cl_input 392 // 393 typedef struct { 394 int down[2]; // key nums holding it down 395 int state; // low bit is down state 396 } kbutton_t; 397 398 extern kbutton_t in_mlook; 399 extern kbutton_t in_strafe; 400 extern kbutton_t in_speed; 401 402 void CL_InitInput(void); 403 void CL_SendCmd(void); 404 void CL_SendMove(usercmd_t *cmd); 405 406 void CL_ParseTEnt(void); 407 void CL_UpdateTEnts(void); 408 409 void CL_ClearState(void); 410 411 void CL_ReadPackets(void); 412 413 int CL_ReadFromServer(void); 414 void CL_WriteToServer(usercmd_t *cmd); 415 void CL_BaseMove(usercmd_t *cmd); 416 417 // 418 // cl_demo.c 419 // 420 void CL_StopPlayback(void); 421 qboolean CL_GetMessage(void); 422 void CL_WriteDemoCmd(usercmd_t *pcmd); 423 424 void CL_Stop_f(void); 425 void CL_Record_f(void); 426 void CL_ReRecord_f(void); 427 428 void CL_PlayDemo_f(void); 429 void CL_TimeDemo_f(void); 430 struct stree_root *CL_Demo_Arg_f(const char *arg); 431 432 // 433 // cl_parse.c 434 // 435 #define NET_TIMINGS 256 436 #define NET_TIMINGSMASK 255 437 extern int packet_latency[NET_TIMINGS]; 438 int CL_CalcNet(void); 439 void CL_ParseServerMessage(void); 440 qboolean CL_CheckOrDownloadFile(char *filename); 441 qboolean CL_IsUploading(void); 442 void CL_NextUpload(void); 443 void CL_StartUpload(byte *data, int size); 444 void CL_StopUpload(void); 445 446 // 447 // view.c 448 // 449 void V_StartPitchDrift(void); 450 void V_StopPitchDrift(void); 451 452 void V_RenderView(void); 453 void V_UpdatePalette(void); 454 void V_Register(void); 455 void V_ParseDamage(void); 456 void V_SetContentsColor(int contents); 457 void V_CalcBlend(void); 458 459 // 460 // cl_tent 461 // 462 void CL_InitTEnts(void); 463 void CL_ClearTEnts(void); 464 465 // 466 // cl_ents.c 467 // 468 void CL_SetSolidPlayers(int playernum); 469 void CL_SetUpPlayerPrediction(qboolean dopred); 470 void CL_EmitEntities(void); 471 void CL_ClearProjectiles(void); 472 void CL_ParseProjectiles(void); 473 void CL_ParsePacketEntities(qboolean delta); 474 void CL_SetSolidEntities(void); 475 void CL_ParsePlayerinfo(void); 476 477 // 478 // cl_pred.c 479 // 480 void CL_InitPrediction(void); 481 void CL_PredictMove(void); 482 void CL_PredictUsercmd(player_state_t * from, player_state_t * to, 483 usercmd_t *u, qboolean spectator); 484 485 // 486 // cl_cam.c 487 // 488 #define CAM_NONE 0 489 #define CAM_TRACK 1 490 491 extern int autocam; 492 extern int spec_track; // player# of who we are tracking 493 494 qboolean Cam_DrawViewModel(void); 495 qboolean Cam_DrawPlayer(int playernum); 496 void Cam_Track(usercmd_t *cmd); 497 void Cam_FinishMove(usercmd_t *cmd); 498 void Cam_Reset(void); 499 void CL_InitCam(void); 500 501 // 502 // skin.c 503 // 504 505 typedef struct { 506 char manufacturer; 507 char version; 508 char encoding; 509 char bits_per_pixel; 510 unsigned short xmin, ymin, xmax, ymax; 511 unsigned short hres, vres; 512 unsigned char palette[48]; 513 char reserved; 514 char color_planes; 515 unsigned short bytes_per_line; 516 unsigned short palette_type; 517 char filler[58]; 518 unsigned char data; /* unbounded */ 519 } pcx_t; 520 521 522 void Skin_Find(player_info_t * sc); 523 byte *Skin_Cache(skin_t * skin); 524 void Skin_Skins_f(void); 525 void Skin_AllSkins_f(void); 526 void Skin_NextDownload(void); 527 528 #define RSSHOT_WIDTH 320 529 #define RSSHOT_HEIGHT 200 530 531 #endif /* CLIENT_H */ 532