1 /* 2 client.h 3 4 Client definitions 5 6 Copyright (C) 1996-1997 Id Software, Inc. 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2 11 of the License, or (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 17 See the GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to: 21 22 Free Software Foundation, Inc. 23 59 Temple Place - Suite 330 24 Boston, MA 02111-1307, USA 25 26 */ 27 28 #ifndef __client_h 29 #define __client_h 30 31 #include <stdio.h> 32 33 #include "QF/input.h" 34 #include "QF/mathlib.h" 35 #include "QF/model.h" 36 #include "QF/quakefs.h" 37 #include "QF/sound.h" 38 #include "QF/render.h" 39 40 #include "client/entities.h" 41 42 #include "game.h" 43 #include "netmain.h" 44 #include "protocol.h" 45 46 47 typedef struct usercmd_s { 48 vec3_t viewangles; 49 50 // intended velocities 51 float forwardmove; 52 float sidemove; 53 float upmove; 54 } usercmd_t; 55 56 typedef struct { 57 struct info_s *info; 58 struct info_key_s *name; 59 float entertime; 60 int frags; 61 int topcolor; 62 int bottomcolor; 63 } scoreboard_t; 64 65 66 // client_state_t should hold all pieces of the client state 67 68 typedef enum { 69 so_none, 70 so_prespawn, 71 so_spawn, 72 so_begin, 73 so_active, 74 } signon_t; 75 76 #define MAX_DEMOS 8 77 #define MAX_DEMONAME 16 78 79 typedef enum { 80 ca_dedicated, // a dedicated server with no ability to start a client 81 ca_disconnected, // full screen console with no connection 82 ca_connected, // talking to a server 83 ca_active, // everything is in, so frames can be rendered 84 } cactive_t; 85 86 typedef enum { 87 dl_none, 88 dl_model, 89 dl_sound, 90 dl_skin, 91 dl_single 92 } dltype_t; // download type 93 94 /* 95 the client_static_t structure is persistant through an arbitrary number 96 of server connections 97 */ 98 typedef struct { 99 // connection information 100 cactive_t state; 101 signon_t signon; 102 103 // network stuff 104 struct qsocket_s *netcon; 105 sizebuf_t message; // writing buffer to send to server 106 107 // demo loop control 108 int demonum; // -1 = don't play demos 109 char demos[MAX_DEMOS][MAX_DEMONAME]; // when not playing 110 111 QFile *demofile; 112 qboolean demorecording; 113 qboolean demo_capture; 114 qboolean demoplayback; 115 int forcetrack; // -1 = use normal cd track 116 qboolean timedemo; 117 int td_lastframe; // to meter out one message a frame 118 int td_startframe; // host_framecount at start 119 float td_starttime; // realtime at second frame of timedemo 120 } client_static_t; 121 122 extern client_static_t cls; 123 124 #define FPD_NO_MACROS 0x0001 // Many clients ignore this, and it isn't used, but let's honor it 125 #define FPD_NO_TIMERS 0x0002 // We never allow timers anyway 126 #define FPD_NO_STRIGGER 0x0004 // Don't have soundtrigger yet, but this disables it 127 #define FPD_HIDE_PERCENTE 0x0020 // Ditto 128 #define FPD_HIDE_POINT 0x0080 // Can ignore if we do visibility checking for point 129 #define FPD_NO_TEAMSKIN 0x0100 // Disable skin force 130 #define FPD_NO_TEAMCOLOR 0x0200 // Disable color force 131 #define FPD_HIDE_ITEM 0x0400 // No idea what this does 132 #define FPD_LIMIT_PITCH 0x4000 // Limit pitchspeed 133 #define FPD_LIMIT_YAW 0x8000 // Limit yawspeed 134 135 #define FPD_DEFAULT (FPD_HIDE_PERCENTE | FPD_NO_TEAMSKIN) 136 137 // These limits prevent a usable RJ script, requiring > 0.1 sec of turning time. 138 #define FPD_MAXPITCH 1000 139 #define FPD_MAXYAW 2000 140 141 142 /* 143 the client_state_t structure is wiped completely at every server signon 144 */ 145 typedef struct { 146 qboolean loading; 147 148 int movemessages; // Since connecting to this server throw out 149 // the first couple, so the player doesn't 150 // accidentally do something the first frame 151 usercmd_t cmd; // Last command sent to the server 152 153 // information for local display 154 int stats[MAX_CL_STATS]; // Health, etc 155 float item_gettime[32]; // cl.time of aquiring item, for blinking 156 float faceanimtime; // Use anim frame if cl.time < this 157 158 cshift_t cshifts[NUM_CSHIFTS]; // Color shifts for damage, powerups 159 cshift_t prev_cshifts[NUM_CSHIFTS]; // and content types 160 161 // The client maintains its own idea of view angles, which are sent to the 162 // server each frame. The server sets punchangle when the view is temporarily 163 // offset, and an angle reset commands at the start of each level and after 164 // teleporting. 165 int mindex; 166 vec3_t mviewangles[2]; // During demo playback viewangles is lerped 167 // between these 168 vec3_t viewangles; 169 vec3_t mvelocity[2]; // Update by server, used for lean+bob 170 // (0 is newest) 171 vec3_t velocity; // Lerped between mvelocity[0] and [1] 172 vec3_t punchangle; // Temporary offset 173 174 // pitch drifting vars 175 float idealpitch; 176 float pitchvel; 177 qboolean nodrift; 178 float driftmove; 179 double laststop; 180 181 qboolean paused; // Sent over by server 182 int onground; 183 float viewheight; 184 float crouch; // Local amount for smoothing stepups 185 qboolean inwater; 186 187 int intermission; // Don't change view angle, full screen, etc 188 int completed_time; // Latched at intermission start 189 190 double mtime[2]; // The timestamp of last two messages 191 double time; // Clients view of time, should be between 192 // servertime and oldvertime to generate a 193 // lerp point for other data 194 double oldtime; // Previous cl.time, time-oldtime is used 195 // to decay light values and smooth step ups 196 197 float last_received_message; // (realtime) for net trouble icon 198 199 /* information that is static for the entire time connected to a server */ 200 201 struct model_s *model_precache[MAX_MODELS]; 202 struct sfx_s *sound_precache[MAX_SOUNDS]; 203 int nummodels; 204 int numsounds; 205 206 struct plitem_s *edicts; 207 struct plitem_s *worldspawn; 208 209 char levelname[40]; // for display on solo scoreboard 210 int spectator; 211 int viewentity; // cl_entitites[cl.viewentity] = player 212 unsigned protocol; 213 int gametype; 214 int maxclients; 215 int chase; 216 int sv_cshifts; 217 int watervis; 218 int fpd; 219 220 // refresh related state 221 struct model_s *worldmodel; // cl_entitites[0].model 222 int num_entities; // held in cl_entities array 223 entity_t viewent; // the weapon model 224 225 int cdtrack; // cd audio 226 227 // frag scoreboard 228 scoreboard_t *scores; // [cl.maxclients] 229 230 lightstyle_t lightstyle[MAX_LIGHTSTYLES]; 231 } client_state_t; 232 233 // cvars 234 extern struct cvar_s *cl_name; 235 extern struct cvar_s *cl_color; 236 237 extern struct cvar_s *cl_upspeed; 238 extern struct cvar_s *cl_forwardspeed; 239 extern struct cvar_s *cl_backspeed; 240 extern struct cvar_s *cl_sidespeed; 241 242 extern struct cvar_s *cl_movespeedkey; 243 244 extern struct cvar_s *cl_yawspeed; 245 extern struct cvar_s *cl_pitchspeed; 246 247 extern struct cvar_s *cl_anglespeedkey; 248 249 extern struct cvar_s *cl_autofire; 250 251 extern struct cvar_s *cl_shownet; 252 extern struct cvar_s *cl_nolerp; 253 254 extern struct cvar_s *hud_sbar; 255 256 extern struct cvar_s *cl_pitchdriftspeed; 257 extern struct cvar_s *lookspring; 258 259 extern struct cvar_s *m_pitch; 260 extern struct cvar_s *m_yaw; 261 extern struct cvar_s *m_forward; 262 extern struct cvar_s *m_side; 263 264 extern struct cvar_s *cl_name; 265 extern struct cvar_s *cl_writecfg; 266 267 extern struct cvar_s *cl_cshift_bonus; 268 extern struct cvar_s *cl_cshift_contents; 269 extern struct cvar_s *cl_cshift_damage; 270 extern struct cvar_s *cl_cshift_powerup; 271 272 extern struct cvar_s *noskins; 273 274 extern client_state_t cl; 275 276 // FIXME, allocate dynamically 277 extern entity_t cl_entities[MAX_EDICTS]; 278 extern double cl_msgtime[MAX_EDICTS]; 279 extern byte cl_forcelink[MAX_EDICTS]; 280 281 extern int fps_count; 282 283 extern void (*write_angles) (sizebuf_t *sb, const vec3_t angles); 284 285 // cl_main 286 struct cbuf_s; 287 void CL_Init (struct cbuf_s *cbuf); 288 void CL_InitCvars (void); 289 void CL_Shutdown (void); 290 291 void CL_EstablishConnection (const char *host); 292 void CL_Signon1 (void); 293 void CL_Signon2 (void); 294 void CL_Signon3 (void); 295 void CL_Signon4 (void); 296 297 void CL_Disconnect (void); 298 void CL_Disconnect_f (void); 299 void CL_NextDemo (void); 300 301 302 // cl_input 303 void CL_Input_Init (void); 304 void CL_SendCmd (void); 305 void CL_SendMove (usercmd_t *cmd); 306 307 void CL_ParseParticleEffect (void); 308 void CL_ParseTEnt (void); 309 void CL_UpdateTEnts (void); 310 311 void CL_ClearState (void); 312 313 int CL_ReadFromServer (void); 314 void CL_WriteToServer (usercmd_t *cmd); 315 void CL_BaseMove (usercmd_t *cmd); 316 317 float CL_KeyState (kbutton_t *key); 318 319 // cl_demo.c 320 void CL_StopPlayback (void); 321 void CL_StopRecording (void); 322 void CL_Record (const char *argv1, int track); 323 int CL_GetMessage (void); 324 void CL_Demo_Init (void); 325 326 extern struct cvar_s *demo_gzip; 327 extern struct cvar_s *demo_speed; 328 329 // cl_parse.c 330 struct skin_s; 331 void CL_ParseServerMessage (void); 332 void CL_NewTranslation (int slot, struct skin_s *skin); 333 334 335 // view 336 void V_StartPitchDrift (void); 337 void V_StopPitchDrift (void); 338 339 void V_RenderView (void); 340 void V_UpdatePalette (void); 341 void V_Register (void); 342 void V_ParseDamage (void); 343 void V_SetContentsColor (int contents); 344 void V_PrepBlend (void); 345 346 // cl_tent 347 void CL_TEnts_Init (void); 348 void CL_ClearTEnts (void); 349 void CL_Init_Entity (struct entity_s *ent); 350 void CL_ParseTEnt (void); 351 void CL_SignonReply (void); 352 void CL_TransformEntity (struct entity_s *ent, const vec3_t 353 angles, qboolean force); 354 void CL_RelinkEntities (void); 355 void CL_ClearEnts (void); 356 357 extern kbutton_t in_left, in_right, in_forward, in_back; 358 extern kbutton_t in_lookup, in_lookdown, in_moveleft, in_moveright; 359 extern kbutton_t in_use, in_jump, in_attack; 360 extern kbutton_t in_up, in_down; 361 362 extern double realtime; 363 364 extern qboolean recording; 365 366 void Cvar_Info (struct cvar_s *var); 367 368 void CL_UpdateScreen (double realtime); 369 370 void CL_SetState (cactive_t state); 371 372 void CL_Cmd_ForwardToServer (void); 373 374 #endif // __client_h 375