mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
public: refactor variable declarations
This commit is contained in:
@@ -17,15 +17,13 @@ GNU General Public License for more details.
|
|||||||
|
|
||||||
qboolean Atlas_AllocBlock( atlas_t *atlas, int w, int h, int *x, int *y )
|
qboolean Atlas_AllocBlock( atlas_t *atlas, int w, int h, int *x, int *y )
|
||||||
{
|
{
|
||||||
int i, j;
|
|
||||||
int best, best2;
|
|
||||||
int size = atlas->size;
|
int size = atlas->size;
|
||||||
|
int best = size;
|
||||||
|
int j;
|
||||||
|
|
||||||
best = size;
|
for( int i = 0; i <= size - w; )
|
||||||
|
|
||||||
for( i = 0; i <= size - w; )
|
|
||||||
{
|
{
|
||||||
best2 = 0;
|
int best2 = 0;
|
||||||
|
|
||||||
for( j = 0; j < w; j++ )
|
for( j = 0; j < w; j++ )
|
||||||
{
|
{
|
||||||
@@ -52,7 +50,7 @@ qboolean Atlas_AllocBlock( atlas_t *atlas, int w, int h, int *x, int *y )
|
|||||||
if( best + h > size )
|
if( best + h > size )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for( i = 0; i < w; i++ )
|
for( int i = 0; i < w; i++ )
|
||||||
atlas->allocated[*x + i] = best + h;
|
atlas->allocated[*x + i] = best + h;
|
||||||
|
|
||||||
if( best + h > atlas->max_height )
|
if( best + h > atlas->max_height )
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ static const char mond[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|||||||
|
|
||||||
int Q_buildnum_iso( const char *date )
|
int Q_buildnum_iso( const char *date )
|
||||||
{
|
{
|
||||||
int y, m, d, b, i;
|
int y, m, d;
|
||||||
|
|
||||||
if( sscanf( date, "%d-%d-%d", &y, &m, &d ) != 3 || y <= 1900 || m <= 0 || d <= 0 )
|
if( sscanf( date, "%d-%d-%d", &y, &m, &d ) != 3 || y <= 1900 || m <= 0 || d <= 0 )
|
||||||
return -1;
|
return -1;
|
||||||
@@ -29,11 +29,11 @@ int Q_buildnum_iso( const char *date )
|
|||||||
m--;
|
m--;
|
||||||
d--;
|
d--;
|
||||||
|
|
||||||
for( i = 0; i < m; i++ )
|
for( int i = 0; i < m; i++ )
|
||||||
d += mond[i];
|
d += mond[i];
|
||||||
|
|
||||||
y -= 1900;
|
y -= 1900;
|
||||||
b = d + (int)((y - 1) * 365.25f );
|
int b = d + (int)((y - 1) * 365.25f );
|
||||||
|
|
||||||
if((( y % 4 ) == 0 ) && m > 1 )
|
if((( y % 4 ) == 0 ) && m > 1 )
|
||||||
b += 1;
|
b += 1;
|
||||||
|
|||||||
@@ -97,11 +97,13 @@ void GAME_EXPORT CRC32_ProcessByte( uint32_t *pulCRC, byte ch )
|
|||||||
|
|
||||||
void GAME_EXPORT CRC32_ProcessBuffer( uint32_t *pulCRC, const void *pBuffer, int nBuffer )
|
void GAME_EXPORT CRC32_ProcessBuffer( uint32_t *pulCRC, const void *pBuffer, int nBuffer )
|
||||||
{
|
{
|
||||||
uint32_t ulCrc = *pulCRC, tmp;
|
uint32_t ulCrc = *pulCRC;
|
||||||
byte *pb = (byte *)pBuffer;
|
byte *pb = (byte *)pBuffer;
|
||||||
|
|
||||||
while( nBuffer >= sizeof( uint64_t ))
|
while( nBuffer >= sizeof( uint64_t ))
|
||||||
{
|
{
|
||||||
|
uint32_t tmp;
|
||||||
|
|
||||||
memcpy( &tmp, pb, sizeof( tmp ));
|
memcpy( &tmp, pb, sizeof( tmp ));
|
||||||
ulCrc ^= LittleLong( tmp );
|
ulCrc ^= LittleLong( tmp );
|
||||||
ulCrc = crc32table[(byte)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = crc32table[(byte)ulCrc] ^ (ulCrc >> 8);
|
||||||
@@ -120,6 +122,8 @@ void GAME_EXPORT CRC32_ProcessBuffer( uint32_t *pulCRC, const void *pBuffer, int
|
|||||||
|
|
||||||
if( nBuffer & sizeof( uint32_t ))
|
if( nBuffer & sizeof( uint32_t ))
|
||||||
{
|
{
|
||||||
|
uint32_t tmp;
|
||||||
|
|
||||||
memcpy( &tmp, pb, sizeof( tmp ));
|
memcpy( &tmp, pb, sizeof( tmp ));
|
||||||
ulCrc ^= LittleLong( tmp );
|
ulCrc ^= LittleLong( tmp );
|
||||||
ulCrc = crc32table[(byte)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = crc32table[(byte)ulCrc] ^ (ulCrc >> 8);
|
||||||
@@ -147,23 +151,22 @@ For proxy protecting
|
|||||||
*/
|
*/
|
||||||
byte CRC32_BlockSequence( byte *base, int length, int sequence )
|
byte CRC32_BlockSequence( byte *base, int length, int sequence )
|
||||||
{
|
{
|
||||||
uint32_t CRC;
|
char buffer[64];
|
||||||
char buffer[64];
|
|
||||||
int off;
|
|
||||||
uint32_t le[2];
|
|
||||||
|
|
||||||
if( sequence < 0 ) sequence = abs( sequence );
|
if( sequence < 0 ) sequence = abs( sequence );
|
||||||
|
|
||||||
if( length > 60 ) length = 60;
|
if( length > 60 ) length = 60;
|
||||||
memcpy( buffer, base, length );
|
memcpy( buffer, base, length );
|
||||||
|
|
||||||
off = sequence % 0x3FC;
|
int off = sequence % 0x3FC;
|
||||||
|
uint32_t le[2];
|
||||||
le[0] = LittleLong( crc32table[off / 4] );
|
le[0] = LittleLong( crc32table[off / 4] );
|
||||||
le[1] = LittleLong( crc32table[off / 4 + 1] );
|
le[1] = LittleLong( crc32table[off / 4 + 1] );
|
||||||
memcpy( buffer + length, (char *)le + ( off & 3 ), 4 );
|
memcpy( buffer + length, (char *)le + ( off & 3 ), 4 );
|
||||||
|
|
||||||
length += 4;
|
length += 4;
|
||||||
|
|
||||||
|
uint32_t CRC;
|
||||||
CRC32_Init( &CRC );
|
CRC32_Init( &CRC );
|
||||||
CRC32_ProcessBuffer( &CRC, buffer, length );
|
CRC32_ProcessBuffer( &CRC, buffer, length );
|
||||||
CRC = CRC32_Final( CRC );
|
CRC = CRC32_Final( CRC );
|
||||||
@@ -188,10 +191,8 @@ Update context to reflect the concatenation of another buffer full of bytes.
|
|||||||
*/
|
*/
|
||||||
void MD5Update( MD5Context_t *ctx, const byte *buf, uint len )
|
void MD5Update( MD5Context_t *ctx, const byte *buf, uint len )
|
||||||
{
|
{
|
||||||
uint t;
|
|
||||||
|
|
||||||
// update bitcount
|
// update bitcount
|
||||||
t = ctx->bits[0];
|
uint t = ctx->bits[0];
|
||||||
|
|
||||||
if(( ctx->bits[0] = t + ((uint) len << 3 )) < t )
|
if(( ctx->bits[0] = t + ((uint) len << 3 )) < t )
|
||||||
ctx->bits[1]++; // carry from low to high
|
ctx->bits[1]++; // carry from low to high
|
||||||
@@ -242,15 +243,12 @@ Final wrapup - pad to 64-byte boundary with the bit pattern
|
|||||||
*/
|
*/
|
||||||
void MD5Final( byte digest[16], MD5Context_t *ctx )
|
void MD5Final( byte digest[16], MD5Context_t *ctx )
|
||||||
{
|
{
|
||||||
uint count;
|
|
||||||
byte *p;
|
|
||||||
|
|
||||||
// compute number of bytes mod 64
|
// compute number of bytes mod 64
|
||||||
count = ( ctx->bits[0] >> 3 ) & 0x3F;
|
uint count = ( ctx->bits[0] >> 3 ) & 0x3F;
|
||||||
|
|
||||||
// set the first char of padding to 0x80.
|
// set the first char of padding to 0x80.
|
||||||
// this is safe since there is always at least one byte free
|
// this is safe since there is always at least one byte free
|
||||||
p = (byte*)ctx->in + count;
|
byte *p = (byte*)ctx->in + count;
|
||||||
*p++ = 0x80;
|
*p++ = 0x80;
|
||||||
|
|
||||||
// bytes of padding needed to make 64 bytes
|
// bytes of padding needed to make 64 bytes
|
||||||
@@ -308,12 +306,10 @@ the data and converts bytes into longwords for this routine.
|
|||||||
*/
|
*/
|
||||||
void MD5Transform( uint buf[4], const uint in[16] )
|
void MD5Transform( uint buf[4], const uint in[16] )
|
||||||
{
|
{
|
||||||
register uint a, b, c, d;
|
register uint a = buf[0];
|
||||||
|
register uint b = buf[1];
|
||||||
a = buf[0];
|
register uint c = buf[2];
|
||||||
b = buf[1];
|
register uint d = buf[3];
|
||||||
c = buf[2];
|
|
||||||
d = buf[3];
|
|
||||||
|
|
||||||
MD5STEP( F1, a, b, c, d, in[0] + 0xd76aa478, 7 );
|
MD5STEP( F1, a, b, c, d, in[0] + 0xd76aa478, 7 );
|
||||||
MD5STEP( F1, d, a, b, c, in[1] + 0xe8c7b756, 12 );
|
MD5STEP( F1, d, a, b, c, in[1] + 0xe8c7b756, 12 );
|
||||||
@@ -425,12 +421,11 @@ transform hash to hexadecimal printable symbols
|
|||||||
*/
|
*/
|
||||||
char *MD5_Print( byte hash[16] )
|
char *MD5_Print( byte hash[16] )
|
||||||
{
|
{
|
||||||
static char szReturn[64];
|
static char szReturn[64];
|
||||||
int i;
|
|
||||||
|
|
||||||
memset( szReturn, 0, 64 );
|
memset( szReturn, 0, 64 );
|
||||||
|
|
||||||
for( i = 0; i < 16; i++ )
|
for( int i = 0; i < 16; i++ )
|
||||||
COM_Hex2String( hash[i], &szReturn[i * 2] );
|
COM_Hex2String( hash[i], &szReturn[i * 2] );
|
||||||
|
|
||||||
return szReturn;
|
return szReturn;
|
||||||
|
|||||||
124
public/crtlib.c
124
public/crtlib.c
@@ -48,24 +48,22 @@ char *GAME_EXPORT Q_memfgets( byte *data, int data_len, int *data_offset, char *
|
|||||||
|
|
||||||
void Q_strnlwr( const char *in, char *out, size_t size_out )
|
void Q_strnlwr( const char *in, char *out, size_t size_out )
|
||||||
{
|
{
|
||||||
size_t len, i;
|
size_t len = Q_strncpy( out, in, size_out );
|
||||||
|
|
||||||
len = Q_strncpy( out, in, size_out );
|
for( size_t i = 0; i < len; i++ )
|
||||||
|
|
||||||
for( i = 0; i < len; i++ )
|
|
||||||
out[i] = Q_tolower( out[i] );
|
out[i] = Q_tolower( out[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
int Q_atoi_hex( int sign, const char *str )
|
int Q_atoi_hex( int sign, const char *str )
|
||||||
{
|
{
|
||||||
int c, val = 0;
|
int val = 0;
|
||||||
|
|
||||||
if( str[0] == '0' && ( str[1] == 'x' || str[1] == 'X' ))
|
if( str[0] == '0' && ( str[1] == 'x' || str[1] == 'X' ))
|
||||||
str += 2;
|
str += 2;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
c = *str++;
|
int c = *str++;
|
||||||
if( c >= '0' && c <= '9' ) val = (val<<4) + c - '0';
|
if( c >= '0' && c <= '9' ) val = (val<<4) + c - '0';
|
||||||
else if( c >= 'a' && c <= 'f' ) val = (val<<4) + c - 'a' + 10;
|
else if( c >= 'a' && c <= 'f' ) val = (val<<4) + c - 'a' + 10;
|
||||||
else if( c >= 'A' && c <= 'F' ) val = (val<<4) + c - 'A' + 10;
|
else if( c >= 'A' && c <= 'F' ) val = (val<<4) + c - 'A' + 10;
|
||||||
@@ -88,9 +86,6 @@ static const char *Q_atoi_strip_whitespace( const char *str )
|
|||||||
|
|
||||||
int Q_atoi( const char *str )
|
int Q_atoi( const char *str )
|
||||||
{
|
{
|
||||||
int val = 0;
|
|
||||||
int c, sign;
|
|
||||||
|
|
||||||
if( COM_StringEmptyOrNULL( str ))
|
if( COM_StringEmptyOrNULL( str ))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -99,6 +94,7 @@ int Q_atoi( const char *str )
|
|||||||
if( COM_StringEmptyOrNULL( str ))
|
if( COM_StringEmptyOrNULL( str ))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
int sign;
|
||||||
if( *str == '-' )
|
if( *str == '-' )
|
||||||
{
|
{
|
||||||
sign = -1;
|
sign = -1;
|
||||||
@@ -115,9 +111,10 @@ int Q_atoi( const char *str )
|
|||||||
return Q_atoi_character( sign, str );
|
return Q_atoi_character( sign, str );
|
||||||
|
|
||||||
// assume decimal
|
// assume decimal
|
||||||
|
int val = 0;
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
c = *str++;
|
int c = *str++;
|
||||||
if( c < '0' || c > '9' )
|
if( c < '0' || c > '9' )
|
||||||
return val * sign;
|
return val * sign;
|
||||||
val = val * 10 + c - '0';
|
val = val * 10 + c - '0';
|
||||||
@@ -127,9 +124,6 @@ int Q_atoi( const char *str )
|
|||||||
|
|
||||||
float Q_atof( const char *str )
|
float Q_atof( const char *str )
|
||||||
{
|
{
|
||||||
double val = 0;
|
|
||||||
int c, sign, decimal, total;
|
|
||||||
|
|
||||||
if( COM_StringEmptyOrNULL( str ))
|
if( COM_StringEmptyOrNULL( str ))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -138,6 +132,7 @@ float Q_atof( const char *str )
|
|||||||
if( COM_StringEmptyOrNULL( str ))
|
if( COM_StringEmptyOrNULL( str ))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
int sign;
|
||||||
if( *str == '-' )
|
if( *str == '-' )
|
||||||
{
|
{
|
||||||
sign = -1;
|
sign = -1;
|
||||||
@@ -154,12 +149,13 @@ float Q_atof( const char *str )
|
|||||||
return Q_atoi_character( sign, str );
|
return Q_atoi_character( sign, str );
|
||||||
|
|
||||||
// assume decimal
|
// assume decimal
|
||||||
decimal = -1;
|
double val = 0;
|
||||||
total = 0;
|
int decimal = -1;
|
||||||
|
int total = 0;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
c = *str++;
|
int c = *str++;
|
||||||
if( c == '.' )
|
if( c == '.' )
|
||||||
{
|
{
|
||||||
decimal = total;
|
decimal = total;
|
||||||
@@ -186,13 +182,12 @@ float Q_atof( const char *str )
|
|||||||
|
|
||||||
void Q_atov( float *vec, const char *str, size_t siz )
|
void Q_atov( float *vec, const char *str, size_t siz )
|
||||||
{
|
{
|
||||||
const char *pstr, *pfront;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
memset( vec, 0, sizeof( *vec ) * siz );
|
memset( vec, 0, sizeof( *vec ) * siz );
|
||||||
pstr = pfront = str;
|
|
||||||
|
|
||||||
for( j = 0; j < siz; j++ )
|
const char *pstr = str;
|
||||||
|
const char *pfront = str;
|
||||||
|
|
||||||
|
for( size_t j = 0; j < siz; j++ )
|
||||||
{
|
{
|
||||||
vec[j] = Q_atof( pfront );
|
vec[j] = Q_atof( pfront );
|
||||||
|
|
||||||
@@ -208,8 +203,8 @@ void Q_atov( float *vec, const char *str, size_t siz )
|
|||||||
|
|
||||||
static qboolean Q_starcmp( const char *pattern, const char *text )
|
static qboolean Q_starcmp( const char *pattern, const char *text )
|
||||||
{
|
{
|
||||||
char c, c1;
|
char c;
|
||||||
const char *p = pattern, *t = text;
|
const char *p = pattern, *t = text;
|
||||||
|
|
||||||
while(( c = *p++ ) == '?' || c == '*' )
|
while(( c = *p++ ) == '?' || c == '*' )
|
||||||
{
|
{
|
||||||
@@ -219,7 +214,7 @@ static qboolean Q_starcmp( const char *pattern, const char *text )
|
|||||||
|
|
||||||
if( c == '\0' ) return true;
|
if( c == '\0' ) return true;
|
||||||
|
|
||||||
for( c1 = (( c == '\\' ) ? *p : c ); ; )
|
for( char c1 = (( c == '\\' ) ? *p : c ); ; )
|
||||||
{
|
{
|
||||||
if( Q_tolower( *t ) == c1 && Q_stricmpext( p - 1, t ))
|
if( Q_tolower( *t ) == c1 && Q_stricmpext( p - 1, t ))
|
||||||
return true;
|
return true;
|
||||||
@@ -298,19 +293,17 @@ const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *need
|
|||||||
|
|
||||||
void Q_memor( byte *XASH_RESTRICT dst, const byte *XASH_RESTRICT src, size_t len )
|
void Q_memor( byte *XASH_RESTRICT dst, const byte *XASH_RESTRICT src, size_t len )
|
||||||
{
|
{
|
||||||
size_t i;
|
for( size_t i = 0; i < len; i++ ) // msvc likes to optimize this loop form
|
||||||
for( i = 0; i < len; i++ ) // msvc likes to optimize this loop form
|
|
||||||
dst[i] |= src[i];
|
dst[i] |= src[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Q_timestamp( int format )
|
const char *Q_timestamp( int format )
|
||||||
{
|
{
|
||||||
static string timestamp;
|
static string timestamp;
|
||||||
time_t crt_time;
|
time_t crt_time;
|
||||||
const struct tm *crt_tm;
|
|
||||||
|
|
||||||
time( &crt_time );
|
time( &crt_time );
|
||||||
crt_tm = localtime( &crt_time );
|
const struct tm *crt_tm = localtime( &crt_time );
|
||||||
|
|
||||||
switch( format )
|
switch( format )
|
||||||
{
|
{
|
||||||
@@ -350,13 +343,10 @@ const char *Q_timestamp( int format )
|
|||||||
#if !HAVE_STRCASESTR
|
#if !HAVE_STRCASESTR
|
||||||
char *Q_stristr( const char *string, const char *string2 )
|
char *Q_stristr( const char *string, const char *string2 )
|
||||||
{
|
{
|
||||||
int c;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if( !string || !string2 ) return NULL;
|
if( !string || !string2 ) return NULL;
|
||||||
|
|
||||||
c = Q_tolower( *string2 );
|
int c = Q_tolower( *string2 );
|
||||||
len = Q_strlen( string2 );
|
size_t len = Q_strlen( string2 );
|
||||||
|
|
||||||
while( string )
|
while( string )
|
||||||
{
|
{
|
||||||
@@ -376,11 +366,10 @@ char *Q_stristr( const char *string, const char *string2 )
|
|||||||
|
|
||||||
int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args )
|
int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args )
|
||||||
{
|
{
|
||||||
int result;
|
|
||||||
|
|
||||||
if( unlikely( buffersize == 0 ))
|
if( unlikely( buffersize == 0 ))
|
||||||
return -1; // report as overflow
|
return -1; // report as overflow
|
||||||
|
|
||||||
|
int result;
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
result = vsnprintf( buffer, buffersize, format, args );
|
result = vsnprintf( buffer, buffersize, format, args );
|
||||||
#else
|
#else
|
||||||
@@ -408,11 +397,10 @@ int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list ar
|
|||||||
|
|
||||||
int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... )
|
int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... )
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
int result;
|
|
||||||
|
|
||||||
va_start( args, format );
|
va_start( args, format );
|
||||||
result = Q_vsnprintf( buffer, buffersize, format, args );
|
int result = Q_vsnprintf( buffer, buffersize, format, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -431,18 +419,16 @@ void COM_StripColors( const char *in, char *out )
|
|||||||
|
|
||||||
char *Q_pretifymem( float value, int digitsafterdecimal )
|
char *Q_pretifymem( float value, int digitsafterdecimal )
|
||||||
{
|
{
|
||||||
static char output[8][32];
|
static char output[8][32];
|
||||||
static int current;
|
static int current;
|
||||||
const float onekb = 1024.0f;
|
const float onekb = 1024.0f;
|
||||||
const float onemb = onekb * onekb;
|
const float onemb = onekb * onekb;
|
||||||
const char *suffix;
|
char *out = output[current];
|
||||||
char *out = output[current];
|
|
||||||
char val[32], *i, *o, *dot;
|
|
||||||
int pos;
|
|
||||||
|
|
||||||
current = ( current + 1 ) & ( 8 - 1 );
|
current = ( current + 1 ) & ( 8 - 1 );
|
||||||
|
|
||||||
// first figure out which bin to use
|
// first figure out which bin to use
|
||||||
|
const char *suffix;
|
||||||
if( value > onemb )
|
if( value > onemb )
|
||||||
{
|
{
|
||||||
value /= onemb;
|
value /= onemb;
|
||||||
@@ -459,20 +445,21 @@ char *Q_pretifymem( float value, int digitsafterdecimal )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if it's basically integral, don't do any decimals
|
// if it's basically integral, don't do any decimals
|
||||||
|
char val[32];
|
||||||
if( fabs( value - (int)value ) < 0.00001f || digitsafterdecimal <= 0 )
|
if( fabs( value - (int)value ) < 0.00001f || digitsafterdecimal <= 0 )
|
||||||
Q_snprintf( val, sizeof( val ), "%i %s", (int)Q_rint( value ), suffix );
|
Q_snprintf( val, sizeof( val ), "%i %s", (int)Q_rint( value ), suffix );
|
||||||
else if( digitsafterdecimal >= 1 )
|
else if( digitsafterdecimal >= 1 )
|
||||||
Q_snprintf( val, sizeof( val ), "%.*f %s", digitsafterdecimal, (double)value, suffix );
|
Q_snprintf( val, sizeof( val ), "%.*f %s", digitsafterdecimal, (double)value, suffix );
|
||||||
|
|
||||||
// copy from in to out
|
// copy from in to out
|
||||||
i = val;
|
char *i = val;
|
||||||
o = out;
|
char *o = out;
|
||||||
|
|
||||||
// search for decimal or if it was integral, find the space after the raw number
|
// search for decimal or if it was integral, find the space after the raw number
|
||||||
dot = Q_strchr( i, '.' );
|
char *dot = Q_strchr( i, '.' );
|
||||||
if( !dot ) dot = Q_strchr( i, ' ' );
|
if( !dot ) dot = Q_strchr( i, ' ' );
|
||||||
|
|
||||||
pos = dot - i; // compute position of dot
|
int pos = dot - i; // compute position of dot
|
||||||
pos -= 3; // don't put a comma if it's <= 3 long
|
pos -= 3; // don't put a comma if it's <= 3 long
|
||||||
|
|
||||||
while( *i )
|
while( *i )
|
||||||
@@ -503,17 +490,16 @@ a1ba: adapted and simplified version from QuakeSpasm
|
|||||||
*/
|
*/
|
||||||
void COM_FileBase( const char *in, char *out, size_t size )
|
void COM_FileBase( const char *in, char *out, size_t size )
|
||||||
{
|
{
|
||||||
const char *dot, *slash, *s;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if( unlikely( COM_StringEmptyOrNULL( in ) || size <= 1 ))
|
if( unlikely( COM_StringEmptyOrNULL( in ) || size <= 1 ))
|
||||||
{
|
{
|
||||||
out[0] = 0;
|
out[0] = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
slash = in;
|
const char *slash = in;
|
||||||
dot = NULL;
|
const char *dot = NULL;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
for( s = in; *s; s++ )
|
for( s = in; *s; s++ )
|
||||||
{
|
{
|
||||||
if( *s == '/' || *s == '\\' )
|
if( *s == '/' || *s == '\\' )
|
||||||
@@ -526,7 +512,7 @@ void COM_FileBase( const char *in, char *out, size_t size )
|
|||||||
if( dot == NULL || dot < slash )
|
if( dot == NULL || dot < slash )
|
||||||
dot = s;
|
dot = s;
|
||||||
|
|
||||||
len = Q_min( size - 1, dot - slash );
|
size_t len = Q_min( size - 1, dot - slash );
|
||||||
|
|
||||||
memcpy( out, slash, len );
|
memcpy( out, slash, len );
|
||||||
out[len] = 0;
|
out[len] = 0;
|
||||||
@@ -539,9 +525,7 @@ COM_FileExtension
|
|||||||
*/
|
*/
|
||||||
const char *COM_FileExtension( const char *in )
|
const char *COM_FileExtension( const char *in )
|
||||||
{
|
{
|
||||||
const char *dot;
|
const char *dot = Q_strrchr( in, '.' );
|
||||||
|
|
||||||
dot = Q_strrchr( in, '.' );
|
|
||||||
|
|
||||||
// quickly exit if there is no dot at all
|
// quickly exit if there is no dot at all
|
||||||
if( dot == NULL )
|
if( dot == NULL )
|
||||||
@@ -561,15 +545,13 @@ COM_FileWithoutPath
|
|||||||
*/
|
*/
|
||||||
const char *COM_FileWithoutPath( const char *in )
|
const char *COM_FileWithoutPath( const char *in )
|
||||||
{
|
{
|
||||||
const char *separator, *backslash, *colon;
|
const char *separator = Q_strrchr( in, '/' );
|
||||||
|
const char *backslash = Q_strrchr( in, '\\' );
|
||||||
separator = Q_strrchr( in, '/' );
|
|
||||||
backslash = Q_strrchr( in, '\\' );
|
|
||||||
|
|
||||||
if( !separator || separator < backslash )
|
if( !separator || separator < backslash )
|
||||||
separator = backslash;
|
separator = backslash;
|
||||||
|
|
||||||
colon = Q_strrchr( in, ':' );
|
const char *colon = Q_strrchr( in, ':' );
|
||||||
|
|
||||||
if( !separator || separator < colon )
|
if( !separator || separator < colon )
|
||||||
separator = colon;
|
separator = colon;
|
||||||
@@ -621,14 +603,12 @@ COM_DefaultExtension
|
|||||||
*/
|
*/
|
||||||
void COM_DefaultExtension( char *path, const char *extension, size_t size )
|
void COM_DefaultExtension( char *path, const char *extension, size_t size )
|
||||||
{
|
{
|
||||||
size_t len;
|
|
||||||
|
|
||||||
// if path doesn't have a .EXT, append extension
|
// if path doesn't have a .EXT, append extension
|
||||||
// (extension should include the .)
|
// (extension should include the .)
|
||||||
if( !COM_StringEmptyOrNULL( COM_FileExtension( path )))
|
if( !COM_StringEmptyOrNULL( COM_FileExtension( path )))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
len = Q_strlen( path );
|
size_t len = Q_strlen( path );
|
||||||
Q_strncpy( &path[len], extension, size - len );
|
Q_strncpy( &path[len], extension, size - len );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,9 +630,7 @@ COM_RemoveLineFeed
|
|||||||
*/
|
*/
|
||||||
void COM_RemoveLineFeed( char *str, size_t bufsize )
|
void COM_RemoveLineFeed( char *str, size_t bufsize )
|
||||||
{
|
{
|
||||||
size_t i;
|
for( size_t i = 0; i < bufsize && *str != '\0'; i++, str++ )
|
||||||
|
|
||||||
for( i = 0; i < bufsize && *str != '\0'; i++, str++ )
|
|
||||||
{
|
{
|
||||||
if( *str == '\r' || *str == '\n' )
|
if( *str == '\r' || *str == '\n' )
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
@@ -910,8 +888,6 @@ int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive
|
|||||||
// if false * matches 0 or more characters
|
// if false * matches 0 or more characters
|
||||||
int matchpattern_with_separator( const char *in, const char *pattern, qboolean caseinsensitive, const char *separators, qboolean wildcard_least_one )
|
int matchpattern_with_separator( const char *in, const char *pattern, qboolean caseinsensitive, const char *separators, qboolean wildcard_least_one )
|
||||||
{
|
{
|
||||||
int c1, c2;
|
|
||||||
|
|
||||||
while( *pattern )
|
while( *pattern )
|
||||||
{
|
{
|
||||||
switch( *pattern )
|
switch( *pattern )
|
||||||
@@ -948,10 +924,10 @@ int matchpattern_with_separator( const char *in, const char *pattern, qboolean c
|
|||||||
{
|
{
|
||||||
if( !caseinsensitive )
|
if( !caseinsensitive )
|
||||||
return 0; // no match
|
return 0; // no match
|
||||||
c1 = *in;
|
int c1 = *in;
|
||||||
if( c1 >= 'A' && c1 <= 'Z' )
|
if( c1 >= 'A' && c1 <= 'Z' )
|
||||||
c1 += 'a' - 'A';
|
c1 += 'a' - 'A';
|
||||||
c2 = *pattern;
|
int c2 = *pattern;
|
||||||
if( c2 >= 'A' && c2 <= 'Z' )
|
if( c2 >= 'A' && c2 <= 'Z' )
|
||||||
c2 += 'a' - 'A';
|
c2 += 'a' - 'A';
|
||||||
if( c1 != c2 )
|
if( c1 != c2 )
|
||||||
|
|||||||
@@ -16,17 +16,13 @@ GNU General Public License for more details.
|
|||||||
|
|
||||||
void ClearExports( const dllfunc_t *funcs, size_t num_funcs )
|
void ClearExports( const dllfunc_t *funcs, size_t num_funcs )
|
||||||
{
|
{
|
||||||
size_t i;
|
for( size_t i = 0; i < num_funcs; i++ )
|
||||||
|
|
||||||
for( i = 0; i < num_funcs; i++ )
|
|
||||||
*(funcs[i].func) = NULL;
|
*(funcs[i].func) = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
qboolean ValidateExports( const dllfunc_t *funcs, size_t num_funcs )
|
qboolean ValidateExports( const dllfunc_t *funcs, size_t num_funcs )
|
||||||
{
|
{
|
||||||
size_t i;
|
for( size_t i = 0; i < num_funcs; i++ )
|
||||||
|
|
||||||
for( i = 0; i < num_funcs; i++ )
|
|
||||||
{
|
{
|
||||||
if( *(funcs[i].func) == NULL )
|
if( *(funcs[i].func) == NULL )
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ void Matrix3x4_VectorTransform( const matrix3x4 in, const float v[3], float out[
|
|||||||
|
|
||||||
void Matrix3x4_VectorITransform( const matrix3x4 in, const float v[3], float out[3] )
|
void Matrix3x4_VectorITransform( const matrix3x4 in, const float v[3], float out[3] )
|
||||||
{
|
{
|
||||||
vec3_t dir;
|
vec3_t dir;
|
||||||
|
|
||||||
dir[0] = v[0] - in[0][3];
|
dir[0] = v[0] - in[0][3];
|
||||||
dir[1] = v[1] - in[1][3];
|
dir[1] = v[1] - in[1][3];
|
||||||
dir[2] = v[2] - in[2][3];
|
dir[2] = v[2] - in[2][3];
|
||||||
@@ -116,10 +115,10 @@ void Matrix3x4_FromOriginQuat( matrix3x4 out, const vec4_t quaternion, const vec
|
|||||||
|
|
||||||
void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_t origin, float scale )
|
void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_t origin, float scale )
|
||||||
{
|
{
|
||||||
float angle, sr, sp, sy, cr, cp, cy;
|
|
||||||
|
|
||||||
if( angles[ROLL] )
|
if( angles[ROLL] )
|
||||||
{
|
{
|
||||||
|
float angle, sr, sp, sy, cr, cp, cy;
|
||||||
|
|
||||||
angle = angles[YAW] * (M_PI2 / 360.0f);
|
angle = angles[YAW] * (M_PI2 / 360.0f);
|
||||||
SinCos( angle, &sy, &cy );
|
SinCos( angle, &sy, &cy );
|
||||||
angle = angles[PITCH] * (M_PI2 / 360.0f);
|
angle = angles[PITCH] * (M_PI2 / 360.0f);
|
||||||
@@ -142,6 +141,8 @@ void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_
|
|||||||
}
|
}
|
||||||
else if( angles[PITCH] )
|
else if( angles[PITCH] )
|
||||||
{
|
{
|
||||||
|
float angle, sp, sy, cp, cy;
|
||||||
|
|
||||||
angle = angles[YAW] * (M_PI2 / 360.0f);
|
angle = angles[YAW] * (M_PI2 / 360.0f);
|
||||||
SinCos( angle, &sy, &cy );
|
SinCos( angle, &sy, &cy );
|
||||||
angle = angles[PITCH] * (M_PI2 / 360.0f);
|
angle = angles[PITCH] * (M_PI2 / 360.0f);
|
||||||
@@ -162,6 +163,8 @@ void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_
|
|||||||
}
|
}
|
||||||
else if( angles[YAW] )
|
else if( angles[YAW] )
|
||||||
{
|
{
|
||||||
|
float angle, sy, cy;
|
||||||
|
|
||||||
angle = angles[YAW] * (M_PI2 / 360.0f);
|
angle = angles[YAW] * (M_PI2 / 360.0f);
|
||||||
SinCos( angle, &sy, &cy );
|
SinCos( angle, &sy, &cy );
|
||||||
|
|
||||||
@@ -202,12 +205,11 @@ Matrix3x4_TransformAABB
|
|||||||
*/
|
*/
|
||||||
void Matrix3x4_TransformAABB( const matrix3x4 world, const vec3_t mins, const vec3_t maxs, vec3_t absmin, vec3_t absmax )
|
void Matrix3x4_TransformAABB( const matrix3x4 world, const vec3_t mins, const vec3_t maxs, vec3_t absmin, vec3_t absmax )
|
||||||
{
|
{
|
||||||
vec3_t localCenter, localExtents;
|
vec3_t localCenter, localExtents;
|
||||||
vec3_t worldCenter, worldExtents;
|
|
||||||
|
|
||||||
VectorAverage( mins, maxs, localCenter );
|
VectorAverage( mins, maxs, localCenter );
|
||||||
VectorSubtract( maxs, localCenter, localExtents );
|
VectorSubtract( maxs, localCenter, localExtents );
|
||||||
|
|
||||||
|
vec3_t worldCenter, worldExtents;
|
||||||
Matrix3x4_VectorTransform( world, localCenter, worldCenter );
|
Matrix3x4_VectorTransform( world, localCenter, worldCenter );
|
||||||
worldExtents[0] = DotProductFabs( localExtents, world[0] ); // auto-transposed!
|
worldExtents[0] = DotProductFabs( localExtents, world[0] ); // auto-transposed!
|
||||||
worldExtents[1] = DotProductFabs( localExtents, world[1] );
|
worldExtents[1] = DotProductFabs( localExtents, world[1] );
|
||||||
@@ -233,8 +235,7 @@ void Matrix4x4_VectorTransform( const matrix4x4 in, const float v[3], float out[
|
|||||||
|
|
||||||
void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out[3] )
|
void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out[3] )
|
||||||
{
|
{
|
||||||
vec3_t dir;
|
vec3_t dir;
|
||||||
|
|
||||||
dir[0] = v[0] - in[0][3];
|
dir[0] = v[0] - in[0][3];
|
||||||
dir[1] = v[1] - in[1][3];
|
dir[1] = v[1] - in[1][3];
|
||||||
dir[2] = v[2] - in[2][3];
|
dir[2] = v[2] - in[2][3];
|
||||||
@@ -276,10 +277,10 @@ void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matri
|
|||||||
|
|
||||||
void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale )
|
void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale )
|
||||||
{
|
{
|
||||||
float angle, sr, sp, sy, cr, cp, cy;
|
|
||||||
|
|
||||||
if( angles[ROLL] )
|
if( angles[ROLL] )
|
||||||
{
|
{
|
||||||
|
float angle, sr, sp, sy, cr, cp, cy;
|
||||||
|
|
||||||
angle = angles[YAW] * (M_PI2 / 360.0f);
|
angle = angles[YAW] * (M_PI2 / 360.0f);
|
||||||
SinCos( angle, &sy, &cy );
|
SinCos( angle, &sy, &cy );
|
||||||
angle = angles[PITCH] * (M_PI2 / 360.0f);
|
angle = angles[PITCH] * (M_PI2 / 360.0f);
|
||||||
@@ -306,6 +307,8 @@ void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_
|
|||||||
}
|
}
|
||||||
else if( angles[PITCH] )
|
else if( angles[PITCH] )
|
||||||
{
|
{
|
||||||
|
float angle, sp, sy, cp, cy;
|
||||||
|
|
||||||
angle = angles[YAW] * (M_PI2 / 360.0f);
|
angle = angles[YAW] * (M_PI2 / 360.0f);
|
||||||
SinCos( angle, &sy, &cy );
|
SinCos( angle, &sy, &cy );
|
||||||
angle = angles[PITCH] * (M_PI2 / 360.0f);
|
angle = angles[PITCH] * (M_PI2 / 360.0f);
|
||||||
@@ -330,6 +333,8 @@ void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_
|
|||||||
}
|
}
|
||||||
else if( angles[YAW] )
|
else if( angles[YAW] )
|
||||||
{
|
{
|
||||||
|
float angle, sy, cy;
|
||||||
|
|
||||||
angle = angles[YAW] * (M_PI2 / 360.0f);
|
angle = angles[YAW] * (M_PI2 / 360.0f);
|
||||||
SinCos( angle, &sy, &cy );
|
SinCos( angle, &sy, &cy );
|
||||||
|
|
||||||
@@ -439,11 +444,10 @@ void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 )
|
|||||||
|
|
||||||
qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 )
|
qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 )
|
||||||
{
|
{
|
||||||
float *temp;
|
float *r[4];
|
||||||
float *r[4];
|
float rtemp[4][8];
|
||||||
float rtemp[4][8];
|
float m[4];
|
||||||
float m[4];
|
float s;
|
||||||
float s;
|
|
||||||
|
|
||||||
r[0] = rtemp[0];
|
r[0] = rtemp[0];
|
||||||
r[1] = rtemp[1];
|
r[1] = rtemp[1];
|
||||||
@@ -488,21 +492,21 @@ qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 )
|
|||||||
|
|
||||||
if( fabs( r[3][0] ) > fabs( r[2][0] ))
|
if( fabs( r[3][0] ) > fabs( r[2][0] ))
|
||||||
{
|
{
|
||||||
temp = r[3];
|
float *temp = r[3];
|
||||||
r[3] = r[2];
|
r[3] = r[2];
|
||||||
r[2] = temp;
|
r[2] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fabs( r[2][0] ) > fabs( r[1][0] ))
|
if( fabs( r[2][0] ) > fabs( r[1][0] ))
|
||||||
{
|
{
|
||||||
temp = r[2];
|
float *temp = r[2];
|
||||||
r[2] = r[1];
|
r[2] = r[1];
|
||||||
r[1] = temp;
|
r[1] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fabs( r[1][0] ) > fabs( r[0][0] ))
|
if( fabs( r[1][0] ) > fabs( r[0][0] ))
|
||||||
{
|
{
|
||||||
temp = r[1];
|
float *temp = r[1];
|
||||||
r[1] = r[0];
|
r[1] = r[0];
|
||||||
r[0] = temp;
|
r[0] = temp;
|
||||||
}
|
}
|
||||||
@@ -562,14 +566,14 @@ qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 )
|
|||||||
|
|
||||||
if( fabs( r[3][1] ) > fabs( r[2][1] ))
|
if( fabs( r[3][1] ) > fabs( r[2][1] ))
|
||||||
{
|
{
|
||||||
temp = r[3];
|
float *temp = r[3];
|
||||||
r[3] = r[2];
|
r[3] = r[2];
|
||||||
r[2] = temp;
|
r[2] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fabs( r[2][1] ) > fabs( r[1][1] ))
|
if( fabs( r[2][1] ) > fabs( r[1][1] ))
|
||||||
{
|
{
|
||||||
temp = r[2];
|
float *temp = r[2];
|
||||||
r[2] = r[1];
|
r[2] = r[1];
|
||||||
r[1] = temp;
|
r[1] = temp;
|
||||||
}
|
}
|
||||||
@@ -613,7 +617,7 @@ qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 )
|
|||||||
|
|
||||||
if( fabs( r[3][2] ) > fabs( r[2][2] ))
|
if( fabs( r[3][2] ) > fabs( r[2][2] ))
|
||||||
{
|
{
|
||||||
temp = r[3];
|
float *temp = r[3];
|
||||||
r[3] = r[2];
|
r[3] = r[2];
|
||||||
r[2] = temp;
|
r[2] = temp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,23 +173,20 @@ size_t Q_UTF8Length( const char *s )
|
|||||||
|
|
||||||
size_t Q_UTF16ToUTF8( char *dst, size_t dstsize, const uint16_t *src, size_t srcsize )
|
size_t Q_UTF16ToUTF8( char *dst, size_t dstsize, const uint16_t *src, size_t srcsize )
|
||||||
{
|
{
|
||||||
utfstate_t state = { 0 };
|
|
||||||
size_t dsti = 0, srci;
|
|
||||||
|
|
||||||
if( !dst || !src || !dstsize || !srcsize )
|
if( !dst || !src || !dstsize || !srcsize )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for( srci = 0; srci < srcsize && src[srci]; srci++ )
|
utfstate_t state = { 0 };
|
||||||
{
|
size_t dsti = 0;
|
||||||
uint32_t ch;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
ch = Q_DecodeUTF16( &state, src[srci] );
|
for( size_t srci = 0; srci < srcsize && src[srci]; srci++ )
|
||||||
|
{
|
||||||
|
uint32_t ch = Q_DecodeUTF16( &state, src[srci] );
|
||||||
|
|
||||||
if( ch == 0 )
|
if( ch == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
len = Q_CodepointLength( ch );
|
size_t len = Q_CodepointLength( ch );
|
||||||
|
|
||||||
if( dsti + len + 1 > dstsize )
|
if( dsti + len + 1 > dstsize )
|
||||||
break;
|
break;
|
||||||
@@ -215,8 +212,6 @@ static const uint16_t table_cp1251[64] = {
|
|||||||
|
|
||||||
uint32_t Q_UnicodeToCP1251( uint32_t uc )
|
uint32_t Q_UnicodeToCP1251( uint32_t uc )
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if( uc < 0x80 )
|
if( uc < 0x80 )
|
||||||
return uc;
|
return uc;
|
||||||
|
|
||||||
@@ -226,7 +221,7 @@ uint32_t Q_UnicodeToCP1251( uint32_t uc )
|
|||||||
if( uc >= 0x0430 && uc <= 0x044F )
|
if( uc >= 0x0430 && uc <= 0x044F )
|
||||||
return uc - 0x430 + 0xE0;
|
return uc - 0x430 + 0xE0;
|
||||||
|
|
||||||
for( i = 0; i < sizeof( table_cp1251 ) / sizeof( table_cp1251[0] ); i++ )
|
for( size_t i = 0; i < sizeof( table_cp1251 ) / sizeof( table_cp1251[0] ); i++ )
|
||||||
{
|
{
|
||||||
if( uc == (uint32_t)table_cp1251[i] )
|
if( uc == (uint32_t)table_cp1251[i] )
|
||||||
return i + 0x80;
|
return i + 0x80;
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ const float m_bytenormals[NUMVERTEXNORMALS][3] =
|
|||||||
|
|
||||||
uint16_t FloatToHalf( float v )
|
uint16_t FloatToHalf( float v )
|
||||||
{
|
{
|
||||||
unsigned int i = FloatAsUint( v );
|
unsigned int i = FloatAsUint( v );
|
||||||
unsigned int e = (i >> 23) & 0x00ff;
|
unsigned int e = (i >> 23) & 0x00ff;
|
||||||
unsigned int m = i & 0x007fffff;
|
unsigned int m = i & 0x007fffff;
|
||||||
unsigned short h;
|
unsigned short h;
|
||||||
|
|
||||||
if( e <= 127 - 15 )
|
if( e <= 127 - 15 )
|
||||||
h = ((m | 0x00800000) >> (127 - 14 - e)) >> 13;
|
h = ((m | 0x00800000) >> (127 - 14 - e)) >> 13;
|
||||||
@@ -94,20 +94,17 @@ round the hullsize to nearest 'right' value
|
|||||||
*/
|
*/
|
||||||
void RoundUpHullSize( vec3_t size )
|
void RoundUpHullSize( vec3_t size )
|
||||||
{
|
{
|
||||||
int i, j;
|
for( int i = 0; i < 3; i++)
|
||||||
|
|
||||||
for( i = 0; i < 3; i++)
|
|
||||||
{
|
{
|
||||||
qboolean negative = false;
|
qboolean negative = false;
|
||||||
float result, value;
|
float value = size[i];
|
||||||
|
|
||||||
value = size[i];
|
|
||||||
if( value < 0.0f ) negative = true;
|
if( value < 0.0f ) negative = true;
|
||||||
value = Q_ceil( fabs( value ));
|
value = Q_ceil( fabs( value ));
|
||||||
result = Q_ceil( size[i] );
|
float result = Q_ceil( size[i] );
|
||||||
|
|
||||||
// lookup hull table to find nearest supposed value
|
// lookup hull table to find nearest supposed value
|
||||||
for( j = 0; j < sizeof( hull_table ) / sizeof( hull_table[0] ); j++ )
|
for( size_t j = 0; j < sizeof( hull_table ) / sizeof( hull_table[0] ); j++ )
|
||||||
{
|
{
|
||||||
if( value > hull_table[j] )
|
if( value > hull_table[j] )
|
||||||
continue; // ceil only
|
continue; // ceil only
|
||||||
@@ -143,16 +140,13 @@ rsqrt
|
|||||||
*/
|
*/
|
||||||
float Q_rsqrt( float number )
|
float Q_rsqrt( float number )
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
float x, y;
|
|
||||||
|
|
||||||
if( number == 0.0f )
|
if( number == 0.0f )
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
||||||
x = number * 0.5f;
|
float x = number * 0.5f;
|
||||||
i = FloatAsInt( number ); // evil floating point bit level hacking
|
int i = FloatAsInt( number ); // evil floating point bit level hacking
|
||||||
i = 0x5f3759df - (i >> 1); // what the fuck?
|
i = 0x5f3759df - (i >> 1); // what the fuck?
|
||||||
y = IntAsFloat( i );
|
float y = IntAsFloat( i );
|
||||||
y = y * (1.5f - (x * y * y)); // first iteration
|
y = y * (1.5f - (x * y * y)); // first iteration
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
@@ -160,13 +154,11 @@ float Q_rsqrt( float number )
|
|||||||
|
|
||||||
void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up )
|
void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up )
|
||||||
{
|
{
|
||||||
float d;
|
|
||||||
|
|
||||||
right[0] = forward[2];
|
right[0] = forward[2];
|
||||||
right[1] = -forward[0];
|
right[1] = -forward[0];
|
||||||
right[2] = forward[1];
|
right[2] = forward[1];
|
||||||
|
|
||||||
d = DotProduct( forward, right );
|
float d = DotProduct( forward, right );
|
||||||
VectorMA( right, -d, forward, right );
|
VectorMA( right, -d, forward, right );
|
||||||
VectorNormalize( right );
|
VectorNormalize( right );
|
||||||
CrossProduct( right, forward, up );
|
CrossProduct( right, forward, up );
|
||||||
@@ -181,14 +173,14 @@ VectorAngles
|
|||||||
*/
|
*/
|
||||||
void GAME_EXPORT VectorAngles( const float *forward, float *angles )
|
void GAME_EXPORT VectorAngles( const float *forward, float *angles )
|
||||||
{
|
{
|
||||||
float tmp, yaw, pitch;
|
|
||||||
|
|
||||||
if( !forward || !angles )
|
if( !forward || !angles )
|
||||||
{
|
{
|
||||||
if( angles ) VectorClear( angles );
|
if( angles ) VectorClear( angles );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float yaw, pitch;
|
||||||
|
|
||||||
if( forward[1] == 0 && forward[0] == 0 )
|
if( forward[1] == 0 && forward[0] == 0 )
|
||||||
{
|
{
|
||||||
// fast case
|
// fast case
|
||||||
@@ -202,7 +194,7 @@ void GAME_EXPORT VectorAngles( const float *forward, float *angles )
|
|||||||
yaw = ( atan2( forward[1], forward[0] ) * 180 / M_PI_F );
|
yaw = ( atan2( forward[1], forward[0] ) * 180 / M_PI_F );
|
||||||
if( yaw < 0 ) yaw += 360;
|
if( yaw < 0 ) yaw += 360;
|
||||||
|
|
||||||
tmp = sqrt( forward[0] * forward[0] + forward[1] * forward[1] );
|
float tmp = sqrt( forward[0] * forward[0] + forward[1] * forward[1] );
|
||||||
pitch = ( atan2( forward[2], tmp ) * 180 / M_PI_F );
|
pitch = ( atan2( forward[2], tmp ) * 180 / M_PI_F );
|
||||||
if( pitch < 0 ) pitch += 360;
|
if( pitch < 0 ) pitch += 360;
|
||||||
}
|
}
|
||||||
@@ -218,10 +210,9 @@ VectorsAngles
|
|||||||
*/
|
*/
|
||||||
void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, vec3_t angles )
|
void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, vec3_t angles )
|
||||||
{
|
{
|
||||||
float pitch, cpitch, yaw, roll;
|
float pitch = -asin( forward[2] );
|
||||||
|
float cpitch = cos( pitch );
|
||||||
pitch = -asin( forward[2] );
|
float yaw, roll;
|
||||||
cpitch = cos( pitch );
|
|
||||||
|
|
||||||
if( fabs( cpitch ) > EQUAL_EPSILON ) // gimball lock?
|
if( fabs( cpitch ) > EQUAL_EPSILON ) // gimball lock?
|
||||||
{
|
{
|
||||||
@@ -252,17 +243,15 @@ SphereIntersect
|
|||||||
*/
|
*/
|
||||||
qboolean SphereIntersect( const vec3_t vSphereCenter, float fSphereRadiusSquared, const vec3_t vLinePt, const vec3_t vLineDir )
|
qboolean SphereIntersect( const vec3_t vSphereCenter, float fSphereRadiusSquared, const vec3_t vLinePt, const vec3_t vLineDir )
|
||||||
{
|
{
|
||||||
float a, b, c, insideSqr;
|
|
||||||
vec3_t p;
|
|
||||||
|
|
||||||
// translate sphere to origin.
|
// translate sphere to origin.
|
||||||
|
vec3_t p;
|
||||||
VectorSubtract( vLinePt, vSphereCenter, p );
|
VectorSubtract( vLinePt, vSphereCenter, p );
|
||||||
|
|
||||||
a = DotProduct( vLineDir, vLineDir );
|
float a = DotProduct( vLineDir, vLineDir );
|
||||||
b = 2.0f * DotProduct( p, vLineDir );
|
float b = 2.0f * DotProduct( p, vLineDir );
|
||||||
c = DotProduct( p, p ) - fSphereRadiusSquared;
|
float c = DotProduct( p, p ) - fSphereRadiusSquared;
|
||||||
|
|
||||||
insideSqr = b * b - 4.0f * a * c;
|
float insideSqr = b * b - 4.0f * a * c;
|
||||||
if( insideSqr <= 0.000001f )
|
if( insideSqr <= 0.000001f )
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -283,11 +272,10 @@ if not, reverse q
|
|||||||
static void QuaternionAlign( const vec4_t p, const vec4_t q, vec4_t qt )
|
static void QuaternionAlign( const vec4_t p, const vec4_t q, vec4_t qt )
|
||||||
{
|
{
|
||||||
// decide if one of the quaternions is backwards
|
// decide if one of the quaternions is backwards
|
||||||
float a = 0.0f;
|
float a = 0.0f;
|
||||||
float b = 0.0f;
|
float b = 0.0f;
|
||||||
int i;
|
|
||||||
|
|
||||||
for( i = 0; i < 4; i++ )
|
for( int i = 0; i < 4; i++ )
|
||||||
{
|
{
|
||||||
a += (p[i] - q[i]) * (p[i] - q[i]);
|
a += (p[i] - q[i]) * (p[i] - q[i]);
|
||||||
b += (p[i] + q[i]) * (p[i] + q[i]);
|
b += (p[i] + q[i]) * (p[i] + q[i]);
|
||||||
@@ -295,12 +283,12 @@ static void QuaternionAlign( const vec4_t p, const vec4_t q, vec4_t qt )
|
|||||||
|
|
||||||
if( a > b )
|
if( a > b )
|
||||||
{
|
{
|
||||||
for( i = 0; i < 4; i++ )
|
for( int i = 0; i < 4; i++ )
|
||||||
qt[i] = -q[i];
|
qt[i] = -q[i];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for( i = 0; i < 4; i++ )
|
for( int i = 0; i < 4; i++ )
|
||||||
qt[i] = q[i];
|
qt[i] = q[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,18 +300,16 @@ QuaternionSlerpNoAlign
|
|||||||
*/
|
*/
|
||||||
static void QuaternionSlerpNoAlign( const vec4_t p, const vec4_t q, float t, vec4_t qt )
|
static void QuaternionSlerpNoAlign( const vec4_t p, const vec4_t q, float t, vec4_t qt )
|
||||||
{
|
{
|
||||||
float omega, cosom, sinom, sclp, sclq;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// 0.0 returns p, 1.0 return q.
|
// 0.0 returns p, 1.0 return q.
|
||||||
cosom = p[0] * q[0] + p[1] * q[1] + p[2] * q[2] + p[3] * q[3];
|
float cosom = p[0] * q[0] + p[1] * q[1] + p[2] * q[2] + p[3] * q[3];
|
||||||
|
float sclp, sclq;
|
||||||
|
|
||||||
if(( 1.0f + cosom ) > 0.000001f )
|
if(( 1.0f + cosom ) > 0.000001f )
|
||||||
{
|
{
|
||||||
if(( 1.0f - cosom ) > 0.000001f )
|
if(( 1.0f - cosom ) > 0.000001f )
|
||||||
{
|
{
|
||||||
omega = acos( cosom );
|
float omega = acos( cosom );
|
||||||
sinom = sin( omega );
|
float sinom = sin( omega );
|
||||||
sclp = sin( (1.0f - t) * omega) / sinom;
|
sclp = sin( (1.0f - t) * omega) / sinom;
|
||||||
sclq = sin( t * omega ) / sinom;
|
sclq = sin( t * omega ) / sinom;
|
||||||
}
|
}
|
||||||
@@ -333,7 +319,7 @@ static void QuaternionSlerpNoAlign( const vec4_t p, const vec4_t q, float t, vec
|
|||||||
sclq = t;
|
sclq = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i = 0; i < 4; i++ )
|
for( int i = 0; i < 4; i++ )
|
||||||
{
|
{
|
||||||
qt[i] = sclp * p[i] + sclq * q[i];
|
qt[i] = sclp * p[i] + sclq * q[i];
|
||||||
}
|
}
|
||||||
@@ -347,7 +333,7 @@ static void QuaternionSlerpNoAlign( const vec4_t p, const vec4_t q, float t, vec
|
|||||||
sclp = sin(( 1.0f - t ) * ( 0.5f * M_PI_F ));
|
sclp = sin(( 1.0f - t ) * ( 0.5f * M_PI_F ));
|
||||||
sclq = sin( t * ( 0.5f * M_PI_F ));
|
sclq = sin( t * ( 0.5f * M_PI_F ));
|
||||||
|
|
||||||
for( i = 0; i < 3; i++ )
|
for( int i = 0; i < 3; i++ )
|
||||||
{
|
{
|
||||||
qt[i] = sclp * p[i] + sclq * qt[i];
|
qt[i] = sclp * p[i] + sclq * qt[i];
|
||||||
}
|
}
|
||||||
@@ -437,11 +423,9 @@ int BoxOnPlaneSide( const vec3_t emins, const vec3_t emaxs, const mplane_t *p )
|
|||||||
void R_StudioCalcBones( int frame, float s, const mstudiobone_t *pbone, const mstudioanim_t *panim, const float *adj, vec3_t pos, vec4_t q )
|
void R_StudioCalcBones( int frame, float s, const mstudiobone_t *pbone, const mstudioanim_t *panim, const float *adj, vec3_t pos, vec4_t q )
|
||||||
{
|
{
|
||||||
float v1[6], v2[6];
|
float v1[6], v2[6];
|
||||||
int i, max;
|
int max = q != NULL ? 6 : 3;
|
||||||
|
|
||||||
max = q != NULL ? 6 : 3;
|
for( int i = 0; i < max; i++ )
|
||||||
|
|
||||||
for( i = 0; i < max; i++ )
|
|
||||||
{
|
{
|
||||||
mstudioanimvalue_t *panimvalue = (mstudioanimvalue_t *)((byte *)panim + panim->offset[i] );
|
mstudioanimvalue_t *panimvalue = (mstudioanimvalue_t *)((byte *)panim + panim->offset[i] );
|
||||||
int j = frame;
|
int j = frame;
|
||||||
|
|||||||
Reference in New Issue
Block a user