1 /*
2 Copyright (C) 1997-2001 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 //
21 // cl_local.h
22 // Primary header for client
23 //
24 
25 #ifdef DEDICATED_ONLY
26 # error You should not be including this file in a dedicated server build
27 #endif // DEDICATED_ONLY
28 #include <math.h>
29 #include <string.h>
30 #include <stdarg.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 
34 #include "../renderer/r_public.h"
35 #include "snd_public.h"
36 #include "../cgame/cg_shared.h"
37 #include "cl_keys.h"
38 #include "gui_public.h"
39 
40 #define CL_ANTICHEAT	1
41 
42 #ifdef USE_CURL
43 # define CL_HTTPDL		1
44 #endif
45 
46 extern struct memPool_s	*cl_cGameSysPool;
47 extern struct memPool_s	*cl_cinSysPool;
48 extern struct memPool_s	*cl_guiSysPool;
49 extern struct memPool_s	*cl_soundSysPool;
50 
51 /*
52 =============================================================================
53 
54 	CLIENT STATE
55 
56 	The clientState_t structure is wiped at every server map change
57 =============================================================================
58 */
59 
60 typedef struct clientState_s {
61 	int					timeOutCount;
62 
63 	int					timeDemoFrames;
64 	int					timeDemoStart;
65 
66 	int					maxClients;
67 	int					parseEntities;				// index (not anded off) into cl_parseEntities[]
68 
69 	userCmd_t			cmd;
70 	userCmd_t			cmds[CMD_BACKUP];			// each mesage will send several old cmds
71 	int					cmdTime[CMD_BACKUP];		// time sent, for calculating pings
72 	int					cmdNum;
73 
74 	frame_t				frame;						// received from server
75 	int					surpressCount;				// number of messages rate supressed
76 	frame_t				frames[UPDATE_BACKUP];
77 
78 	refDef_t			refDef;
79 	// the client maintains its own idea of view angles, which are
80 	// sent to the server each frame.  It is cleared to 0 upon entering each level.
81 	// the server sends a delta each frame which is added to the locally
82 	// tracked view angles to account for standing on rotating objects,
83 	// and teleport direction changes
84 	vec3_t				viewAngles;
85 
86 	//
87 	// cinematic playback
88 	//
89 	cinematic_t			cin;
90 
91 	//
92 	// demo recording
93 	//
94 	netMsg_t			demoBuffer;
95 	byte				demoFrame[MAX_SV_MSGLEN];
96 
97 	//
98 	// server state information
99 	//
100 	qBool				attractLoop;				// running the attract loop, any key will menu
101 	int					serverCount;				// server identification for prespawns
102 	int					enhancedServer;				// ENHANCED_SERVER_PROTOCOL
103 	qBool				strafeHack;
104 	char				gameDir[MAX_QPATH];
105 	int					playerNum;
106 
107 	char				configStrings[MAX_CFGSTRINGS][MAX_CFGSTRLEN];
108 	struct sfx_s		*soundCfgStrings[MAX_CS_SOUNDS];
109 } clientState_t;
110 
111 extern	clientState_t	cl;
112 
113 /*
114 =============================================================================
115 
116 	MEDIA
117 
118 =============================================================================
119 */
120 
121 typedef struct clMedia_s {
122 	qBool				initialized;
123 
124 	// sounds
125 	struct sfx_s		*talkSfx;
126 
127 	// images
128 	struct shader_s		*cinMaterial;
129 	struct shader_s		*consoleShader;
130 	struct shader_s		*whiteTexture;
131 	struct shader_s		*blackTexture;
132 } clMedia_t;
133 
134 extern clMedia_t	clMedia;
135 
136 void	CL_ImageMediaInit (void);
137 void	CL_SoundMediaInit (void);
138 void	CL_MediaInit (void);
139 
140 void	CL_MediaShutdown (void);
141 void	CL_MediaRestart (void);
142 /*
143 =============================================================================
144 
145 	CLIENT STATIC
146 
147 	Persistant through an arbitrary number of server connections
148 =============================================================================
149 */
150 
151 #define NET_RETRYDELAY	3000.0f
152 
153 typedef struct downloadStatic_s {
154 	FILE				*file;						// file transfer from server
155 	char				tempName[MAX_OSPATH];
156 	char				name[MAX_OSPATH];
157 	int					percent;
158 
159 #ifdef CL_HTTPDL
160 	char				httpServer[512];
161 	char				httpReferer[32];
162 #endif
163 } downloadStatic_t;
164 
165 typedef struct clientStatic_s {
166 	int					connectCount;
167 	float				connectTime;				// for connection retransmits
168 
169 	float				netFrameTime;				// seconds since last net packet frame
170 	float				trueNetFrameTime;			// un-clamped net frametime that is passed to cgame
171 	float				refreshFrameTime;			// seconds since last refresh frame
172 	float				trueRefreshFrameTime;		// un-clamped refresh frametime that is passed to cgame
173 
174 	int					realTime;					// system realtime
175 
176 	// Screen rendering information
177 	qBool				refreshPrepped;				// false if on new level or new ref dll
178 	qBool				disableScreen;				// skip rendering until this is true
179 
180 	// Audio information
181 	qBool				soundPrepped;				// once loading is started, sounds can't play until the frame is valid
182 
183 	// Connection information
184 	char				serverMessage[MAX_STRING_TOKENS];
185 	char				serverName[MAX_OSPATH];		// name of server from original connect
186 	char				serverNameLast[MAX_OSPATH];
187 	int					serverProtocol;				// in case we are doing some kind of version hack
188 
189 	netAdr_t			netFrom;
190 	netMsg_t			netMessage;
191 	byte				netBuffer[MAX_CL_MSGLEN];
192 
193 	netChan_t			netChan;
194 	int					quakePort;					// a 16 bit value that allows quake servers
195 													// to work around address translating routers
196 	int					challenge;					// from the server to use for connecting
197 	qBool				forcePacket;				// forces a packet to be sent the next frame
198 
199 	downloadStatic_t	download;
200 
201 	//
202 	// demo recording info must be here, so it isn't cleared on level change
203 	//
204 	fileHandle_t		demoFile;
205 	qBool				demoRecording;
206 	qBool				demoWaiting;				// don't record until a non-delta message is received
207 
208 	//
209 	// cgame information
210 	//
211 	qBool				mapLoading;
212 	qBool				mapLoaded;
213 
214 	//
215 	// video settings
216 	//
217 	refConfig_t			refConfig;
218 } clientStatic_t;
219 
220 extern clientStatic_t	cls;
221 
222 /*
223 =============================================================================
224 
225 	CVARS
226 
227 =============================================================================
228 */
229 
230 extern cVar_t	*allow_download;
231 extern cVar_t	*allow_download_players;
232 extern cVar_t	*allow_download_models;
233 extern cVar_t	*allow_download_sounds;
234 extern cVar_t	*allow_download_maps;
235 
236 extern cVar_t	*cl_downloadToBase;
237 extern cVar_t	*cl_upspeed;
238 extern cVar_t	*cl_forwardspeed;
239 extern cVar_t	*cl_sidespeed;
240 extern cVar_t	*cl_yawspeed;
241 extern cVar_t	*cl_pitchspeed;
242 extern cVar_t	*cl_shownet;
243 extern cVar_t	*cl_stereo_separation;
244 extern cVar_t	*cl_lightlevel;
245 extern cVar_t	*cl_paused;
246 extern cVar_t	*cl_timedemo;
247 
248 extern cVar_t	*freelook;
249 extern cVar_t	*lookspring;
250 extern cVar_t	*lookstrafe;
251 extern cVar_t	*sensitivity;
252 extern cVar_t	*s_khz;
253 
254 extern cVar_t	*m_pitch;
255 extern cVar_t	*m_yaw;
256 extern cVar_t	*m_forward;
257 extern cVar_t	*m_side;
258 
259 extern cVar_t	*cl_timestamp;
260 extern cVar_t	*con_chatHud;
261 extern cVar_t	*con_chatHudLines;
262 extern cVar_t	*con_chatHudPosX;
263 extern cVar_t	*con_chatHudPosY;
264 extern cVar_t	*con_chatHudShadow;
265 extern cVar_t	*con_notifyfade;
266 extern cVar_t	*con_notifylarge;
267 extern cVar_t	*con_notifylines;
268 extern cVar_t	*con_notifytime;
269 extern cVar_t	*con_alpha;
270 extern cVar_t	*con_clock;
271 extern cVar_t	*con_drop;
272 extern cVar_t	*con_scroll;
273 extern cVar_t	*m_accel;
274 extern cVar_t	*r_fontScale;
275 
276 extern cVar_t	*scr_conspeed;
277 
278 /*
279 =============================================================================
280 
281 	MISCELLANEOUS
282 
283 =============================================================================
284 */
285 
286 //
287 // cl_acapi.c
288 //
289 
290 #ifdef CL_ANTICHEAT
291 qBool		CL_ACAPI_Init (void);
292 #endif // CL_ANTICHEAT
293 
294 //
295 // cl_cgapi.c
296 //
297 
298 void		CL_CGModule_LoadMap (void);
299 
300 void		CL_CGModule_UpdateConnectInfo (void);
301 
302 void		CL_CGModule_BeginFrameSequence (void);
303 void		CL_CGModule_NewPacketEntityState (int entNum, entityState_t state);
304 void		CL_CGModule_EndFrameSequence (void);
305 
306 void		CL_CGModule_GetEntitySoundOrigin (int entNum, vec3_t origin, vec3_t velocity);
307 
308 void		CL_CGModule_ParseConfigString (int num, char *str);
309 
310 void		CL_CGModule_DebugGraph (float value, int color);
311 
312 void		CL_CGModule_StartServerMessage (void);
313 qBool		CL_CGModule_ParseServerMessage (int command);
314 void		CL_CGModule_EndServerMessage (void);
315 
316 qBool		CL_CGModule_Pmove (pMoveNew_t *pMove, float airAcceleration);
317 
318 void		CL_CGModule_RegisterSounds (void);
319 void		CL_CGModule_RenderView (float stereoSeparation);
320 
321 void		CL_CGameAPI_Init (void);
322 void		CL_CGameAPI_Shutdown (void);
323 
324 void		CL_CGModule_SetRefConfig (void);
325 
326 void		CL_CGModule_MainMenu (void);
327 void		CL_CGModule_ForceMenuOff (void);
328 void		CL_CGModule_MoveMouse (float mx, float my);
329 void		CL_CGModule_KeyEvent (keyNum_t keyNum, qBool isDown);
330 qBool		CL_CGModule_ParseServerInfo (char *adr, char *info);
331 qBool		CL_CGModule_ParseServerStatus (char *adr, char *info);
332 void		CL_CGModule_StartSound (vec3_t origin, int entNum, entChannel_t entChannel, int soundNum, float volume, float attenuation, float timeOffset);
333 void		CL_CGModule_RegisterSounds (void);
334 
335 //
336 // cl_cin.c
337 //
338 
339 void		RoQ_Init (void);
340 
341 void		CIN_PlayCinematic (char *name);
342 void		CIN_DrawCinematic (void);
343 void		CIN_RunCinematic (void);
344 void		CIN_StopCinematic (void);
345 void		CIN_FinishCinematic (void);
346 
347 //
348 // cl_console.c
349 //
350 
351 void		CL_ClearNotifyLines (void);
352 void		CL_ConsoleClose (void);
353 void		CL_MoveConsoleDisplay (int value);
354 void		CL_SetConsoleDisplay (qBool top);
355 
356 void		CL_ToggleConsole_f (void);
357 
358 void		CL_ConsoleCheckResize (void);
359 
360 void		CL_ConsoleInit (void);
361 
362 void		CL_DrawConsole (void);
363 
364 //
365 // cl_demo.c
366 //
367 
368 void		CL_WriteDemoPlayerstate (frame_t *from, frame_t *to, netMsg_t *msg);
369 void		CL_WriteDemoPacketEntities (const frame_t *from, frame_t *to, netMsg_t *msg);
370 void		CL_WriteDemoMessageChunk (byte *buffer, int length, qBool forceFlush);
371 void		CL_WriteDemoMessageFull (void);
372 
373 qBool		CL_StartDemoRecording (char *name);
374 void		CL_StopDemoRecording (void);
375 
376 //
377 // cl_download.c
378 //
379 
380 qBool		CL_CheckOrDownloadFile (char *fileName);
381 
382 void		CL_ParseDownload (qBool compressed);
383 
384 void		CL_ResetDownload (void);
385 void		CL_RequestNextDownload (void);
386 
387 #ifdef CL_HTTPDL
388 void		CL_HTTPDL_Init (void);
389 void		CL_HTTPDL_SetServer (char *url);
390 void		CL_HTTPDL_CancelDownloads (qBool permKill);
391 qBool		CL_HTTPDL_QueueDownload (char *file);
392 qBool		CL_HTTPDL_PendingDownloads (void);
393 void		CL_HTTPDL_Cleanup (qBool shutdown);
394 void		CL_HTTPDL_RunDownloads (void);
395 #endif
396 
397 //
398 // cl_input.c
399 //
400 
401 qBool		CL_GetRunState (void);
402 qBool		CL_GetStrafeState (void);
403 qBool		CL_GetMLookState (void);
404 void		CL_MoveMouse (int xMove, int yMove);
405 
406 void		CL_RefreshCmd (void);
407 void		CL_SendCmd (void);
408 void		CL_SendMove (userCmd_t *cmd);
409 
410 void		CL_InputInit (void);
411 
412 //
413 // cl_main.c
414 //
415 
416 // delta from this if not from a previous frame
417 extern entityState_t	cl_baseLines[MAX_CS_EDICTS];
418 
419 // the cl_parseEntities must be large enough to hold UPDATE_BACKUP frames of
420 // entities, so that when a delta compressed message arives from the server
421 // it can be un-deltad from the original
422 extern entityState_t	cl_parseEntities[MAX_PARSE_ENTITIES];
423 
424 qBool		CL_ForwardCmdToServer (void);
425 
426 void		CL_ResetServerCount (void);
427 
428 void		CL_SetRefConfig (void);
429 void		CL_SetState (caState_t state);
430 void		CL_ClearState (void);
431 
432 void		CL_Disconnect (qBool openMenu);
433 
434 void		__fastcall CL_Frame (int msec);
435 
436 void		CL_ClientInit (void);
437 void		CL_ClientShutdown (qBool error);
438 
439 //
440 // cl_parse.c
441 //
442 
443 extern char *cl_svcStrings[256];
444 
445 void		CL_ParseServerMessage (void);
446 
447 //
448 // cl_screen.c
449 //
450 
451 void		CL_DrawFill (float x, float y, int w, int h, vec4_t color);
452 
453 void		SCR_BeginLoadingPlaque (void);
454 void		SCR_EndLoadingPlaque (void);
455 
456 void		SCR_UpdateScreen (void);
457 
458 /*
459 =============================================================================
460 
461 	IMPLEMENTATION SPECIFIC
462 
463 =============================================================================
464 */
465 
466 //
467 // in_imp.c
468 //
469 
470 int			In_MapKey (int wParam, int lParam);
471 qBool		In_GetKeyState (keyNum_t keyNum);
472 
473 void		IN_Restart_f (void);
474 void		IN_Init (void);
475 void		IN_Shutdown (void);
476 
477 void		IN_Commands (void);	// oportunity for devices to stick commands on the script buffer
478 void		IN_Frame (void);
479 void		IN_Move (userCmd_t *cmd);	// add additional movement on top of the keyboard move cmd
480 
481 void		IN_Activate (qBool active);
482 
483 //
484 // vid_imp.c
485 //
486 
487 void		VID_CheckChanges (refConfig_t *outConfig);
488 void		VID_Init (refConfig_t *outConfig);
489 void		VID_Shutdown (void);
490