openmohaa/code/client/client.h

691 lines
20 KiB
C
Raw Normal View History

2016-03-27 11:49:47 +02:00
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// client.h -- primary header for client
#ifndef __CLIENT_H__
#define __CLIENT_H__
#include "../qcommon/q_shared.h"
#include "../qcommon/qcommon.h"
2023-05-27 15:36:19 +02:00
#include "../cgame/tr_types.h"
#include "../renderercommon/tr_public.h"
2016-03-27 11:49:47 +02:00
#include "keys.h"
#include "snd_public.h"
#include "../cgame/cg_public.h"
2023-06-15 23:44:02 +02:00
#include "../fgame/bg_public.h"
2016-03-27 11:49:47 +02:00
#ifdef USE_CURL
#include "cl_curl.h"
#endif /* USE_CURL */
// file full of random crap that gets used to create cl_guid
#define QKEY_FILE "qkey"
#define QKEY_SIZE 2048
#define RETRANSMIT_TIMEOUT 3000 // time between connection packet retransmits
#ifdef __cplusplus
extern "C" {
#endif
// snapshots are a view of the server at a given time
typedef struct {
qboolean valid; // cleared if delta parsing was invalid
int snapFlags; // rate delayed and dropped commands
int serverTime; // server time the message is valid for (in msec)
int serverTimeResidual;
int messageNum; // copied from netchan->incoming_sequence
int deltaNum; // messageNum the delta is from
int ping; // time from when cmdNum-1 was sent to time packet was reeceived
byte areamask[MAX_MAP_AREA_BYTES]; // portalarea visibility bits
int cmdNum; // the next cmdNum the server is expecting
playerState_t ps; // complete information about the current player at this time
int numEntities; // all of the entities that need to be presented
int parseEntitiesNum; // at the time of this snapshot
int serverCommandNum; // execute all commands up to this before
// making the snapshot current
int number_of_sounds;
server_sound_t sounds[64];
} clSnapshot_t;
/*
=============================================================================
the clientActive_t structure is wiped completely at every
new gamestate_t, potentially several times during an established connection
=============================================================================
*/
typedef struct {
int p_cmdNumber; // cl.cmdNumber when packet was sent
int p_serverTime; // usercmd->serverTime when packet was sent
int p_realtime; // cls.realtime when packet was sent
usereyes_t p_eyeinfo; // eyeInfo when packet was sent
} outPacket_t;
// the parseEntities array must be large enough to hold PACKET_BACKUP frames of
// entities, so that when a delta compressed message arives from the server
// it can be un-deltad from the original
#define MAX_PARSE_ENTITIES 2048
extern int g_console_field_width;
extern int g_console_charWidth;
extern int g_console_charHeight;
typedef struct {
int timeoutcount; // it requres several frames in a timeout condition
// to disconnect, preventing debugging breaks from
// causing immediate disconnects on continue
clSnapshot_t snap; // latest received from server
int serverTime; // may be paused during play
int oldServerTime; // to prevent time from flowing bakcwards
int serverStartTime;
int oldFrameServerTime; // to check tournament restarts
int serverTimeDelta; // cl.serverTime = cls.realtime + cl.serverTimeDelta
// this value changes as net lag varies
qboolean extrapolatedSnapshot; // set if any cgame frame has been forced to extrapolate
// cleared when CL_AdjustTimeDelta looks at it
qboolean newSnapshots; // set on parse of any valid packet
gameState_t gameState; // configstrings
char mapname[MAX_QPATH]; // extracted from CS_SERVERINFO
int parseEntitiesNum; // index (not anded off) into cl_parse_entities[]
int mouseDx[2], mouseDy[2]; // added to by mouse events
int mouseIndex;
int mousex, mousey;
unsigned int mouseButtons;
int joystickAxis[MAX_JOYSTICK_AXIS]; // set by joystick events
// cmds[cmdNumber] is the predicted command, [cmdNumber-1] is the last
// properly generated command
usercmd_t cmds[CMD_BACKUP]; // each mesage will send several old cmds
int cmdNumber; // incremented each frame, because multiple
// frames may need to be packed into a single packet
outPacket_t outPackets[PACKET_BACKUP]; // information about each packet we have sent out
// the client maintains its own idea of view angles, which are
// sent to the server each frame. It is cleared to 0 upon entering each level.
// the server sends a delta each frame which is added to the locally
// tracked view angles to account for standing on rotating objects,
// and teleport direction changes
vec3_t viewangles;
int serverId; // included in each client message so the server
// can tell if it is for a prior map_restart
// big stuff at end of structure so most offsets are 15 bits or less
clSnapshot_t snapshots[PACKET_BACKUP];
entityState_t entityBaselines[MAX_GENTITIES]; // for delta compression when not in previous frame
entityState_t parseEntities[MAX_PARSE_ENTITIES];
} clientActive_t;
extern clientActive_t cl;
/*
=============================================================================
the clientConnection_t structure is wiped when disconnecting from a server,
either to go to a full screen console, play a demo, or connect to a different server
A connection can be to either a server through the network layer or a
demo through a file.
=============================================================================
*/
#define MAX_TIMEDEMO_DURATIONS 4096
typedef struct {
2023-05-26 20:53:00 +02:00
connstate_t state; // connection status
2016-03-27 11:49:47 +02:00
int clientNum;
int lastPacketSentTime; // for retransmits during connection
int lastPacketTime; // for timeouts
netadr_t serverAddress;
int connectTime; // for connection retransmits
int connectStartTime;
2016-03-27 11:49:47 +02:00
int connectPacketCount; // for display on connection dialog
char serverMessage[MAX_STRING_TOKENS]; // for display on connection dialog
int challenge; // from the server to use for connecting
int checksumFeed; // from the server for checksum calculations
// these are our reliable messages that go to the server
int reliableSequence;
int reliableAcknowledge; // the last one the server has executed
char reliableCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS];
// server message (unreliable) and command (reliable) sequence
// numbers are NOT cleared at level changes, but continue to
// increase as long as the connection is valid
// message sequence is used by both the network layer and the
// delta compression layer
int serverMessageSequence;
// reliable messages received from server
int serverCommandSequence;
int lastExecutedServerCommand; // last server command grabbed or executed with CL_GetServerCommand
char serverCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS];
// file transfer from server
fileHandle_t download;
char downloadTempName[MAX_OSPATH];
char downloadName[MAX_OSPATH];
#ifdef USE_CURL
qboolean cURLEnabled;
qboolean cURLUsed;
qboolean cURLDisconnected;
char downloadURL[MAX_OSPATH];
CURL *downloadCURL;
CURLM *downloadCURLM;
#endif /* USE_CURL */
int sv_allowDownload;
char sv_dlURL[MAX_CVAR_VALUE_STRING];
int downloadNumber;
int downloadBlock; // block we are waiting for
size_t downloadCount; // how many bytes we got
size_t downloadSize; // how many bytes we got
2016-03-27 11:49:47 +02:00
char downloadList[MAX_INFO_STRING]; // list of paks we need to download
qboolean downloadRestart; // if true, we need to do another FS_Restart because we downloaded a pak
// demo information
char demoName[MAX_QPATH];
qboolean spDemoRecording;
qboolean demorecording;
qboolean demoplaying;
qboolean demowaiting; // don't record until a non-delta message is received
qboolean firstDemoFrameSkipped;
fileHandle_t demofile;
int timeDemoFrames; // counter of rendered frames
int timeDemoStart; // cls.realtime before first frame
int timeDemoBaseTime; // each frame will be at this time + frameNum * 50
int timeDemoLastFrame;// time the last frame was rendered
int timeDemoMinDuration; // minimum frame duration
int timeDemoMaxDuration; // maximum frame duration
unsigned char timeDemoDurations[ MAX_TIMEDEMO_DURATIONS ]; // log of frame durations
2023-05-28 21:36:09 +02:00
#ifdef LEGACY_PROTOCOL
qboolean compat;
#endif
2016-03-27 11:49:47 +02:00
// big stuff at end of structure so most offsets are 15 bits or less
netchan_t netchan;
float aviVideoFrameRemainder;
float aviSoundFrameRemainder;
2016-03-27 11:49:47 +02:00
} clientConnection_t;
extern clientConnection_t clc;
/*
==================================================================
the clientStatic_t structure is never wiped, and is used even when
no client connection is active at all
==================================================================
*/
typedef struct {
netadr_t adr;
int start;
int time;
char info[MAX_INFO_STRING];
} ping_t;
typedef struct {
netadr_t adr;
char hostName[ MAX_NAME_LENGTH ];
char mapName[ MAX_NAME_LENGTH ];
char game[ MAX_NAME_LENGTH ];
char gameTypeString[ MAX_NAME_LENGTH ];
int netType;
int gameType;
int clients;
int maxClients;
int minPing;
int maxPing;
int ping;
qboolean visible;
} serverInfo_t;
typedef struct {
byte ip[4];
unsigned short port;
} serverAddress_t;
typedef struct {
int startStage;
int loading;
int keyCatchers;
qboolean vid_restart;
qboolean cddialog; // bring up the cd needed dialog next frame
qboolean no_menus;
char servername[MAX_OSPATH]; // name of server from original connect (used by reconnect)
// when the server clears the hunk, all of these must be restarted
qboolean rendererRegistered;
qboolean cgameStarted;
qboolean uiStarted;
qboolean timeScaled;
int framecount;
int frametime; // msec since last frame
2023-05-21 19:58:32 +02:00
float serverFrameTime;
2016-03-27 11:49:47 +02:00
int realtime; // ignores pause
int realFrametime; // ignoring pause, so console always works
int numlocalservers;
serverInfo_t localServers[ MAX_OTHER_SERVERS ];
qboolean bNewLocalServerInfo;
int numglobalservers;
serverInfo_t globalServers[MAX_GLOBAL_SERVERS];
// additional global servers
int numGlobalServerAddresses;
serverAddress_t globalServerAddresses[MAX_GLOBAL_SERVERS];
int numfavoriteservers;
serverInfo_t favoriteServers[MAX_OTHER_SERVERS];
int nummplayerservers;
serverInfo_t mplayerServers[MAX_OTHER_SERVERS];
int pingUpdateSource; // source currently pinging or updating
int masterNum;
// update server info
netadr_t updateServer;
char updateChallenge[MAX_TOKEN_CHARS];
char updateInfoString[MAX_INFO_STRING];
netadr_t authorizeServer;
// rendering info
glconfig_t glconfig;
int total_tris;
int total_verts;
int total_texels;
int world_tris;
int world_verts;
int character_lights;
hdelement_t HudDrawElements[ MAX_HUDDRAW_ELEMENTS ];
clientAnim_t anim;
2023-04-30 00:05:07 +02:00
stopWatch_t stopwatch;
2023-05-21 21:21:07 +02:00
void* savedCgameState;
int savedCgameStateSize;
char gcdResponse[73];
int unknown3_0;
int currentRate;
2016-03-27 11:49:47 +02:00
qhandle_t charSetShader;
qhandle_t whiteShader;
qhandle_t consoleShader;
fontInfo_t consoleFont;
} clientStatic_t;
extern clientStatic_t cls;
//=============================================================================
//extern vm_t *cgvm; // interface to cgame dll or vm
extern clientGameExport_t *cge;
extern refexport_t re; // interface to refresh .dll
2023-05-09 21:58:24 +02:00
extern qboolean scr_initialized;
2016-03-27 11:49:47 +02:00
//
// cvars
//
extern cvar_t *cl_nodelta;
extern cvar_t *cl_debugMove;
extern cvar_t *cl_noprint;
extern cvar_t *cl_timegraph;
2023-05-15 17:27:31 +02:00
extern cvar_t *cl_debuggraph;
2016-03-27 11:49:47 +02:00
extern cvar_t *cl_timeout;
extern cvar_t *cl_connect_timeout;
extern cvar_t *cl_maxpackets;
extern cvar_t *cl_packetdup;
extern cvar_t *cl_shownet;
extern cvar_t *cl_showSend;
extern cvar_t *cl_timeNudge;
extern cvar_t *cl_showTimeDelta;
extern cvar_t *cl_freezeDemo;
extern cvar_t *cl_yawspeed;
extern cvar_t *cl_pitchspeed;
extern cvar_t *cl_run;
extern cvar_t *cl_anglespeedkey;
extern cvar_t *cl_sensitivity;
extern cvar_t *cl_freelook;
extern cvar_t *cl_mouseAccel;
2023-05-29 21:17:53 +02:00
extern cvar_t *cl_mouseAccelOffset;
extern cvar_t *cl_mouseAccelStyle;
2016-03-27 11:49:47 +02:00
extern cvar_t *cl_showMouseRate;
extern cvar_t *cl_altbindings;
extern cvar_t *cl_ctrlbindings;
extern cvar_t *m_pitch;
extern cvar_t *m_yaw;
extern cvar_t *m_forward;
extern cvar_t *m_side;
extern cvar_t *m_filter;
2023-05-29 21:17:53 +02:00
extern cvar_t *j_pitch;
extern cvar_t *j_yaw;
extern cvar_t *j_forward;
extern cvar_t *j_side;
extern cvar_t *j_up;
extern cvar_t *j_pitch_axis;
extern cvar_t *j_yaw_axis;
extern cvar_t *j_forward_axis;
extern cvar_t *j_side_axis;
extern cvar_t *j_up_axis;
2016-03-27 11:49:47 +02:00
extern cvar_t *cl_timedemo;
extern cvar_t *cl_aviFrameRate;
extern cvar_t *cl_aviMotionJpeg;
extern cvar_t *cl_activeAction;
extern cvar_t *cl_allowDownload;
extern cvar_t *cl_downloadMethod;
extern cvar_t *cl_conXOffset;
extern cvar_t *cl_inGameVideo;
extern cvar_t *cl_lanForcePackets;
extern cvar_t *cl_langamerefreshstatus;
extern cvar_t *cl_autoRecordDemo;
extern cvar_t *cl_r_fullscreen;
extern cvar_t *cl_consoleKeys;
extern cvar_t *cg_gametype;
extern cvar_t* j_pitch;
extern cvar_t* j_yaw;
extern cvar_t* j_forward;
extern cvar_t* j_side;
extern cvar_t* j_up;
extern cvar_t* j_pitch_axis;
extern cvar_t* j_yaw_axis;
extern cvar_t* j_forward_axis;
extern cvar_t* j_side_axis;
extern cvar_t* j_up_axis;
2016-03-27 11:49:47 +02:00
//=================================================
//
// cl_main
//
void CL_Init (void);
2023-06-25 20:26:47 +02:00
void CL_InitClientSavedData(void);
void CL_AddReliableCommand(const char *cmd, qboolean isDisconnectCmd);
2016-03-27 11:49:47 +02:00
2023-06-25 20:26:47 +02:00
void CL_StartHunkUsers( qboolean rendererOnly );
2016-03-27 11:49:47 +02:00
void CL_Connect( const char *server );
void CL_Disconnect_f (void);
void CL_GetChallengePacket (void);
void CL_Vid_Restart_f( void );
void CL_Snd_Restart_f (void);
const char *CL_ConfigString( int index );
void CL_StartDemoLoop( void );
void CL_NextDemo( void );
void CL_ReadDemoMessage( void );
void CL_StopRecord_f(void);
void CL_InitDownloads(void);
void CL_NextDownload(void);
void CL_GetPing( int n, char *buf, int buflen, int *pingtime );
void CL_GetPingInfo( int n, char *buf, int buflen );
void CL_ClearPing( int n );
int CL_GetPingQueueCount( void );
void CL_ShutdownRef( void );
void CL_InitRef( void );
qboolean CL_CDKeyValidate( const char *key, const char *checksum );
int CL_ServerStatus( const char *serverAddress, char *serverStatusString, int maxLen );
void UI_ClearResource( void );
void UI_LoadResource( const char *name );
qboolean CL_CheckPaused(void);
//
// cl_input
//
typedef struct {
int down[2]; // key nums holding it down
unsigned downtime; // msec timestamp
unsigned msec; // msec down this frame if both a down and up happened
qboolean active; // current state
qboolean wasPressed; // set when down, not cleared when up
} kbutton_t;
extern kbutton_t in_mlook, in_klook;
extern kbutton_t in_strafe;
extern kbutton_t in_speed;
extern qboolean in_guimouse;
void IN_ToggleMouse( void );
void IN_MouseOn( void );
void IN_MouseOff( void );
void CL_InitInput (void);
void CL_SendCmd (void);
void CL_ClearState (void);
void CL_ReadPackets (void);
void CL_WritePacket( void );
void IN_CenterView (void);
void CL_VerifyCode( void );
float CL_KeyState (kbutton_t *key);
const char *Key_KeynumToString( int keynum );
const char *Key_KeynumToBindString( int keynum );
void Key_GetKeysForCommand( const char *command, int *key1, int *key2 );
int Key_GetCatcher( void );
void Key_SetCatcher( int catcher );
2023-05-16 18:59:56 +02:00
void CL_EyeInfo(usereyes_t *info);
2016-03-27 11:49:47 +02:00
//
// cl_parse.c
//
extern int cl_connectedToPureServer;
extern int cl_connectedToCheatServer;
extern msg_t *cl_currentMSG;
void CL_SystemInfoChanged( void );
void CL_ParseServerMessage( msg_t *msg );
int CL_MSG_ReadBits( int bits );
int CL_MSG_ReadChar( void );
int CL_MSG_ReadByte( void );
int CL_MSG_ReadSVC( void );
int CL_MSG_ReadShort( void );
int CL_MSG_ReadLong( void );
float CL_MSG_ReadFloat( void );
char *CL_MSG_ReadString( void );
char *CL_MSG_ReadStringLine( void );
float CL_MSG_ReadAngle8( void );
float CL_MSG_ReadAngle16( void );
void CL_MSG_ReadData( void *data, int len );
float CL_MSG_ReadCoord( void );
void CL_MSG_ReadDir( vec3_t dir );
//====================================================================
void CL_ServerInfoPacket( netadr_t from, msg_t *msg );
void CL_LocalServers_f( void );
void CL_GlobalServers_f( void );
void CL_FavoriteServers_f( void );
void CL_Ping_f( void );
void CL_SaveShot_f( void );
void CL_Dialog_f( void );
qboolean CL_UpdateVisiblePings_f( int source );
//
// console
//
void Con_DrawCharacter (int cx, int line, int num);
void Con_CheckResize (void);
void Con_Init (void);
void Con_Clear_f (void);
void Con_ToggleConsole_f (void);
void Con_DrawNotify (void);
void Con_ClearNotify (void);
void Con_RunConsole (void);
void Con_DrawConsole (void);
void Con_PageUp( void );
void Con_PageDown( void );
void Con_Top( void );
void Con_Bottom( void );
//
// cl_scrn.c
//
void SCR_Init (void);
2023-05-15 17:27:31 +02:00
void SCR_DrawDebugGraph(void);
2019-06-25 01:17:10 +02:00
void SCR_DrawScreenField(void);
2016-03-27 11:49:47 +02:00
void SCR_UpdateScreen (void);
2023-05-24 19:40:02 +02:00
void SCR_DebugGraph (float value);
2016-03-27 11:49:47 +02:00
int SCR_GetBigStringWidth( const char *str ); // returns in virtual 640x480 coordinates
void SCR_AdjustFrom640( float *x, float *y, float *w, float *h );
void SCR_FillRect( float x, float y, float width, float height,
const float *color );
void SCR_DrawPic( float x, float y, float width, float height, qhandle_t hShader );
void SCR_DrawNamedPic( float x, float y, float width, float height, const char *picname );
void SCR_DrawBigString( int x, int y, const char *s, float alpha, qboolean noColorEscape ); // draws a string with embedded color control characters with fade
void SCR_DrawBigStringColor( int x, int y, const char *s, vec4_t color, qboolean noColorEscape ); // ignores embedded color control characters
void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, qboolean forceColor, qboolean noColorEscape );
void SCR_DrawSmallChar( int x, int y, int ch );
void UpdateStereoSide( stereoFrame_t s );
//
// cl_cin.c
//
void CL_PlayCinematic_f( void );
void SCR_DrawCinematic (void);
void SCR_RunCinematic (void);
void SCR_StopCinematic (void);
int CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits);
e_status CIN_StopCinematic(int handle);
e_status CIN_RunCinematic (int handle);
void CIN_DrawCinematic (int handle);
void CIN_SetExtents (int handle, int x, int y, int w, int h);
void CIN_SetLooping (int handle, qboolean loop);
void CIN_UploadCinematic(int handle);
void CIN_CloseAllVideos(void);
//
// cl_cgame.cpp
//
void CL_InitCGame( void );
void CL_InitCGameDLL( void );
void CL_ShutdownCGame( void );
qboolean CL_GameCommand( void );
void CL_CGameRendering( stereoFrame_t stereo );
void CL_CGame2D( stereoFrame_t stereo );
void CL_UpdateSnapFlags( void );
void CL_SetCGameTime( void );
void CL_FirstSnapshot( void );
void CL_ShaderStateChanged( void );
baseshader_t *CL_GetShaderPointer( int iShaderNum );
//
// cl_ui.c
//
/*
void CL_InitializeUI( void );
void CL_ShutdownUI( void );
int Key_GetCatcher( void );
void Key_SetCatcher( int catcher );
void LAN_LoadCachedServers( void );
void LAN_SaveServersToCache( void );
*/
//
// cl_net_chan.c
//
void CL_Netchan_Transmit( netchan_t *chan, msg_t* msg); //int length, const byte *data );
void CL_Netchan_TransmitNextFragment( netchan_t *chan );
qboolean CL_Netchan_Process( netchan_t *chan, msg_t *msg );
//
// cl_avi.c
//
qboolean CL_OpenAVIForWriting( const char *filename );
void CL_TakeVideoFrame( void );
void CL_WriteAVIVideoFrame( const byte *imageBuffer, int size );
void CL_WriteAVIAudioFrame( const byte *pcmBuffer, int size );
qboolean CL_CloseAVI( void );
qboolean CL_VideoRecording( void );
//
// cl_consolecmds.cpp
//
void CL_InitConsoleCommands( void );
#ifdef __cplusplus
}
#endif
#endif // __CLIENT_H__