sys_defines.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef SYS_DEFINES_H
  21. #define SYS_DEFINES_H
  22. /*
  23. ================================================================================================
  24. Platform Specific ID_ Defines
  25. The ID_ defines are the only platform defines we should be using.
  26. ================================================================================================
  27. */
  28. #undef ID_PC
  29. #undef ID_PC_WIN
  30. #undef ID_PC_WIN64
  31. #undef ID_CONSOLE
  32. #undef ID_WIN32
  33. #undef ID_LITTLE_ENDIAN
  34. #if defined(_WIN32)
  35. // _WIN32 always defined
  36. // _WIN64 also defined for x64 target
  37. /*
  38. #if !defined( _MANAGED )
  39. #if !defined( _WIN64 )
  40. #define ID_WIN_X86_ASM
  41. #define ID_WIN_X86_MMX_ASM
  42. #define ID_WIN_X86_MMX_INTRIN
  43. #define ID_WIN_X86_SSE_ASM
  44. #define ID_WIN_X86_SSE_INTRIN
  45. #define ID_WIN_X86_SSE2_ASM
  46. #define ID_WIN_X86_SSE2_INTRIN
  47. // the 32 bit build is now as close to the console builds as possible
  48. #define ID_CONSOLE
  49. #else
  50. #define ID_PC_WIN64
  51. #define ID_WIN_X86_MMX_INTRIN
  52. #define ID_WIN_X86_SSE_INTRIN
  53. #define ID_WIN_X86_SSE2_INTRIN
  54. #define ID_WIN_X86_SSE3_INTRIN
  55. #endif
  56. #endif
  57. */
  58. #define ID_PC
  59. #define ID_PC_WIN
  60. #define ID_WIN32
  61. #define ID_LITTLE_ENDIAN
  62. #else
  63. #error Unknown Platform
  64. #endif
  65. #define ID_OPENGL
  66. /*
  67. ================================================================================================
  68. PC Windows
  69. ================================================================================================
  70. */
  71. #ifdef ID_PC_WIN
  72. #define CPUSTRING "x86"
  73. #define BUILD_STRING "win-" CPUSTRING
  74. #define BUILD_OS_ID 0
  75. #define ALIGN16( x ) __declspec(align(16)) x
  76. #define ALIGNTYPE16 __declspec(align(16))
  77. #define ALIGNTYPE128 __declspec(align(128))
  78. #define FORMAT_PRINTF( x )
  79. #define PATHSEPARATOR_STR "\\"
  80. #define PATHSEPARATOR_CHAR '\\'
  81. #define NEWLINE "\r\n"
  82. #define ID_INLINE inline
  83. #define ID_FORCE_INLINE __forceinline
  84. // lint complains that extern used with definition is a hazard, but it
  85. // has the benefit (?) of making it illegal to take the address of the function
  86. #ifdef _lint
  87. #define ID_INLINE_EXTERN inline
  88. #define ID_FORCE_INLINE_EXTERN __forceinline
  89. #else
  90. #define ID_INLINE_EXTERN extern inline
  91. #define ID_FORCE_INLINE_EXTERN extern __forceinline
  92. #endif
  93. // we should never rely on this define in our code. this is here so dodgy external libraries don't get confused
  94. #ifndef WIN32
  95. #define WIN32
  96. #endif
  97. #endif
  98. /*
  99. ================================================================================================
  100. Defines and macros usable in all code
  101. ================================================================================================
  102. */
  103. #define ALIGN( x, a ) ( ( ( x ) + ((a)-1) ) & ~((a)-1) )
  104. #define _alloca16( x ) ((void *)ALIGN( (UINT_PTR)_alloca( ALIGN( x, 16 ) + 16 ), 16 ) )
  105. #define _alloca128( x ) ((void *)ALIGN( (UINT_PTR)_alloca( ALIGN( x, 128 ) + 128 ), 128 ) )
  106. #define likely( x ) ( x )
  107. #define unlikely( x ) ( x )
  108. // A macro to disallow the copy constructor and operator= functions
  109. // NOTE: The macro contains "private:" so all members defined after it will be private until
  110. // public: or protected: is specified.
  111. #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
  112. private: \
  113. TypeName(const TypeName&); \
  114. void operator=(const TypeName&);
  115. /*
  116. ================================================================================================
  117. Setup for /analyze code analysis, which we currently only have on the 360, but
  118. we may get later for win32 if we buy the higher end vc++ licenses.
  119. Even with VS2010 ultmate, /analyze only works for x86, not x64
  120. Also note the __analysis_assume macro in sys_assert.h relates to code analysis.
  121. This header should be included even by job code that doesn't reference the
  122. bulk of the codebase, so it is the best place for analyze pragmas.
  123. ================================================================================================
  124. */
  125. #if defined( ID_WIN32 )
  126. // disable some /analyze warnings here
  127. #pragma warning( disable: 6255 ) // warning C6255: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead. (Note: _malloca requires _freea.)
  128. #pragma warning( disable: 6262 ) // warning C6262: Function uses '36924' bytes of stack: exceeds /analyze:stacksize'32768'. Consider moving some data to heap
  129. #pragma warning( disable: 6326 ) // warning C6326: Potential comparison of a constant with another constant
  130. #pragma warning( disable: 6031 ) // warning C6031: Return value ignored
  131. // this warning fires whenever you have two calls to new in a function, but we assume new never fails, so it is not relevant for us
  132. #pragma warning( disable: 6211 ) // warning C6211: Leaking memory 'staticModel' due to an exception. Consider using a local catch block to clean up memory
  133. // we want to fix all these at some point...
  134. #pragma warning( disable: 6246 ) // warning C6246: Local declaration of 'es' hides declaration of the same name in outer scope. For additional information, see previous declaration at line '969' of 'w:\tech5\rage\game\ai\fsm\fsm_combat.cpp': Lines: 969
  135. #pragma warning( disable: 6244 ) // warning C6244: Local declaration of 'viewList' hides previous declaration at line '67' of 'w:\tech5\engine\renderer\rendertools.cpp'
  136. // win32 needs this, but 360 doesn't
  137. #pragma warning( disable: 6540 ) // warning C6540: The use of attribute annotations on this function will invalidate all of its existing __declspec annotations [D:\tech5\engine\engine-10.vcxproj]
  138. // checking format strings catches a LOT of errors
  139. #include <CodeAnalysis\SourceAnnotations.h>
  140. #define VERIFY_FORMAT_STRING [SA_FormatString(Style="printf")]
  141. // We need to inform the compiler that Error() and FatalError() will
  142. // never return, so any conditions that leeds to them being called are
  143. // guaranteed to be false in the following code
  144. #define NO_RETURN __declspec(noreturn)
  145. #endif
  146. // I don't want to disable "warning C6031: Return value ignored" from /analyze
  147. // but there are several cases with sprintf where we pre-initialized the variables
  148. // being scanned into, so we truly don't care if they weren't all scanned.
  149. // Rather than littering #pragma statements around these cases, we can assign the
  150. // return value to this, which means we have considered the issue and decided that
  151. // it doesn't require action.
  152. // The volatile qualifier is to prevent:PVS-Studio warnings like:
  153. // False 2 4214 V519 The 'ignoredReturnValue' object is assigned values twice successively. Perhaps this is a mistake. Check lines: 545, 547. Rage collisionmodelmanager_debug.cpp 547 False
  154. extern volatile int ignoredReturnValue;
  155. #define MAX_TYPE( x ) ( ( ( ( 1 << ( ( sizeof( x ) - 1 ) * 8 - 1 ) ) - 1 ) << 8 ) | 255 )
  156. #define MIN_TYPE( x ) ( - MAX_TYPE( x ) - 1 )
  157. #define MAX_UNSIGNED_TYPE( x ) ( ( ( ( 1U << ( ( sizeof( x ) - 1 ) * 8 ) ) - 1 ) << 8 ) | 255U )
  158. #define MIN_UNSIGNED_TYPE( x ) 0
  159. #endif