client.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. vec3_t viewangles;
  19. // intended velocities
  20. float forwardmove;
  21. float sidemove;
  22. float upmove;
  23. #ifdef QUAKE2
  24. byte lightlevel;
  25. #endif
  26. } usercmd_t;
  27. typedef struct
  28. {
  29. int length;
  30. char map[MAX_STYLESTRING];
  31. } lightstyle_t;
  32. typedef struct
  33. {
  34. char name[MAX_SCOREBOARDNAME];
  35. float entertime;
  36. int frags;
  37. int colors; // two 4 bit fields
  38. byte translations[VID_GRADES*256];
  39. } scoreboard_t;
  40. typedef struct
  41. {
  42. int destcolor[3];
  43. int percent; // 0-256
  44. } cshift_t;
  45. #define CSHIFT_CONTENTS 0
  46. #define CSHIFT_DAMAGE 1
  47. #define CSHIFT_BONUS 2
  48. #define CSHIFT_POWERUP 3
  49. #define NUM_CSHIFTS 4
  50. #define NAME_LENGTH 64
  51. //
  52. // client_state_t should hold all pieces of the client state
  53. //
  54. #define SIGNONS 4 // signon messages to receive before connected
  55. #define MAX_DLIGHTS 32
  56. typedef struct
  57. {
  58. vec3_t origin;
  59. float radius;
  60. float die; // stop lighting after this time
  61. float decay; // drop this each second
  62. float minlight; // don't add when contributing less
  63. int key;
  64. #ifdef QUAKE2
  65. qboolean dark; // subtracts light instead of adding
  66. #endif
  67. } dlight_t;
  68. #define MAX_BEAMS 24
  69. typedef struct
  70. {
  71. int entity;
  72. struct model_s *model;
  73. float endtime;
  74. vec3_t start, end;
  75. } beam_t;
  76. #define MAX_EFRAGS 640
  77. #define MAX_MAPSTRING 2048
  78. #define MAX_DEMOS 8
  79. #define MAX_DEMONAME 16
  80. typedef enum {
  81. ca_dedicated, // a dedicated server with no ability to start a client
  82. ca_disconnected, // full screen console with no connection
  83. ca_connected // valid netcon, talking to a server
  84. } cactive_t;
  85. //
  86. // the client_static_t structure is persistant through an arbitrary number
  87. // of server connections
  88. //
  89. typedef struct
  90. {
  91. cactive_t state;
  92. // personalization data sent to server
  93. char mapstring[MAX_QPATH];
  94. char spawnparms[MAX_MAPSTRING]; // to restart a level
  95. // demo loop control
  96. int demonum; // -1 = don't play demos
  97. char demos[MAX_DEMOS][MAX_DEMONAME]; // when not playing
  98. // demo recording info must be here, because record is started before
  99. // entering a map (and clearing client_state_t)
  100. qboolean demorecording;
  101. qboolean demoplayback;
  102. qboolean timedemo;
  103. int forcetrack; // -1 = use normal cd track
  104. FILE *demofile;
  105. int td_lastframe; // to meter out one message a frame
  106. int td_startframe; // host_framecount at start
  107. float td_starttime; // realtime at second frame of timedemo
  108. // connection information
  109. int signon; // 0 to SIGNONS
  110. struct qsocket_s *netcon;
  111. sizebuf_t message; // writing buffer to send to server
  112. } client_static_t;
  113. extern client_static_t cls;
  114. //
  115. // the client_state_t structure is wiped completely at every
  116. // server signon
  117. //
  118. typedef struct
  119. {
  120. int movemessages; // since connecting to this server
  121. // throw out the first couple, so the player
  122. // doesn't accidentally do something the
  123. // first frame
  124. usercmd_t cmd; // last command sent to the server
  125. // information for local display
  126. int stats[MAX_CL_STATS]; // health, etc
  127. int items; // inventory bit flags
  128. float item_gettime[32]; // cl.time of aquiring item, for blinking
  129. float faceanimtime; // use anim frame if cl.time < this
  130. cshift_t cshifts[NUM_CSHIFTS]; // color shifts for damage, powerups
  131. cshift_t prev_cshifts[NUM_CSHIFTS]; // and content types
  132. // the client maintains its own idea of view angles, which are
  133. // sent to the server each frame. The server sets punchangle when
  134. // the view is temporarliy offset, and an angle reset commands at the start
  135. // of each level and after teleporting.
  136. vec3_t mviewangles[2]; // during demo playback viewangles is lerped
  137. // between these
  138. vec3_t viewangles;
  139. vec3_t mvelocity[2]; // update by server, used for lean+bob
  140. // (0 is newest)
  141. vec3_t velocity; // lerped between mvelocity[0] and [1]
  142. vec3_t punchangle; // temporary offset
  143. // pitch drifting vars
  144. float idealpitch;
  145. float pitchvel;
  146. qboolean nodrift;
  147. float driftmove;
  148. double laststop;
  149. float viewheight;
  150. float crouch; // local amount for smoothing stepups
  151. qboolean paused; // send over by server
  152. qboolean onground;
  153. qboolean inwater;
  154. int intermission; // don't change view angle, full screen, etc
  155. int completed_time; // latched at intermission start
  156. double mtime[2]; // the timestamp of last two messages
  157. double time; // clients view of time, should be between
  158. // servertime and oldservertime to generate
  159. // a lerp point for other data
  160. double oldtime; // previous cl.time, time-oldtime is used
  161. // to decay light values and smooth step ups
  162. float last_received_message; // (realtime) for net trouble icon
  163. //
  164. // information that is static for the entire time connected to a server
  165. //
  166. struct model_s *model_precache[MAX_MODELS];
  167. struct sfx_s *sound_precache[MAX_SOUNDS];
  168. char levelname[40]; // for display on solo scoreboard
  169. int viewentity; // cl_entitites[cl.viewentity] = player
  170. int maxclients;
  171. int gametype;
  172. // refresh related state
  173. struct model_s *worldmodel; // cl_entitites[0].model
  174. struct efrag_s *free_efrags;
  175. int num_entities; // held in cl_entities array
  176. int num_statics; // held in cl_staticentities array
  177. entity_t viewent; // the gun model
  178. int cdtrack, looptrack; // cd audio
  179. // frag scoreboard
  180. scoreboard_t *scores; // [cl.maxclients]
  181. #ifdef QUAKE2
  182. // light level at player's position including dlights
  183. // this is sent back to the server each frame
  184. // architectually ugly but it works
  185. int light_level;
  186. #endif
  187. } client_state_t;
  188. //
  189. // cvars
  190. //
  191. extern cvar_t cl_name;
  192. extern cvar_t cl_color;
  193. extern cvar_t cl_upspeed;
  194. extern cvar_t cl_forwardspeed;
  195. extern cvar_t cl_backspeed;
  196. extern cvar_t cl_sidespeed;
  197. extern cvar_t cl_movespeedkey;
  198. extern cvar_t cl_yawspeed;
  199. extern cvar_t cl_pitchspeed;
  200. extern cvar_t cl_anglespeedkey;
  201. extern cvar_t cl_autofire;
  202. extern cvar_t cl_shownet;
  203. extern cvar_t cl_nolerp;
  204. extern cvar_t cl_pitchdriftspeed;
  205. extern cvar_t lookspring;
  206. extern cvar_t lookstrafe;
  207. extern cvar_t sensitivity;
  208. extern cvar_t m_pitch;
  209. extern cvar_t m_yaw;
  210. extern cvar_t m_forward;
  211. extern cvar_t m_side;
  212. #define MAX_TEMP_ENTITIES 64 // lightning bolts, etc
  213. #define MAX_STATIC_ENTITIES 128 // torches, etc
  214. extern client_state_t cl;
  215. // FIXME, allocate dynamically
  216. extern efrag_t cl_efrags[MAX_EFRAGS];
  217. extern entity_t cl_entities[MAX_EDICTS];
  218. extern entity_t cl_static_entities[MAX_STATIC_ENTITIES];
  219. extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
  220. extern dlight_t cl_dlights[MAX_DLIGHTS];
  221. extern entity_t cl_temp_entities[MAX_TEMP_ENTITIES];
  222. extern beam_t cl_beams[MAX_BEAMS];
  223. //=============================================================================
  224. //
  225. // cl_main
  226. //
  227. dlight_t *CL_AllocDlight (int key);
  228. void CL_DecayLights (void);
  229. void CL_Init (void);
  230. void CL_EstablishConnection (char *host);
  231. void CL_Signon1 (void);
  232. void CL_Signon2 (void);
  233. void CL_Signon3 (void);
  234. void CL_Signon4 (void);
  235. void CL_Disconnect (void);
  236. void CL_Disconnect_f (void);
  237. void CL_NextDemo (void);
  238. #define MAX_VISEDICTS 256
  239. extern int cl_numvisedicts;
  240. extern entity_t *cl_visedicts[MAX_VISEDICTS];
  241. //
  242. // cl_input
  243. //
  244. typedef struct
  245. {
  246. int down[2]; // key nums holding it down
  247. int state; // low bit is down state
  248. } kbutton_t;
  249. extern kbutton_t in_mlook, in_klook;
  250. extern kbutton_t in_strafe;
  251. extern kbutton_t in_speed;
  252. void CL_InitInput (void);
  253. void CL_SendCmd (void);
  254. void CL_SendMove (usercmd_t *cmd);
  255. void CL_ParseTEnt (void);
  256. void CL_UpdateTEnts (void);
  257. void CL_ClearState (void);
  258. int CL_ReadFromServer (void);
  259. void CL_WriteToServer (usercmd_t *cmd);
  260. void CL_BaseMove (usercmd_t *cmd);
  261. float CL_KeyState (kbutton_t *key);
  262. char *Key_KeynumToString (int keynum);
  263. //
  264. // cl_demo.c
  265. //
  266. void CL_StopPlayback (void);
  267. int CL_GetMessage (void);
  268. void CL_Stop_f (void);
  269. void CL_Record_f (void);
  270. void CL_PlayDemo_f (void);
  271. void CL_TimeDemo_f (void);
  272. //
  273. // cl_parse.c
  274. //
  275. void CL_ParseServerMessage (void);
  276. void CL_NewTranslation (int slot);
  277. //
  278. // view
  279. //
  280. void V_StartPitchDrift (void);
  281. void V_StopPitchDrift (void);
  282. void V_RenderView (void);
  283. void V_UpdatePalette (void);
  284. void V_Register (void);
  285. void V_ParseDamage (void);
  286. void V_SetContentsColor (int contents);
  287. //
  288. // cl_tent
  289. //
  290. void CL_InitTEnts (void);
  291. void CL_SignonReply (void);