mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-11 22:52:09 +08:00
engine: common: refactor variable declarations
This commit is contained in:
+15
-22
@@ -308,8 +308,6 @@ void MSG_WriteUBitLong( sizebuf_t *sb, uint curData, int numbits )
|
||||
int nBitsLeft = numbits;
|
||||
int iCurBit = sb->iCurBit;
|
||||
uint iDWord = iCurBit >> 5; // Mask in a dword.
|
||||
uint32_t iCurBitMasked;
|
||||
int nBitsWritten;
|
||||
|
||||
Assert( numbits >= 1 && numbits <= 32 );
|
||||
|
||||
@@ -320,14 +318,14 @@ void MSG_WriteUBitLong( sizebuf_t *sb, uint curData, int numbits )
|
||||
return;
|
||||
}
|
||||
|
||||
iCurBitMasked = iCurBit & 31;
|
||||
uint32_t iCurBitMasked = iCurBit & 31;
|
||||
uint32_t dword = LittleLong(((uint32_t *)sb->pData)[iDWord] );
|
||||
dword &= BitWriteMasks[iCurBitMasked][nBitsLeft-1];
|
||||
dword |= curData << iCurBitMasked;
|
||||
((uint32_t *)sb->pData)[iDWord] = LittleLong( dword );
|
||||
|
||||
// did it span a dword?
|
||||
nBitsWritten = 32 - iCurBitMasked;
|
||||
int nBitsWritten = 32 - iCurBitMasked;
|
||||
|
||||
if( nBitsWritten < nBitsLeft )
|
||||
{
|
||||
@@ -429,13 +427,12 @@ void MSG_WriteBitAngle( sizebuf_t *sb, float fAngle, int numbits )
|
||||
{
|
||||
const uint shift = ( 1 << numbits );
|
||||
const uint mask = shift - 1;
|
||||
int d;
|
||||
|
||||
// clamp the angle before receiving
|
||||
fAngle = fmod( fAngle, 360.0f );
|
||||
if( fAngle < 0 ) fAngle += 360.0f;
|
||||
|
||||
d = (int)(( fAngle * shift ) / 360.0f );
|
||||
int d = (int)(( fAngle * shift ) / 360.0f );
|
||||
d &= mask;
|
||||
|
||||
MSG_WriteUBitLong( sb, (uint)d, numbits );
|
||||
@@ -546,11 +543,10 @@ 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 );
|
||||
len = Q_vsnprintf( buf, sizeof( buf ), format, va );
|
||||
int len = Q_vsnprintf( buf, sizeof( buf ), format, va );
|
||||
va_end( va );
|
||||
|
||||
if( len < 0 )
|
||||
@@ -577,9 +573,6 @@ int MSG_ReadOneBit( sizebuf_t *sb )
|
||||
|
||||
uint MSG_ReadUBitLong( sizebuf_t *sb, int numbits )
|
||||
{
|
||||
int idword1;
|
||||
uint dword1, ret;
|
||||
|
||||
if( numbits == 8 )
|
||||
{
|
||||
int leftBits = MSG_GetNumBitsLeft( sb );
|
||||
@@ -597,12 +590,12 @@ uint MSG_ReadUBitLong( sizebuf_t *sb, int numbits )
|
||||
Assert( numbits > 0 && numbits <= 32 );
|
||||
|
||||
// Read the current dword.
|
||||
idword1 = sb->iCurBit >> 5;
|
||||
dword1 = LittleLong(((uint *)sb->pData)[idword1] );
|
||||
int idword1 = sb->iCurBit >> 5;
|
||||
uint dword1 = LittleLong(((uint *)sb->pData)[idword1] );
|
||||
dword1 >>= ( sb->iCurBit & 31 ); // get the bits we're interested in.
|
||||
|
||||
sb->iCurBit += numbits;
|
||||
ret = dword1;
|
||||
uint ret = dword1;
|
||||
|
||||
// Does it span this dword?
|
||||
if(( sb->iCurBit - 1 ) >> 5 == idword1 )
|
||||
@@ -726,10 +719,10 @@ int MSG_ReadCmd( sizebuf_t *sb, netsrc_t type )
|
||||
|
||||
int MSG_ReadChar( sizebuf_t *sb )
|
||||
{
|
||||
int alt = sb->iAlternateSign, ret;
|
||||
int alt = sb->iAlternateSign;
|
||||
|
||||
sb->iAlternateSign = 0;
|
||||
ret = MSG_ReadSBitLong( sb, sizeof( int8_t ) << 3 );
|
||||
int ret = MSG_ReadSBitLong( sb, sizeof( int8_t ) << 3 );
|
||||
sb->iAlternateSign = alt;
|
||||
|
||||
return ret;
|
||||
@@ -742,10 +735,10 @@ int MSG_ReadByte( sizebuf_t *sb )
|
||||
|
||||
int MSG_ReadShort( sizebuf_t *sb )
|
||||
{
|
||||
int alt = sb->iAlternateSign, ret;
|
||||
int alt = sb->iAlternateSign;
|
||||
|
||||
sb->iAlternateSign = 0;
|
||||
ret = MSG_ReadSBitLong( sb, sizeof( int16_t ) << 3 );
|
||||
int ret = MSG_ReadSBitLong( sb, sizeof( int16_t ) << 3 );
|
||||
sb->iAlternateSign = alt;
|
||||
|
||||
return ret;
|
||||
@@ -780,10 +773,10 @@ void MSG_ReadVec3Angles( sizebuf_t *sb, vec3_t fa )
|
||||
|
||||
int MSG_ReadLong( sizebuf_t *sb )
|
||||
{
|
||||
int alt = sb->iAlternateSign, ret;
|
||||
int alt = sb->iAlternateSign;
|
||||
|
||||
sb->iAlternateSign = 0;
|
||||
ret = MSG_ReadSBitLong( sb, sizeof( int32_t ) << 3 );
|
||||
int ret = MSG_ReadSBitLong( sb, sizeof( int32_t ) << 3 );
|
||||
sb->iAlternateSign = alt;
|
||||
|
||||
return ret;
|
||||
@@ -842,14 +835,14 @@ char *MSG_ReadStringLine( sizebuf_t *sb )
|
||||
|
||||
void MSG_ExciseBits( sizebuf_t *sb, int startbit, int bitstoremove )
|
||||
{
|
||||
int i, endbit = startbit + bitstoremove;
|
||||
int endbit = startbit + bitstoremove;
|
||||
int remaining_to_end = sb->nDataBits - endbit;
|
||||
sizebuf_t temp;
|
||||
|
||||
MSG_StartWriting( &temp, sb->pData, MSG_GetMaxBytes( sb ), startbit, -1 );
|
||||
MSG_SeekToBit( sb, endbit, SEEK_SET );
|
||||
|
||||
for( i = 0; i < remaining_to_end; i++ )
|
||||
for( int i = 0; i < remaining_to_end; i++ )
|
||||
{
|
||||
MSG_WriteOneBit( &temp, MSG_ReadOneBit( sb ));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user