Settings.hpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3  * Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
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  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 
27 #ifndef PLAYRHO_COMMON_SETTINGS_HPP
28 #define PLAYRHO_COMMON_SETTINGS_HPP
29 
30 #include <cstddef>
31 #include <cassert>
32 #include <cfloat>
33 #include <cmath>
34 #include <cstdint>
35 #include <algorithm>
36 
39 #include <PlayRho/Common/Units.hpp>
40 #include <PlayRho/Common/Wider.hpp>
41 
42 namespace playrho {
43 namespace detail {
44 
46 template <typename T>
47 struct Defaults
48 {
50  static PLAYRHO_CONSTEXPR inline auto GetLinearSlop() noexcept
51  {
52  // Return the value used by Box2D 2.3.2 b2_linearSlop define....
53  return 0.005_m;
54  }
55 
57  static PLAYRHO_CONSTEXPR inline auto GetMaxVertexRadius() noexcept
58  {
59  // DefaultLinearSlop * Real{2 * 1024 * 1024};
60  // linearSlop * 2550000
61  return 255_m;
62  }
63 };
64 
66 template <unsigned int FRACTION_BITS>
67 struct Defaults<Fixed<std::int32_t,FRACTION_BITS>>
68 {
70  static PLAYRHO_CONSTEXPR inline auto GetLinearSlop() noexcept
71  {
72  // Needs to be big enough that the step tolerance doesn't go to zero.
73  // ex: FRACTION_BITS==10, then divisor==256
74  return Length{1_m / Real{(1u << (FRACTION_BITS - 2))}};
75  }
76 
78  static PLAYRHO_CONSTEXPR inline auto GetMaxVertexRadius() noexcept
79  {
80  // linearSlop * 2550000
81  return Length{Real(1u << (28 - FRACTION_BITS)) * 1_m};
82  }
83 };
84 
85 } // namespace detail
86 
88 PLAYRHO_CONSTEXPR const auto MaxSimplexEdges = std::uint8_t{3};
89 
91 PLAYRHO_CONSTEXPR const auto MaxChildCount = std::numeric_limits<std::uint32_t>::max() >> 6;
92 
97 using ChildCounter = std::remove_const<decltype(MaxChildCount)>::type;
98 
101 using TimestepIters = std::uint8_t;
102 
104 PLAYRHO_CONSTEXPR const auto MaxFloat = std::numeric_limits<Real>::max(); // FLT_MAX
105 
106 // Collision
107 
112 PLAYRHO_CONSTEXPR const auto MaxManifoldPoints = std::uint8_t{2};
113 
117 PLAYRHO_CONSTEXPR const auto MaxShapeVertices = std::uint8_t{254};
118 
122 using VertexCounter = std::remove_const<decltype(MaxShapeVertices)>::type;
123 
125 PLAYRHO_CONSTEXPR const auto InvalidVertex = static_cast<VertexCounter>(-1);
126 
135 
138 
141 
144 
147 
152 PLAYRHO_CONSTEXPR const auto DefaultAngularSlop = (Pi * 2_rad) / Real{180};
153 
159 
162 PLAYRHO_CONSTEXPR const auto DefaultMaxAngularCorrection = Real(8.0f / 180.0f) * Pi * 1_rad;
163 
166 
171 PLAYRHO_CONSTEXPR const auto DefaultMaxRotation = Angle{Pi * 1_rad / Real(2)};
172 
174 PLAYRHO_CONSTEXPR const auto DefaultMaxToiIters = std::uint8_t{20};
175 
177 PLAYRHO_CONSTEXPR const auto DefaultMaxToiRootIters = std::uint8_t{30};
178 
180 PLAYRHO_CONSTEXPR const auto DefaultMaxDistanceIters = std::uint8_t{20};
181 
188 PLAYRHO_CONSTEXPR const auto DefaultMaxSubSteps = std::uint8_t{8};
189 
190 // Dynamics
191 
194 
197 
200 
203 PLAYRHO_CONSTEXPR const auto MaxBodies = static_cast<std::uint16_t>(std::numeric_limits<std::uint16_t>::max() -
204  std::uint16_t{1});
205 
208 using BodyCounter = std::remove_const<decltype(MaxBodies)>::type;
209 
213 
216 
222 
225 PLAYRHO_CONSTEXPR const auto MaxJoints = static_cast<std::uint16_t>(std::numeric_limits<std::uint16_t>::max() -
226  std::uint16_t{1});
227 
230 using JointCounter = std::remove_const<decltype(MaxJoints)>::type;
231 
233 PLAYRHO_CONSTEXPR const auto DefaultStepTime = Time{1_s / 60};
234 
237 
238 // Sleep
239 
242 PLAYRHO_CONSTEXPR const auto DefaultMinStillTimeToSleep = Time{1_s / 2}; // aka 0.5 secs
243 
246 PLAYRHO_CONSTEXPR const auto DefaultLinearSleepTolerance = 0.01_mps; // aka 0.01
247 
251 
256 
257 } // namespace playrho
258 
259 #endif // PLAYRHO_COMMON_SETTINGS_HPP