BFPlatform.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #pragma once
  2. #ifndef NOMINMAX
  3. #define NOMINMAX
  4. #endif
  5. #if (defined __MINGW32__) && (!defined BF_MINGW)
  6. #define BF_MINGW
  7. #endif
  8. #define WIN32_LEAN_AND_MEAN
  9. #define BF_PLATFORM_WINDOWS
  10. #define BF_PLATFORM_NAME "BF_PLATFORM_WINDOWS"
  11. #ifdef BF_MINGW
  12. #pragma clang diagnostic ignored "-Wunused-variable"
  13. #pragma clang diagnostic ignored "-Wunknown-pragmas"
  14. #pragma clang diagnostic ignored "-Wunused-function"
  15. #pragma clang diagnostic ignored "-Wunknown-attributes"
  16. #pragma clang diagnostic ignored "-Wunused-member-function"
  17. #pragma clang diagnostic ignored "-Wunused-conversion-function"
  18. #pragma clang diagnostic ignored "-Wunused-private-field"
  19. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  20. #else
  21. #define BF_VC
  22. #endif
  23. #include <windows.h>
  24. #include <assert.h>
  25. #include <stdint.h>
  26. #include <assert.h>
  27. #include <wtypes.h>
  28. #define DIR_SEP_CHAR '\\'
  29. #define DIR_SEP_CHAR_ALT '/'
  30. #ifndef BF_NO_FFI
  31. extern "C"
  32. {
  33. #define FFI_BUILDING
  34. #include "libffi/i686-pc-cygwin/include/ffi.h"
  35. }
  36. #endif
  37. //#define BF_FORCE_SDL
  38. #ifdef SDL_FORCE_OPENGL_ES2
  39. #define BF_PLATFORM_OPENGL_ES2
  40. #endif
  41. #if (_MSC_VER == 1800) && (!defined BFSYSLIB_STATIC)
  42. #define BF_WWISE_ENABLED
  43. #endif
  44. #define CPP11
  45. #ifdef _DEBUG
  46. #define BF_DEBUG
  47. //#define DEBUG
  48. #endif
  49. #ifdef BF_MINGW
  50. #define NOP asm volatile("nop");
  51. extern "C" _CRTIMP int __cdecl __MINGW_NOTHROW _stricmp (const char*, const char*);
  52. #elif defined _WIN64
  53. #define BF64
  54. #define NOP GetTickCount()
  55. #else
  56. #define BF32
  57. #define NOP __asm nop;
  58. #endif
  59. #define BF_HAS_TLS_DECLSPEC
  60. #ifdef BF_MINGW
  61. #define BF_TLS_DECLSPEC __thread
  62. #else
  63. #define BF_TLS_DECLSPEC __declspec(thread)
  64. #endif
  65. #if defined _DEBUG || defined BF_DEBUG_ASSERTS
  66. #define BF_ASSERT(_Expression) (void)( (!!(_Expression)) || (Beefy::BFFatalError(#_Expression, __FILE__, __LINE__), 0) )
  67. #else
  68. #define BF_ASSERT(_Expression) (void)(0)
  69. #endif
  70. #define BF_ASSERT_REL(_Expression) (void)( (!!(_Expression)) || (Beefy::BFFatalError(#_Expression, __FILE__, __LINE__), 0) )
  71. #define BF_FATAL(msg) (void) ((Beefy::BFFatalError(msg, __FILE__, __LINE__), 0) )
  72. #if defined _DEBUG || defined BF_DEBUG_ASSERTS
  73. #define BF_DBG_FATAL(msg) (void) ((Beefy::BFFatalError(msg, __FILE__, __LINE__), 0) )
  74. #else
  75. #define BF_DBG_FATAL(msg)
  76. #endif
  77. #define BFSTDCALL __stdcall
  78. #define BF_IMPORT extern "C" __declspec(dllimport)
  79. #ifdef BFSYSLIB_DYNAMIC
  80. #define BF_EXPORT extern "C" __declspec(dllexport)
  81. #define BF_CALLTYPE __stdcall
  82. #ifdef BFP_NOEXPORT
  83. #define BFP_EXPORT extern "C"
  84. #define BFP_CALLTYPE __stdcall
  85. #endif
  86. #else
  87. #define BF_EXPORT extern "C"
  88. #define BF_CALLTYPE __stdcall
  89. #endif
  90. #define BF_NOINLINE __declspec(noinline)
  91. #define BF_NAKED __declspec(naked)
  92. #define BF_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
  93. #define BF_ALIGNED(x) __declspec(align(x))
  94. #ifndef BF_MINGW
  95. #define strtoull _strtoui64
  96. #endif
  97. //#define snprintf _snprintf
  98. #define __func__ __FUNCTION__
  99. typedef uint64_t uint64;
  100. typedef uint32_t uint32;
  101. typedef uint16_t uint16;
  102. typedef uint8_t uint8;
  103. typedef int64_t int64;
  104. typedef int32_t int32;
  105. typedef int16_t int16;
  106. typedef int8_t int8;
  107. typedef unsigned int uint;
  108. typedef intptr_t intptr;
  109. typedef uintptr_t uintptr;
  110. typedef DWORD BF_THREADID;
  111. typedef HANDLE BF_THREADHANDLE;
  112. #ifdef BF_MINGW
  113. #define BF_COMPILER_FENCE() __asm__ __volatile__("mfence" : : : "memory");
  114. #define BF_FULL_MEMORY_FENCE() __asm__ __volatile__("mfence" : : : "memory");
  115. #define BF_SPINWAIT_NOP() __asm__ __volatile__( "pause;" )
  116. #define BF_DEBUG_BREAK() __asm__ __volatile__( "int $0x03;" )
  117. #else
  118. #define BF_COMPILER_FENCE() _ReadWriteBarrier()
  119. //#define BF_FULL_MEMORY_FENCE() __asm { lock add dword ptr [esp],0 }
  120. #ifdef BF32
  121. #define BF_FULL_MEMORY_FENCE() ::MemoryBarrier()
  122. #else
  123. #define BF_FULL_MEMORY_FENCE() _mm_mfence()
  124. #endif
  125. //#define BF_SPINWAIT_NOP() _asm { pause }
  126. #define BF_SPINWAIT_NOP() _mm_pause()
  127. #define BF_DEBUG_BREAK() DebugBreak()
  128. #endif
  129. typedef DWORD BfTLSKey;
  130. #define BfTLSGetValue ::TlsGetValue
  131. #define BfTLSSetValue ::TlsSetValue
  132. #define BfTLSAlloc ::TlsAlloc
  133. #define BfTLSFree ::TlsFree
  134. #define BF_THREAD_YIELD() ::SwitchToThread()
  135. #define BF_UNUSED
  136. #define BF_EXPLICIT explicit
  137. #define BF_ENDIAN_LITTLE
  138. #define WaitForSingleObject_Thread WaitForSingleObject
  139. #define CloseHandle_File CloseHandle
  140. #define CloseHandle_Event CloseHandle
  141. #define CloseHandle_Thread CloseHandle
  142. #define CloseHandle_Process CloseHandle
  143. #ifdef BF32
  144. #define BF_REGISTER_COUNT 7
  145. #else
  146. #define BF_REGISTER_COUNT 15
  147. #endif
  148. #ifndef BF_MINGW
  149. #define __thread __declspec(thread)
  150. #endif
  151. #ifdef BF_MINGW
  152. //
  153. #else
  154. #define strcasecmp stricmp
  155. #endif
  156. struct BfpEvent
  157. {
  158. CRITICAL_SECTION mCritSect;
  159. CONDITION_VARIABLE mCondVariable;
  160. bool mSet;
  161. bool mManualReset;
  162. };
  163. #include "../PlatformInterface.h"