mirror of
https://github.com/dhewm/dhewm3-sdk.git
synced 2025-01-31 21:10:47 +00:00
Use SDL for everything endian
This commit is contained in:
parent
0a945baff1
commit
f41d2347b1
2 changed files with 35 additions and 138 deletions
149
idlib/Lib.cpp
149
idlib/Lib.cpp
|
@ -32,6 +32,8 @@ If you have questions concerning this license or the applicable additional terms
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <SDL_endian.h>
|
||||||
|
|
||||||
#include "sys/platform.h"
|
#include "sys/platform.h"
|
||||||
#include "idlib/math/Vector.h"
|
#include "idlib/math/Vector.h"
|
||||||
#include "idlib/math/Polynomial.h"
|
#include "idlib/math/Polynomial.h"
|
||||||
|
@ -159,12 +161,10 @@ dword PackColor( const idVec4 &color ) {
|
||||||
dz = ColorFloatToByte( color.z );
|
dz = ColorFloatToByte( color.z );
|
||||||
dw = ColorFloatToByte( color.w );
|
dw = ColorFloatToByte( color.w );
|
||||||
|
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
return ( dx << 0 ) | ( dy << 8 ) | ( dz << 16 ) | ( dw << 24 );
|
return ( dx << 0 ) | ( dy << 8 ) | ( dz << 16 ) | ( dw << 24 );
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return ( dx << 24 ) | ( dy << 16 ) | ( dz << 8 ) | ( dw << 0 );
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
return ( dx << 24 ) | ( dy << 16 ) | ( dz << 8 ) | ( dw << 0 );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,18 +174,16 @@ UnpackColor
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
void UnpackColor( const dword color, idVec4 &unpackedColor ) {
|
void UnpackColor( const dword color, idVec4 &unpackedColor ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
unpackedColor.Set( ( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ),
|
unpackedColor.Set( ( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ),
|
( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 24 ) & 255 ) * ( 1.0f / 255.0f ) );
|
( ( color >> 24 ) & 255 ) * ( 1.0f / 255.0f ) );
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
#else
|
||||||
unpackedColor.Set( ( ( color >> 24 ) & 255 ) * ( 1.0f / 255.0f ),
|
unpackedColor.Set( ( ( color >> 24 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ),
|
( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ) );
|
( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ) );
|
||||||
#else
|
|
||||||
#error unknown endianness!
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,12 +199,10 @@ dword PackColor( const idVec3 &color ) {
|
||||||
dy = ColorFloatToByte( color.y );
|
dy = ColorFloatToByte( color.y );
|
||||||
dz = ColorFloatToByte( color.z );
|
dz = ColorFloatToByte( color.z );
|
||||||
|
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
return ( dx << 0 ) | ( dy << 8 ) | ( dz << 16 );
|
return ( dx << 0 ) | ( dy << 8 ) | ( dz << 16 );
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return ( dy << 16 ) | ( dz << 8 ) | ( dx << 0 );
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
return ( dy << 16 ) | ( dz << 8 ) | ( dx << 0 );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,16 +212,14 @@ UnpackColor
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
void UnpackColor( const dword color, idVec3 &unpackedColor ) {
|
void UnpackColor( const dword color, idVec3 &unpackedColor ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
unpackedColor.Set( ( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ),
|
unpackedColor.Set( ( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ) );
|
( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ) );
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
#else
|
||||||
unpackedColor.Set( ( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ),
|
unpackedColor.Set( ( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||||
( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ) );
|
( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ) );
|
||||||
#else
|
|
||||||
#error unknown endianness!
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,36 +263,6 @@ void idLib::Warning( const char *fmt, ... ) {
|
||||||
===============================================================================
|
===============================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
ShortSwap
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
ID_INLINE static short ShortSwap( short l ) {
|
|
||||||
byte b1,b2;
|
|
||||||
|
|
||||||
b1 = l&255;
|
|
||||||
b2 = (l>>8)&255;
|
|
||||||
|
|
||||||
return (b1<<8) + b2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
LongSwap
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
ID_INLINE static int LongSwap ( int l ) {
|
|
||||||
byte b1,b2,b3,b4;
|
|
||||||
|
|
||||||
b1 = l&255;
|
|
||||||
b2 = (l>>8)&255;
|
|
||||||
b3 = (l>>16)&255;
|
|
||||||
b4 = (l>>24)&255;
|
|
||||||
|
|
||||||
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
================
|
================
|
||||||
FloatSwap
|
FloatSwap
|
||||||
|
@ -307,16 +271,13 @@ FloatSwap
|
||||||
ID_INLINE static float FloatSwap( float f ) {
|
ID_INLINE static float FloatSwap( float f ) {
|
||||||
union {
|
union {
|
||||||
float f;
|
float f;
|
||||||
byte b[4];
|
unsigned int u;
|
||||||
} dat1, dat2;
|
} id_attribute((may_alias)) dat;
|
||||||
|
|
||||||
|
dat.f = f;
|
||||||
|
dat.u = SDL_Swap32(dat.u);
|
||||||
|
|
||||||
dat1.f = f;
|
return dat.f;
|
||||||
dat2.b[0] = dat1.b[3];
|
|
||||||
dat2.b[1] = dat1.b[2];
|
|
||||||
dat2.b[2] = dat1.b[1];
|
|
||||||
dat2.b[3] = dat1.b[0];
|
|
||||||
return dat2.f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -459,122 +420,82 @@ Swap_IsBigEndian
|
||||||
==========
|
==========
|
||||||
*/
|
*/
|
||||||
bool Swap_IsBigEndian( void ) {
|
bool Swap_IsBigEndian( void ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
return false;
|
return false;
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return true;
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
short BigShort( short l ) {
|
short BigShort( short l ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
return SDL_SwapBE16(l);
|
||||||
return ShortSwap(l);
|
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return l;
|
|
||||||
#else
|
|
||||||
#error unknown endianness!
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
short LittleShort( short l ) {
|
short LittleShort( short l ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
return SDL_SwapLE16(l);
|
||||||
return l;
|
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return ShortSwap(l);
|
|
||||||
#else
|
|
||||||
#error unknown endianness!
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int BigLong( int l ) {
|
int BigLong( int l ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
return SDL_SwapBE32(l);
|
||||||
return LongSwap(l);
|
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return l;
|
|
||||||
#else
|
|
||||||
#error unknown endianness!
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int LittleLong( int l ) {
|
int LittleLong( int l ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
return SDL_SwapLE32(l);
|
||||||
return l;
|
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return LongSwap(l);
|
|
||||||
#else
|
|
||||||
#error unknown endianness!
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float BigFloat( float l ) {
|
float BigFloat( float l ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
return FloatSwap(l);
|
return FloatSwap(l);
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return l;
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
return l;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float LittleFloat( float l ) {
|
float LittleFloat( float l ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
return l;
|
return l;
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return FloatSwap(l);
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
return FloatSwap(l);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void BigRevBytes( void *bp, int elsize, int elcount ) {
|
void BigRevBytes( void *bp, int elsize, int elcount ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
RevBytesSwap(bp, elsize, elcount);
|
RevBytesSwap(bp, elsize, elcount);
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return;
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
return;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void LittleRevBytes( void *bp, int elsize, int elcount ){
|
void LittleRevBytes( void *bp, int elsize, int elcount ){
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
return;
|
return;
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
RevBytesSwap(bp, elsize, elcount);
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
RevBytesSwap(bp, elsize, elcount);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void LittleBitField( void *bp, int elsize ){
|
void LittleBitField( void *bp, int elsize ){
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
return;
|
return;
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
RevBitFieldSwap(bp, elsize);
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
RevBitFieldSwap(bp, elsize);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SixtetsForInt( byte *out, int src) {
|
void SixtetsForInt( byte *out, int src) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
SixtetsForIntLittle(out, src);
|
SixtetsForIntLittle(out, src);
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
SixtetsForIntBig(out, src);
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
SixtetsForIntBig(out, src);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int IntForSixtets( byte *in ) {
|
int IntForSixtets( byte *in ) {
|
||||||
#if defined(ID_LITTLE_ENDIAN)
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
return IntForSixtetsLittle(in);
|
return IntForSixtetsLittle(in);
|
||||||
#elif defined(ID_BIG_ENDIAN)
|
|
||||||
return IntForSixtetsBig(in);
|
|
||||||
#else
|
#else
|
||||||
#error unknown endianness!
|
return IntForSixtetsBig(in);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,6 @@ If you have questions concerning this license or the applicable additional terms
|
||||||
|
|
||||||
#define THREAD_RETURN_TYPE DWORD
|
#define THREAD_RETURN_TYPE DWORD
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
|
|
||||||
#define ID_LITTLE_ENDIAN 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -172,26 +168,6 @@ If you have questions concerning this license or the applicable additional terms
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !defined(ID_LITTLE_ENDIAN) && !defined(ID_BIG_ENDIAN)
|
|
||||||
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
|
|
||||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
||||||
#define ID_LITTLE_ENDIAN
|
|
||||||
#endif
|
|
||||||
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
|
|
||||||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
||||||
#define ID_BIG_ENDIAN
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(ID_LITTLE_ENDIAN) && !defined(ID_BIG_ENDIAN)
|
|
||||||
#if defined(__i386__) || defined(__x86_64__)
|
|
||||||
#define ID_LITTLE_ENDIAN 1
|
|
||||||
#elif defined(__ppc__)
|
|
||||||
#define ID_BIG_ENDIAN 1
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define id_attribute(x) __attribute__(x)
|
#define id_attribute(x) __attribute__(x)
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in a new issue