Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Constraints/CalculateSolverSteps.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2023 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/PhysicsSettings.h>78JPH_NAMESPACE_BEGIN910/// Class used to calculate the total number of velocity and position steps11class CalculateSolverSteps12{13public:14/// Constructor15JPH_INLINE explicit CalculateSolverSteps(const PhysicsSettings &inSettings) : mSettings(inSettings) { }1617/// Combine the number of velocity and position steps for this body/constraint with the current values18template <class Type>19JPH_INLINE void operator () (const Type *inObject)20{21uint num_velocity_steps = inObject->GetNumVelocityStepsOverride();22mNumVelocitySteps = max(mNumVelocitySteps, num_velocity_steps);23mApplyDefaultVelocity |= num_velocity_steps == 0;2425uint num_position_steps = inObject->GetNumPositionStepsOverride();26mNumPositionSteps = max(mNumPositionSteps, num_position_steps);27mApplyDefaultPosition |= num_position_steps == 0;28}2930/// Must be called after all bodies/constraints have been processed31JPH_INLINE void Finalize()32{33// If we have a default velocity/position step count, take the max of the default and the overrides34if (mApplyDefaultVelocity)35mNumVelocitySteps = max(mNumVelocitySteps, mSettings.mNumVelocitySteps);36if (mApplyDefaultPosition)37mNumPositionSteps = max(mNumPositionSteps, mSettings.mNumPositionSteps);38}3940/// Get the results of the calculation41JPH_INLINE uint GetNumPositionSteps() const { return mNumPositionSteps; }42JPH_INLINE uint GetNumVelocitySteps() const { return mNumVelocitySteps; }4344private:45const PhysicsSettings & mSettings;4647uint mNumVelocitySteps = 0;48uint mNumPositionSteps = 0;4950bool mApplyDefaultVelocity = false;51bool mApplyDefaultPosition = false;52};5354/// Dummy class to replace the steps calculator when we don't need the result55class DummyCalculateSolverSteps56{57public:58template <class Type>59JPH_INLINE void operator () (const Type *) const60{61/* Nothing to do */62}63};6465JPH_NAMESPACE_END666768