Skip to content

Commit 80c825c

Browse files
committed
environment: Add some convars for controlling env settings
1 parent c7db355 commit 80c825c

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

vphysics_jolt/vjolt_environment.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//=================================================================================================
1414

1515
#include "cbase.h"
16+
#include "coordsize.h"
1617

1718
#include "vjolt_callstack.h"
1819
#include "vjolt_collide.h"
@@ -53,9 +54,11 @@ static ConVar vjolt_linearcast( "vjolt_linearcast", "1", FCVAR_NONE, "Whether bo
5354
static ConVar vjolt_enhanced_inactive_edge_detection( "vjolt_enhanced_inactive_edge_detection", "1", FCVAR_NONE, "Whether bodies will be created with enhanced inactive edge detection (only takes effect after map restart)." );
5455
static ConVar vjolt_initial_simulation( "vjolt_initial_simulation", "0", FCVAR_NONE, "Whether to pre-settle physics objects on map load." );
5556

56-
static ConVar vjolt_substeps_collision_low( "vjolt_substeps_collision_low", "8", FCVAR_NONE, "Number of collision steps to perform in low state.", true, 0.0f, true, 8.0f );
57-
static ConVar vjolt_substeps_collision_high( "vjolt_substeps_collision_high", "1", FCVAR_NONE, "Number of collision steps to perform in high state.", true, 0.0f, true, 8.0f );
58-
static ConVar vjolt_substeps_collision_body_count_threshold( "vjolt_substeps_collision_body_count_threshold", "25", FCVAR_NONE, "Number of active bodies needed to go from low -> high substep count.", true, 0.0f, true, 8.0f );
57+
static ConVar vjolt_substeps( "vjolt_substeps", "1", FCVAR_NONE, "Number of substeps to perform.", true, 0.0f, true, 8.0f );
58+
59+
static ConVar vjolt_velocity_steps( "vjolt_velocity_steps", "10", FCVAR_NONE, "Number of velocity steps to perform.", true, 0.0f, true, 64.0f );
60+
static ConVar vjolt_position_steps( "vjolt_position_steps", "2", FCVAR_NONE, "Number of velocity steps to perform.", true, 0.0f, true, 64.0f );
61+
static ConVar vjolt_deterministic( "vjolt_deterministic", "0", FCVAR_NONE, "Whether the simulation is deterministic or not." );
5962

6063
static ConVar vjolt_baumgarte_factor( "vjolt_baumgarte_factor", "0.2", FCVAR_NONE, "Baumgarte stabilization factor (how much of the position error to 'fix' in 1 update). Changing this may help with constraint stability. Requires a map restart to change.", true, 0.0f, true, 1.0f );
6164

@@ -209,12 +212,6 @@ JoltPhysicsEnvironment::JoltPhysicsEnvironment()
209212
kMaxBodies, kNumBodyMutexes, kMaxBodyPairs, kMaxContactConstraints,
210213
s_BroadPhaseLayerInterface, s_BroadPhaseFilter, s_LayerPairFilter);
211214

212-
{
213-
JPH::PhysicsSettings settings = m_PhysicsSystem.GetPhysicsSettings();
214-
settings.mBaumgarte = vjolt_baumgarte_factor.GetFloat();
215-
m_PhysicsSystem.SetPhysicsSettings( settings );
216-
}
217-
218215
// A body activation listener gets notified when bodies activate and go to sleep
219216
// Note that this is called from a job so whatever you do here needs to be thread safe.
220217
// Registering one is entirely optional.
@@ -769,6 +766,15 @@ void JoltPhysicsEnvironment::Simulate( float deltaTime )
769766
if ( deltaTime == 0.0f )
770767
return;
771768

769+
{
770+
JPH::PhysicsSettings settings = m_PhysicsSystem.GetPhysicsSettings();
771+
settings.mBaumgarte = vjolt_baumgarte_factor.GetFloat(); // 0.2 def
772+
settings.mNumVelocitySteps = vjolt_velocity_steps.GetInt();
773+
settings.mNumPositionSteps = vjolt_position_steps.GetInt();
774+
settings.mDeterministicSimulation = vjolt_deterministic.GetBool();
775+
m_PhysicsSystem.SetPhysicsSettings( settings );
776+
}
777+
772778
// Grab our shared assets from the interface
773779
JPH::TempAllocator *tempAllocator = JoltPhysicsInterface::GetInstance().GetTempAllocator();
774780
JPH::JobSystem *jobSystem = JoltPhysicsInterface::GetInstance().GetJobSystem();
@@ -788,7 +794,7 @@ void JoltPhysicsEnvironment::Simulate( float deltaTime )
788794
for ( IJoltPhysicsController *pController : m_pPhysicsControllers )
789795
pController->OnPreSimulate( deltaTime );
790796

791-
const int nCollisionSubSteps = m_PhysicsSystem.GetNumActiveBodies( JPH::EBodyType::RigidBody ) > vjolt_substeps_collision_body_count_threshold.GetInt() ? vjolt_substeps_collision_high.GetInt() : vjolt_substeps_collision_low.GetInt();
797+
const int nCollisionSubSteps = vjolt_substeps.GetInt();
792798

793799
// If we haven't already, optimize the broadphase, currently this can only happen once per-environment
794800
if ( !m_bOptimizedBroadPhase )

0 commit comments

Comments
 (0)