irrTypes.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef IRR_TYPES_H_INCLUDED
  5. #define IRR_TYPES_H_INCLUDED
  6. #include "IrrCompileConfig.h"
  7. #if defined(__GNUC__)
  8. // For __WORDSIZE (which we maybe don't even need anymore with LP64 checks now)
  9. #include <limits.h>
  10. #endif
  11. namespace irr
  12. {
  13. //! 8 bit unsigned variable.
  14. /** This is a typedef for unsigned char, it ensures portability of the engine. */
  15. #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))
  16. typedef unsigned __int8 u8;
  17. #else
  18. typedef unsigned char u8;
  19. #endif
  20. //! 8 bit signed variable.
  21. /** This is a typedef for signed char, it ensures portability of the engine. */
  22. #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))
  23. typedef __int8 s8;
  24. #else
  25. typedef signed char s8;
  26. #endif
  27. //! 8 bit character variable.
  28. /** This is a typedef for char, it ensures portability of the engine. */
  29. typedef char c8;
  30. //! 16 bit unsigned variable.
  31. /** This is a typedef for unsigned short, it ensures portability of the engine. */
  32. #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))
  33. typedef unsigned __int16 u16;
  34. #else
  35. typedef unsigned short u16;
  36. #endif
  37. //! 16 bit signed variable.
  38. /** This is a typedef for signed short, it ensures portability of the engine. */
  39. #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))
  40. typedef __int16 s16;
  41. #else
  42. typedef signed short s16;
  43. #endif
  44. //! 32 bit unsigned variable.
  45. /** This is a typedef for unsigned int, it ensures portability of the engine. */
  46. #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))
  47. typedef unsigned __int32 u32;
  48. #else
  49. typedef unsigned int u32;
  50. #endif
  51. //! 32 bit signed variable.
  52. /** This is a typedef for signed int, it ensures portability of the engine. */
  53. #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))
  54. typedef __int32 s32;
  55. #else
  56. typedef signed int s32;
  57. #endif
  58. #ifdef __IRR_HAS_S64
  59. //! 64 bit unsigned variable.
  60. /** This is a typedef for 64bit uint, it ensures portability of the engine. */
  61. #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))
  62. typedef unsigned __int64 u64;
  63. #elif defined(__GNUC__)
  64. #if (defined(__LP64__) && __LP64__ == 1) || (defined(_LP64) && _LP64 == 1) || (defined(__WORDSIZE) && __WORDSIZE == 64)
  65. typedef unsigned long int u64;
  66. #else
  67. __extension__ typedef unsigned long long u64;
  68. #endif
  69. #else
  70. typedef unsigned long long u64;
  71. #endif
  72. //! 64 bit signed variable.
  73. /** This is a typedef for 64bit int, it ensures portability of the engine. */
  74. #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))
  75. typedef __int64 s64;
  76. #elif defined(__GNUC__)
  77. #if (defined(__LP64__) && __LP64__ == 1) || (defined(_LP64) && _LP64 == 1) || (defined(__WORDSIZE) && __WORDSIZE == 64)
  78. typedef long int s64;
  79. #else
  80. __extension__ typedef long long s64;
  81. #endif
  82. #else
  83. typedef long long s64;
  84. #endif
  85. #endif // __IRR_HAS_S64
  86. //! 32 bit floating point variable.
  87. /** This is a typedef for float, it ensures portability of the engine. */
  88. typedef float f32;
  89. //! 64 bit floating point variable.
  90. /** This is a typedef for double, it ensures portability of the engine. */
  91. typedef double f64;
  92. } // end namespace irr
  93. #include <wchar.h>
  94. #ifdef _IRR_WINDOWS_API_
  95. //! Defines for s{w,n}printf_irr because s{w,n}printf methods do not match the ISO C
  96. //! standard on Windows platforms.
  97. //! We want int snprintf_irr(char *str, size_t size, const char *format, ...);
  98. //! and int swprintf_irr(wchar_t *wcs, size_t maxlen, const wchar_t *format, ...);
  99. #if defined(_MSC_VER) && _MSC_VER > 1310 && !defined (_WIN32_WCE)
  100. #define swprintf_irr swprintf_s
  101. #define snprintf_irr sprintf_s
  102. #elif !defined(__CYGWIN__)
  103. #define swprintf_irr _snwprintf
  104. #define snprintf_irr _snprintf
  105. #endif
  106. // define the wchar_t type if not already built in.
  107. // It's usually set when VS compiler sets /Zc:wchar_t
  108. #ifdef _MSC_VER
  109. #ifndef _WCHAR_T_DEFINED
  110. //! A 16 bit wide character type.
  111. /**
  112. Defines the wchar_t-type.
  113. In VS6, its not possible to tell
  114. the standard compiler to treat wchar_t as a built-in type, and
  115. sometimes we just don't want to include the huge stdlib.h or wchar.h,
  116. so we'll use this.
  117. */
  118. typedef unsigned short wchar_t;
  119. #define _WCHAR_T_DEFINED
  120. #endif // wchar is not defined
  121. #endif // microsoft compiler
  122. #else
  123. #define swprintf_irr swprintf
  124. #define snprintf_irr snprintf
  125. #endif // _IRR_WINDOWS_API_
  126. namespace irr
  127. {
  128. //! Type name for character type used by the filesystem.
  129. /** Should the wide character version of the filesystem be used it is a
  130. 16 bit character variable. Used for Unicode filesystem and Unicode strings.
  131. Else it is a 8 bit character variable. Used for ansi filesystem and non-unicode
  132. strings
  133. */
  134. #if defined(_IRR_WCHAR_FILESYSTEM)
  135. typedef wchar_t fschar_t;
  136. #define IRR_TEXT(X) L##X
  137. #else
  138. typedef char fschar_t;
  139. #define IRR_TEXT(X) X
  140. #endif
  141. } // end namespace irr
  142. //! define a break macro for debugging.
  143. #if defined(_DEBUG)
  144. #if defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) && !defined (_WIN32_WCE)
  145. #if defined(WIN64) || defined(_WIN64) // using portable common solution for x64 configuration
  146. #include <crtdbg.h>
  147. #define IRR_DEBUG_BREAK_IF( _CONDITION_ ) if (_CONDITION_) {_CrtDbgBreak();}
  148. #else
  149. #define IRR_DEBUG_BREAK_IF( _CONDITION_ ) if (_CONDITION_) {_asm int 3}
  150. #endif
  151. #else
  152. #include "assert.h"
  153. #define IRR_DEBUG_BREAK_IF( _CONDITION_ ) assert( !(_CONDITION_) );
  154. #endif
  155. #else
  156. #define IRR_DEBUG_BREAK_IF( _CONDITION_ )
  157. #endif
  158. //! Defines a deprecated macro which generates a warning at compile time
  159. /** The usage is simple
  160. For typedef: typedef IRR_DEPRECATED int test1;
  161. For classes/structs: class IRR_DEPRECATED test2 { ... };
  162. For methods: class test3 { IRR_DEPRECATED virtual void foo() {} };
  163. For functions: template<class T> IRR_DEPRECATED void test4(void) {}
  164. **/
  165. #if defined(IGNORE_DEPRECATED_WARNING)
  166. #define IRR_DEPRECATED
  167. #elif _MSC_VER >= 1310 //vs 2003 or higher
  168. #define IRR_DEPRECATED __declspec(deprecated)
  169. #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) // all versions above 3.0 should support this feature
  170. #define IRR_DEPRECATED __attribute__ ((deprecated))
  171. #else
  172. #define IRR_DEPRECATED
  173. #endif
  174. //! Defines an override macro, to protect virtual functions from typos and other mismatches
  175. /** Usage in a derived class:
  176. virtual void somefunc() IRR_OVERRIDE;
  177. */
  178. #if ( ((__GNUC__ > 4 ) || ((__GNUC__ == 4 ) && (__GNUC_MINOR__ >= 7))) && (defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L) )
  179. #define IRR_OVERRIDE override
  180. #elif (_MSC_VER >= 1600 ) /* supported since MSVC 2010 */
  181. #define IRR_OVERRIDE override
  182. #elif (__clang_major__ >= 3 && __has_feature(cxx_override_control))
  183. #define IRR_OVERRIDE override
  184. #else
  185. #define IRR_OVERRIDE
  186. #endif
  187. // memory debugging
  188. #if defined(_DEBUG) && defined(IRRLICHT_EXPORTS) && defined(_MSC_VER) && \
  189. (_MSC_VER > 1299) && !defined(IRR_DONT_DO_MEMORY_DEBUGGING_HERE) && !defined(_WIN32_WCE)
  190. #define CRTDBG_MAP_ALLOC
  191. #define _CRTDBG_MAP_ALLOC
  192. #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
  193. #include <stdlib.h>
  194. #include <crtdbg.h>
  195. #define new DEBUG_CLIENTBLOCK
  196. #endif
  197. //! ignore VC8 warning deprecated
  198. /** The Microsoft compiler */
  199. #if defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) && (_MSC_VER >= 1400)
  200. //#pragma warning( disable: 4996)
  201. //#define _CRT_SECURE_NO_DEPRECATE 1
  202. //#define _CRT_NONSTDC_NO_DEPRECATE 1
  203. #endif
  204. //! creates four CC codes used in Irrlicht for simple ids
  205. /** some compilers can create those by directly writing the
  206. code like 'code', but some generate warnings so we use this macro here */
  207. #define MAKE_IRR_ID(c0, c1, c2, c3) \
  208. ((irr::u32)(irr::u8)(c0) | ((irr::u32)(irr::u8)(c1) << 8) | \
  209. ((irr::u32)(irr::u8)(c2) << 16) | ((irr::u32)(irr::u8)(c3) << 24 ))
  210. #endif // IRR_TYPES_H_INCLUDED