home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quakeworld_src / client / client.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-17  |  12.5 KB  |  519 lines

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