Skip to content

Commit e486a34

Browse files
committed
tier1: Use x86-64 lengths for bitbuf APIs
1 parent 6e615e4 commit e486a34

File tree

5 files changed

+71
-81
lines changed

5 files changed

+71
-81
lines changed

common/netmessages.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ bool CLC_VoiceData::ReadFromBuffer( bf_read &buffer )
5454

5555
m_nLength = buffer.ReadWord(); // length in bits
5656

57-
#if defined ( _X360 )
58-
m_xuid = buffer.ReadLongLong();
59-
#endif
60-
6157
m_DataIn = buffer;
6258

6359
return buffer.SeekRelative( m_nLength );
@@ -1015,11 +1011,6 @@ bool SVC_VoiceData::ReadFromBuffer( bf_read &buffer )
10151011
m_bProximity = !!buffer.ReadByte();
10161012
m_nLength = buffer.ReadWord();
10171013

1018-
if ( IsX360() )
1019-
{
1020-
m_xuid = buffer.ReadLongLong();
1021-
}
1022-
10231014
m_DataIn = buffer;
10241015
return buffer.SeekRelative( m_nLength );
10251016
}
@@ -1850,7 +1841,7 @@ bool MM_ClientInfo::WriteToBuffer( bf_write &buffer )
18501841
buffer.WriteLongLong( m_id ); // 64 bit
18511842
buffer.WriteByte( m_cPlayers );
18521843
buffer.WriteByte( m_bInvited );
1853-
for ( int i = 0; i < m_cPlayers; ++i )
1844+
for ( byte i = 0; i < m_cPlayers; ++i )
18541845
{
18551846
buffer.WriteLongLong( m_xuids[i] ); // 64 bit
18561847
buffer.WriteBytes( &m_cVoiceState, sizeof( m_cVoiceState ) );
@@ -1868,7 +1859,7 @@ bool MM_ClientInfo::ReadFromBuffer( bf_read &buffer )
18681859
m_id = buffer.ReadLongLong(); // 64 bit
18691860
m_cPlayers = buffer.ReadByte();
18701861
m_bInvited = (buffer.ReadByte() != 0);
1871-
for ( int i = 0; i < m_cPlayers; ++i )
1862+
for ( byte i = 0; i < m_cPlayers; ++i )
18721863
{
18731864
m_xuids[i] = buffer.ReadLongLong(); // 64 bit
18741865
buffer.ReadBytes( m_cVoiceState );
@@ -1882,7 +1873,7 @@ bool MM_ClientInfo::ReadFromBuffer( bf_read &buffer )
18821873

18831874
const char *MM_ClientInfo::ToString( void ) const
18841875
{
1885-
Q_snprintf( s_text, sizeof( s_text ), "Client Info: ID: %llu, Players: %d", m_id, m_cPlayers );
1876+
Q_snprintf( s_text, sizeof( s_text ), "Client Info: ID: %llu, Players: %hhu", m_id, m_cPlayers );
18861877
return s_text;
18871878
}
18881879

@@ -1909,7 +1900,7 @@ bool MM_Mutelist::WriteToBuffer( bf_write &buffer )
19091900

19101901
buffer.WriteLongLong( m_id );
19111902
buffer.WriteByte( m_cPlayers );
1912-
for ( int i = 0; i < m_cPlayers; ++i )
1903+
for ( byte i = 0; i < m_cPlayers; ++i )
19131904
{
19141905
buffer.WriteByte( m_cRemoteTalkers[i] );
19151906
buffer.WriteLongLong( m_xuid[i] ); // 64 bit
@@ -1926,12 +1917,12 @@ bool MM_Mutelist::ReadFromBuffer( bf_read &buffer )
19261917
{
19271918
m_id = buffer.ReadLongLong();
19281919
m_cPlayers = buffer.ReadByte();
1929-
for ( int i = 0; i < m_cPlayers; ++i )
1920+
for ( byte i = 0; i < m_cPlayers; ++i )
19301921
{
19311922
m_cRemoteTalkers[i] = buffer.ReadByte();
19321923
m_xuid[i] = buffer.ReadLongLong(); // 64 bit
19331924
m_cMuted[i] = buffer.ReadByte();
1934-
for ( int j = 0; j < m_cMuted[i]; ++j )
1925+
for ( byte j = 0; j < m_cMuted[i]; ++j )
19351926
{
19361927
m_Muted[i].AddToTail( buffer.ReadLongLong() );
19371928
}

common/netmessages.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ class MM_ClientInfo : public CNetMessage
885885
uint64 m_xuids[MAX_PLAYERS_PER_CLIENT];
886886
byte m_cVoiceState[MAX_PLAYERS_PER_CLIENT];
887887
bool m_bInvited;
888-
char m_cPlayers;
888+
byte m_cPlayers;
889889
char m_iControllers[MAX_PLAYERS_PER_CLIENT];
890890
char m_iTeam[MAX_PLAYERS_PER_CLIENT];
891891
char m_szGamertags[MAX_PLAYERS_PER_CLIENT][MAX_PLAYER_NAME_LENGTH];

game/client/c_tesla.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ void C_Tesla::ReceiveMessage( int classID, bf_read &msg )
2626
{
2727
CTeslaInfo teslaInfo;
2828

29+
// See CTesla::DoSpark
30+
2931
msg.ReadBitVec3Coord( teslaInfo.m_vPos );
3032
teslaInfo.m_vAngles.Init();
3133

3234
teslaInfo.m_nEntIndex = msg.ReadShort();
3335
teslaInfo.m_flRadius = msg.ReadFloat();
3436

35-
teslaInfo.m_vColor.x = ((unsigned char)msg.ReadChar()) / 255.0f;
36-
teslaInfo.m_vColor.y = ((unsigned char)msg.ReadChar()) / 255.0f;
37-
teslaInfo.m_vColor.z = ((unsigned char)msg.ReadChar()) / 255.0f;
37+
teslaInfo.m_vColor.x = msg.ReadByte() / 255.0f;
38+
teslaInfo.m_vColor.y = msg.ReadByte() / 255.0f;
39+
teslaInfo.m_vColor.z = msg.ReadByte() / 255.0f;
3840

39-
float flAlpha = 0;
40-
flAlpha = ((unsigned char)msg.ReadChar()) / 255.0f;
41+
float flAlpha = msg.ReadByte() / 255.0f;
4142

4243
teslaInfo.m_nBeams = msg.ReadChar();
4344

public/tier1/bitbuf.h

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -169,32 +169,31 @@ class bf_write
169169
void SetDebugName( const char *pDebugName );
170170

171171

172-
// Seek to a specific position.
173172
public:
174-
173+
// Seek to a specific position.
175174
void SeekToBit( intp bitPos );
176175

177176

178177
// Bit functions.
179178
public:
180179

181-
void WriteOneBit(int nValue);
182-
void WriteOneBitNoCheck(int nValue);
180+
void WriteOneBit( int nValue );
181+
void WriteOneBitNoCheck( int nValue );
183182
void WriteOneBitAt( int iBit, int nValue );
184183

185184
// Write signed or unsigned. Range is only checked in debug.
186-
void WriteUBitLong( unsigned int data, int numbits, bool bCheckRange=true );
187-
void WriteSBitLong( int data, int numbits );
185+
void WriteUBitLong( uint32 data, int numbits, bool bCheckRange=true );
186+
void WriteSBitLong( int32 data, int numbits );
188187

189188
// Tell it whether or not the data is unsigned. If it's signed,
190189
// cast to unsigned before passing in (it will cast back inside).
191-
void WriteBitLong(unsigned int data, int numbits, bool bSigned);
190+
void WriteBitLong( uint32 data, int numbits, bool bSigned );
192191

193192
// Write a list of bits in.
194-
bool WriteBits(const void *pIn, int nBits);
193+
bool WriteBits( const void *pIn, intp nBits );
195194

196195
// writes an unsigned integer with variable bit length
197-
void WriteUBitVar( unsigned int data );
196+
void WriteUBitVar( uint32 data );
198197

199198
// writes a varint encoded integer
200199
void WriteVarInt32( uint32 data );
@@ -208,12 +207,12 @@ class bf_write
208207

209208
// Copy the bits straight out of pIn. This seeks pIn forward by nBits.
210209
// Returns an error if this buffer or the read buffer overflows.
211-
bool WriteBitsFromBuffer( class bf_read *pIn, int nBits );
210+
bool WriteBitsFromBuffer( class bf_read *pIn, intp nBits );
212211

213212
void WriteBitAngle( float fAngle, int numbits );
214-
void WriteBitCoord (const float f);
213+
void WriteBitCoord( const float f );
215214
void WriteBitCoordMP( const float f, bool bIntegral, bool bLowPrecision );
216-
void WriteBitFloat(float val);
215+
void WriteBitFloat( float val );
217216
void WriteBitVec3Coord( const Vector& fa );
218217
void WriteBitNormal( float f );
219218
void WriteBitVec3Normal( const Vector& fa );
@@ -232,7 +231,7 @@ class bf_write
232231
void WriteLongLong(int64 val);
233232
void WriteULongLong(uint64 val);
234233
void WriteFloat(float val);
235-
bool WriteBytes( const void *pBuf, int nBytes );
234+
bool WriteBytes( const void *pBuf, intp nBytes );
236235

237236
// Returns false if it overflows the buffer.
238237
bool WriteString(const char *pStr);
@@ -247,8 +246,8 @@ class bf_write
247246
[[nodiscard]] intp GetMaxNumBits() const;
248247
[[nodiscard]] intp GetNumBitsLeft() const;
249248
[[nodiscard]] intp GetNumBytesLeft() const;
250-
[[nodiscard]] unsigned char* GetData();
251-
[[nodiscard]] const unsigned char* GetData() const;
249+
[[nodiscard]] byte* GetData();
250+
[[nodiscard]] const byte* GetData() const;
252251

253252
// Has the buffer overflowed?
254253
[[nodiscard]] bool CheckForOverflow(intp nBits);
@@ -306,14 +305,14 @@ inline intp bf_write::GetNumBytesLeft() const
306305
return GetNumBitsLeft() >> 3;
307306
}
308307

309-
inline unsigned char* bf_write::GetData() //-V524
308+
inline byte* bf_write::GetData() //-V524
310309
{
311-
return (unsigned char*) m_pData;
310+
return (byte*) m_pData;
312311
}
313312

314-
inline const unsigned char* bf_write::GetData() const
313+
inline const byte* bf_write::GetData() const
315314
{
316-
return (unsigned char*) m_pData;
315+
return (byte*) m_pData;
317316
}
318317

319318
BITBUF_INLINE bool bf_write::CheckForOverflow(intp nBits)
@@ -391,7 +390,7 @@ inline void bf_write::WriteOneBitAt( int iBit, int nValue )
391390
#endif
392391
}
393392

394-
BITBUF_INLINE void bf_write::WriteUBitLong( unsigned int curData, int numbits, [[maybe_unused]] bool bCheckRange )
393+
BITBUF_INLINE void bf_write::WriteUBitLong( uint32 curData, int numbits, [[maybe_unused]] bool bCheckRange )
395394
{
396395
#ifdef _DEBUG
397396
// Make sure it doesn't overflow.
@@ -444,7 +443,7 @@ BITBUF_INLINE void bf_write::WriteUBitLong( unsigned int curData, int numbits, [
444443
}
445444

446445
// writes an unsigned integer with variable bit length
447-
BITBUF_INLINE void bf_write::WriteUBitVar( unsigned int data )
446+
BITBUF_INLINE void bf_write::WriteUBitVar( uint32 data )
448447
{
449448
/* Reference:
450449
if ( data < 0x10u )
@@ -544,7 +543,7 @@ class bf_read
544543
// Get the base pointer.
545544
[[nodiscard]] const unsigned char* GetBasePointer() const { return m_pData; }
546545

547-
[[nodiscard]] BITBUF_INLINE intp TotalBytesAvailable( void ) const
546+
[[nodiscard]] BITBUF_INLINE intp TotalBytesAvailable() const
548547
{
549548
return m_nDataBytes;
550549
}
@@ -554,23 +553,23 @@ class bf_read
554553
// Read a list of bits in, but don't overrun the destination buffer.
555554
// Returns the number of bits read into the buffer. The remaining
556555
// bits are skipped over.
557-
int ReadBitsClamped_ptr(void *pOut, size_t outSizeBytes, size_t nBits);
556+
intp ReadBitsClamped_ptr(void *pOut, intp outSizeBytes, intp nBits);
558557
// Helper 'safe' template function that infers the size of the destination
559558
// array. This version of the function should be preferred.
560559
// Usage: char databuffer[100];
561560
// ReadBitsClamped( dataBuffer, msg->m_nLength );
562-
template <typename T, size_t N>
563-
int ReadBitsClamped( T (&pOut)[N], size_t nBits )
561+
template <typename T, intp N>
562+
intp ReadBitsClamped( T (&pOut)[N], intp nBits )
564563
{
565564
return ReadBitsClamped_ptr( pOut, N * sizeof(T), nBits );
566565
}
567566

568567
[[nodiscard]] float ReadBitAngle( int numbits );
569568

570-
[[nodiscard]] unsigned int ReadUBitLong( int numbits );
571-
[[nodiscard]] unsigned int ReadUBitLongNoInline( int numbits );
572-
[[nodiscard]] unsigned int PeekUBitLong( int numbits );
573-
[[nodiscard]] int ReadSBitLong( int numbits );
569+
[[nodiscard]] uint32 ReadUBitLong( int numbits );
570+
[[nodiscard]] uint32 ReadUBitLongNoInline( int numbits );
571+
[[nodiscard]] uint32 PeekUBitLong( int numbits );
572+
[[nodiscard]] int32 ReadSBitLong( int numbits );
574573

575574
// reads an unsigned integer with variable bit length
576575
[[nodiscard]] unsigned int ReadUBitVar();
@@ -792,7 +791,7 @@ BITBUF_INLINE unsigned int bf_read::ReadUBitVar()
792791
return sixbits >> 2;
793792
}
794793

795-
BITBUF_INLINE unsigned int bf_read::ReadUBitLong( int numbits )
794+
BITBUF_INLINE uint32 bf_read::ReadUBitLong( int numbits )
796795
{
797796
Assert( numbits > 0 && numbits <= 32 );
798797

0 commit comments

Comments
 (0)