engine: client: more accurate clc_move for GoldSrc protocol

This commit is contained in:
Alibek Omarov 2024-10-10 23:27:02 +03:00
parent 8b8c3d8116
commit 18afaf0eaf
2 changed files with 35 additions and 19 deletions

View file

@ -680,21 +680,16 @@ static void CL_CreateCmd( void )
void CL_WriteUsercmd( sizebuf_t *msg, int from, int to ) void CL_WriteUsercmd( sizebuf_t *msg, int from, int to )
{ {
usercmd_t nullcmd; const usercmd_t nullcmd = { 0 };
usercmd_t *f, *t; usercmd_t *f, *t;
Assert( from == -1 || ( from >= 0 && from < MULTIPLAYER_BACKUP )); Assert( from == -1 || ( from >= 0 && from < MULTIPLAYER_BACKUP ));
Assert( to >= 0 && to < MULTIPLAYER_BACKUP ); Assert( to >= 0 && to < MULTIPLAYER_BACKUP );
if( from == -1 ) if( from == -1 )
{
memset( &nullcmd, 0, sizeof( nullcmd ));
f = &nullcmd; f = &nullcmd;
}
else else
{
f = &cl.commands[from].cmd; f = &cl.commands[from].cmd;
}
t = &cl.commands[to].cmd; t = &cl.commands[to].cmd;
@ -737,8 +732,15 @@ static void CL_WritePacket( void )
MSG_Init( &buf, "ClientData", data, sizeof( data )); MSG_Init( &buf, "ClientData", data, sizeof( data ));
// Determine number of backup commands to send along // Determine number of backup commands to send along
numbackup = bound( 0, cl_cmdbackup.value, cls.legacymode ? MAX_LEGACY_BACKUP_CMDS : MAX_BACKUP_COMMANDS ); if( cls.legacymode == PROTO_GOLDSRC )
if( cls.state == ca_connected ) numbackup = 0; numbackup = bound( 0, cl_cmdbackup.value, MAX_GOLDSRC_BACKUP_CMDS );
else if( cls.legacymode == PROTO_LEGACY )
numbackup = bound( 0, cl_cmdbackup.value, MAX_LEGACY_BACKUP_CMDS );
else
numbackup = bound( 0, cl_cmdbackup.value, MAX_BACKUP_COMMANDS );
if( cls.state == ca_connected )
numbackup = 0;
// clamp cmdrate // clamp cmdrate
if( cl_cmdrate.value < 10.0f ) if( cl_cmdrate.value < 10.0f )
@ -805,14 +807,14 @@ static void CL_WritePacket( void )
MSG_BeginClientCmd( &buf, clc_move ); MSG_BeginClientCmd( &buf, clc_move );
if( cls.legacymode == PROTO_GOLDSRC ) if( cls.legacymode == PROTO_GOLDSRC )
MSG_WriteByte( &buf, 0 ); MSG_WriteByte( &buf, 0 ); // length
// save the position for a checksum byte // save the position for a checksum byte
key = MSG_GetRealBytesWritten( &buf ); key = MSG_GetRealBytesWritten( &buf );
MSG_WriteByte( &buf, 0 ); MSG_WriteByte( &buf, 0 );
// write packet lossage percentation // write packet lossage percentation
MSG_WriteByte( &buf, cls.packet_loss ); MSG_WriteByte( &buf, bound( 0, (int)cls.packet_loss, 100 ) );
// say how many backups we'll be sending // say how many backups we'll be sending
MSG_WriteByte( &buf, numbackup ); MSG_WriteByte( &buf, numbackup );
@ -821,8 +823,15 @@ static void CL_WritePacket( void )
newcmds = ( cls.netchan.outgoing_sequence - cls.lastoutgoingcommand ); newcmds = ( cls.netchan.outgoing_sequence - cls.lastoutgoingcommand );
// put an upper/lower bound on this // put an upper/lower bound on this
newcmds = bound( 0, newcmds, cls.legacymode ? MAX_LEGACY_TOTAL_CMDS: MAX_TOTAL_CMDS ); if( cls.legacymode == PROTO_GOLDSRC )
if( cls.state == ca_connected ) newcmds = 0; newcmds = bound( 0, newcmds, MAX_GOLDSRC_TOTAL_CMDS );
else if( cls.legacymode == PROTO_LEGACY )
newcmds = bound( 0, newcmds, MAX_LEGACY_TOTAL_CMDS );
else
newcmds = bound( 0, newcmds, MAX_TOTAL_CMDS );
if( cls.state == ca_connected )
newcmds = 0;
MSG_WriteByte( &buf, newcmds ); MSG_WriteByte( &buf, newcmds );
@ -843,16 +852,20 @@ static void CL_WritePacket( void )
} }
// calculate a checksum over the move commands // calculate a checksum over the move commands
size = MSG_GetRealBytesWritten( &buf ) - key - 1;
if( cls.legacymode == PROTO_GOLDSRC ) if( cls.legacymode == PROTO_GOLDSRC )
{ {
size = Q_min( size, 255 ); size = MSG_GetRealBytesWritten( &buf ) - key - 1;
buf.pData[key - 1] = size;
}
buf.pData[key] = CRC32_BlockSequence( buf.pData + key + 1, size, cls.netchan.outgoing_sequence );
if( cls.legacymode == PROTO_GOLDSRC ) buf.pData[key - 1] = Q_min( size, 255 );
COM_Munge( buf.pData + key + 1, size, cls.netchan.outgoing_sequence ); buf.pData[key] = CRC32_BlockSequence( buf.pData + key + 1, size, cls.netchan.outgoing_sequence );
COM_Munge( buf.pData + key + 1, Q_min( size, 255 ), cls.netchan.outgoing_sequence );
}
else
{
size = MSG_GetRealBytesWritten( &buf ) - key - 1;
buf.pData[key] = CRC32_BlockSequence( buf.pData + key + 1, size, cls.netchan.outgoing_sequence );
}
// message we are constructing. // message we are constructing.
i = cls.netchan.outgoing_sequence & CL_UPDATE_MASK; i = cls.netchan.outgoing_sequence & CL_UPDATE_MASK;

View file

@ -347,7 +347,10 @@ extern const char *clc_strings[clc_lastmsg+1];
#define S2C_REJECT '9' #define S2C_REJECT '9'
#define S2C_CHALLENGE "A00000000" #define S2C_CHALLENGE "A00000000"
#define S2C_CONNECTION "B" #define S2C_CONNECTION "B"
#define A2C_PRINT 'l'
#define MAX_GOLDSRC_BACKUP_CMDS 8
#define MAX_GOLDSRC_TOTAL_CMDS 16
#define MAX_GOLDSRC_MODEL_BITS 10 #define MAX_GOLDSRC_MODEL_BITS 10
#define MAX_GOLDSRC_RESOURCE_BITS 12 #define MAX_GOLDSRC_RESOURCE_BITS 12
#define MAX_GOLDSRC_ENTITY_BITS 11 #define MAX_GOLDSRC_ENTITY_BITS 11