2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-22 09:56:22 +01:00

engine: common: faster and simpler MSG_WriteString

This commit is contained in:
Alibek Omarov 2024-08-08 04:35:34 +03:00
parent 8fcaf18897
commit 6bfa525080

View File

@ -395,15 +395,11 @@ qboolean MSG_WriteBytes( sizebuf_t *sb, const void *pBuf, int nBytes )
qboolean MSG_WriteString( sizebuf_t *sb, const char *pStr )
{
if( pStr )
{
do
{
MSG_WriteChar( sb, (signed char)*pStr );
pStr++;
} while( *( pStr - 1 ));
}
else MSG_WriteChar( sb, 0 );
int len = Q_strlen( pStr );
if( len )
MSG_WriteBytes( sb, pStr, len + 1 );
else MSG_WriteByte( sb, 0 );
return !sb->bOverflow;
}
@ -411,13 +407,22 @@ qboolean MSG_WriteString( sizebuf_t *sb, const char *pStr )
qboolean MSG_WriteStringf( sizebuf_t *sb, const char *format, ... )
{
va_list va;
int len;
char buf[MAX_VA_STRING];
va_start( va, format );
Q_vsnprintf( buf, sizeof( buf ), format, va );
len = Q_vsnprintf( buf, sizeof( buf ), format, va );
va_end( va );
return MSG_WriteString( sb, buf );
if( len < 0 )
{
Host_Error( "%s: snprintf overflow!\n", __func__ );
return false;
}
MSG_WriteBytes( sb, buf, len + 1 );
return !sb->bOverflow;
}
int MSG_ReadOneBit( sizebuf_t *sb )
@ -629,9 +634,7 @@ float MSG_ReadFloat( sizebuf_t *sb )
{
float ret;
Assert( sizeof( ret ) == 4 );
MSG_ReadBits( sb, &ret, 32 );
MSG_ReadBits( sb, &ret, sizeof( ret ) << 3 );
return ret;
}