parent
f86f8e8ed8
commit
c754d6fdfb
15 changed files with 91 additions and 108 deletions
|
@ -131,10 +131,7 @@ SquareRootFloat
|
|||
================
|
||||
*/
|
||||
float SquareRootFloat(float number) {
|
||||
union {
|
||||
float f;
|
||||
int i;
|
||||
} t;
|
||||
floatint_t t;
|
||||
float x, y;
|
||||
const float f = 1.5F;
|
||||
|
||||
|
|
|
@ -291,13 +291,9 @@ void MSG_WriteLong( msg_t *sb, int c ) {
|
|||
}
|
||||
|
||||
void MSG_WriteFloat( msg_t *sb, float f ) {
|
||||
union {
|
||||
float f;
|
||||
int l;
|
||||
} dat;
|
||||
|
||||
floatint_t dat;
|
||||
dat.f = f;
|
||||
MSG_WriteBits( sb, dat.l, 32 );
|
||||
MSG_WriteBits( sb, dat.i, 32 );
|
||||
}
|
||||
|
||||
void MSG_WriteString( msg_t *sb, const char *s ) {
|
||||
|
@ -423,13 +419,9 @@ int MSG_ReadLong( msg_t *msg ) {
|
|||
}
|
||||
|
||||
float MSG_ReadFloat( msg_t *msg ) {
|
||||
union {
|
||||
byte b[4];
|
||||
float f;
|
||||
int l;
|
||||
} dat;
|
||||
floatint_t dat;
|
||||
|
||||
dat.l = MSG_ReadBits( msg, 32 );
|
||||
dat.i = MSG_ReadBits( msg, 32 );
|
||||
if ( msg->readcount > msg->cursize ) {
|
||||
dat.f = -1;
|
||||
}
|
||||
|
@ -563,20 +555,22 @@ int MSG_ReadDelta( msg_t *msg, int oldV, int bits ) {
|
|||
}
|
||||
|
||||
void MSG_WriteDeltaFloat( msg_t *msg, float oldV, float newV ) {
|
||||
floatint_t fi;
|
||||
if ( oldV == newV ) {
|
||||
MSG_WriteBits( msg, 0, 1 );
|
||||
return;
|
||||
}
|
||||
fi.f = newV;
|
||||
MSG_WriteBits( msg, 1, 1 );
|
||||
MSG_WriteBits( msg, *(int *)&newV, 32 );
|
||||
MSG_WriteBits( msg, fi.i, 32 );
|
||||
}
|
||||
|
||||
float MSG_ReadDeltaFloat( msg_t *msg, float oldV ) {
|
||||
if ( MSG_ReadBits( msg, 1 ) ) {
|
||||
float newV;
|
||||
floatint_t fi;
|
||||
|
||||
*(int *)&newV = MSG_ReadBits( msg, 32 );
|
||||
return newV;
|
||||
fi.i = MSG_ReadBits( msg, 32 );
|
||||
return fi.f;
|
||||
}
|
||||
return oldV;
|
||||
}
|
||||
|
@ -617,20 +611,22 @@ int MSG_ReadDeltaKey( msg_t *msg, int key, int oldV, int bits ) {
|
|||
}
|
||||
|
||||
void MSG_WriteDeltaKeyFloat( msg_t *msg, int key, float oldV, float newV ) {
|
||||
floatint_t fi;
|
||||
if ( oldV == newV ) {
|
||||
MSG_WriteBits( msg, 0, 1 );
|
||||
return;
|
||||
}
|
||||
fi.f = newV;
|
||||
MSG_WriteBits( msg, 1, 1 );
|
||||
MSG_WriteBits( msg, (*(int *)&newV) ^ key, 32 );
|
||||
MSG_WriteBits( msg, fi.i ^ key, 32 );
|
||||
}
|
||||
|
||||
float MSG_ReadDeltaKeyFloat( msg_t *msg, int key, float oldV ) {
|
||||
if ( MSG_ReadBits( msg, 1 ) ) {
|
||||
float newV;
|
||||
floatint_t fi;
|
||||
|
||||
*(int *)&newV = MSG_ReadBits( msg, 32 ) ^ key;
|
||||
return newV;
|
||||
fi.i = MSG_ReadBits( msg, 32 ) ^ key;
|
||||
return fi.f;
|
||||
}
|
||||
return oldV;
|
||||
}
|
||||
|
|
|
@ -501,10 +501,7 @@ void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out )
|
|||
*/
|
||||
float Q_rsqrt( float number )
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
int i;
|
||||
} t;
|
||||
floatint_t t;
|
||||
float x2, y;
|
||||
const float threehalfs = 1.5F;
|
||||
|
||||
|
@ -519,9 +516,10 @@ float Q_rsqrt( float number )
|
|||
}
|
||||
|
||||
float Q_fabs( float f ) {
|
||||
int tmp = * ( int * ) &f;
|
||||
tmp &= 0x7FFFFFFF;
|
||||
return * ( float * ) &tmp;
|
||||
floatint_t fi;
|
||||
fi.f = f;
|
||||
fi.i &= 0x7FFFFFFF;
|
||||
return fi.f;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1301,15 +1299,11 @@ Don't pass doubles to this
|
|||
*/
|
||||
int Q_isnan( float x )
|
||||
{
|
||||
union
|
||||
{
|
||||
float f;
|
||||
unsigned int i;
|
||||
} t;
|
||||
floatint_t fi;
|
||||
|
||||
t.f = x;
|
||||
t.i &= 0x7FFFFFFF;
|
||||
t.i = 0x7F800000 - t.i;
|
||||
fi.f = x;
|
||||
fi.ui &= 0x7FFFFFFF;
|
||||
fi.ui = 0x7F800000 - fi.ui;
|
||||
|
||||
return (int)( (unsigned int)t.i >> 31 );
|
||||
return (int)( (unsigned int)fi.ui >> 31 );
|
||||
}
|
||||
|
|
|
@ -205,16 +205,11 @@ qint64 Long64NoSwap (qint64 ll)
|
|||
return ll;
|
||||
}
|
||||
|
||||
typedef union {
|
||||
float f;
|
||||
unsigned int i;
|
||||
} _FloatByteUnion;
|
||||
|
||||
float FloatSwap (const float *f) {
|
||||
_FloatByteUnion out;
|
||||
floatint_t out;
|
||||
|
||||
out.f = *f;
|
||||
out.i = LongSwap(out.i);
|
||||
out.ui = LongSwap(out.ui);
|
||||
|
||||
return out.f;
|
||||
}
|
||||
|
|
|
@ -151,6 +151,12 @@ typedef unsigned char byte;
|
|||
|
||||
typedef enum {qfalse, qtrue} qboolean;
|
||||
|
||||
typedef union {
|
||||
float f;
|
||||
int i;
|
||||
unsigned int ui;
|
||||
} floatint_t;
|
||||
|
||||
typedef int qhandle_t;
|
||||
typedef int sfxHandle_t;
|
||||
typedef int fileHandle_t;
|
||||
|
|
|
@ -356,12 +356,9 @@ void *VM_ExplicitArgPtr( vm_t *vm, intptr_t intValue );
|
|||
#define VMA(x) VM_ArgPtr(args[x])
|
||||
static ID_INLINE float _vmf(intptr_t x)
|
||||
{
|
||||
union {
|
||||
int i;
|
||||
float f;
|
||||
} t;
|
||||
t.i = (int)x;
|
||||
return t.f;
|
||||
floatint_t fi;
|
||||
fi.i = (int) x;
|
||||
return fi.f;
|
||||
}
|
||||
#define VMF(x) _vmf(args[x])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue