include/AK/Tools/Common/AkBankReadHelpers.h
Go to the documentation of this file.00001
00002
00003
00004
00006
00007 #ifndef _AK_BANKREADHELPERS_H_
00008 #define _AK_BANKREADHELPERS_H_
00009
00010 #ifdef AK_WIIU
00011 #pragma ghs nowarning 1518
00012 #endif
00013
00015 template< typename T >
00016 inline T ReadBankData(
00017 AkUInt8*& in_rptr
00018 #ifdef _DEBUG
00019 ,AkUInt32& in_rSize
00020 #endif
00021 )
00022 {
00023 T l_Value;
00024 #if defined(AK_IOS) || defined(AK_3DS) || defined(AK_ANDROID) || defined(AK_VITA) || defined(AK_LINUX)
00025 typedef struct {T t;} __attribute__((__packed__)) packedStruct;
00026 l_Value = ((packedStruct *)in_rptr)->t;
00027 #else
00028 l_Value = *( ( T* )in_rptr );
00029 #endif
00030
00031 in_rptr += sizeof( T );
00032 #ifdef _DEBUG
00033 in_rSize -= sizeof( T );
00034 #endif
00035 return l_Value;
00036 }
00037
00038 inline char * ReadBankStringUtf8(
00039 AkUInt8*& in_rptr
00040 #ifdef _DEBUG
00041 ,AkUInt32& in_rSize
00042 #endif
00043 ,AkUInt32& out_uStringSize )
00044 {
00045 out_uStringSize = ReadBankData<AkUInt32>( in_rptr
00046 #ifdef _DEBUG
00047 ,in_rSize
00048 #endif
00049 );
00050
00051 char * pString = 0;
00052 if ( out_uStringSize > 0 )
00053 {
00054 pString = reinterpret_cast<char*>( in_rptr );
00055 in_rptr += out_uStringSize;
00056 #ifdef _DEBUG
00057 in_rSize -= out_uStringSize;
00058 #endif
00059 }
00060 return pString;
00061 }
00062
00064 template< typename T >
00065 inline T ReadUnaligned( const AkUInt8* in_rptr, AkUInt32 in_bytesToSkip = 0 )
00066 {
00067 #ifdef _DEBUG
00068 AkUInt32 size = sizeof(T);
00069 #endif
00070 AkUInt8* ptr = const_cast<AkUInt8*>(in_rptr) + in_bytesToSkip;
00071 return ReadBankData<T>(ptr
00072 #ifdef _DEBUG
00073 , size
00074 #endif
00075 );
00076 }
00077
00078
00079 #ifdef AK_XBOX360
00080
00081 inline AkReal32 AlignFloat( AkReal32* __unaligned ptr )
00082 {
00083 return *ptr;
00084 }
00085
00087 template<>
00088 inline AkReal32 ReadBankData<AkReal32>(
00089 AkUInt8*& in_rptr
00090 #ifdef _DEBUG
00091 ,AkUInt32& in_rSize
00092 #endif
00093 )
00094 {
00095 AkReal32 l_Value = AlignFloat( ( AkReal32* )in_rptr );
00096 in_rptr += sizeof( AkReal32 );
00097 #ifdef _DEBUG
00098 in_rSize -= sizeof( AkReal32 );
00099 #endif
00100 return l_Value;
00101 }
00102
00104 inline AkReal64 AlignFloat( AkReal64* __unaligned ptr )
00105 {
00106 return *ptr;
00107 }
00108
00110 template<>
00111 inline AkReal64 ReadBankData<AkReal64>(
00112 AkUInt8*& in_rptr
00113 #ifdef _DEBUG
00114 ,AkUInt32& in_rSize
00115 #endif
00116 )
00117 {
00118 AkReal64 l_Value = AlignFloat( ( AkReal64* )in_rptr );
00119 in_rptr += sizeof( AkReal64 );
00120 #ifdef _DEBUG
00121 in_rSize -= sizeof( AkReal64 );
00122 #endif
00123 return l_Value;
00124 }
00125
00126 #endif //AK_XBOX360
00127
00128 #if defined( __SNC__ ) // Valid for both Vita and PS3 (w/SN Compiler)
00129
00130 inline AkReal32 AlignFloat( AkReal32 __unaligned * ptr )
00131 {
00132 return *ptr;
00133 }
00134
00136 template<>
00137 inline AkReal32 ReadBankData<AkReal32>(
00138 AkUInt8*& in_rptr
00139 #ifdef _DEBUG
00140 ,AkUInt32& in_rSize
00141 #endif
00142 )
00143 {
00144 AkReal32 l_Value = AlignFloat( ( AkReal32* )in_rptr );
00145 in_rptr += sizeof( AkReal32 );
00146 #ifdef _DEBUG
00147 in_rSize -= sizeof( AkReal32 );
00148 #endif
00149 return l_Value;
00150 }
00151
00153 inline AkReal64 AlignFloat( AkReal64 __unaligned * ptr )
00154 {
00155 return *ptr;
00156 }
00157
00159 template<>
00160 inline AkReal64 ReadBankData<AkReal64>(
00161 AkUInt8*& in_rptr
00162 #ifdef _DEBUG
00163 ,AkUInt32& in_rSize
00164 #endif
00165 )
00166 {
00167 AkReal64 l_Value = AlignFloat( ( AkReal64* )in_rptr );
00168 in_rptr += sizeof( AkReal64 );
00169 #ifdef _DEBUG
00170 in_rSize -= sizeof( AkReal64 );
00171 #endif
00172 return l_Value;
00173 }
00174
00175 #elif defined (AK_PS3) || defined(AK_WII) || defined (AK_WIIU) || (defined(AK_IOS) && defined(_DEBUG)) // bug with iOS SDK 4.3 in Debug only
00176
00178 template < typename TO, typename FROM >
00179 inline TO union_cast( FROM value )
00180 {
00181 union { FROM from; TO to; } convert;
00182 convert.from = value;
00183 return convert.to;
00184 }
00185
00187 inline AkReal32 AlignFloat( AkReal32* ptr )
00188 {
00189 AkUInt32 *puint = reinterpret_cast<AkUInt32 *>( ptr );
00190 volatile AkUInt32 uint = *puint;
00191 return union_cast<AkReal32>( uint );
00192 }
00193
00195 template<>
00196 inline AkReal32 ReadBankData<AkReal32>(
00197 AkUInt8*& in_rptr
00198 #ifdef _DEBUG
00199 ,AkUInt32& in_rSize
00200 #endif
00201 )
00202 {
00203 AkReal32 l_Value = AlignFloat( ( AkReal32* )in_rptr );
00204 in_rptr += sizeof( AkReal32 );
00205 #ifdef _DEBUG
00206 in_rSize -= sizeof( AkReal32 );
00207 #endif
00208 return l_Value;
00209 }
00210
00212 inline AkReal64 AlignFloat( AkReal64* ptr )
00213 {
00214 AkUInt64 *puint = reinterpret_cast<AkUInt64 *>( ptr );
00215 volatile AkUInt64 uint = *puint;
00216 return union_cast<AkReal64>( uint );
00217 }
00218
00220 template<>
00221 inline AkReal64 ReadBankData<AkReal64>(
00222 AkUInt8*& in_rptr
00223 #ifdef _DEBUG
00224 ,AkUInt32& in_rSize
00225 #endif
00226 )
00227 {
00228 AkReal64 l_Value = AlignFloat( ( AkReal64* )in_rptr );
00229 in_rptr += sizeof( AkReal64 );
00230 #ifdef _DEBUG
00231 in_rSize -= sizeof( AkReal64 );
00232 #endif
00233 return l_Value;
00234 }
00235 #endif // AK_PS3 || AK_WII
00236
00237 #ifdef _DEBUG
00238
00240 #define READBANKDATA( _Type, _Ptr, _Size ) \
00241 ReadBankData<_Type>( _Ptr, _Size )
00242
00244 #define READBANKSTRING_UTF8( _Ptr, _Size, _out_StringSize ) \
00245 ReadBankStringUtf8( _Ptr, _Size, _out_StringSize )
00246
00248 #define READBANKSTRING( _Ptr, _Size, _out_StringSize ) \
00249 ReadBankStringUtf8( _Ptr, _Size, _out_StringSize ) //same as UTF-8 for now.
00250
00252 #define SKIPBANKDATA( _Type, _Ptr, _Size ) \
00253 ( _Ptr ) += sizeof( _Type ); \
00254 ( _Size ) -= sizeof( _Type )
00255
00257 #define SKIPBANKBYTES( _NumBytes, _Ptr, _Size ) \
00258 ( _Ptr ) += _NumBytes; \
00259 ( _Size ) -= _NumBytes
00260
00261 #else
00262
00264 #define READBANKDATA( _Type, _Ptr, _Size ) \
00265 ReadBankData<_Type>( _Ptr )
00266
00267 #define READBANKSTRING_UTF8( _Ptr, _Size, _out_StringSize ) \
00268 ReadBankStringUtf8( _Ptr, _out_StringSize )
00269
00270 #define READBANKSTRING( _Ptr, _Size, _out_StringSize ) \
00271 ReadBankStringUtf8( _Ptr, _out_StringSize )
00272
00274 #define SKIPBANKDATA( _Type, _Ptr, _Size ) \
00275 ( _Ptr ) += sizeof( _Type )
00276
00278 #define SKIPBANKBYTES( _NumBytes, _Ptr, _Size ) \
00279 ( _Ptr ) += _NumBytes;
00280
00281 #endif
00282
00283 #define GETBANKDATABIT( _Data, _Shift ) \
00284 (((_Data) >> (_Shift)) & 0x1)
00285
00287 #ifdef _DEBUG
00288 #define CHECKBANKDATASIZE( _DATASIZE_, _ERESULT_ ) AKASSERT( _DATASIZE_ == 0 || _ERESULT_ != AK_Success );
00289 #else
00290 #define CHECKBANKDATASIZE(_DATASIZE_, _ERESULT_ )
00291 #endif
00292
00293 #ifdef AK_WIIU
00294 #pragma ghs endnowarning 1518
00295 #endif
00296
00297 #endif //_AK_BANKREADHELPERS_H_
介绍一下自己的项目。我们会竭力为您提供帮助。
来注册自己的项目,我们帮您快速入门,不带任何附加条件!
开始 Wwise 之旅