Sources/CcgDump/CrySkinBase.cpp
//------------------------------------------------------------------------------
//-----     this is the serialize version for big-endian CPUs              -----
//------------------------------------------------------------------------------

this is the serialize version for big-endian CPUs
this is the serialize version for big - endian CPUs
unsigned CrySkinBase::Serialize_GC (bool bSave, void* pStream, unsigned nBufSize)
{
	SerialHeader Header;
	if (bSave)
	{
		Header.initFromSkin(this);
	}
	else
	{
		if (!pStream)
			return 0;
		if (nBufSize < sizeof(Header))
			return 0;
		Header = *((SerialHeader*)pStream);
	}
	unsigned nSizeAuxInts = ((sizeof(CrySkinAuxInt)*Header.numAuxInts+3)&~3);
	unsigned nSizeRequired = 
		sizeof(SerialHeader) +
		nSizeAuxInts +
		sizeof(Vertex) * Header.numVertices;									 
	if (!pStream)
		return bSave?nSizeRequired:0;
	if (nBufSize < nSizeRequired)
		return 0;
	CrySkinAuxInt* pAuxInts = (CrySkinAuxInt*)(((SerialHeader*)pStream) + 1);
	Vertex* pVertices				= (Vertex*)(((char*)pAuxInts) + nSizeAuxInts);
	if (bSave) 
	{
		Header.numBones			=	SWAP32(Header.numBones);
		Header.numSkipBones	=	SWAP32(Header.numSkipBones);
		Header.numDests			=	SWAP32(Header.numDests);
		Header.numAuxInts		=	SWAP32(Header.numAuxInts);
		Header.numVertices	=	SWAP32(Header.numVertices);
		*((SerialHeader*)pStream) = Header;
		unsigned sa	= sizeof(CrySkinAuxInt);
		unsigned a		=	(unsigned)m_arrAux.size();
		unsigned x;
		for (x=0; x<a; x++) {
			pAuxInts[x]=SWAP16(pAuxInts[x]);
		}
		unsigned va	=	sizeof(m_arrVertices.size());
		unsigned v		=	(unsigned)m_arrVertices.size();
		for (x=0; x<(v); x++) {
			pVertices[x].nDest		=	SWAP32(pVertices[x].nDest);
			pVertices[x].pt.x			=	FSWAP32(pVertices[x].pt.x);
			pVertices[x].pt.y			=	FSWAP32(pVertices[x].pt.y);
			pVertices[x].pt.z			=	FSWAP32(pVertices[x].pt.z);
		}
		memcpy (pAuxInts,		&m_arrAux[0],				sizeof(CrySkinAuxInt)*m_arrAux.size());
		memcpy (pVertices,	&m_arrVertices[0],	sizeof(Vertex)*m_arrVertices.size());
		for (x=0; x<a; x++) {
			pAuxInts[x]=SWAP16(pAuxInts[x]);
		}
		for (x=0; x<(v); x++) {
			pVertices[x].nDest		=	SWAP32(pVertices[x].nDest);
			pVertices[x].pt.x			=	FSWAP32(pVertices[x].pt.x);
			pVertices[x].pt.y			=	FSWAP32(pVertices[x].pt.y);
			pVertices[x].pt.z			=	FSWAP32(pVertices[x].pt.z);
		}
	}
	else
	{
		m_arrAux.clear();
		m_arrAux.resize (Header.numAuxInts);
		m_arrVertices.clear();
		m_arrVertices.resize (Header.numVertices);
		m_numBones			= Header.numBones;
		m_numSkipBones	= Header.numSkipBones;
		m_numDests			= Header.numDests;
		memcpy (&m_arrAux[0], pAuxInts, sizeof(CrySkinAuxInt)*m_arrAux.size());
		memcpy (&m_arrVertices[0], pVertices, sizeof(Vertex)*m_arrVertices.size());
	}
	return nSizeRequired;
}
unsigned CrySkinBase :: Serialize_GC ( bool bSave , void * pStream , unsigned nBufSize ) { SerialHeader Header ; if ( bSave ) { Header . initFromSkin ( this ) ; } else { if ( ! pStream ) return 0 ; if ( nBufSize < sizeof ( Header ) ) return 0 ; Header = * ( ( SerialHeader * ) pStream ) ; } unsigned nSizeAuxInts = ( ( sizeof ( CrySkinAuxInt ) * Header . numAuxInts + 3 ) & ~ 3 ) ; unsigned nSizeRequired = sizeof ( SerialHeader ) + nSizeAuxInts + sizeof ( Vertex ) * Header . numVertices ; if ( ! pStream ) return bSave ? nSizeRequired : 0 ; if ( nBufSize < nSizeRequired ) return 0 ; CrySkinAuxInt * pAuxInts = ( CrySkinAuxInt * ) ( ( ( SerialHeader * ) pStream ) + 1 ) ; Vertex * pVertices = ( Vertex * ) ( ( ( char * ) pAuxInts ) + nSizeAuxInts ) ; if ( bSave ) { Header . numBones = SWAP32 ( Header . numBones ) ; Header . numSkipBones = SWAP32 ( Header . numSkipBones ) ; Header . numDests = SWAP32 ( Header . numDests ) ; Header . numAuxInts = SWAP32 ( Header . numAuxInts ) ; Header . numVertices = SWAP32 ( Header . numVertices ) ; * ( ( SerialHeader * ) pStream ) = Header ; unsigned sa = sizeof ( CrySkinAuxInt ) ; unsigned a = ( unsigned ) m_arrAux . size ( ) ; unsigned x ; for ( x = 0 ; x < a ; x ++ ) { pAuxInts [ x ] = SWAP16 ( pAuxInts [ x ] ) ; } unsigned va = sizeof ( m_arrVertices . size ( ) ) ; unsigned v = ( unsigned ) m_arrVertices . size ( ) ; for ( x = 0 ; x < ( v ) ; x ++ ) { pVertices [ x ] . nDest = SWAP32 ( pVertices [ x ] . nDest ) ; pVertices [ x ] . pt . x = FSWAP32 ( pVertices [ x ] . pt . x ) ; pVertices [ x ] . pt . y = FSWAP32 ( pVertices [ x ] . pt . y ) ; pVertices [ x ] . pt . z = FSWAP32 ( pVertices [ x ] . pt . z ) ; } memcpy ( pAuxInts , & m_arrAux [ 0 ] , sizeof ( CrySkinAuxInt ) * m_arrAux . size ( ) ) ; memcpy ( pVertices , & m_arrVertices [ 0 ] , sizeof ( Vertex ) * m_arrVertices . size ( ) ) ; for ( x = 0 ; x < a ; x ++ ) { pAuxInts [ x ] = SWAP16 ( pAuxInts [ x ] ) ; } for ( x = 0 ; x < ( v ) ; x ++ ) { pVertices [ x ] . nDest = SWAP32 ( pVertices [ x ] . nDest ) ; pVertices [ x ] . pt . x = FSWAP32 ( pVertices [ x ] . pt . x ) ; pVertices [ x ] . pt . y = FSWAP32 ( pVertices [ x ] . pt . y ) ; pVertices [ x ] . pt . z = FSWAP32 ( pVertices [ x ] . pt . z ) ; } } else { m_arrAux . clear ( ) ; m_arrAux . resize ( Header . numAuxInts ) ; m_arrVertices . clear ( ) ; m_arrVertices . resize ( Header . numVertices ) ; m_numBones = Header . numBones ; m_numSkipBones = Header . numSkipBones ; m_numDests = Header . numDests ; memcpy ( & m_arrAux [ 0 ] , pAuxInts , sizeof ( CrySkinAuxInt ) * m_arrAux . size ( ) ) ; memcpy ( & m_arrVertices [ 0 ] , pVertices , sizeof ( Vertex ) * m_arrVertices . size ( ) ) ; } return nSizeRequired ; }
this is the serialize version for big-endian CPUs
this is the serialize version for big - endian CPUs
// the m_numBones, m_numSkipBones, m_numDests
 // m_arrAux.size(), m_arrVertices.size()
 //saving
 //swap data into big-endian-format
 //copy into stream 
 //..and new swap-back to little-endian,
 //because we need the original format for futher calculation on PC
 // loading
