/****************************************************************************** libx42 - skinned vertex animation library Copyright (C) 2007 HermitWorks Entertainment Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA. ******************************************************************************/ #ifndef INC_COMMON_H #define INC_COMMON_H #if _MSC_VER >= 1400 #define _CRT_SECURE_NO_DEPRECATE #endif #include #include #include #include "libx42_setup.h" #include "include/x42.h" #ifdef LIBX42_NO_MATH_F //so far we just use sqrtf #define sqrtf( x ) (float)sqrt( x ) #endif typedef unsigned char byte; #define X42_RF_LOAD_SWAPPED 0x0001 #ifdef __cplusplus #define X42_CONST_CAST( T, v ) const_cast< T* >( v ) #else #define X42_CONST_CAST( T, v ) ((T*)(v)) #endif #ifdef _MSC_VER #define INLINE static __inline #define ALWAYS_INLINE static __forceinline #define REF_PARAM( x ) (void)sizeof( x ) #if _MSC_VER >= 1400 #define RESTRICT __restrict #define NOGLOBALALIAS __declspec( noalias ) #else #define RESTRICT #define NOGLOBALALIAS #endif #define NO_DEFAULT default: __assume( 0 ); break; #else #include #define INLINE static #define ALWAYS_INLINE static #define REF_PARAM( x ) (x) = (x) #define RESTRICT #define NOGLOBALALIAS #define NO_DEFAULT default: break; #define _alloca(X) alloca(X) #endif #define lengthof( x ) (sizeof( x ) / sizeof( (x)[0] )) INLINE intptr_t align( intptr_t s, intptr_t a ) { return s + ((a - (s % a)) % a); } #define align_ptr( s, a ) (byte*)align( (intptr_t)(s), (intptr_t)(a) ) #define is_aligned( p, a ) (((intptr_t)(p) % a) == 0) //util NOGLOBALALIAS bool x42name_eq( const x42data_t *x42, x42NameIndex_t a, x42NameIndex_t b ); NOGLOBALALIAS bool x42name_eq2( const x42data_t *x42, x42NameIndex_t a, const char *b ); #include "math-util.h" #include "memstream.h" //optimized code paths bool opt_SkinGroupVerts( x42memStream_t *oPos, x42memStream_t *oNorm, x42memStream_t *oTan, x42memStream_t *oBin, const x42data_t *x42, uint groupNum, const affine_t *boneMats, x42opts_t *opts ); bool opt_CopyStreamToStream( x42memStream_t *dest, x42memStream_t *src, size_t elemSize, uint numElems, x42opts_t *opts ); /* Shuts up MSVC's "constant conditional expression" warning and compiles away in release builds. */ #define const_cond_false (true,false) #define fail_r( code, msg ) if( !const_cond_false ) { LIBX42_ERROR_EVENT( code, msg ); return; } else return #define fail_rn( code, msg ) if( !const_cond_false ) { LIBX42_ERROR_EVENT( code, msg ); return NULL; } return NULL #define fail_rz( code, msg ) if( !const_cond_false ) { LIBX42_ERROR_EVENT( code, msg ); return 0; } else return 0 #define fail_rf( code, msg ) if( !const_cond_false ) { LIBX42_ERROR_EVENT( code, msg ); return false; } else return false #define fail_rv( code, msg, v ) if( !const_cond_false ) { LIBX42_ERROR_EVENT( code, msg ); return (v); } else return (v) #define demand_r( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return; } else (void)0 #define demand_rn( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return NULL; } else (void)0 #define demand_rz( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return 0; } else (void)0 #define demand_rf( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return false; } else (void)0 #define demand_rv( cond, code, msg, v ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return (v); } else (void)0 #ifdef DEBUG #define assert( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); /* force a crash! */ *(int*)0 = 1; } else (void)0 #else #define assert( cond, code, msg ) if( !const_cond_false ) { (void)sizeof( cond ); } else (void)0 #endif #endif