defs.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**************************************************************************/
  2. /* defs.hpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef GODOT_DEFS_HPP
  31. #define GODOT_DEFS_HPP
  32. #include <cstddef>
  33. #include <cstdint>
  34. #include <cstring>
  35. namespace godot {
  36. #if !defined(GDE_EXPORT)
  37. #if defined(_WIN32)
  38. #define GDE_EXPORT __declspec(dllexport)
  39. #elif defined(__GNUC__)
  40. #define GDE_EXPORT __attribute__((visibility("default")))
  41. #else
  42. #define GDE_EXPORT
  43. #endif
  44. #endif
  45. // Turn argument to string constant:
  46. // https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html#Stringizing
  47. #ifndef _STR
  48. #define _STR(m_x) #m_x
  49. #define _MKSTR(m_x) _STR(m_x)
  50. #endif
  51. // Should always inline no matter what.
  52. #ifndef _ALWAYS_INLINE_
  53. #if defined(__GNUC__)
  54. #define _ALWAYS_INLINE_ __attribute__((always_inline)) inline
  55. #elif defined(_MSC_VER)
  56. #define _ALWAYS_INLINE_ __forceinline
  57. #else
  58. #define _ALWAYS_INLINE_ inline
  59. #endif
  60. #endif
  61. // Should always inline, except in debug builds because it makes debugging harder.
  62. #ifndef _FORCE_INLINE_
  63. #ifdef DISABLE_FORCED_INLINE
  64. #define _FORCE_INLINE_ inline
  65. #else
  66. #define _FORCE_INLINE_ _ALWAYS_INLINE_
  67. #endif
  68. #endif
  69. // Windows badly defines a lot of stuff we'll never use. Undefine it.
  70. #ifdef _WIN32
  71. #undef min // override standard definition
  72. #undef max // override standard definition
  73. #undef ERROR // override (really stupid) wingdi.h standard definition
  74. #undef DELETE // override (another really stupid) winnt.h standard definition
  75. #undef MessageBox // override winuser.h standard definition
  76. #undef MIN // override standard definition
  77. #undef MAX // override standard definition
  78. #undef CLAMP // override standard definition
  79. #undef Error
  80. #undef OK
  81. #undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enum
  82. #endif
  83. #if defined(__GNUC__)
  84. #define likely(x) __builtin_expect(!!(x), 1)
  85. #define unlikely(x) __builtin_expect(!!(x), 0)
  86. #else
  87. #define likely(x) x
  88. #define unlikely(x) x
  89. #endif
  90. #ifdef REAL_T_IS_DOUBLE
  91. typedef double real_t;
  92. #else
  93. typedef float real_t;
  94. #endif
  95. // Generic swap template.
  96. #ifndef SWAP
  97. #define SWAP(m_x, m_y) __swap_tmpl((m_x), (m_y))
  98. template <typename T>
  99. inline void __swap_tmpl(T &x, T &y) {
  100. T aux = x;
  101. x = y;
  102. y = aux;
  103. }
  104. #endif // SWAP
  105. // Home-made index sequence trick, so it can be used everywhere without the costly include of std::tuple.
  106. // https://stackoverflow.com/questions/15014096/c-index-of-type-during-variadic-template-expansion
  107. template <size_t... Is>
  108. struct IndexSequence {};
  109. template <size_t N, size_t... Is>
  110. struct BuildIndexSequence : BuildIndexSequence<N - 1, N - 1, Is...> {};
  111. template <size_t... Is>
  112. struct BuildIndexSequence<0, Is...> : IndexSequence<Is...> {};
  113. } //namespace godot
  114. // To maintain compatibility an alias is defined outside the namespace.
  115. // Consider it deprecated.
  116. using real_t = godot::real_t;
  117. #endif // GODOT_DEFS_HPP