Skip to content

Commit e7a1af4

Browse files
Merge pull request #394 from louis-langholtz/updates-20210414
Updates 20210414
2 parents 9940ec5 + 41b3b17 commit e7a1af4

9 files changed

Lines changed: 273 additions & 240 deletions

File tree

PlayRho/Common/IndexingNamedType.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,52 @@ static_assert(std::is_nothrow_move_constructible<IndexingNamedType<int, struct T
139139

140140
/// @brief Gets the underlying value.
141141
template <typename T, typename Tag>
142+
[[deprecated("Use to_underlying instead")]]
142143
constexpr T& UnderlyingValue(IndexingNamedType<T, Tag>& o) noexcept
143144
{
144145
return static_cast<T&>(o);
145146
}
146147

147148
/// @brief Gets the underlying value.
148149
template <typename T, typename Tag>
150+
[[deprecated("Use to_underlying instead")]]
149151
constexpr const T& UnderlyingValue(const IndexingNamedType<T, Tag>& o) noexcept
150152
{
151153
return static_cast<const T&>(o);
152154
}
153155

154156
} // namespace detail
157+
158+
/// Underlying-type template class.
159+
template <class T, class Enable = void>
160+
struct underlying_type {};
161+
162+
/// Underlying-type class specialization for enum types.
163+
template <class T>
164+
struct underlying_type<T, std::enable_if_t<std::is_enum_v<T>>>
165+
{
166+
using type = std::underlying_type_t<T>;
167+
};
168+
169+
/// Underlying-type template class for <code>detail::IndexingNamedType</code> types.
170+
template <class T, class Tag>
171+
struct underlying_type<detail::IndexingNamedType<T, Tag>>
172+
{
173+
using type = T;
174+
};
175+
176+
/// Underlying-type convenience alias.
177+
template <class T>
178+
using underlying_type_t = typename underlying_type<T>::type;
179+
180+
/// Converts the given value to the value as the underlying type.
181+
/// @note This is like <code>std::to_underlying</code> slated for C++23.
182+
template <typename T>
183+
constexpr auto to_underlying(T value) noexcept -> underlying_type_t<T>
184+
{
185+
return static_cast<underlying_type_t<T>>(value);
186+
}
187+
155188
} // namespace playrho
156189

