Common.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // Copyright 2008 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #ifndef __has_feature
  9. #define __has_feature(x) 0
  10. #endif
  11. // Git version number
  12. extern const char *scm_desc_str;
  13. extern const char *scm_branch_str;
  14. extern const char *scm_rev_str;
  15. extern const char *scm_rev_git_str;
  16. extern const char *netplay_dolphin_ver;
  17. // Force enable logging in the right modes. For some reason, something had changed
  18. // so that debugfast no longer logged.
  19. #if defined(_DEBUG) || defined(DEBUGFAST)
  20. #undef LOGGING
  21. #define LOGGING 1
  22. #endif
  23. #if defined(__GNUC__) || __clang__
  24. // Disable "unused function" warnings for the ones manually marked as such.
  25. #define UNUSED __attribute__((unused))
  26. #else
  27. // Not sure MSVC even checks this...
  28. #define UNUSED
  29. #endif
  30. #if defined(__GNUC__) || __clang__
  31. #define EXPECT(x, y) __builtin_expect(x, y)
  32. #define LIKELY(x) __builtin_expect(!!(x), 1)
  33. #define UNLIKELY(x) __builtin_expect(!!(x), 0)
  34. // Careful, wrong assumptions result in undefined behavior!
  35. #define UNREACHABLE __builtin_unreachable()
  36. // Careful, wrong assumptions result in undefined behavior!
  37. #define ASSUME(x) do { if (!x) __builtin_unreachable(); } while (0)
  38. #else
  39. #define EXPECT(x, y) (x)
  40. #define LIKELY(x) (x)
  41. #define UNLIKELY(x) (x)
  42. // Careful, wrong assumptions result in undefined behavior!
  43. #define UNREACHABLE ASSUME(0)
  44. #if defined(_MSC_VER)
  45. // Careful, wrong assumptions result in undefined behavior!
  46. #define ASSUME(x) __assume(x)
  47. #else
  48. #define ASSUME(x) do { void(x); } while (0)
  49. #endif
  50. #endif
  51. // An inheritable class to disallow the copy constructor and operator= functions
  52. class NonCopyable
  53. {
  54. protected:
  55. NonCopyable() {}
  56. NonCopyable(const NonCopyable&&) {}
  57. void operator=(const NonCopyable&&) {}
  58. private:
  59. NonCopyable(NonCopyable&);
  60. NonCopyable& operator=(NonCopyable& other);
  61. };
  62. #if defined _WIN32
  63. // Memory leak checks
  64. #define CHECK_HEAP_INTEGRITY()
  65. // Alignment
  66. #define GC_ALIGNED16(x) __declspec(align(16)) x
  67. #define GC_ALIGNED32(x) __declspec(align(32)) x
  68. #define GC_ALIGNED64(x) __declspec(align(64)) x
  69. #define GC_ALIGNED128(x) __declspec(align(128)) x
  70. #define GC_ALIGNED16_DECL(x) __declspec(align(16)) x
  71. #define GC_ALIGNED64_DECL(x) __declspec(align(64)) x
  72. // Since they are always around on Windows
  73. #define HAVE_WX 1
  74. #define HAVE_OPENAL 1
  75. #define HAVE_PORTAUDIO 1
  76. // Debug definitions
  77. #if defined(_DEBUG)
  78. #include <crtdbg.h>
  79. #undef CHECK_HEAP_INTEGRITY
  80. #define CHECK_HEAP_INTEGRITY() {if (!_CrtCheckMemory()) PanicAlert("memory corruption detected. see log.");}
  81. // If you want to see how much a pain in the ass singletons are, for example:
  82. // {614} normal block at 0x030C5310, 188 bytes long.
  83. // Data: <Master Log > 4D 61 73 74 65 72 20 4C 6F 67 00 00 00 00 00 00
  84. struct CrtDebugBreak { CrtDebugBreak(int spot) { _CrtSetBreakAlloc(spot); } };
  85. //CrtDebugBreak breakAt(614);
  86. #endif // end DEBUG/FAST
  87. #endif
  88. // Windows compatibility
  89. #ifndef _WIN32
  90. #include <limits.h>
  91. #define MAX_PATH PATH_MAX
  92. #define __forceinline inline __attribute__((always_inline))
  93. #define GC_ALIGNED16(x) __attribute__((aligned(16))) x
  94. #define GC_ALIGNED32(x) __attribute__((aligned(32))) x
  95. #define GC_ALIGNED64(x) __attribute__((aligned(64))) x
  96. #define GC_ALIGNED128(x) __attribute__((aligned(128))) x
  97. #define GC_ALIGNED16_DECL(x) __attribute__((aligned(16))) x
  98. #define GC_ALIGNED64_DECL(x) __attribute__((aligned(64))) x
  99. #endif
  100. #ifdef _MSC_VER
  101. #define __strdup _strdup
  102. #define __getcwd _getcwd
  103. #define __chdir _chdir
  104. #else
  105. #define __strdup strdup
  106. #define __getcwd getcwd
  107. #define __chdir chdir
  108. #endif
  109. // Dummy macro for marking translatable strings that can not be immediately translated.
  110. // wxWidgets does not have a true dummy macro for this.
  111. #define _trans(a) a
  112. // Host communication.
  113. enum HOST_COMM
  114. {
  115. // Begin at 10 in case there is already messages with wParam = 0, 1, 2 and so on
  116. WM_USER_STOP = 10,
  117. WM_USER_CREATE,
  118. WM_USER_SETCURSOR,
  119. };
  120. // Used for notification on emulation state
  121. enum EMUSTATE_CHANGE
  122. {
  123. EMUSTATE_CHANGE_PLAY = 1,
  124. EMUSTATE_CHANGE_PAUSE,
  125. EMUSTATE_CHANGE_STOP
  126. };
  127. #include "Common/CommonTypes.h" // IWYU pragma: export
  128. #include "Common/CommonFuncs.h" // IWYU pragma: export // NOLINT
  129. #include "Common/MsgHandler.h" // IWYU pragma: export
  130. #include "Common/Logging/Log.h" // IWYU pragma: export