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