📄 qcommon.h
字号:
// them through Cmd_ExecuteString. Stops when the buffer is empty.
// Normally called once per frame, but may be explicitly invoked.
// Do not call inside a command function, or current args will be destroyed.
//===========================================================================
/*
Command execution takes a null terminated string, breaks it into tokens,
then searches for a command or variable that matches the first token.
*/
typedef void (*xcommand_t) (void);
void Cmd_Init (void);
void Cmd_AddCommand( const char *cmd_name, xcommand_t function );
// called by the init functions of other parts of the program to
// register commands and functions to call for them.
// The cmd_name is referenced later, so it should not be in temp memory
// if function is NULL, the command will be forwarded to the server
// as a clc_clientCommand instead of executed locally
void Cmd_RemoveCommand( const char *cmd_name );
void Cmd_CommandCompletion( void(*callback)(const char *s) );
// callback with each valid string
int Cmd_Argc (void);
char *Cmd_Argv (int arg);
void Cmd_ArgvBuffer( int arg, char *buffer, int bufferLength );
char *Cmd_Args (void);
char *Cmd_ArgsFrom( int arg );
void Cmd_ArgsBuffer( char *buffer, int bufferLength );
char *Cmd_Cmd (void);
// The functions that execute commands get their parameters with these
// functions. Cmd_Argv () will return an empty string, not a NULL
// if arg > argc, so string operations are allways safe.
void Cmd_TokenizeString( const char *text );
// Takes a null terminated string. Does not need to be /n terminated.
// breaks the string up into arg tokens.
void Cmd_ExecuteString( const char *text );
// Parses a single line of text into arguments and tries to execute it
// as if it was typed at the console
/*
==============================================================
CVAR
==============================================================
*/
/*
cvar_t variables are used to hold scalar or string variables that can be changed
or displayed at the console or prog code as well as accessed directly
in C code.
The user can access cvars from the console in three ways:
r_draworder prints the current value
r_draworder 0 sets the current value to 0
set r_draworder 0 as above, but creates the cvar if not present
Cvars are restricted from having the same names as commands to keep this
interface from being ambiguous.
The are also occasionally used to communicated information between different
modules of the program.
*/
cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
// creates the variable if it doesn't exist, or returns the existing one
// if it exists, the value will not be changed, but flags will be ORed in
// that allows variables to be unarchived without needing bitflags
// if value is "", the value will not override a previously set value.
void Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags );
// basically a slightly modified Cvar_Get for the interpreted modules
void Cvar_Update( vmCvar_t *vmCvar );
// updates an interpreted modules' version of a cvar
void Cvar_Set( const char *var_name, const char *value );
// will create the variable with no flags if it doesn't exist
void Cvar_SetLatched( const char *var_name, const char *value);
// don't set the cvar immediately
void Cvar_SetValue( const char *var_name, float value );
// expands value to a string and calls Cvar_Set
float Cvar_VariableValue( const char *var_name );
int Cvar_VariableIntegerValue( const char *var_name );
// returns 0 if not defined or non numeric
char *Cvar_VariableString( const char *var_name );
void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize );
// returns an empty string if not defined
void Cvar_CommandCompletion( void(*callback)(const char *s) );
// callback with each valid string
void Cvar_Reset( const char *var_name );
void Cvar_SetCheatState( void );
// reset all testing vars to a safe value
qboolean Cvar_Command( void );
// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
// command. Returns true if the command was a variable reference that
// was handled. (print or change)
void Cvar_WriteVariables( fileHandle_t f );
// writes lines containing "set variable value" for all variables
// with the archive flag set to true.
void Cvar_Init( void );
char *Cvar_InfoString( int bit );
char *Cvar_InfoString_Big( int bit );
// returns an info string containing all the cvars that have the given bit set
// in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
void Cvar_Restart_f( void );
extern int cvar_modifiedFlags;
// whenever a cvar is modifed, its flags will be OR'd into this, so
// a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
// etc, variables have been modified since the last check. The bit
// can then be cleared to allow another change detection.
/*
==============================================================
FILESYSTEM
No stdio calls should be used by any part of the game, because
we need to deal with all sorts of directory and seperator char
issues.
==============================================================
*/
// referenced flags
// these are in loop specific order so don't change the order
#define FS_GENERAL_REF 0x01
#define FS_UI_REF 0x02
#define FS_CGAME_REF 0x04
#define FS_QAGAME_REF 0x08
// number of id paks that will never be autodownloaded from baseq3
#define NUM_ID_PAKS 9
#define MAX_FILE_HANDLES 64
#define BASEGAME "baseq3"
qboolean FS_Initialized();
void FS_InitFilesystem (void);
void FS_Shutdown( qboolean closemfp );
qboolean FS_ConditionalRestart( int checksumFeed );
void FS_Restart( int checksumFeed );
// shutdown and restart the filesystem so changes to fs_gamedir can take effect
char **FS_ListFiles( const char *directory, const char *extension, int *numfiles );
// directory should not have either a leading or trailing /
// if extension is "/", only subdirectories will be returned
// the returned files will not include any directories or /
void FS_FreeFileList( char **list );
qboolean FS_FileExists( const char *file );
int FS_LoadStack();
int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
int FS_GetModList( char *listbuf, int bufsize );
fileHandle_t FS_FOpenFileWrite( const char *qpath );
// will properly create any needed paths and deal with seperater character issues
int FS_filelength( fileHandle_t f );
fileHandle_t FS_SV_FOpenFileWrite( const char *filename );
int FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp );
void FS_SV_Rename( const char *from, const char *to );
int FS_FOpenFileRead( const char *qpath, fileHandle_t *file, qboolean uniqueFILE );
// if uniqueFILE is true, then a new FILE will be fopened even if the file
// is found in an already open pak file. If uniqueFILE is false, you must call
// FS_FCloseFile instead of fclose, otherwise the pak FILE would be improperly closed
// It is generally safe to always set uniqueFILE to true, because the majority of
// file IO goes through FS_ReadFile, which Does The Right Thing already.
int FS_FileIsInPAK(const char *filename, int *pChecksum );
// returns 1 if a file is in the PAK file, otherwise -1
int FS_Write( const void *buffer, int len, fileHandle_t f );
int FS_Read2( void *buffer, int len, fileHandle_t f );
int FS_Read( void *buffer, int len, fileHandle_t f );
// properly handles partial reads and reads from other dlls
void FS_FCloseFile( fileHandle_t f );
// note: you can't just fclose from another DLL, due to MS libc issues
int FS_ReadFile( const char *qpath, void **buffer );
// returns the length of the file
// a null buffer will just return the file length without loading
// as a quick check for existance. -1 length == not present
// A 0 byte will always be appended at the end, so string ops are safe.
// the buffer should be considered read-only, because it may be cached
// for other uses.
void FS_ForceFlush( fileHandle_t f );
// forces flush on files we're writing to.
void FS_FreeFile( void *buffer );
// frees the memory returned by FS_ReadFile
void FS_WriteFile( const char *qpath, const void *buffer, int size );
// writes a complete file, creating any subdirectories needed
int FS_filelength( fileHandle_t f );
// doesn't work for files that are opened from a pack file
int FS_FTell( fileHandle_t f );
// where are we?
void FS_Flush( fileHandle_t f );
void QDECL FS_Printf( fileHandle_t f, const char *fmt, ... );
// like fprintf
int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode );
// opens a file for reading, writing, or appending depending on the value of mode
int FS_Seek( fileHandle_t f, long offset, int origin );
// seek on a file (doesn't work for zip files!!!!!!!!)
qboolean FS_FilenameCompare( const char *s1, const char *s2 );
const char *FS_GamePureChecksum( void );
// Returns the checksum of the pk3 from which the server loaded the qagame.qvm
const char *FS_LoadedPakNames( void );
const char *FS_LoadedPakChecksums( void );
const char *FS_LoadedPakPureChecksums( void );
// Returns a space separated string containing the checksums of all loaded pk3 files.
// Servers with sv_pure set will get this string and pass it to clients.
const char *FS_ReferencedPakNames( void );
const char *FS_ReferencedPakChecksums( void );
const char *FS_ReferencedPakPureChecksums( void );
// Returns a space separated string containing the checksums of all loaded
// AND referenced pk3 files. Servers with sv_pure set will get this string
// back from clients for pure validation
void FS_ClearPakReferences( int flags );
// clears referenced booleans on loaded pk3s
void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames );
void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames );
// If the string is empty, all data sources will be allowed.
// If not empty, only pk3 files that match one of the space
// separated checksums will be checked for files, with the
// sole exception of .cfg files.
qboolean FS_idPak( char *pak, char *base );
qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring );
void FS_Rename( const char *from, const char *to );
/*
==============================================================
Edit fields and command line history/completion
==============================================================
*/
#define MAX_EDIT_LINE 256
typedef struct {
int cursor;
int scroll;
int widthInChars;
char buffer[MAX_EDIT_LINE];
} field_t;
void Field_Clear( field_t *edit );
void Field_CompleteCommand( field_t *edit );
/*
==============================================================
MISC
==============================================================
*/
// TTimo
// vsnprintf is ISO/IEC 9899:1999
// abstracting this to make it portable
#ifdef WIN32
#define Q_vsnprintf _vsnprintf
#else
// TODO: do we need Mac define?
#define Q_vsnprintf vsnprintf
#endif
// centralizing the declarations for cl_cdkey
// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470
extern char cl_cdkey[34];
// returnbed by Sys_GetProcessorId
#define CPUID_GENERIC 0 // any unrecognized processor
#define CPUID_AXP 0x10
#define CPUID_INTEL_UNSUPPORTED 0x20 // Intel 386/486
#define CPUID_INTEL_PENTIUM 0x21 // Intel Pentium or PPro
#define CPUID_INTEL_MMX 0x22 // Intel Pentium/MMX or P2/MMX
#define CPUID_INTEL_KATMAI 0x23 // Intel Katmai
#define CPUID_AMD_3DNOW 0x30 // AMD K6 3DNOW!
// TTimo
// centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
#define MAXPRINTMSG 4096
char *CopyString( const char *in );
void Info_Print( const char *s );
void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
void Com_EndRedirect( void );
void QDECL Com_Printf( const char *fmt, ... );
void QDECL Com_DPrintf( const char *fmt, ... );
void QDECL Com_Error( int code, const char *fmt, ... );
void Com_Quit_f( void );
int Com_EventLoop( void );
int Com_Milliseconds( void ); // will be journaled properly
unsigned Com_BlockChecksum( const void *buffer, int length );
unsigned Com_BlockChecksumKey (void *buffer, int length, int key);
int Com_HashKey(char *string, int maxlen);
int Com_Filter(char *filter, char *name, int casesensitive);
int Com_FilterPath(char *filter, char *name, int casesensitive);
int Com_RealTime(qtime_t *qtime);
qboolean Com_SafeMode( void );
void Com_StartupVariable( const char *match );
// checks for and removes command line "+set var arg" constructs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -