PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/quakeforge-old/branches/modular_input/common/client.h

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