📄 qcommon.h
字号:
/*
===========================================================================
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 Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// qcommon.h -- definitions common between client and server, but not game.or ref modules
#ifndef _QCOMMON_H_
#define _QCOMMON_H_
#include "../qcommon/cm_public.h"
//#define PRE_RELEASE_DEMO
//============================================================================
//
// msg.c
//
typedef struct {
qboolean allowoverflow; // if false, do a Com_Error
qboolean overflowed; // set to true if the buffer size failed (with allowoverflow set)
qboolean oob; // set to true if the buffer size failed (with allowoverflow set)
byte *data;
int maxsize;
int cursize;
int readcount;
int bit; // for bitwise reads and writes
} msg_t;
void MSG_Init (msg_t *buf, byte *data, int length);
void MSG_InitOOB( msg_t *buf, byte *data, int length );
void MSG_Clear (msg_t *buf);
void MSG_WriteData (msg_t *buf, const void *data, int length);
void MSG_Bitstream( msg_t *buf );
// TTimo
// copy a msg_t in case we need to store it as is for a bit
// (as I needed this to keep an msg_t from a static var for later use)
// sets data buffer as MSG_Init does prior to do the copy
void MSG_Copy(msg_t *buf, byte *data, int length, msg_t *src);
struct usercmd_s;
struct entityState_s;
struct playerState_s;
void MSG_WriteBits( msg_t *msg, int value, int bits );
void MSG_WriteChar (msg_t *sb, int c);
void MSG_WriteByte (msg_t *sb, int c);
void MSG_WriteShort (msg_t *sb, int c);
void MSG_WriteLong (msg_t *sb, int c);
void MSG_WriteFloat (msg_t *sb, float f);
void MSG_WriteString (msg_t *sb, const char *s);
void MSG_WriteBigString (msg_t *sb, const char *s);
void MSG_WriteAngle16 (msg_t *sb, float f);
void MSG_BeginReading (msg_t *sb);
void MSG_BeginReadingOOB(msg_t *sb);
int MSG_ReadBits( msg_t *msg, int bits );
int MSG_ReadChar (msg_t *sb);
int MSG_ReadByte (msg_t *sb);
int MSG_ReadShort (msg_t *sb);
int MSG_ReadLong (msg_t *sb);
float MSG_ReadFloat (msg_t *sb);
char *MSG_ReadString (msg_t *sb);
char *MSG_ReadBigString (msg_t *sb);
char *MSG_ReadStringLine (msg_t *sb);
float MSG_ReadAngle16 (msg_t *sb);
void MSG_ReadData (msg_t *sb, void *buffer, int size);
void MSG_WriteDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
void MSG_ReadDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
void MSG_WriteDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
void MSG_ReadDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to
, qboolean force );
void MSG_ReadDeltaEntity( msg_t *msg, entityState_t *from, entityState_t *to,
int number );
void MSG_WriteDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
void MSG_ReadDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
void MSG_ReportChangeVectors_f( void );
//============================================================================
/*
==============================================================
NET
==============================================================
*/
#define PACKET_BACKUP 32 // number of old messages that must be kept on client and
// server for delta comrpession and ping estimation
#define PACKET_MASK (PACKET_BACKUP-1)
#define MAX_PACKET_USERCMDS 32 // max number of usercmd_t in a packet
#define PORT_ANY -1
#define MAX_RELIABLE_COMMANDS 64 // max string commands buffered for restransmit
typedef enum {
NA_BOT,
NA_BAD, // an address lookup failed
NA_LOOPBACK,
NA_BROADCAST,
NA_IP,
NA_IPX,
NA_BROADCAST_IPX
} netadrtype_t;
typedef enum {
NS_CLIENT,
NS_SERVER
} netsrc_t;
typedef struct {
netadrtype_t type;
byte ip[4];
byte ipx[10];
unsigned short port;
} netadr_t;
void NET_Init( void );
void NET_Shutdown( void );
void NET_Restart( void );
void NET_Config( qboolean enableNetworking );
void NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to);
void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...);
void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
qboolean NET_CompareAdr (netadr_t a, netadr_t b);
qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
qboolean NET_IsLocalAddress (netadr_t adr);
const char *NET_AdrToString (netadr_t a);
qboolean NET_StringToAdr ( const char *s, netadr_t *a);
qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
void NET_Sleep(int msec);
#define MAX_MSGLEN 16384 // max length of a message, which may
// be fragmented into multiple packets
#define MAX_DOWNLOAD_WINDOW 8 // max of eight download frames
#define MAX_DOWNLOAD_BLKSIZE 2048 // 2048 byte block chunks
/*
Netchan handles packet fragmentation and out of order / duplicate suppression
*/
typedef struct {
netsrc_t sock;
int dropped; // between last packet and previous
netadr_t remoteAddress;
int qport; // qport value to write when transmitting
// sequencing variables
int incomingSequence;
int outgoingSequence;
// incoming fragment assembly buffer
int fragmentSequence;
int fragmentLength;
byte fragmentBuffer[MAX_MSGLEN];
// outgoing fragment buffer
// we need to space out the sending of large fragmented messages
qboolean unsentFragments;
int unsentFragmentStart;
int unsentLength;
byte unsentBuffer[MAX_MSGLEN];
} netchan_t;
void Netchan_Init( int qport );
void Netchan_Setup( netsrc_t sock, netchan_t *chan, netadr_t adr, int qport );
void Netchan_Transmit( netchan_t *chan, int length, const byte *data );
void Netchan_TransmitNextFragment( netchan_t *chan );
qboolean Netchan_Process( netchan_t *chan, msg_t *msg );
/*
==============================================================
PROTOCOL
==============================================================
*/
#define PROTOCOL_VERSION 68
// 1.31 - 67
// maintain a list of compatible protocols for demo playing
// NOTE: that stuff only works with two digits protocols
extern int demo_protocols[];
#define UPDATE_SERVER_NAME "update.quake3arena.com"
// override on command line, config files etc.
#ifndef MASTER_SERVER_NAME
#define MASTER_SERVER_NAME "master.quake3arena.com"
#endif
#ifndef AUTHORIZE_SERVER_NAME
#define AUTHORIZE_SERVER_NAME "authorize.quake3arena.com"
#endif
#define PORT_MASTER 27950
#define PORT_UPDATE 27951
#ifndef PORT_AUTHORIZE
#define PORT_AUTHORIZE 27952
#endif
#define PORT_SERVER 27960
#define NUM_SERVER_PORTS 4 // broadcast scan this many ports after
// PORT_SERVER so a single machine can
// run multiple servers
// the svc_strings[] array in cl_parse.c should mirror this
//
// server to client
//
enum svc_ops_e {
svc_bad,
svc_nop,
svc_gamestate,
svc_configstring, // [short] [string] only in gamestate messages
svc_baseline, // only in gamestate messages
svc_serverCommand, // [string] to be executed by client game module
svc_download, // [short] size [size bytes]
svc_snapshot,
svc_EOF
};
//
// client to server
//
enum clc_ops_e {
clc_bad,
clc_nop,
clc_move, // [[usercmd_t]
clc_moveNoDelta, // [[usercmd_t]
clc_clientCommand, // [string] message
clc_EOF
};
/*
==============================================================
VIRTUAL MACHINE
==============================================================
*/
typedef struct vm_s vm_t;
typedef enum {
VMI_NATIVE,
VMI_BYTECODE,
VMI_COMPILED
} vmInterpret_t;
typedef enum {
TRAP_MEMSET = 100,
TRAP_MEMCPY,
TRAP_STRNCPY,
TRAP_SIN,
TRAP_COS,
TRAP_ATAN2,
TRAP_SQRT,
TRAP_MATRIXMULTIPLY,
TRAP_ANGLEVECTORS,
TRAP_PERPENDICULARVECTOR,
TRAP_FLOOR,
TRAP_CEIL,
TRAP_TESTPRINTINT,
TRAP_TESTPRINTFLOAT
} sharedTraps_t;
void VM_Init( void );
vm_t *VM_Create( const char *module, int (*systemCalls)(int *),
vmInterpret_t interpret );
// module should be bare: "cgame", not "cgame.dll" or "vm/cgame.qvm"
void VM_Free( vm_t *vm );
void VM_Clear(void);
vm_t *VM_Restart( vm_t *vm );
int QDECL VM_Call( vm_t *vm, int callNum, ... );
void VM_Debug( int level );
void *VM_ArgPtr( int intValue );
void *VM_ExplicitArgPtr( vm_t *vm, int intValue );
/*
==============================================================
CMD
Command text buffering and command execution
==============================================================
*/
/*
Any number of commands can be added in a frame, from several different sources.
Most commands come from either keybindings or console line input, but entire text
files can be execed.
*/
void Cbuf_Init (void);
// allocates an initial text buffer that will grow as needed
void Cbuf_AddText( const char *text );
// Adds command text at the end of the buffer, does NOT add a final \n
void Cbuf_ExecuteText( int exec_when, const char *text );
// this can be used in place of either Cbuf_AddText or Cbuf_InsertText
void Cbuf_Execute (void);
// Pulls off \n terminated lines of text from the command buffer and sends
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -