Skip to content

Commit

Permalink
Changes for loosening coupling with Fixed class template code & impro…
Browse files Browse the repository at this point in the history
…ving support for other Real types
  • Loading branch information
louis-langholtz committed Oct 20, 2023
1 parent 013dd6a commit 99b9c32
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 252 deletions.
2 changes: 2 additions & 0 deletions Build/xcode5/PlayRho.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@
991988332ACEA0780076F969 /* NgonWithFwdNormals.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = NgonWithFwdNormals.hpp; sourceTree = "<group>"; };
991988392AD5FEE80076F969 /* IslandStats.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IslandStats.cpp; sourceTree = "<group>"; };
9919883B2ADAFEE20076F969 /* CheckedMath.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CheckedMath.hpp; sourceTree = "<group>"; };
991988C22AE2D46F0076F969 /* Settings.hpp.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Settings.hpp.in; sourceTree = "<group>"; };
9921FFD629AD43C30043F23F /* TypeInfo.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeInfo.cpp; sourceTree = "<group>"; };
996B7B7E2A6DF1A400A8207F /* PoolMemoryResource.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = PoolMemoryResource.hpp; sourceTree = "<group>"; };
996B7B7F2A6DF1A400A8207F /* MemoryResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryResource.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1521,6 +1522,7 @@
470ADAB92555F72B00EEE99D /* Real.hpp.in */,
47B58F621F64C19600354C34 /* RealConstants.hpp */,
80BB8947141C3E5900F1753A /* Settings.hpp */,
991988C22AE2D46F0076F969 /* Settings.hpp.in */,
4795B61C262B557100FB3EC6 /* ShapeID.hpp */,
4734B21E1DC1340500F15E29 /* Span.hpp */,
80BB8949141C3E5900F1753A /* StackAllocator.hpp */,
Expand Down
24 changes: 24 additions & 0 deletions Library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ if(NOT PLAYRHO_REAL_TYPE)
endif()
message(STATUS "PLAYRHO_REAL_TYPE=${PLAYRHO_REAL_TYPE}")

if(NOT PLAYRHO_REAL_LINEARSLOP)
set(PLAYRHO_REAL_LINEARSLOP "0.005_m")
endif()
message(STATUS "PLAYRHO_REAL_LINEARSLOP=${PLAYRHO_REAL_LINEARSLOP}")

if(NOT PLAYRHO_REAL_MINVERTEXRADIUS)
set(PLAYRHO_REAL_MINVERTEXRADIUS "0.01_m")
endif()
message(STATUS "PLAYRHO_REAL_MINVERTEXRADIUS=${PLAYRHO_REAL_MINVERTEXRADIUS}")

if(NOT PLAYRHO_REAL_MAXVERTEXRADIUS)
set(PLAYRHO_REAL_MAXVERTEXRADIUS "255_m")
endif()
message(STATUS "PLAYRHO_REAL_MAXVERTEXRADIUS=${PLAYRHO_REAL_MAXVERTEXRADIUS}")

if(PLAYRHO_REAL_INCLUDE)
foreach(line IN LISTS PLAYRHO_REAL_INCLUDE)
string(APPEND PLAYRHO_REAL_INCLUDES "${line}\n")
endforeach()
message(STATUS "PLAYRHO_REAL_INCLUDES=${PLAYRHO_REAL_INCLUDES}")
endif()

