mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-01-11 11:22:09 +08:00
Rename byteswap to cbyteswap (#140)
Resolves include collision with protobuf dependency
This commit is contained in:
parent
f6fe5165fc
commit
05a5907e05
@ -1,4 +1,4 @@
|
|||||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
//========= Copyright <EFBFBD> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||||
//
|
//
|
||||||
// Purpose: Swap a compiled caption file.
|
// Purpose: Swap a compiled caption file.
|
||||||
//
|
//
|
||||||
@ -6,7 +6,7 @@
|
|||||||
//=============================================================================//
|
//=============================================================================//
|
||||||
|
|
||||||
#include "utlbuffer.h"
|
#include "utlbuffer.h"
|
||||||
#include "byteswap.h"
|
#include "cbyteswap.h"
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
#include "tier2/fileutils.h"
|
#include "tier2/fileutils.h"
|
||||||
#include "captioncompiler.h"
|
#include "captioncompiler.h"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//========= Copyright © 1996-2006, Valve LLC, All rights reserved. ============
|
//========= Copyright <EFBFBD> 1996-2006, Valve LLC, All rights reserved. ============
|
||||||
//
|
//
|
||||||
// Purpose: StudioMDL byteswapping functions.
|
// Purpose: StudioMDL byteswapping functions.
|
||||||
//
|
//
|
||||||
@ -11,7 +11,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "byteswap.h"
|
#include "cbyteswap.h"
|
||||||
struct studiohdr_t;
|
struct studiohdr_t;
|
||||||
class IPhysicsCollision;
|
class IPhysicsCollision;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
//========= Copyright <EFBFBD> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||||
//
|
//
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//
|
//
|
||||||
@ -27,7 +27,7 @@
|
|||||||
#include <game/client/iviewport.h>
|
#include <game/client/iviewport.h>
|
||||||
#include <stdlib.h> // MAX_PATH define
|
#include <stdlib.h> // MAX_PATH define
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "byteswap.h"
|
#include "cbyteswap.h"
|
||||||
#include "vgui_int.h"
|
#include "vgui_int.h"
|
||||||
|
|
||||||
// memdbgon must be the last include file in a .cpp file!!!
|
// memdbgon must be the last include file in a .cpp file!!!
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
//========= Copyright <EFBFBD> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||||
//
|
//
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//
|
//
|
||||||
@ -22,7 +22,7 @@
|
|||||||
#include "sceneentity.h"
|
#include "sceneentity.h"
|
||||||
#include "ai_baseactor.h"
|
#include "ai_baseactor.h"
|
||||||
#include "datacache/imdlcache.h"
|
#include "datacache/imdlcache.h"
|
||||||
#include "tier1/byteswap.h"
|
#include "tier1/cbyteswap.h"
|
||||||
#include "toolframework/itoolframework.h"
|
#include "toolframework/itoolframework.h"
|
||||||
#include "flexcycler.h"
|
#include "flexcycler.h"
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\public\tier1\bitbuf.h" />
|
<ClInclude Include="..\public\tier1\bitbuf.h" />
|
||||||
<ClInclude Include="..\public\tier1\byteswap.h" />
|
<ClInclude Include="..\public\tier1\cbyteswap.h" />
|
||||||
<ClInclude Include="..\public\tier1\callqueue.h" />
|
<ClInclude Include="..\public\tier1\callqueue.h" />
|
||||||
<ClInclude Include="..\public\tier1\characterset.h" />
|
<ClInclude Include="..\public\tier1\characterset.h" />
|
||||||
<ClInclude Include="..\public\tier1\checksum_crc.h" />
|
<ClInclude Include="..\public\tier1\checksum_crc.h" />
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<ClInclude Include="..\public\tier1\bitbuf.h">
|
<ClInclude Include="..\public\tier1\bitbuf.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\public\tier1\byteswap.h">
|
<ClInclude Include="..\public\tier1\cbyteswap.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\public\tier1\callqueue.h">
|
<ClInclude Include="..\public\tier1\callqueue.h">
|
||||||
|
@ -1,268 +1,268 @@
|
|||||||
//========= Copyright © 1996-2006, Valve LLC, All rights reserved. ============
|
//========= Copyright © 1996-2006, Valve LLC, All rights reserved. ============
|
||||||
//
|
//
|
||||||
// Purpose: Low level byte swapping routines.
|
// Purpose: Low level byte swapping routines.
|
||||||
//
|
//
|
||||||
// $NoKeywords: $
|
// $NoKeywords: $
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
#ifndef BYTESWAP_H
|
#ifndef BYTESWAP_H
|
||||||
#define BYTESWAP_H
|
#define BYTESWAP_H
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tier0/dbg.h"
|
#include "tier0/dbg.h"
|
||||||
#include "datamap.h" // needed for typedescription_t. note datamap.h is tier1 as well.
|
#include "datamap.h" // needed for typedescription_t. note datamap.h is tier1 as well.
|
||||||
|
|
||||||
class CByteswap
|
class CByteswap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CByteswap()
|
CByteswap()
|
||||||
{
|
{
|
||||||
// Default behavior sets the target endian to match the machine native endian (no swap).
|
// Default behavior sets the target endian to match the machine native endian (no swap).
|
||||||
SetTargetBigEndian( IsMachineBigEndian() );
|
SetTargetBigEndian( IsMachineBigEndian() );
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Write a single field.
|
// Write a single field.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typedescription_t *pField );
|
void SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typedescription_t *pField );
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Write a block of fields. Works a bit like the saverestore code.
|
// Write a block of fields. Works a bit like the saverestore code.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void SwapFieldsToTargetEndian( void *pOutputBuffer, void *pBaseData, datamap_t *pDataMap );
|
void SwapFieldsToTargetEndian( void *pOutputBuffer, void *pBaseData, datamap_t *pDataMap );
|
||||||
|
|
||||||
// Swaps fields for the templated type to the output buffer.
|
// Swaps fields for the templated type to the output buffer.
|
||||||
template<typename T> inline void SwapFieldsToTargetEndian( T* pOutputBuffer, void *pBaseData, unsigned int objectCount = 1 )
|
template<typename T> inline void SwapFieldsToTargetEndian( T* pOutputBuffer, void *pBaseData, unsigned int objectCount = 1 )
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 0; i < objectCount; ++i, ++pOutputBuffer )
|
for ( unsigned int i = 0; i < objectCount; ++i, ++pOutputBuffer )
|
||||||
{
|
{
|
||||||
SwapFieldsToTargetEndian( (void*)pOutputBuffer, pBaseData, &T::m_DataMap );
|
SwapFieldsToTargetEndian( (void*)pOutputBuffer, pBaseData, &T::m_DataMap );
|
||||||
pBaseData = (byte*)pBaseData + sizeof(T);
|
pBaseData = (byte*)pBaseData + sizeof(T);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swaps fields for the templated type in place.
|
// Swaps fields for the templated type in place.
|
||||||
template<typename T> inline void SwapFieldsToTargetEndian( T* pOutputBuffer, unsigned int objectCount = 1 )
|
template<typename T> inline void SwapFieldsToTargetEndian( T* pOutputBuffer, unsigned int objectCount = 1 )
|
||||||
{
|
{
|
||||||
SwapFieldsToTargetEndian<T>( pOutputBuffer, (void*)pOutputBuffer, objectCount );
|
SwapFieldsToTargetEndian<T>( pOutputBuffer, (void*)pOutputBuffer, objectCount );
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// True if the current machine is detected as big endian.
|
// True if the current machine is detected as big endian.
|
||||||
// (Endienness is effectively detected at compile time when optimizations are
|
// (Endienness is effectively detected at compile time when optimizations are
|
||||||
// enabled)
|
// enabled)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
static bool IsMachineBigEndian()
|
static bool IsMachineBigEndian()
|
||||||
{
|
{
|
||||||
short nIsBigEndian = 1;
|
short nIsBigEndian = 1;
|
||||||
|
|
||||||
// if we are big endian, the first byte will be a 0, if little endian, it will be a one.
|
// if we are big endian, the first byte will be a 0, if little endian, it will be a one.
|
||||||
return (bool)(0 == *(char *)&nIsBigEndian );
|
return (bool)(0 == *(char *)&nIsBigEndian );
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Sets the target byte ordering we are swapping to or from.
|
// Sets the target byte ordering we are swapping to or from.
|
||||||
//
|
//
|
||||||
// Braindead Endian Reference:
|
// Braindead Endian Reference:
|
||||||
// x86 is LITTLE Endian
|
// x86 is LITTLE Endian
|
||||||
// PowerPC is BIG Endian
|
// PowerPC is BIG Endian
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
inline void SetTargetBigEndian( bool bigEndian )
|
inline void SetTargetBigEndian( bool bigEndian )
|
||||||
{
|
{
|
||||||
m_bBigEndian = bigEndian;
|
m_bBigEndian = bigEndian;
|
||||||
m_bSwapBytes = IsMachineBigEndian() != bigEndian;
|
m_bSwapBytes = IsMachineBigEndian() != bigEndian;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes target endian
|
// Changes target endian
|
||||||
inline void FlipTargetEndian( void )
|
inline void FlipTargetEndian( void )
|
||||||
{
|
{
|
||||||
m_bSwapBytes = !m_bSwapBytes;
|
m_bSwapBytes = !m_bSwapBytes;
|
||||||
m_bBigEndian = !m_bBigEndian;
|
m_bBigEndian = !m_bBigEndian;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forces byte swapping state, regardless of endianess
|
// Forces byte swapping state, regardless of endianess
|
||||||
inline void ActivateByteSwapping( bool bActivate )
|
inline void ActivateByteSwapping( bool bActivate )
|
||||||
{
|
{
|
||||||
SetTargetBigEndian( IsMachineBigEndian() != bActivate );
|
SetTargetBigEndian( IsMachineBigEndian() != bActivate );
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Returns true if the target machine is the same as this one in endianness.
|
// Returns true if the target machine is the same as this one in endianness.
|
||||||
//
|
//
|
||||||
// Used to determine when a byteswap needs to take place.
|
// Used to determine when a byteswap needs to take place.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
inline bool IsSwappingBytes( void ) // Are bytes being swapped?
|
inline bool IsSwappingBytes( void ) // Are bytes being swapped?
|
||||||
{
|
{
|
||||||
return m_bSwapBytes;
|
return m_bSwapBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsTargetBigEndian( void ) // What is the current target endian?
|
inline bool IsTargetBigEndian( void ) // What is the current target endian?
|
||||||
{
|
{
|
||||||
return m_bBigEndian;
|
return m_bBigEndian;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// IsByteSwapped()
|
// IsByteSwapped()
|
||||||
//
|
//
|
||||||
// When supplied with a chunk of input data and a constant or magic number
|
// When supplied with a chunk of input data and a constant or magic number
|
||||||
// (in native format) determines the endienness of the current machine in
|
// (in native format) determines the endienness of the current machine in
|
||||||
// relation to the given input data.
|
// relation to the given input data.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// 1 if input is the same as nativeConstant.
|
// 1 if input is the same as nativeConstant.
|
||||||
// 0 if input is byteswapped relative to nativeConstant.
|
// 0 if input is byteswapped relative to nativeConstant.
|
||||||
// -1 if input is not the same as nativeConstant and not byteswapped either.
|
// -1 if input is not the same as nativeConstant and not byteswapped either.
|
||||||
//
|
//
|
||||||
// ( This is useful for detecting byteswapping in magic numbers in structure
|
// ( This is useful for detecting byteswapping in magic numbers in structure
|
||||||
// headers for example. )
|
// headers for example. )
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template<typename T> inline int SourceIsNativeEndian( T input, T nativeConstant )
|
template<typename T> inline int SourceIsNativeEndian( T input, T nativeConstant )
|
||||||
{
|
{
|
||||||
// If it's the same, it isn't byteswapped:
|
// If it's the same, it isn't byteswapped:
|
||||||
if( input == nativeConstant )
|
if( input == nativeConstant )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
int output;
|
int output;
|
||||||
LowLevelByteSwap<T>( &output, &input );
|
LowLevelByteSwap<T>( &output, &input );
|
||||||
if( output == nativeConstant )
|
if( output == nativeConstant )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Assert( 0 ); // if we get here, input is neither a swapped nor unswapped version of nativeConstant.
|
Assert( 0 ); // if we get here, input is neither a swapped nor unswapped version of nativeConstant.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Swaps an input buffer full of type T into the given output buffer.
|
// Swaps an input buffer full of type T into the given output buffer.
|
||||||
//
|
//
|
||||||
// Swaps [count] items from the inputBuffer to the outputBuffer.
|
// Swaps [count] items from the inputBuffer to the outputBuffer.
|
||||||
// If inputBuffer is omitted or NULL, then it is assumed to be the same as
|
// If inputBuffer is omitted or NULL, then it is assumed to be the same as
|
||||||
// outputBuffer - effectively swapping the contents of the buffer in place.
|
// outputBuffer - effectively swapping the contents of the buffer in place.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template<typename T> inline void SwapBuffer( T* outputBuffer, T* inputBuffer = NULL, int count = 1 )
|
template<typename T> inline void SwapBuffer( T* outputBuffer, T* inputBuffer = NULL, int count = 1 )
|
||||||
{
|
{
|
||||||
Assert( count >= 0 );
|
Assert( count >= 0 );
|
||||||
Assert( outputBuffer );
|
Assert( outputBuffer );
|
||||||
|
|
||||||
// Fail gracefully in release:
|
// Fail gracefully in release:
|
||||||
if( count <=0 || !outputBuffer )
|
if( count <=0 || !outputBuffer )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Optimization for the case when we are swapping in place.
|
// Optimization for the case when we are swapping in place.
|
||||||
if( inputBuffer == NULL )
|
if( inputBuffer == NULL )
|
||||||
{
|
{
|
||||||
inputBuffer = outputBuffer;
|
inputBuffer = outputBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swap everything in the buffer:
|
// Swap everything in the buffer:
|
||||||
for( int i = 0; i < count; i++ )
|
for( int i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
LowLevelByteSwap<T>( &outputBuffer[i], &inputBuffer[i] );
|
LowLevelByteSwap<T>( &outputBuffer[i], &inputBuffer[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Swaps an input buffer full of type T into the given output buffer.
|
// Swaps an input buffer full of type T into the given output buffer.
|
||||||
//
|
//
|
||||||
// Swaps [count] items from the inputBuffer to the outputBuffer.
|
// Swaps [count] items from the inputBuffer to the outputBuffer.
|
||||||
// If inputBuffer is omitted or NULL, then it is assumed to be the same as
|
// If inputBuffer is omitted or NULL, then it is assumed to be the same as
|
||||||
// outputBuffer - effectively swapping the contents of the buffer in place.
|
// outputBuffer - effectively swapping the contents of the buffer in place.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template<typename T> inline void SwapBufferToTargetEndian( T* outputBuffer, T* inputBuffer = NULL, int count = 1 )
|
template<typename T> inline void SwapBufferToTargetEndian( T* outputBuffer, T* inputBuffer = NULL, int count = 1 )
|
||||||
{
|
{
|
||||||
Assert( count >= 0 );
|
Assert( count >= 0 );
|
||||||
Assert( outputBuffer );
|
Assert( outputBuffer );
|
||||||
|
|
||||||
// Fail gracefully in release:
|
// Fail gracefully in release:
|
||||||
if( count <=0 || !outputBuffer )
|
if( count <=0 || !outputBuffer )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Optimization for the case when we are swapping in place.
|
// Optimization for the case when we are swapping in place.
|
||||||
if( inputBuffer == NULL )
|
if( inputBuffer == NULL )
|
||||||
{
|
{
|
||||||
inputBuffer = outputBuffer;
|
inputBuffer = outputBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are we already the correct endienness? ( or are we swapping 1 byte items? )
|
// Are we already the correct endienness? ( or are we swapping 1 byte items? )
|
||||||
if( !m_bSwapBytes || ( sizeof(T) == 1 ) )
|
if( !m_bSwapBytes || ( sizeof(T) == 1 ) )
|
||||||
{
|
{
|
||||||
// If we were just going to swap in place then return.
|
// If we were just going to swap in place then return.
|
||||||
if( !inputBuffer )
|
if( !inputBuffer )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Otherwise copy the inputBuffer to the outputBuffer:
|
// Otherwise copy the inputBuffer to the outputBuffer:
|
||||||
if ( outputBuffer != inputBuffer )
|
if ( outputBuffer != inputBuffer )
|
||||||
memcpy( outputBuffer, inputBuffer, count * sizeof( T ) );
|
memcpy( outputBuffer, inputBuffer, count * sizeof( T ) );
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swap everything in the buffer:
|
// Swap everything in the buffer:
|
||||||
for( int i = 0; i < count; i++ )
|
for( int i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
LowLevelByteSwap<T>( &outputBuffer[i], &inputBuffer[i] );
|
LowLevelByteSwap<T>( &outputBuffer[i], &inputBuffer[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// The lowest level byte swapping workhorse of doom. output always contains the
|
// The lowest level byte swapping workhorse of doom. output always contains the
|
||||||
// swapped version of input. ( Doesn't compare machine to target endianness )
|
// swapped version of input. ( Doesn't compare machine to target endianness )
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template<typename T> static void LowLevelByteSwap( T *output, T *input )
|
template<typename T> static void LowLevelByteSwap( T *output, T *input )
|
||||||
{
|
{
|
||||||
T temp = *output;
|
T temp = *output;
|
||||||
#if defined( _X360 )
|
#if defined( _X360 )
|
||||||
// Intrinsics need the source type to be fixed-point
|
// Intrinsics need the source type to be fixed-point
|
||||||
DWORD* word = (DWORD*)input;
|
DWORD* word = (DWORD*)input;
|
||||||
switch( sizeof(T) )
|
switch( sizeof(T) )
|
||||||
{
|
{
|
||||||
case 8:
|
case 8:
|
||||||
{
|
{
|
||||||
__storewordbytereverse( *(word+1), 0, &temp );
|
__storewordbytereverse( *(word+1), 0, &temp );
|
||||||
__storewordbytereverse( *(word+0), 4, &temp );
|
__storewordbytereverse( *(word+0), 4, &temp );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
__storewordbytereverse( *word, 0, &temp );
|
__storewordbytereverse( *word, 0, &temp );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
__storeshortbytereverse( *input, 0, &temp );
|
__storeshortbytereverse( *input, 0, &temp );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
Q_memcpy( &temp, input, 1 );
|
Q_memcpy( &temp, input, 1 );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Assert( "Invalid size in CByteswap::LowLevelByteSwap" && 0 );
|
Assert( "Invalid size in CByteswap::LowLevelByteSwap" && 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
for( size_t i = 0; i < sizeof(T); i++ )
|
for( size_t i = 0; i < sizeof(T); i++ )
|
||||||
{
|
{
|
||||||
((unsigned char* )&temp)[i] = ((unsigned char*)input)[sizeof(T)-(i+1)];
|
((unsigned char* )&temp)[i] = ((unsigned char*)input)[sizeof(T)-(i+1)];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Q_memcpy( output, &temp, sizeof(T) );
|
Q_memcpy( output, &temp, sizeof(T) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined( _X360 )
|
#if defined( _X360 )
|
||||||
// specialized for void * to get 360 XDK compile working despite changelist 281331
|
// specialized for void * to get 360 XDK compile working despite changelist 281331
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// The lowest level byte swapping workhorse of doom. output always contains the
|
// The lowest level byte swapping workhorse of doom. output always contains the
|
||||||
// swapped version of input. ( Doesn't compare machine to target endianness )
|
// swapped version of input. ( Doesn't compare machine to target endianness )
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template<> static void LowLevelByteSwap( void **output, void **input )
|
template<> static void LowLevelByteSwap( void **output, void **input )
|
||||||
{
|
{
|
||||||
AssertMsgOnce( sizeof(void *) == sizeof(unsigned int) , "void *'s on this platform are not four bytes!" );
|
AssertMsgOnce( sizeof(void *) == sizeof(unsigned int) , "void *'s on this platform are not four bytes!" );
|
||||||
__storewordbytereverse( *reinterpret_cast<unsigned int *>(input), 0, output );
|
__storewordbytereverse( *reinterpret_cast<unsigned int *>(input), 0, output );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned int m_bSwapBytes : 1;
|
unsigned int m_bSwapBytes : 1;
|
||||||
unsigned int m_bBigEndian : 1;
|
unsigned int m_bBigEndian : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* !BYTESWAP_H */
|
#endif /* !BYTESWAP_H */
|
@ -1,4 +1,4 @@
|
|||||||
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======//
|
//====== Copyright <EFBFBD> 1996-2005, Valve Corporation, All rights reserved. =======//
|
||||||
//
|
//
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//
|
//
|
||||||
@ -17,7 +17,7 @@
|
|||||||
#include "unitlib/unitlib.h" // just here for tests - remove before checking in!!!
|
#include "unitlib/unitlib.h" // just here for tests - remove before checking in!!!
|
||||||
|
|
||||||
#include "tier1/utlmemory.h"
|
#include "tier1/utlmemory.h"
|
||||||
#include "tier1/byteswap.h"
|
#include "tier1/cbyteswap.h"
|
||||||
#include "tier1/bufferstring.h"
|
#include "tier1/bufferstring.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#include "zip_utils.h"
|
#include "zip_utils.h"
|
||||||
#include "zip_uncompressed.h"
|
#include "zip_uncompressed.h"
|
||||||
#include "checksum_crc.h"
|
#include "checksum_crc.h"
|
||||||
#include "byteswap.h"
|
#include "cbyteswap.h"
|
||||||
#include "utlstring.h"
|
#include "utlstring.h"
|
||||||
|
|
||||||
// NOTE: This has to be the last file included!
|
// NOTE: This has to be the last file included!
|
||||||
|
@ -1,90 +1,90 @@
|
|||||||
//========= Copyright © 1996-2006, Valve LLC, All rights reserved. ============
|
//========= Copyright <EFBFBD> 1996-2006, Valve LLC, All rights reserved. ============
|
||||||
//
|
//
|
||||||
// Purpose: Low level byte swapping routines.
|
// Purpose: Low level byte swapping routines.
|
||||||
//
|
//
|
||||||
// $NoKeywords: $
|
// $NoKeywords: $
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|
||||||
#include "byteswap.h"
|
#include "cbyteswap.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Copy a single field from the input buffer to the output buffer, swapping the bytes if necessary
|
// Copy a single field from the input buffer to the output buffer, swapping the bytes if necessary
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void CByteswap::SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typedescription_t *pField )
|
void CByteswap::SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typedescription_t *pField )
|
||||||
{
|
{
|
||||||
switch ( pField->fieldType )
|
switch ( pField->fieldType )
|
||||||
{
|
{
|
||||||
case FIELD_CHARACTER:
|
case FIELD_CHARACTER:
|
||||||
SwapBufferToTargetEndian<char>( (char*)pOutputBuffer, (char*)pData, pField->fieldSize );
|
SwapBufferToTargetEndian<char>( (char*)pOutputBuffer, (char*)pData, pField->fieldSize );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_BOOLEAN:
|
case FIELD_BOOLEAN:
|
||||||
SwapBufferToTargetEndian<bool>( (bool*)pOutputBuffer, (bool*)pData, pField->fieldSize );
|
SwapBufferToTargetEndian<bool>( (bool*)pOutputBuffer, (bool*)pData, pField->fieldSize );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_SHORT:
|
case FIELD_SHORT:
|
||||||
SwapBufferToTargetEndian<short>( (short*)pOutputBuffer, (short*)pData, pField->fieldSize );
|
SwapBufferToTargetEndian<short>( (short*)pOutputBuffer, (short*)pData, pField->fieldSize );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_FLOAT:
|
case FIELD_FLOAT:
|
||||||
SwapBufferToTargetEndian<uint>( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize );
|
SwapBufferToTargetEndian<uint>( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_INTEGER:
|
case FIELD_INTEGER:
|
||||||
SwapBufferToTargetEndian<int>( (int*)pOutputBuffer, (int*)pData, pField->fieldSize );
|
SwapBufferToTargetEndian<int>( (int*)pOutputBuffer, (int*)pData, pField->fieldSize );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_VECTOR:
|
case FIELD_VECTOR:
|
||||||
SwapBufferToTargetEndian<uint>( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 3 );
|
SwapBufferToTargetEndian<uint>( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 3 );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_VECTOR2D:
|
case FIELD_VECTOR2D:
|
||||||
SwapBufferToTargetEndian<uint>( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 2 );
|
SwapBufferToTargetEndian<uint>( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 2 );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_QUATERNION:
|
case FIELD_QUATERNION:
|
||||||
SwapBufferToTargetEndian<uint>( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 4 );
|
SwapBufferToTargetEndian<uint>( (uint*)pOutputBuffer, (uint*)pData, pField->fieldSize * 4 );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_EMBEDDED:
|
case FIELD_EMBEDDED:
|
||||||
{
|
{
|
||||||
typedescription_t *pEmbed = pField->td->dataDesc;
|
typedescription_t *pEmbed = pField->td->dataDesc;
|
||||||
for ( int i = 0; i < pField->fieldSize; ++i )
|
for ( int i = 0; i < pField->fieldSize; ++i )
|
||||||
{
|
{
|
||||||
SwapFieldsToTargetEndian( (byte*)pOutputBuffer + pEmbed->fieldOffset,
|
SwapFieldsToTargetEndian( (byte*)pOutputBuffer + pEmbed->fieldOffset,
|
||||||
(byte*)pData + pEmbed->fieldOffset,
|
(byte*)pData + pEmbed->fieldOffset,
|
||||||
pField->td );
|
pField->td );
|
||||||
|
|
||||||
pOutputBuffer = (byte*)pOutputBuffer + pField->fieldSizeInBytes;
|
pOutputBuffer = (byte*)pOutputBuffer + pField->fieldSizeInBytes;
|
||||||
pData = (byte*)pData + pField->fieldSizeInBytes;
|
pData = (byte*)pData + pField->fieldSizeInBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Assert(0);
|
Assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Write a block of fields. Works a bit like the saverestore code.
|
// Write a block of fields. Works a bit like the saverestore code.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void CByteswap::SwapFieldsToTargetEndian( void *pOutputBuffer, void *pBaseData, datamap_t *pDataMap )
|
void CByteswap::SwapFieldsToTargetEndian( void *pOutputBuffer, void *pBaseData, datamap_t *pDataMap )
|
||||||
{
|
{
|
||||||
// deal with base class first
|
// deal with base class first
|
||||||
if ( pDataMap->baseMap )
|
if ( pDataMap->baseMap )
|
||||||
{
|
{
|
||||||
SwapFieldsToTargetEndian( pOutputBuffer, pBaseData, pDataMap->baseMap );
|
SwapFieldsToTargetEndian( pOutputBuffer, pBaseData, pDataMap->baseMap );
|
||||||
}
|
}
|
||||||
|
|
||||||
typedescription_t *pFields = pDataMap->dataDesc;
|
typedescription_t *pFields = pDataMap->dataDesc;
|
||||||
int fieldCount = pDataMap->dataNumFields;
|
int fieldCount = pDataMap->dataNumFields;
|
||||||
for ( int i = 0; i < fieldCount; ++i )
|
for ( int i = 0; i < fieldCount; ++i )
|
||||||
{
|
{
|
||||||
typedescription_t *pField = &pFields[i];
|
typedescription_t *pField = &pFields[i];
|
||||||
SwapFieldToTargetEndian( (BYTE*)pOutputBuffer + pField->fieldOffset,
|
SwapFieldToTargetEndian( (BYTE*)pOutputBuffer + pField->fieldOffset,
|
||||||
(BYTE*)pBaseData + pField->fieldOffset,
|
(BYTE*)pBaseData + pField->fieldOffset,
|
||||||
pField );
|
pField );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -217,7 +217,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\byteswap.cpp"
|
RelativePath=".\cbyteswap.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
@ -346,7 +346,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\public\tier1\byteswap.h"
|
RelativePath="..\public\tier1\cbyteswap.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
@ -319,7 +319,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="bitbuf.cpp" />
|
<ClCompile Include="bitbuf.cpp" />
|
||||||
<ClCompile Include="byteswap.cpp" />
|
<ClCompile Include="cbyteswap.cpp" />
|
||||||
<ClCompile Include="characterset.cpp" />
|
<ClCompile Include="characterset.cpp" />
|
||||||
<ClCompile Include="checksum_crc.cpp" />
|
<ClCompile Include="checksum_crc.cpp" />
|
||||||
<ClCompile Include="checksum_md5.cpp" />
|
<ClCompile Include="checksum_md5.cpp" />
|
||||||
@ -346,7 +346,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\public\tier1\bitbuf.h" />
|
<ClInclude Include="..\public\tier1\bitbuf.h" />
|
||||||
<ClInclude Include="..\public\tier1\byteswap.h" />
|
<ClInclude Include="..\public\tier1\cbyteswap.h" />
|
||||||
<ClInclude Include="..\public\tier1\callqueue.h" />
|
<ClInclude Include="..\public\tier1\callqueue.h" />
|
||||||
<ClInclude Include="..\public\tier1\characterset.h" />
|
<ClInclude Include="..\public\tier1\characterset.h" />
|
||||||
<ClInclude Include="..\public\tier1\checksum_crc.h" />
|
<ClInclude Include="..\public\tier1\checksum_crc.h" />
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<ClCompile Include="bitbuf.cpp">
|
<ClCompile Include="bitbuf.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="byteswap.cpp">
|
<ClCompile Include="cbyteswap.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="characterset.cpp">
|
<ClCompile Include="characterset.cpp">
|
||||||
@ -76,7 +76,7 @@
|
|||||||
<ClInclude Include="..\public\tier1\bitbuf.h">
|
<ClInclude Include="..\public\tier1\bitbuf.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\public\tier1\byteswap.h">
|
<ClInclude Include="..\public\tier1\cbyteswap.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\public\tier1\callqueue.h">
|
<ClInclude Include="..\public\tier1\callqueue.h">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user