client.h 12 KB

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