client.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*
  2. Copyright (C) 1997-2001 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 -- primary header for client
  16. //define PARANOID // speed sapping error checking
  17. #include <math.h>
  18. #include <string.h>
  19. #include <stdarg.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include "ref.h"
  23. #include "vid.h"
  24. #include "screen.h"
  25. #include "sound.h"
  26. #include "input.h"
  27. #include "keys.h"
  28. #include "console.h"
  29. #include "cdaudio.h"
  30. //=============================================================================
  31. typedef struct
  32. {
  33. qboolean valid; // cleared if delta parsing was invalid
  34. int serverframe;
  35. int servertime; // server time the message is valid for (in msec)
  36. int deltaframe;
  37. byte areabits[MAX_MAP_AREAS/8]; // portalarea visibility bits
  38. player_state_t playerstate;
  39. int num_entities;
  40. int parse_entities; // non-masked index into cl_parse_entities array
  41. } frame_t;
  42. typedef struct
  43. {
  44. entity_state_t baseline; // delta from this if not from a previous frame
  45. entity_state_t current;
  46. entity_state_t prev; // will always be valid, but might just be a copy of current
  47. int serverframe; // if not current, this ent isn't in the frame
  48. int trailcount; // for diminishing grenade trails
  49. vec3_t lerp_origin; // for trails (variable hz)
  50. int fly_stoptime;
  51. } centity_t;
  52. #define MAX_CLIENTWEAPONMODELS 20 // PGM -- upped from 16 to fit the chainfist vwep
  53. typedef struct
  54. {
  55. char name[MAX_QPATH];
  56. char cinfo[MAX_QPATH];
  57. struct image_s *skin;
  58. struct image_s *icon;
  59. char iconname[MAX_QPATH];
  60. struct model_s *model;
  61. struct model_s *weaponmodel[MAX_CLIENTWEAPONMODELS];
  62. } clientinfo_t;
  63. extern char cl_weaponmodels[MAX_CLIENTWEAPONMODELS][MAX_QPATH];
  64. extern int num_cl_weaponmodels;
  65. #define CMD_BACKUP 64 // allow a lot of command backups for very fast systems
  66. //
  67. // the client_state_t structure is wiped completely at every
  68. // server map change
  69. //
  70. typedef struct
  71. {
  72. int timeoutcount;
  73. int timedemo_frames;
  74. int timedemo_start;
  75. qboolean refresh_prepped; // false if on new level or new ref dll
  76. qboolean sound_prepped; // ambient sounds can start
  77. qboolean force_refdef; // vid has changed, so we can't use a paused refdef
  78. int parse_entities; // index (not anded off) into cl_parse_entities[]
  79. usercmd_t cmd;
  80. usercmd_t cmds[CMD_BACKUP]; // each mesage will send several old cmds
  81. int cmd_time[CMD_BACKUP]; // time sent, for calculating pings
  82. short predicted_origins[CMD_BACKUP][3]; // for debug comparing against server
  83. float predicted_step; // for stair up smoothing
  84. unsigned predicted_step_time;
  85. vec3_t predicted_origin; // generated by CL_PredictMovement
  86. vec3_t predicted_angles;
  87. vec3_t prediction_error;
  88. frame_t frame; // received from server
  89. int surpressCount; // number of messages rate supressed
  90. frame_t frames[UPDATE_BACKUP];
  91. // the client maintains its own idea of view angles, which are
  92. // sent to the server each frame. It is cleared to 0 upon entering each level.
  93. // the server sends a delta each frame which is added to the locally
  94. // tracked view angles to account for standing on rotating objects,
  95. // and teleport direction changes
  96. vec3_t viewangles;
  97. int time; // this is the time value that the client
  98. // is rendering at. always <= cls.realtime
  99. float lerpfrac; // between oldframe and frame
  100. refdef_t refdef;
  101. vec3_t v_forward, v_right, v_up; // set when refdef.angles is set
  102. //
  103. // transient data from server
  104. //
  105. char layout[1024]; // general 2D overlay
  106. int inventory[MAX_ITEMS];
  107. //
  108. // non-gameserver infornamtion
  109. // FIXME: move this cinematic stuff into the cin_t structure
  110. FILE *cinematic_file;
  111. int cinematictime; // cls.realtime for first cinematic frame
  112. int cinematicframe;
  113. char cinematicpalette[768];
  114. qboolean cinematicpalette_active;
  115. //
  116. // server state information
  117. //
  118. qboolean attractloop; // running the attract loop, any key will menu
  119. int servercount; // server identification for prespawns
  120. char gamedir[MAX_QPATH];
  121. int playernum;
  122. char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
  123. //
  124. // locally derived information from server state
  125. //
  126. struct model_s *model_draw[MAX_MODELS];
  127. struct cmodel_s *model_clip[MAX_MODELS];
  128. struct sfx_s *sound_precache[MAX_SOUNDS];
  129. struct image_s *image_precache[MAX_IMAGES];
  130. clientinfo_t clientinfo[MAX_CLIENTS];
  131. clientinfo_t baseclientinfo;
  132. } client_state_t;
  133. extern client_state_t cl;
  134. /*
  135. ==================================================================
  136. the client_static_t structure is persistant through an arbitrary number
  137. of server connections
  138. ==================================================================
  139. */
  140. typedef enum {
  141. ca_uninitialized,
  142. ca_disconnected, // not talking to a server
  143. ca_connecting, // sending request packets to the server
  144. ca_connected, // netchan_t established, waiting for svc_serverdata
  145. ca_active // game views should be displayed
  146. } connstate_t;
  147. typedef enum {
  148. dl_none,
  149. dl_model,
  150. dl_sound,
  151. dl_skin,
  152. dl_single
  153. } dltype_t; // download type
  154. typedef enum {key_game, key_console, key_message, key_menu} keydest_t;
  155. typedef struct
  156. {
  157. connstate_t state;
  158. keydest_t key_dest;
  159. int framecount;
  160. int realtime; // always increasing, no clamping, etc
  161. float frametime; // seconds since last frame
  162. // screen rendering information
  163. float disable_screen; // showing loading plaque between levels
  164. // or changing rendering dlls
  165. // if time gets > 30 seconds ahead, break it
  166. int disable_servercount; // when we receive a frame and cl.servercount
  167. // > cls.disable_servercount, clear disable_screen
  168. // connection information
  169. char servername[MAX_OSPATH]; // name of server from original connect
  170. float connect_time; // for connection retransmits
  171. int quakePort; // a 16 bit value that allows quake servers
  172. // to work around address translating routers
  173. netchan_t netchan;
  174. int serverProtocol; // in case we are doing some kind of version hack
  175. int challenge; // from the server to use for connecting
  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. // demo recording info must be here, so it isn't cleared on level change
  183. qboolean demorecording;
  184. qboolean demowaiting; // don't record until a non-delta message is received
  185. FILE *demofile;
  186. } client_static_t;
  187. extern client_static_t cls;
  188. //=============================================================================
  189. //
  190. // cvars
  191. //
  192. extern cvar_t *cl_stereo_separation;
  193. extern cvar_t *cl_stereo;
  194. extern cvar_t *cl_gun;
  195. extern cvar_t *cl_add_blend;
  196. extern cvar_t *cl_add_lights;
  197. extern cvar_t *cl_add_particles;
  198. extern cvar_t *cl_add_entities;
  199. extern cvar_t *cl_predict;
  200. extern cvar_t *cl_footsteps;
  201. extern cvar_t *cl_noskins;
  202. extern cvar_t *cl_autoskins;
  203. extern cvar_t *cl_upspeed;
  204. extern cvar_t *cl_forwardspeed;
  205. extern cvar_t *cl_sidespeed;
  206. extern cvar_t *cl_yawspeed;
  207. extern cvar_t *cl_pitchspeed;
  208. extern cvar_t *cl_run;
  209. extern cvar_t *cl_anglespeedkey;
  210. extern cvar_t *cl_shownet;
  211. extern cvar_t *cl_showmiss;
  212. extern cvar_t *cl_showclamp;
  213. extern cvar_t *lookspring;
  214. extern cvar_t *lookstrafe;
  215. extern cvar_t *sensitivity;
  216. extern cvar_t *m_pitch;
  217. extern cvar_t *m_yaw;
  218. extern cvar_t *m_forward;
  219. extern cvar_t *m_side;
  220. extern cvar_t *freelook;
  221. extern cvar_t *cl_lightlevel; // FIXME HACK
  222. extern cvar_t *cl_paused;
  223. extern cvar_t *cl_timedemo;
  224. extern cvar_t *cl_vwep;
  225. typedef struct
  226. {
  227. int key; // so entities can reuse same entry
  228. vec3_t color;
  229. vec3_t origin;
  230. float radius;
  231. float die; // stop lighting after this time
  232. float decay; // drop this each second
  233. float minlight; // don't add when contributing less
  234. } cdlight_t;
  235. extern centity_t cl_entities[MAX_EDICTS];
  236. extern cdlight_t cl_dlights[MAX_DLIGHTS];
  237. // the cl_parse_entities must be large enough to hold UPDATE_BACKUP frames of
  238. // entities, so that when a delta compressed message arives from the server
  239. // it can be un-deltad from the original
  240. #define MAX_PARSE_ENTITIES 1024
  241. extern entity_state_t cl_parse_entities[MAX_PARSE_ENTITIES];
  242. //=============================================================================
  243. extern netadr_t net_from;
  244. extern sizebuf_t net_message;
  245. void DrawString (int x, int y, char *s);
  246. void DrawAltString (int x, int y, char *s); // toggle high bit
  247. qboolean CL_CheckOrDownloadFile (char *filename);
  248. void CL_AddNetgraph (void);
  249. //ROGUE
  250. typedef struct cl_sustain
  251. {
  252. int id;
  253. int type;
  254. int endtime;
  255. int nextthink;
  256. int thinkinterval;
  257. vec3_t org;
  258. vec3_t dir;
  259. int color;
  260. int count;
  261. int magnitude;
  262. void (*think)(struct cl_sustain *self);
  263. } cl_sustain_t;
  264. #define MAX_SUSTAINS 32
  265. void CL_ParticleSteamEffect2(cl_sustain_t *self);
  266. void CL_TeleporterParticles (entity_state_t *ent);
  267. void CL_ParticleEffect (vec3_t org, vec3_t dir, int color, int count);
  268. void CL_ParticleEffect2 (vec3_t org, vec3_t dir, int color, int count);
  269. // RAFAEL
  270. void CL_ParticleEffect3 (vec3_t org, vec3_t dir, int color, int count);
  271. //=================================================
  272. // ========
  273. // PGM
  274. typedef struct particle_s
  275. {
  276. struct particle_s *next;
  277. float time;
  278. vec3_t org;
  279. vec3_t vel;
  280. vec3_t accel;
  281. float color;
  282. float colorvel;
  283. float alpha;
  284. float alphavel;
  285. } cparticle_t;
  286. #define PARTICLE_GRAVITY 40
  287. #define BLASTER_PARTICLE_COLOR 0xe0
  288. // PMM
  289. #define INSTANT_PARTICLE -10000.0
  290. // PGM
  291. // ========
  292. void CL_ClearEffects (void);
  293. void CL_ClearTEnts (void);
  294. void CL_BlasterTrail (vec3_t start, vec3_t end);
  295. void CL_QuadTrail (vec3_t start, vec3_t end);
  296. void CL_RailTrail (vec3_t start, vec3_t end);
  297. void CL_BubbleTrail (vec3_t start, vec3_t end);
  298. void CL_FlagTrail (vec3_t start, vec3_t end, float color);
  299. // RAFAEL
  300. void CL_IonripperTrail (vec3_t start, vec3_t end);
  301. // ========
  302. // PGM
  303. void CL_BlasterParticles2 (vec3_t org, vec3_t dir, unsigned int color);
  304. void CL_BlasterTrail2 (vec3_t start, vec3_t end);
  305. void CL_DebugTrail (vec3_t start, vec3_t end);
  306. void CL_SmokeTrail (vec3_t start, vec3_t end, int colorStart, int colorRun, int spacing);
  307. void CL_Flashlight (int ent, vec3_t pos);
  308. void CL_ForceWall (vec3_t start, vec3_t end, int color);
  309. void CL_FlameEffects (centity_t *ent, vec3_t origin);
  310. void CL_GenericParticleEffect (vec3_t org, vec3_t dir, int color, int count, int numcolors, int dirspread, float alphavel);
  311. void CL_BubbleTrail2 (vec3_t start, vec3_t end, int dist);
  312. void CL_Heatbeam (vec3_t start, vec3_t end);
  313. void CL_ParticleSteamEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude);
  314. void CL_TrackerTrail (vec3_t start, vec3_t end, int particleColor);
  315. void CL_Tracker_Explode(vec3_t origin);
  316. void CL_TagTrail (vec3_t start, vec3_t end, float color);
  317. void CL_ColorFlash (vec3_t pos, int ent, int intensity, float r, float g, float b);
  318. void CL_Tracker_Shell(vec3_t origin);
  319. void CL_MonsterPlasma_Shell(vec3_t origin);
  320. void CL_ColorExplosionParticles (vec3_t org, int color, int run);
  321. void CL_ParticleSmokeEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude);
  322. void CL_Widowbeamout (cl_sustain_t *self);
  323. void CL_Nukeblast (cl_sustain_t *self);
  324. void CL_WidowSplash (vec3_t org);
  325. // PGM
  326. // ========
  327. int CL_ParseEntityBits (unsigned *bits);
  328. void CL_ParseDelta (entity_state_t *from, entity_state_t *to, int number, int bits);
  329. void CL_ParseFrame (void);
  330. void CL_ParseTEnt (void);
  331. void CL_ParseConfigString (void);
  332. void CL_ParseMuzzleFlash (void);
  333. void CL_ParseMuzzleFlash2 (void);
  334. void SmokeAndFlash(vec3_t origin);
  335. void CL_SetLightstyle (int i);
  336. void CL_RunParticles (void);
  337. void CL_RunDLights (void);
  338. void CL_RunLightStyles (void);
  339. void CL_AddEntities (void);
  340. void CL_AddDLights (void);
  341. void CL_AddTEnts (void);
  342. void CL_AddLightStyles (void);
  343. //=================================================
  344. void CL_PrepRefresh (void);
  345. void CL_RegisterSounds (void);
  346. void CL_Quit_f (void);
  347. void IN_Accumulate (void);
  348. void CL_ParseLayout (void);
  349. //
  350. // cl_main
  351. //
  352. extern refexport_t re; // interface to refresh .dll
  353. void CL_Init (void);
  354. void CL_FixUpGender(void);
  355. void CL_Disconnect (void);
  356. void CL_Disconnect_f (void);
  357. void CL_GetChallengePacket (void);
  358. void CL_PingServers_f (void);
  359. void CL_Snd_Restart_f (void);
  360. void CL_RequestNextDownload (void);
  361. //
  362. // cl_input
  363. //
  364. typedef struct
  365. {
  366. int down[2]; // key nums holding it down
  367. unsigned downtime; // msec timestamp
  368. unsigned msec; // msec down this frame
  369. int state;
  370. } kbutton_t;
  371. extern kbutton_t in_mlook, in_klook;
  372. extern kbutton_t in_strafe;
  373. extern kbutton_t in_speed;
  374. void CL_InitInput (void);
  375. void CL_SendCmd (void);
  376. void CL_SendMove (usercmd_t *cmd);
  377. void CL_ClearState (void);
  378. void CL_ReadPackets (void);
  379. int CL_ReadFromServer (void);
  380. void CL_WriteToServer (usercmd_t *cmd);
  381. void CL_BaseMove (usercmd_t *cmd);
  382. void IN_CenterView (void);
  383. float CL_KeyState (kbutton_t *key);
  384. char *Key_KeynumToString (int keynum);
  385. //
  386. // cl_demo.c
  387. //
  388. void CL_WriteDemoMessage (void);
  389. void CL_Stop_f (void);
  390. void CL_Record_f (void);
  391. //
  392. // cl_parse.c
  393. //
  394. extern char *svc_strings[256];
  395. void CL_ParseServerMessage (void);
  396. void CL_LoadClientinfo (clientinfo_t *ci, char *s);
  397. void SHOWNET(char *s);
  398. void CL_ParseClientinfo (int player);
  399. void CL_Download_f (void);
  400. //
  401. // cl_view.c
  402. //
  403. extern int gun_frame;
  404. extern struct model_s *gun_model;
  405. void V_Init (void);
  406. void V_RenderView( float stereo_separation );
  407. void V_AddEntity (entity_t *ent);
  408. void V_AddParticle (vec3_t org, int color, float alpha);
  409. void V_AddLight (vec3_t org, float intensity, float r, float g, float b);
  410. void V_AddLightStyle (int style, float r, float g, float b);
  411. //
  412. // cl_tent.c
  413. //
  414. void CL_RegisterTEntSounds (void);
  415. void CL_RegisterTEntModels (void);
  416. void CL_SmokeAndFlash(vec3_t origin);
  417. //
  418. // cl_pred.c
  419. //
  420. void CL_InitPrediction (void);
  421. void CL_PredictMove (void);
  422. void CL_CheckPredictionError (void);
  423. //
  424. // cl_fx.c
  425. //
  426. cdlight_t *CL_AllocDlight (int key);
  427. void CL_BigTeleportParticles (vec3_t org);
  428. void CL_RocketTrail (vec3_t start, vec3_t end, centity_t *old);
  429. void CL_DiminishingTrail (vec3_t start, vec3_t end, centity_t *old, int flags);
  430. void CL_FlyEffect (centity_t *ent, vec3_t origin);
  431. void CL_BfgParticles (entity_t *ent);
  432. void CL_AddParticles (void);
  433. void CL_EntityEvent (entity_state_t *ent);
  434. // RAFAEL
  435. void CL_TrapParticles (entity_t *ent);
  436. //
  437. // menus
  438. //
  439. void M_Init (void);
  440. void M_Keydown (int key);
  441. void M_Draw (void);
  442. void M_Menu_Main_f (void);
  443. void M_ForceMenuOff (void);
  444. void M_AddToServerList (netadr_t adr, char *info);
  445. //
  446. // cl_inv.c
  447. //
  448. void CL_ParseInventory (void);
  449. void CL_KeyInventory (int key);
  450. void CL_DrawInventory (void);
  451. //
  452. // cl_pred.c
  453. //
  454. void CL_PredictMovement (void);
  455. #if id386
  456. void x86_TimerStart( void );
  457. void x86_TimerStop( void );
  458. void x86_TimerInit( unsigned long smallest, unsigned longest );
  459. unsigned long *x86_TimerGetHistogram( void );
  460. #endif