diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2013-02-20 20:21:25 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2013-02-20 20:21:25 -0600 |
| commit | 8f256237a38e97db13d15ec8a761243755587714 (patch) | |
| tree | 70fc3b8ec14760db376697c2fb2f069c70a489bf /Source/Core/VideoCommon | |
| parent | 6a13a4e5ed10aac3b80e996f5c9e94d000f484b2 (diff) | |
Templatify DataReader a bit.
Diffstat (limited to 'Source/Core/VideoCommon')
| -rw-r--r-- | Source/Core/VideoCommon/Src/DataReader.h | 91 |
1 files changed, 31 insertions, 60 deletions
diff --git a/Source/Core/VideoCommon/Src/DataReader.h b/Source/Core/VideoCommon/Src/DataReader.h index 06668f8bbc..00dca77134 100644 --- a/Source/Core/VideoCommon/Src/DataReader.h +++ b/Source/Core/VideoCommon/Src/DataReader.h @@ -31,43 +31,63 @@ __forceinline void DataSkip(u32 skip) g_pVideoData += skip; } +// probably unnecessary +template <int count> +__forceinline void DataSkip() +{ + g_pVideoData += count; +} + +template <typename T> +__forceinline T DataPeek(int _uOffset) +{ + auto const result = Common::FromBigEndian(*reinterpret_cast<T*>(g_pVideoData + _uOffset)); + return result; +} + +// TODO: kill these __forceinline u8 DataPeek8(int _uOffset) { - return g_pVideoData[_uOffset]; + return DataPeek<u8>(_uOffset); } __forceinline u16 DataPeek16(int _uOffset) { - return Common::swap16(*(u16*)&g_pVideoData[_uOffset]); + return DataPeek<u16>(_uOffset); } __forceinline u32 DataPeek32(int _uOffset) { - return Common::swap32(*(u32*)&g_pVideoData[_uOffset]); + return DataPeek<u32>(_uOffset); } +template <typename T> +__forceinline T DataRead() +{ + auto const result = DataPeek<T>(0); + DataSkip<sizeof(T)>(); + return result; +} + +// TODO: kill these __forceinline u8 DataReadU8() { - return *g_pVideoData++; + return DataRead<u8>(); } __forceinline s8 DataReadS8() { - return (s8)(*g_pVideoData++); + return DataRead<s8>(); } __forceinline u16 DataReadU16() { - u16 tmp = Common::swap16(*(u16*)g_pVideoData); - g_pVideoData += 2; - return tmp; + return DataRead<u16>(); } __forceinline u32 DataReadU32() { - u32 tmp = Common::swap32(*(u32*)g_pVideoData); - g_pVideoData += 4; - return tmp; + return DataRead<u32>(); } typedef void (*DataReadU32xNfunc)(u32 *buf); @@ -120,55 +140,6 @@ __forceinline u32 DataReadU32Unswapped() return tmp; } -template<class T> -__forceinline T DataRead() -{ - T tmp = *(T*)g_pVideoData; - g_pVideoData += sizeof(T); - return tmp; -} - -template <> -__forceinline u16 DataRead() -{ - u16 tmp = Common::swap16(*(u16*)g_pVideoData); - g_pVideoData += 2; - return tmp; -} - -template <> -__forceinline s16 DataRead() -{ - s16 tmp = (s16)Common::swap16(*(u16*)g_pVideoData); - g_pVideoData += 2; - return tmp; -} - -template <> -__forceinline u32 DataRead() -{ - u32 tmp = (u32)Common::swap32(*(u32*)g_pVideoData); - g_pVideoData += 4; - return tmp; -} - -template <> -__forceinline s32 DataRead() -{ - s32 tmp = (s32)Common::swap32(*(u32*)g_pVideoData); - g_pVideoData += 4; - return tmp; -} - -__forceinline float DataReadF32() -{ - union {u32 i; float f;} temp; - temp.i = Common::swap32(*(u32*)g_pVideoData); - g_pVideoData += 4; - float tmp = temp.f; - return tmp; -} - __forceinline u8* DataGetPosition() { return g_pVideoData; |
