Tizen 2.1 base
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / Ice / IceTypes.h
1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 /**
3  *      Contains custom types.
4  *      \file           IceTypes.h
5  *      \author         Pierre Terdiman
6  *      \date           April, 4, 2000
7  */
8 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9
10 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11 // Include Guard
12 #ifndef ICETYPES_H
13 #define ICETYPES_H
14
15         #define USE_HANDLE_MANAGER
16
17         // Constants
18 #ifndef PI
19         #define PI                                      3.1415926535897932384626433832795028841971693993751f    //!< PI
20 #endif
21         #define HALFPI                          1.57079632679489661923f                                                                 //!< 0.5 * PI
22         #define TWOPI                           6.28318530717958647692f                                                                 //!< 2.0 * PI
23         #define INVPI                           0.31830988618379067154f                                                                 //!< 1.0 / PI
24
25         #define RADTODEG                        57.2957795130823208768f                                                                 //!< 180.0 / PI, convert radians to degrees
26         #define DEGTORAD                        0.01745329251994329577f                                                                 //!< PI / 180.0, convert degrees to radians
27
28         #define EXP                                     2.71828182845904523536f                                                                 //!< e
29         #define INVLOG2                         3.32192809488736234787f                                                                 //!< 1.0 / log10(2)
30         #define LN2                                     0.693147180559945f                                                                              //!< ln(2)
31         #define INVLN2                          1.44269504089f                                                                                  //!< 1.0f / ln(2)
32
33         #define INV3                            0.33333333333333333333f                                                                 //!< 1/3
34         #define INV6                            0.16666666666666666666f                                                                 //!< 1/6
35         #define INV7                            0.14285714285714285714f                                                                 //!< 1/7
36         #define INV9                            0.11111111111111111111f                                                                 //!< 1/9
37         #define INV255                          0.00392156862745098039f                                                                 //!< 1/255
38
39         #define SQRT2                           1.41421356237f                                                                                  //!< sqrt(2)
40         #define INVSQRT2                        0.707106781188f                                                                                 //!< 1 / sqrt(2)
41
42         #define SQRT3                           1.73205080757f                                                                                  //!< sqrt(3)
43         #define INVSQRT3                        0.577350269189f                                                                                 //!< 1 / sqrt(3)
44
45         #define null                            0                                                                                                               //!< our own NULL pointer
46
47         // Custom types used in ICE
48         typedef signed char                     sbyte;          //!< sizeof(sbyte)              must be 1
49         typedef unsigned char           ubyte;          //!< sizeof(ubyte)              must be 1
50         typedef signed short            sword;          //!< sizeof(sword)              must be 2
51         typedef unsigned short          uword;          //!< sizeof(uword)              must be 2
52         typedef signed int                      sdword;         //!< sizeof(sdword)             must be 4
53         typedef unsigned int            udword;         //!< sizeof(udword)             must be 4
54 #ifdef WIN32
55         typedef signed __int64          sqword;         //!< sizeof(sqword)             must be 8
56         typedef unsigned __int64        uqword;         //!< sizeof(uqword)             must be 8
57 #elif LINUX
58         typedef signed long long        sqword;         //!< sizeof(sqword)             must be 8
59         typedef unsigned long long      uqword;         //!< sizeof(uqword)             must be 8
60 #elif defined(__APPLE__)
61         typedef signed long long        sqword;         //!< sizeof(sqword)             must be 8
62         typedef unsigned long long      uqword;         //!< sizeof(uqword)             must be 8
63 #elif defined(_XBOX)
64         typedef signed __int64          sqword;         //!< sizeof(sqword)             must be 8
65         typedef unsigned __int64        uqword;         //!< sizeof(uqword)             must be 8
66 #endif
67         typedef float                           float32;        //!< sizeof(float32)    must be 4
68         typedef double                          float64;        //!< sizeof(float64)    must be 8
69         typedef size_t                          regsize;        //!< sizeof(regsize)    must be sizeof(void*)
70
71         // For test purpose you can force one of those:
72 //      typedef udword                          regsize;
73 //      typedef uqword                          regsize;
74
75         ICE_COMPILE_TIME_ASSERT(sizeof(bool)==1);       // ...otherwise things might fail with VC++ 4.2 !
76         ICE_COMPILE_TIME_ASSERT(sizeof(ubyte)==1);
77         ICE_COMPILE_TIME_ASSERT(sizeof(sbyte)==1);
78         ICE_COMPILE_TIME_ASSERT(sizeof(sword)==2);
79         ICE_COMPILE_TIME_ASSERT(sizeof(uword)==2);
80         ICE_COMPILE_TIME_ASSERT(sizeof(udword)==4);
81         ICE_COMPILE_TIME_ASSERT(sizeof(sdword)==4);
82         ICE_COMPILE_TIME_ASSERT(sizeof(uqword)==8);
83         ICE_COMPILE_TIME_ASSERT(sizeof(sqword)==8);
84         ICE_COMPILE_TIME_ASSERT(sizeof(float32)==4);
85         ICE_COMPILE_TIME_ASSERT(sizeof(float64)==8);
86         ICE_COMPILE_TIME_ASSERT(sizeof(regsize)==sizeof(void*));
87
88         //! TO BE DOCUMENTED
89         #define DECLARE_ICE_HANDLE(name)        struct name##__ { int unused; }; typedef struct name##__ *name
90
91         typedef udword                          DynID;          //!< Dynamic identifier
92 #ifdef USE_HANDLE_MANAGER
93         typedef udword                          KID;            //!< Kernel ID
94 //      DECLARE_ICE_HANDLE(KID);
95 #else
96         typedef uword                           KID;            //!< Kernel ID
97 #endif
98         #define INVALID_ID                      0xffffffff      //!< Invalid dword ID (counterpart of null pointers)
99 #ifdef USE_HANDLE_MANAGER
100         #define INVALID_KID                     0xffffffff      //!< Invalid Kernel ID
101 #else
102         #define INVALID_KID                     0xffff          //!< Invalid Kernel ID
103 #endif
104         #define INVALID_NUMBER          0xDEADBEEF      //!< Standard junk value
105
106         // Define BOOL if needed
107         #ifndef BOOL
108         typedef int     BOOL;                                           //!< Another boolean type.
109         #endif
110
111         //! Union of a float and a sdword
112         typedef union {
113                 float   f;                                                      //!< The float
114                 sdword  d;                                                      //!< The integer
115         }scell;
116
117         //! Union of a float and a udword
118         typedef union {
119                 float   f;                                                      //!< The float
120                 udword  d;                                                      //!< The integer
121         }ucell;
122
123         // Type ranges
124         #define MAX_SBYTE                               0x7f                                            //!< max possible sbyte value
125         #define MIN_SBYTE                               0x80                                            //!< min possible sbyte value
126         #define MAX_UBYTE                               0xff                                            //!< max possible ubyte value
127         #define MIN_UBYTE                               0x00                                            //!< min possible ubyte value
128         #define MAX_SWORD                               0x7fff                                          //!< max possible sword value
129         #define MIN_SWORD                               0x8000                                          //!< min possible sword value
130         #define MAX_UWORD                               0xffff                                          //!< max possible uword value
131         #define MIN_UWORD                               0x0000                                          //!< min possible uword value
132         #define MAX_SDWORD                              0x7fffffff                                      //!< max possible sdword value
133         #define MIN_SDWORD                              0x80000000                                      //!< min possible sdword value
134         #define MAX_UDWORD                              0xffffffff                                      //!< max possible udword value
135         #define MIN_UDWORD                              0x00000000                                      //!< min possible udword value
136         #define MAX_FLOAT                               FLT_MAX                                         //!< max possible float value
137         #define MIN_FLOAT                               (-FLT_MAX)                                      //!< min possible loat value
138         #define IEEE_1_0                                0x3f800000                                      //!< integer representation of 1.0
139         #define IEEE_255_0                              0x437f0000                                      //!< integer representation of 255.0
140         #define IEEE_MAX_FLOAT                  0x7f7fffff                                      //!< integer representation of MAX_FLOAT
141         #define IEEE_MIN_FLOAT                  0xff7fffff                                      //!< integer representation of MIN_FLOAT
142         #define IEEE_UNDERFLOW_LIMIT    0x1a000000
143
144         #define ONE_OVER_RAND_MAX               (1.0f / float(RAND_MAX))        //!< Inverse of the max possible value returned by rand()
145
146         typedef void**                                  VTABLE;                                         //!< A V-Table.
147
148         #undef          MIN
149         #undef          MAX
150         #define         MIN(a, b)       ((a) < (b) ? (a) : (b))                 //!< Returns the min value between a and b
151         #define         MAX(a, b)       ((a) > (b) ? (a) : (b))                 //!< Returns the max value between a and b
152         #define         MAXMAX(a,b,c)   ((a) > (b) ? MAX (a,c) : MAX (b,c))     //!<    Returns the max value between a, b and c
153
154         template<class T>       inline_ const T&        TMin    (const T& a, const T& b)        { return b < a ? b : a; }
155         template<class T>       inline_ const T&        TMax    (const T& a, const T& b)        { return a < b ? b : a; }
156         template<class T>       inline_ void            TSetMin (T& a, const T& b)                      { if(a>b)       a = b;          }
157         template<class T>       inline_ void            TSetMax (T& a, const T& b)                      { if(a<b)       a = b;          }
158
159 /* Obsolete stuff - if needed, move to dedicated header and include in few files using this.
160         #define         SQR(x)                  ((x)*(x))                                               //!< Returns x square
161         #define         CUBE(x)                 ((x)*(x)*(x))                                   //!< Returns x cube
162
163         #define         AND             &                                                                               //!< ...
164         #define         OR              |                                                                               //!< ...
165         #define         XOR             ^                                                                               //!< ...
166
167         #define         QUADRAT(x)              ((x)*(x))                                               //!< Returns x square
168
169         typedef int                                     (__stdcall* PROC)();                    //!< A standard procedure call.
170         typedef bool                            (*ENUMERATION)(udword value, udword param, udword context);     //!< ICE standard enumeration call
171
172 #ifdef _WIN32
173         // Used to compile legacy code
174         __forceinline   void    srand48(udword x)       { srand(x);                                                                                                             }
175         __forceinline   void    srandom(udword x)       { srand(x);                                                                                                             }
176         __forceinline   double  random()                        { return (double)rand();                                                                                }
177         __forceinline   double  drand48()                       { return (double) ( ((double)rand()) / ((double)RAND_MAX) );    }
178 #endif
179 */
180
181 #endif // ICETYPES_H