message(STATUS "PROJECT_VERSION=${PROJECT_VERSION}")
if(NOT PlayRho_VERSION_MAJOR)
set(PlayRho_VERSION_MAJOR 0)
Expand Down Expand Up @@ -49,9 +71,11 @@ set(PLAYRHO_DETAIL_HDRS

configure_file("${PLAYRHO_INCLUDE_PREFIX}Defines.hpp.in" "${PLAYRHO_INCLUDE_PREFIX}Defines.hpp" @ONLY)
configure_file("${PLAYRHO_INCLUDE_PREFIX}Real.hpp.in" "${PLAYRHO_INCLUDE_PREFIX}Real.hpp" @ONLY)
configure_file("${PLAYRHO_INCLUDE_PREFIX}Settings.hpp.in" "${PLAYRHO_INCLUDE_PREFIX}Settings.hpp" @ONLY)
set(PLAYRHO_GeneralCfg_HDRS
"${CMAKE_CURRENT_BINARY_DIR}/${PLAYRHO_INCLUDE_PREFIX}Defines.hpp"
"${CMAKE_CURRENT_BINARY_DIR}/${PLAYRHO_INCLUDE_PREFIX}Real.hpp"
"${CMAKE_CURRENT_BINARY_DIR}/${PLAYRHO_INCLUDE_PREFIX}Settings.hpp"
)

set(PLAYRHO_PMR_HDRS
Expand Down
1 change: 0 additions & 1 deletion Library/include/playrho/Math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <type_traits> // for std::decay_t
#include <vector>

#include <playrho/FixedMath.hpp>
#include <playrho/Matrix.hpp>
#include <playrho/NonNegative.hpp>
#include <playrho/Settings.hpp>
Expand Down
14 changes: 5 additions & 9 deletions Library/include/playrho/Real.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
* @brief Real number definition file.
*/

#include <playrho/Fixed.hpp>
#include <playrho/FixedMath.hpp>
#include <playrho/FixedLimits.hpp>
#include <playrho/Templates.hpp> // for IsArithmeticV

// Any header(s) for a user defined arithmetic type for Real go here...

namespace playrho {

Expand All @@ -44,10 +44,6 @@ namespace playrho {
/// @note This can also be implemented using a <code>LiteralType</code> that has
/// necessary support: all common mathematical functions, support for infinity and
/// NaN, and a specialization of the @c std::numeric_limits class template for it.
/// @note At present, the <code>Fixed32</code> and <code>Fixed64</code> aliases of
/// the <code>Fixed</code> template type are provided as examples of qualifying
/// literal types though the usability of these are limited and their use is
/// discouraged.
///
/// @note Regarding division:
/// - While dividing 1 by a real, caching the result, and then doing multiplications
Expand All @@ -57,8 +53,6 @@ namespace playrho {
/// - Meanwhile, dividing every time by a real isolates any underflows to the
/// particular division where underflow occurs.
///
/// @warning Using <code>Fixed32</code> is not advised as its numerical limitations
/// are more likely to result in problems like overflows or underflows.
/// @warning The note regarding division applies even more so when using a
/// fixed-point type (for <code>Real</code>).
///
Expand All @@ -68,6 +62,8 @@ namespace playrho {
///
using Real = float;

static_assert(IsArithmeticV<Real>);

} // namespace playrho

#endif // PLAYRHO_REAL_HPP
21 changes: 9 additions & 12 deletions Library/include/playrho/Real.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
* 3. This notice may not be removed or altered from any source distribution.
*/

#ifndef PLAYRHO_REAL_HPP
#define PLAYRHO_REAL_HPP

/**
* @file
* @brief Real number definition file.
* @details This file was autogenerated from the Real.hpp.in file.
* @note This file was generated from the Real.hpp.in file.
*/

#ifndef PLAYRHO_REAL_HPP
#define PLAYRHO_REAL_HPP
#include <playrho/Templates.hpp> // for IsArithmeticV

#include <playrho/Fixed.hpp>
#include <playrho/FixedMath.hpp>
#include <playrho/FixedLimits.hpp>
// Any header(s) for a user defined arithmetic type for Real go here...
@PLAYRHO_REAL_INCLUDES@

namespace playrho {

Expand All @@ -45,10 +46,6 @@ namespace playrho {
/// @note This can also be implemented using a <code>LiteralType</code> that has
/// necessary support: all common mathematical functions, support for infinity and
/// NaN, and a specialization of the @c std::numeric_limits class template for it.
/// @note At present, the <code>Fixed32</code> and <code>Fixed64</code> aliases of
/// the <code>Fixed</code> template type are provided as examples of qualifying
/// literal types though the usability of these are limited and their use is
/// discouraged.
///
/// @note Regarding division:
/// - While dividing 1 by a real, caching the result, and then doing multiplications
Expand All @@ -58,8 +55,6 @@ namespace playrho {
/// - Meanwhile, dividing every time by a real isolates any underflows to the
/// particular division where underflow occurs.
///
/// @warning Using <code>Fixed32</code> is not advised as its numerical limitations
/// are more likely to result in problems like overflows or underflows.
/// @warning The note regarding division applies even more so when using a
/// fixed-point type (for <code>Real</code>).
///
Expand All @@ -69,6 +64,8 @@ namespace playrho {
///
using Real = @PLAYRHO_REAL_TYPE@;

static_assert(IsArithmeticV<Real>);

} // namespace playrho

#endif // PLAYRHO_REAL_HPP
65 changes: 8 additions & 57 deletions Library/include/playrho/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,58 +42,6 @@
#include <playrho/WiderType.hpp>

namespace playrho {
namespace detail {

/// @brief Defaults object for real types.
template <typename T>
struct Defaults
{
/// @brief Linear slop.
static constexpr auto LinearSlop = 0.005_m;

/// @brief Max vertex radius.
static constexpr auto MaxVertexRadius = 255_m;

/// @brief Gets the linear slop.
static constexpr auto GetLinearSlop() noexcept
{
// Return the value used by Box2D 2.3.2 b2_linearSlop define....
return LinearSlop;
}

/// @brief Gets the max vertex radius.
static constexpr auto GetMaxVertexRadius() noexcept
{
// DefaultLinearSlop * Real(2 * 1024 * 1024);
// linearSlop * 2550000
return MaxVertexRadius;
}
};

/// @brief Specialization of defaults object for fixed point types.
template <unsigned int FRACTION_BITS>
struct Defaults<Fixed<std::int32_t,FRACTION_BITS>>
{
/// @brief Max shift bits.
static constexpr auto MaxShiftBits = 28;

/// @brief Gets the linear slop.
static constexpr auto GetLinearSlop() noexcept
{
// Needs to be big enough that the step tolerance doesn't go to zero.
// ex: FRACTION_BITS==10, then divisor==256
return Length{1_m / Real(1u << (FRACTION_BITS - 2))};
}

/// @brief Gets the max vertex radius.
static constexpr auto GetMaxVertexRadius() noexcept
{
// linearSlop * 2550000
return Length{Real(1u << (MaxShiftBits - FRACTION_BITS)) * 1_m};
}
};

} // namespace detail

/// @brief Maximum number of supportable edges in a simplex.
constexpr auto MaxSimplexEdges = std::uint8_t{3};
Expand All @@ -119,7 +67,7 @@ constexpr auto MaxFloat = std::numeric_limits<Real>::max(); // FLT_MAX
/// Maximum manifold points.
/// This is the maximum number of contact points between two convex shapes.
/// Do not change this value.
/// @note For memory efficiency, uses the smallest integral type that can hold the value.
/// @note For memory efficiency, uses the smallest integral type that can hold the value.
constexpr auto MaxManifoldPoints = std::uint8_t{2};

/// @brief Maximum number of vertices for any shape type.
Expand All @@ -142,13 +90,16 @@ constexpr auto InvalidVertex = static_cast<VertexCounter>(-1);
/// between bodies at rest.
/// @note Smaller values relative to sizes of bodies increases the time it takes
/// for bodies to come to rest.
constexpr auto DefaultLinearSlop = detail::Defaults<Real>::GetLinearSlop();
/// @note The value used by Box2D 2.3.2 b2_linearSlop define is 0.005_m.
constexpr auto DefaultLinearSlop = 0.005_m;

/// @brief Default minimum vertex radius.
constexpr auto DefaultMinVertexRadius = DefaultLinearSlop * Real(2);
/// @note Recommend using <code>0.01_m</code> or <code>DefaultLinearSlop * Real(2)</code>.
constexpr auto DefaultMinVertexRadius = 0.01_m;

/// @brief Default maximum vertex radius.
constexpr auto DefaultMaxVertexRadius = detail::Defaults<Real>::GetMaxVertexRadius();
/// @note Recommend using <code>255_m</code> or <code>DefaultLinearSlop * 2 * 25500</code>.
constexpr auto DefaultMaxVertexRadius = 255_m;

/// @brief Default AABB extension amount.
constexpr auto DefaultAabbExtension = DefaultLinearSlop * Real(20);
Expand Down Expand Up @@ -197,7 +148,7 @@ constexpr auto DefaultMaxDistanceIters = std::uint8_t{20};
/// have continuous collision resolution done for it.
/// @note Used in the TOI phase of step processing.
constexpr auto DefaultMaxSubSteps = std::uint8_t{8};

// Dynamics

/// @brief Default velocity threshold.
Expand Down
Loading

0 comments on commit 99b9c32

Please sign in to comment.