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