157190
namespace std {

PlayRho/Common/TypeInfo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ constexpr TypeID GetTypeID(T)
125125
/// @brief Gets the name associated with the given type ID.
126126
constexpr const char* GetName(TypeID id) noexcept
127127
{
128-
return *id.get();
128+
return *to_underlying(id);
129129
}
130130

131131
/// @brief Gets the name associated with the given template parameter type.

PlayRho/Dynamics/BodyConf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct BodyConf {
147147
/// this increases CPU usage.
148148
bool allowSleep = true;
149149

150-
/// Is this body initially awake or sleeping?
150+
/// Is the body awake or sleeping?
151151
bool awake = true;
152152

153153
/// Should this body be prevented from rotating? Useful for characters.
@@ -159,7 +159,7 @@ struct BodyConf {
159159
/// @note Use this flag sparingly since it increases processing time.
160160
bool bullet = false;
161161

162-
/// Does this body start out enabled?
162+
/// Whether or not the body is enabled.
163163
bool enabled = true;
164164
};
165165

PlayRho/Dynamics/Contacts/ContactSolver.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ VelocityPair GetVelocityDelta(const VelocityConstraint& vc, const Momentum2 impu
6969
{
7070
assert(IsValid(impulses));
7171

72-
const auto bodyA = &bodies[vc.GetBodyA().get()];
73-
const auto bodyB = &bodies[vc.GetBodyB().get()];
72+
const auto bodyA = &bodies[to_underlying(vc.GetBodyA())];
73+
const auto bodyB = &bodies[to_underlying(vc.GetBodyB())];
7474
const auto normal = vc.GetNormal();
7575

7676
const auto invRotInertiaA = bodyA->GetInvRotInertia();
@@ -99,8 +99,8 @@ Momentum BlockSolveUpdate(VelocityConstraint& vc, const Momentum2 newImpulses,
9999
std::vector<BodyConstraint>& bodies)
100100
{
101101
const auto delta_v = GetVelocityDelta(vc, newImpulses - GetNormalImpulses(vc), bodies);
102-
const auto bodyA = &bodies[vc.GetBodyA().get()];
103-
const auto bodyB = &bodies[vc.GetBodyB().get()];
102+
const auto bodyA = &bodies[to_underlying(vc.GetBodyA())];
103+
const auto bodyB = &bodies[to_underlying(vc.GetBodyB())];
104104
bodyA->SetVelocity(bodyA->GetVelocity() + std::get<0>(delta_v));
105105
bodyB->SetVelocity(bodyB->GetVelocity() + std::get<1>(delta_v));
106106
SetNormalImpulses(vc, newImpulses);
@@ -280,8 +280,8 @@ inline Momentum BlockSolveNormalConstraint(VelocityConstraint& vc,
280280
const auto b_prime = [&bodies,&vc]() {
281281
const auto normal = vc.GetNormal();
282282

283-
const auto velA = bodies[vc.GetBodyA().get()].GetVelocity();
284-
const auto velB = bodies[vc.GetBodyB().get()].GetVelocity();
283+
const auto velA = bodies[to_underlying(vc.GetBodyA())].GetVelocity();
284+
const auto velB = bodies[to_underlying(vc.GetBodyB())].GetVelocity();
285285
const auto ra0 = vc.GetPointRelPosA(0);
286286
const auto rb0 = vc.GetPointRelPosB(0);
287287
const auto ra1 = vc.GetPointRelPosA(1);
@@ -338,8 +338,8 @@ inline Momentum SeqSolveNormalConstraint(VelocityConstraint& vc,
338338

339339
const auto direction = vc.GetNormal();
340340
const auto count = vc.GetPointCount();
341-
const auto bodyA = &bodies[vc.GetBodyA().get()];
342-
const auto bodyB = &bodies[vc.GetBodyB().get()];
341+
const auto bodyA = &bodies[to_underlying(vc.GetBodyA())];
342+
const auto bodyB = &bodies[to_underlying(vc.GetBodyB())];
343343

344344
const auto invRotInertiaA = bodyA->GetInvRotInertia();
345345
const auto invMassA = bodyA->GetInvMass();
@@ -398,8 +398,8 @@ inline Momentum SolveTangentConstraint(VelocityConstraint& vc,
398398
const auto friction = vc.GetFriction();
399399
const auto tangentSpeed = vc.GetTangentSpeed();
400400
const auto count = vc.GetPointCount();
401-
const auto bodyA = &bodies[vc.GetBodyA().get()];
402-
const auto bodyB = &bodies[vc.GetBodyB().get()];
401+
const auto bodyA = &bodies[to_underlying(vc.GetBodyA())];
402+
const auto bodyB = &bodies[to_underlying(vc.GetBodyB())];
403403

404404
const auto invRotInertiaA = bodyA->GetInvRotInertia();
405405
const auto invMassA = bodyA->GetInvMass();
@@ -498,8 +498,8 @@ d2::PositionSolution SolvePositionConstraint(const d2::PositionConstraint& pc,
498498
assert(IsValid(conf.linearSlop));
499499
assert(IsValid(conf.maxLinearCorrection));
500500

501-
const auto bodyA = &bodies[pc.GetBodyA().get()];
502-
const auto bodyB = &bodies[pc.GetBodyB().get()];
501+
const auto bodyA = &bodies[to_underlying(pc.GetBodyA())];
502+
const auto bodyB = &bodies[to_underlying(pc.GetBodyB())];
503503

504504
const auto invMassA = moveA? bodyA->GetInvMass(): InvMass{0};
505505
const auto invRotInertiaA = moveA? bodyA->GetInvRotInertia(): InvRotInertia{0};

PlayRho/Dynamics/Contacts/VelocityConstraint.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ inline InvMass3 ComputeK(const VelocityConstraint& vc, const std::vector<BodyCon
3434
assert(vc.GetPointCount() == 2);
3535

3636
const auto normal = vc.GetNormal();
37-
const auto bodyA = &bodies[vc.GetBodyA().get()];
38-
const auto bodyB = &bodies[vc.GetBodyB().get()];
37+
const auto bodyA = &bodies[to_underlying(vc.GetBodyA())];
38+
const auto bodyB = &bodies[to_underlying(vc.GetBodyB())];
3939

4040
const auto relA0 = vc.GetPointRelPosA(0);
4141
const auto relB0 = vc.GetPointRelPosB(0);
@@ -94,8 +94,8 @@ VelocityConstraint::VelocityConstraint(Real friction, Real restitution,
9494
{
9595
const auto ci = worldManifold.GetImpulses(j);
9696
const auto worldPoint = worldManifold.GetPoint(j);
97-
const auto relA = worldPoint - bodies[bA.get()].GetPosition().linear;
98-
const auto relB = worldPoint - bodies[bB.get()].GetPosition().linear;
97+
const auto relA = worldPoint - bodies[to_underlying(bA)].GetPosition().linear;
98+
const auto relB = worldPoint - bodies[to_underlying(bB)].GetPosition().linear;
9999
AddPoint(get<0>(ci), get<1>(ci), relA, relB, bodies, conf);
100100
}
101101

@@ -136,8 +136,8 @@ VelocityConstraint::GetPoint(Momentum normalImpulse, Momentum tangentImpulse,
136136
assert(IsValid(relA));
137137
assert(IsValid(relB));
138138

139-
const auto bodyA = &bodies[GetBodyA().get()];
140-
const auto bodyB = &bodies[GetBodyB().get()];
139+
const auto bodyA = &bodies[to_underlying(GetBodyA())];
140+
const auto bodyB = &bodies[to_underlying(GetBodyB())];
141141

142142
const auto invRotInertiaA = bodyA->GetInvRotInertia();
143143
const auto invMassA = bodyA->GetInvMass();

PlayRho/Dynamics/Joints/Joint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static_assert(std::is_nothrow_destructible<Joint>::value, "Joint must be nothrow
5656

5757
BodyConstraint& At(std::vector<BodyConstraint>& container, BodyID key)
5858
{
59-
return container.at(UnderlyingValue(key));
59+
return container.at(to_underlying(key));
6060
}
6161

6262
Length2 GetLocalAnchorA(const Joint& object)

0 commit comments

Comments
 (0)