b2Settings.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
  3. * Copyright (c) 2013 Google, Inc.
  4. *
  5. * This software is provided 'as-is', without any express or implied
  6. * warranty. In no event will the authors be held liable for any damages
  7. * arising from the use of this software.
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. * 1. The origin of this software must not be misrepresented; you must not
  12. * claim that you wrote the original software. If you use this software
  13. * in a product, an acknowledgment in the product documentation would be
  14. * appreciated but is not required.
  15. * 2. Altered source versions must be plainly marked as such, and must not be
  16. * misrepresented as being the original software.
  17. * 3. This notice may not be removed or altered from any source distribution.
  18. */
  19. #ifndef B2_SETTINGS_H
  20. #define B2_SETTINGS_H
  21. #include <stddef.h>
  22. #include <assert.h>
  23. #include <float.h>
  24. #define B2_NOT_USED(x) ((void)(x))
  25. #if DEBUG && !defined(NDEBUG)
  26. #define b2Assert(A) assert(A)
  27. #define B2_ASSERT_ENABLED 1
  28. #else
  29. #define b2Assert(A)
  30. #define B2_ASSERT_ENABLED 0
  31. #endif
  32. // Statement which is compiled out when DEBUG isn't defined.
  33. #if DEBUG
  34. #define B2_DEBUG_STATEMENT(A) A
  35. #else
  36. #define B2_DEBUG_STATEMENT(A)
  37. #endif // DEBUG
  38. // Calculate the size of a static array.
  39. #define B2_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  40. typedef signed char int8;
  41. typedef signed short int16;
  42. typedef signed int int32;
  43. typedef unsigned char uint8;
  44. typedef unsigned short uint16;
  45. typedef unsigned int uint32;
  46. typedef float float32;
  47. typedef double float64;
  48. #ifdef WIN32
  49. typedef __int64 int64;
  50. typedef unsigned __int64 uint64;
  51. #else // !WIN32
  52. typedef long long int64;
  53. typedef unsigned long long uint64;
  54. #endif
  55. #define b2_maxFloat FLT_MAX
  56. #define b2_epsilon FLT_EPSILON
  57. #define b2_pi 3.14159265359f
  58. #if !defined(b2Inline)
  59. #if defined(__GNUC__)
  60. #define b2Inline __attribute__((always_inline))
  61. #else
  62. #define b2Inline inline
  63. #endif // defined(__GNUC__)
  64. #endif // !defined(b2Inline)
  65. // We expand the API so that other languages (e.g. Java) can call into
  66. // our C++ more easily. Only set if when the flag is not externally defined.
  67. #if !defined(LIQUIDFUN_EXTERNAL_LANGUAGE_API)
  68. #if SWIG || LIQUIDFUN_UNIT_TESTS
  69. #define LIQUIDFUN_EXTERNAL_LANGUAGE_API 1
  70. #else
  71. #define LIQUIDFUN_EXTERNAL_LANGUAGE_API 0
  72. #endif
  73. #endif
  74. /// @file
  75. /// Global tuning constants based on meters-kilograms-seconds (MKS) units.
  76. ///
  77. // Collision
  78. /// The maximum number of contact points between two convex shapes. Do
  79. /// not change this value.
  80. #define b2_maxManifoldPoints 2
  81. /// The maximum number of vertices on a convex polygon. You cannot increase
  82. /// this too much because b2BlockAllocator has a maximum object size.
  83. #define b2_maxPolygonVertices 8
  84. /// This is used to fatten AABBs in the dynamic tree. This allows proxies
  85. /// to move by a small amount without triggering a tree adjustment.
  86. /// This is in meters.
  87. #define b2_aabbExtension 0.1f
  88. /// This is used to fatten AABBs in the dynamic tree. This is used to predict
  89. /// the future position based on the current displacement.
  90. /// This is a dimensionless multiplier.
  91. #define b2_aabbMultiplier 2.0f
  92. /// A small length used as a collision and constraint tolerance. Usually it is
  93. /// chosen to be numerically significant, but visually insignificant.
  94. #define b2_linearSlop 0.005f
  95. /// A small angle used as a collision and constraint tolerance. Usually it is
  96. /// chosen to be numerically significant, but visually insignificant.
  97. #define b2_angularSlop (2.0f / 180.0f * b2_pi)
  98. /// The radius of the polygon/edge shape skin. This should not be modified. Making
  99. /// this smaller means polygons will have an insufficient buffer for continuous collision.
  100. /// Making it larger may create artifacts for vertex collision.
  101. #define b2_polygonRadius (2.0f * b2_linearSlop)
  102. /// Maximum number of sub-steps per contact in continuous physics simulation.
  103. #define b2_maxSubSteps 8
  104. // Dynamics
  105. /// Maximum number of contacts to be handled to solve a TOI impact.
  106. #define b2_maxTOIContacts 32
  107. /// A velocity threshold for elastic collisions. Any collision with a relative linear
  108. /// velocity below this threshold will be treated as inelastic.
  109. #define b2_velocityThreshold 1.0f
  110. /// The maximum linear position correction used when solving constraints. This helps to
  111. /// prevent overshoot.
  112. #define b2_maxLinearCorrection 0.2f
  113. /// The maximum angular position correction used when solving constraints. This helps to
  114. /// prevent overshoot.
  115. #define b2_maxAngularCorrection (8.0f / 180.0f * b2_pi)
  116. /// The maximum linear velocity of a body. This limit is very large and is used
  117. /// to prevent numerical problems. You shouldn't need to adjust this.
  118. #define b2_maxTranslation 2.0f
  119. #define b2_maxTranslationSquared (b2_maxTranslation * b2_maxTranslation)
  120. /// The maximum angular velocity of a body. This limit is very large and is used
  121. /// to prevent numerical problems. You shouldn't need to adjust this.
  122. #define b2_maxRotation (0.5f * b2_pi)
  123. #define b2_maxRotationSquared (b2_maxRotation * b2_maxRotation)
  124. /// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
  125. /// that overlap is removed in one time step. However using values close to 1 often lead
  126. /// to overshoot.
  127. #define b2_baumgarte 0.2f
  128. #define b2_toiBaugarte 0.75f
  129. // Particle
  130. /// NEON SIMD requires 16-bit particle indices
  131. #if !defined(B2_USE_16_BIT_PARTICLE_INDICES) && defined(LIQUIDFUN_SIMD_NEON)
  132. #define B2_USE_16_BIT_PARTICLE_INDICES
  133. #endif
  134. /// A symbolic constant that stands for particle allocation error.
  135. #define b2_invalidParticleIndex (-1)
  136. #ifdef B2_USE_16_BIT_PARTICLE_INDICES
  137. #define b2_maxParticleIndex 0x7FFF
  138. #else
  139. #define b2_maxParticleIndex 0x7FFFFFFF
  140. #endif
  141. /// The default distance between particles, multiplied by the particle diameter.
  142. #define b2_particleStride 0.75f
  143. /// The minimum particle weight that produces pressure.
  144. #define b2_minParticleWeight 1.0f
  145. /// The upper limit for particle pressure.
  146. #define b2_maxParticlePressure 0.25f
  147. /// The upper limit for force between particles.
  148. #define b2_maxParticleForce 0.5f
  149. /// The maximum distance between particles in a triad, multiplied by the
  150. /// particle diameter.
  151. #define b2_maxTriadDistance 2
  152. #define b2_maxTriadDistanceSquared (b2_maxTriadDistance * b2_maxTriadDistance)
  153. /// The initial size of particle data buffers.
  154. #define b2_minParticleSystemBufferCapacity 256
  155. /// The time into the future that collisions against barrier particles will be detected.
  156. #define b2_barrierCollisionTime 2.5f
  157. // Sleep
  158. /// The time that a body must be still before it will go to sleep.
  159. #define b2_timeToSleep 0.5f
  160. /// A body cannot sleep if its linear velocity is above this tolerance.
  161. #define b2_linearSleepTolerance 0.01f
  162. /// A body cannot sleep if its angular velocity is above this tolerance.
  163. #define b2_angularSleepTolerance (2.0f / 180.0f * b2_pi)
  164. // Memory Allocation
  165. /// Implement this function to use your own memory allocator.
  166. void* b2Alloc(int32 size);
  167. /// If you implement b2Alloc, you should also implement this function.
  168. void b2Free(void* mem);
  169. /// Use this function to override b2Alloc() without recompiling this library.
  170. typedef void* (*b2AllocFunction)(int32 size, void* callbackData);
  171. /// Use this function to override b2Free() without recompiling this library.
  172. typedef void (*b2FreeFunction)(void* mem, void* callbackData);
  173. /// Set alloc and free callbacks to override the default behavior of using
  174. /// malloc() and free() for dynamic memory allocation.
  175. /// Set allocCallback and freeCallback to NULL to restore the default
  176. /// allocator (malloc / free).
  177. void b2SetAllocFreeCallbacks(b2AllocFunction allocCallback,
  178. b2FreeFunction freeCallback,
  179. void* callbackData);
  180. /// Set the number of calls to b2Alloc minus the number of calls to b2Free.
  181. /// This can be used to disable the empty heap check in
  182. /// b2SetAllocFreeCallbacks() which can be useful for testing.
  183. void b2SetNumAllocs(const int32 numAllocs);
  184. /// Get number of calls to b2Alloc minus number of calls to b2Free.
  185. int32 b2GetNumAllocs();
  186. /// Logging function.
  187. void b2Log(const char* string, ...);
  188. /// Version numbering scheme.
  189. /// See http://en.wikipedia.org/wiki/Software_versioning
  190. struct b2Version
  191. {
  192. int32 major; ///< significant changes
  193. int32 minor; ///< incremental changes
  194. int32 revision; ///< bug fixes
  195. };
  196. /// Current version.
  197. /// Version of Box2D, LiquidFun is based upon.
  198. extern b2Version b2_version;
  199. /// Global variable is used to identify the version of LiquidFun.
  200. extern const b2Version b2_liquidFunVersion;
  201. /// String which identifies the current version of LiquidFun.
  202. /// b2_liquidFunVersionString is used by Google developers to identify which
  203. /// applications uploaded to Google Play are using this library. This allows
  204. /// the development team at Google to determine the popularity of the library.
  205. /// How it works: Applications that are uploaded to the Google Play Store are
  206. /// scanned for this version string. We track which applications are using it
  207. /// to measure popularity. You are free to remove it (of course) but we would
  208. /// appreciate if you left it in.
  209. extern const char *b2_liquidFunVersionString;
  210. #endif