Skip to content

Commit 768d75a

Browse files
committed
Merge pull request #101254 from mihe/jolt/better-settings
Refactor Jolt-related project settings to only be loaded as needed
2 parents c1b7865 + 3b78ff5 commit 768d75a

18 files changed

+138
-248
lines changed

doc/classes/ProjectSettings.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,13 +2404,11 @@
24042404
[b]Note:[/b] Setting this too high can result in objects not depenetrating properly.
24052405
[b]Note:[/b] This applies to all shape queries, as well as physics bodies within the simulation.
24062406
[b]Note:[/b] This does not apply when enabling Jolt's enhanced internal edge removal, which supersedes this.
2407-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24082407
</member>
24092408
<member name="physics/jolt_physics_3d/collisions/collision_margin_fraction" type="float" setter="" getter="" default="0.08">
24102409
The amount of collision margin to use for certain convex collision shapes, such as [BoxShape3D], [CylinderShape3D] and [ConvexPolygonShape3D], as a fraction of the shape's shortest axis, with [member Shape3D.margin] as the upper bound. This is mainly used to speed up collision detection with convex shapes.
24112410
[b]Note:[/b] Collision margins in Jolt do not add any extra size to the shape. Instead the shape is first shrunk by the margin and then expanded by the same amount, resulting in a shape with rounded corners.
24122411
[b]Note:[/b] Setting this value too close to [code]0.0[/code] may also negatively affect the accuracy of the collision detection with convex shapes.
2413-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24142412
</member>
24152413
<member name="physics/jolt_physics_3d/joints/world_node" type="int" setter="" getter="" default="0">
24162414
Which of the two nodes bound by a joint should represent the world when one of the two is omitted, as either [member Joint3D.node_a] or [member Joint3D.node_b]. This can be thought of as having the omitted node be a [StaticBody3D] at the joint's position. Joint limits are more easily expressed when [member Joint3D.node_a] represents the world.
@@ -2445,28 +2443,23 @@
24452443
<member name="physics/jolt_physics_3d/motion_queries/recovery_amount" type="float" setter="" getter="" default="0.4">
24462444
Fraction of the total penetration to depenetrate per iteration during motion queries.
24472445
[b]Note:[/b] This affects methods [method CharacterBody3D.move_and_slide], [method PhysicsBody3D.move_and_collide], [method PhysicsBody3D.test_move] and [method PhysicsServer3D.body_test_motion].
2448-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24492446
</member>
24502447
<member name="physics/jolt_physics_3d/motion_queries/recovery_iterations" type="int" setter="" getter="" default="4">
24512448
The number of iterations to run when depenetrating during motion queries.
24522449
[b]Note:[/b] This affects methods [method CharacterBody3D.move_and_slide], [method PhysicsBody3D.move_and_collide], [method PhysicsBody3D.test_move] and [method PhysicsServer3D.body_test_motion].
2453-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24542450
</member>
24552451
<member name="physics/jolt_physics_3d/motion_queries/use_enhanced_internal_edge_removal" type="bool" setter="" getter="" default="true">
24562452
If [code]true[/code], enables Jolt's enhanced internal edge removal during motion queries. This can help alleviate ghost collisions, but only with edges within a single body, meaning edges between separate bodies can still cause ghost collisions.
24572453
[b]Note:[/b] This affects methods [method CharacterBody3D.move_and_slide], [method PhysicsBody3D.move_and_collide], [method PhysicsBody3D.test_move] and [method PhysicsServer3D.body_test_motion].
2458-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24592454
</member>
24602455
<member name="physics/jolt_physics_3d/queries/enable_ray_cast_face_index" type="bool" setter="" getter="" default="false">
24612456
If [code]true[/code], populates the [code]face_index[/code] field in the results of [method PhysicsDirectSpaceState3D.intersect_ray], also accessed through [method RayCast3D.get_collision_face_index]. If [code]false[/code], the [code]face_index[/code] field will be left at its default value of [code]-1[/code].
24622457
[b]Note:[/b] Enabling this setting will increase Jolt's memory usage for [ConcavePolygonShape3D] by around 25%.
2463-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24642458
</member>
24652459
<member name="physics/jolt_physics_3d/queries/use_enhanced_internal_edge_removal" type="bool" setter="" getter="" default="false">
24662460
If [code]true[/code], enables Jolt's enhanced internal edge removal during shape queries. This can help alleviate ghost collisions when using shape queries for things like character movement, but only with edges within a single body, meaning edges between separate bodies can still cause ghost collisions.
24672461
[b]Note:[/b] This affects methods [method PhysicsDirectSpaceState3D.cast_motion], [method PhysicsDirectSpaceState3D.collide_shape], [method PhysicsDirectSpaceState3D.get_rest_info] and [method PhysicsDirectSpaceState3D.intersect_shape].
24682462
[b]Note:[/b] Enabling this setting can cause certain shapes to be culled from the results entirely, but you will get at least one intersection per body.
2469-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24702463
</member>
24712464
<member name="physics/jolt_physics_3d/simulation/allow_sleep" type="bool" setter="" getter="" default="true">
24722465
If [code]true[/code], [RigidBody3D] nodes are allowed to go to sleep if their velocity is below the threshold defined in [member physics/jolt_physics_3d/simulation/sleep_velocity_threshold] for the duration set in [member physics/jolt_physics_3d/simulation/sleep_time_threshold]. This can improve physics simulation performance when there are non-moving [RigidBody3D] nodes, at the cost of some nodes possibly failing to wake up in certain scenarios. Consider disabling this temporarily to troubleshoot [RigidBody3D] nodes not moving when they should.
@@ -2492,7 +2485,6 @@
24922485
</member>
24932486
<member name="physics/jolt_physics_3d/simulation/bounce_velocity_threshold" type="float" setter="" getter="" default="1.0">
24942487
The minimum velocity needed before a collision can be bouncy, in meters per second.
2495-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24962488
</member>
24972489
<member name="physics/jolt_physics_3d/simulation/continuous_cd_max_penetration" type="float" setter="" getter="" default="0.25">
24982490
Fraction of a body's inner radius that may penetrate another body while using continuous collision detection.

modules/jolt_physics/joints/jolt_joint_3d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ JoltJoint3D::JoltJoint3D(const JoltJoint3D &p_old_joint, JoltBody3D *p_body_a, J
118118
body_b->add_joint(this);
119119
}
120120

121-
if (body_b == nullptr && JoltProjectSettings::use_joint_world_node_a()) {
121+
if (body_b == nullptr && JoltProjectSettings::joint_world_node == JOLT_JOINT_WORLD_NODE_A) {
122122
// The joint scene nodes will, when omitting one of the two body nodes, always pass in a
123123
// null `body_b` to indicate it being the "world node", regardless of which body node you
124124
// leave blank. So we need to correct for that if we wish to use the arguably more intuitive

modules/jolt_physics/jolt_project_settings.cpp

Lines changed: 48 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@
3232

3333
#include "core/config/project_settings.h"
3434

35-
namespace {
36-
37-
enum JoltJointWorldNode : int {
38-
JOLT_JOINT_WORLD_NODE_A,
39-
JOLT_JOINT_WORLD_NODE_B,
40-
};
41-
42-
} // namespace
43-
4435
void JoltProjectSettings::register_settings() {
4536
GLOBAL_DEF(PropertyInfo(Variant::INT, "physics/jolt_physics_3d/simulation/velocity_steps", PROPERTY_HINT_RANGE, U"2,16,or_greater"), 10);
4637
GLOBAL_DEF(PropertyInfo(Variant::INT, "physics/jolt_physics_3d/simulation/position_steps", PROPERTY_HINT_RANGE, U"1,16,or_greater"), 2);
@@ -80,149 +71,53 @@ void JoltProjectSettings::register_settings() {
8071
GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "physics/jolt_physics_3d/limits/max_bodies", PROPERTY_HINT_RANGE, U"1,10240,or_greater"), 10240);
8172
GLOBAL_DEF(PropertyInfo(Variant::INT, "physics/jolt_physics_3d/limits/max_body_pairs", PROPERTY_HINT_RANGE, U"8,65536,or_greater"), 65536);
8273
GLOBAL_DEF(PropertyInfo(Variant::INT, "physics/jolt_physics_3d/limits/max_contact_constraints", PROPERTY_HINT_RANGE, U"8,20480,or_greater"), 20480);
83-
}
84-
85-
int JoltProjectSettings::get_simulation_velocity_steps() {
86-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/velocity_steps");
87-
}
88-
89-
int JoltProjectSettings::get_simulation_position_steps() {
90-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/position_steps");
91-
}
92-
93-
bool JoltProjectSettings::use_enhanced_internal_edge_removal_for_bodies() {
94-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/use_enhanced_internal_edge_removal");
95-
}
96-
97-
bool JoltProjectSettings::areas_detect_static_bodies() {
98-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/areas_detect_static_bodies");
99-
}
100-
101-
bool JoltProjectSettings::should_generate_all_kinematic_contacts() {
102-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/generate_all_kinematic_contacts");
103-
}
104-
105-
float JoltProjectSettings::get_penetration_slop() {
106-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/penetration_slop");
107-
}
108-
109-
float JoltProjectSettings::get_speculative_contact_distance() {
110-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/speculative_contact_distance");
111-
}
112-
113-
float JoltProjectSettings::get_baumgarte_stabilization_factor() {
114-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/baumgarte_stabilization_factor");
115-
}
116-
117-
float JoltProjectSettings::get_soft_body_point_radius() {
118-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/soft_body_point_radius");
119-
}
120-
121-
float JoltProjectSettings::get_bounce_velocity_threshold() {
122-
static const float value = GLOBAL_GET("physics/jolt_physics_3d/simulation/bounce_velocity_threshold");
123-
return value;
124-
}
125-
126-
bool JoltProjectSettings::is_sleep_allowed() {
127-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/allow_sleep");
128-
}
129-
130-
float JoltProjectSettings::get_sleep_velocity_threshold() {
131-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/sleep_velocity_threshold");
132-
}
133-
134-
float JoltProjectSettings::get_sleep_time_threshold() {
135-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/sleep_time_threshold");
136-
}
137-
138-
float JoltProjectSettings::get_ccd_movement_threshold() {
139-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/continuous_cd_movement_threshold");
140-
}
141-
142-
float JoltProjectSettings::get_ccd_max_penetration() {
143-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/continuous_cd_max_penetration");
144-
}
145-
146-
bool JoltProjectSettings::is_body_pair_contact_cache_enabled() {
147-
return GLOBAL_GET("physics/jolt_physics_3d/simulation/body_pair_contact_cache_enabled");
148-
}
149-
150-
float JoltProjectSettings::get_body_pair_cache_distance_sq() {
151-
const float value = GLOBAL_GET("physics/jolt_physics_3d/simulation/body_pair_contact_cache_distance_threshold");
152-
return value * value;
153-
}
154-
155-
float JoltProjectSettings::get_body_pair_cache_angle_cos_div2() {
156-
return Math::cos((float)GLOBAL_GET("physics/jolt_physics_3d/simulation/body_pair_contact_cache_angle_threshold") / 2.0f);
157-
}
158-
159-
bool JoltProjectSettings::use_enhanced_internal_edge_removal_for_queries() {
160-
static const bool value = GLOBAL_GET("physics/jolt_physics_3d/queries/use_enhanced_internal_edge_removal");
161-
return value;
162-
}
163-
164-
bool JoltProjectSettings::enable_ray_cast_face_index() {
165-
static const bool value = GLOBAL_GET("physics/jolt_physics_3d/queries/enable_ray_cast_face_index");
166-
return value;
167-
}
168-
169-
bool JoltProjectSettings::use_enhanced_internal_edge_removal_for_motion_queries() {
170-
static const bool value = GLOBAL_GET("physics/jolt_physics_3d/motion_queries/use_enhanced_internal_edge_removal");
171-
return value;
172-
}
173-
174-
int JoltProjectSettings::get_motion_query_recovery_iterations() {
175-
static const int value = GLOBAL_GET("physics/jolt_physics_3d/motion_queries/recovery_iterations");
176-
return value;
177-
}
178-
179-
float JoltProjectSettings::get_motion_query_recovery_amount() {
180-
static const float value = GLOBAL_GET("physics/jolt_physics_3d/motion_queries/recovery_amount");
181-
return value;
182-
}
183-
184-
float JoltProjectSettings::get_collision_margin_fraction() {
185-
static const float value = GLOBAL_GET("physics/jolt_physics_3d/collisions/collision_margin_fraction");
186-
return value;
187-
}
188-
189-
float JoltProjectSettings::get_active_edge_threshold() {
190-
static const float value = Math::cos((float)GLOBAL_GET("physics/jolt_physics_3d/collisions/active_edge_threshold"));
191-
return value;
192-
}
193-
194-
bool JoltProjectSettings::use_joint_world_node_a() {
195-
return (int)GLOBAL_GET("physics/jolt_physics_3d/joints/world_node") == JOLT_JOINT_WORLD_NODE_A;
196-
}
197-
198-
int JoltProjectSettings::get_temp_memory_mib() {
199-
return GLOBAL_GET("physics/jolt_physics_3d/limits/temporary_memory_buffer_size");
200-
}
201-
202-
int64_t JoltProjectSettings::get_temp_memory_b() {
203-
return get_temp_memory_mib() * 1024 * 1024;
204-
}
205-
206-
float JoltProjectSettings::get_world_boundary_shape_size() {
207-
return GLOBAL_GET("physics/jolt_physics_3d/limits/world_boundary_shape_size");
208-
}
209-
210-
float JoltProjectSettings::get_max_linear_velocity() {
211-
return GLOBAL_GET("physics/jolt_physics_3d/limits/max_linear_velocity");
212-
}
213-
214-
float JoltProjectSettings::get_max_angular_velocity() {
215-
return GLOBAL_GET("physics/jolt_physics_3d/limits/max_angular_velocity");
216-
}
217-
218-
int JoltProjectSettings::get_max_bodies() {
219-
return GLOBAL_GET("physics/jolt_physics_3d/limits/max_bodies");
220-
}
221-
222-
int JoltProjectSettings::get_max_pairs() {
223-
return GLOBAL_GET("physics/jolt_physics_3d/limits/max_body_pairs");
224-
}
22574

226-
int JoltProjectSettings::get_max_contact_constraints() {
227-
return GLOBAL_GET("physics/jolt_physics_3d/limits/max_contact_constraints");
75+
read_settings();
76+
77+
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp_static(JoltProjectSettings::read_settings));
78+
}
79+
80+
void JoltProjectSettings::read_settings() {
81+
simulation_velocity_steps = GLOBAL_GET("physics/jolt_physics_3d/simulation/velocity_steps");
82+
simulation_position_steps = GLOBAL_GET("physics/jolt_physics_3d/simulation/position_steps");
83+
use_enhanced_internal_edge_removal_for_bodies = GLOBAL_GET("physics/jolt_physics_3d/simulation/use_enhanced_internal_edge_removal");
84+
areas_detect_static_bodies = GLOBAL_GET("physics/jolt_physics_3d/simulation/areas_detect_static_bodies");
85+
generate_all_kinematic_contacts = GLOBAL_GET("physics/jolt_physics_3d/simulation/generate_all_kinematic_contacts");
86+
penetration_slop = GLOBAL_GET("physics/jolt_physics_3d/simulation/penetration_slop");
87+
speculative_contact_distance = GLOBAL_GET("physics/jolt_physics_3d/simulation/speculative_contact_distance");
88+
baumgarte_stabilization_factor = GLOBAL_GET("physics/jolt_physics_3d/simulation/baumgarte_stabilization_factor");
89+
soft_body_point_radius = GLOBAL_GET("physics/jolt_physics_3d/simulation/soft_body_point_radius");
90+
bounce_velocity_threshold = GLOBAL_GET("physics/jolt_physics_3d/simulation/bounce_velocity_threshold");
91+
sleep_allowed = GLOBAL_GET("physics/jolt_physics_3d/simulation/allow_sleep");
92+
sleep_velocity_threshold = GLOBAL_GET("physics/jolt_physics_3d/simulation/sleep_velocity_threshold");
93+
sleep_time_threshold = GLOBAL_GET("physics/jolt_physics_3d/simulation/sleep_time_threshold");
94+
ccd_movement_threshold = GLOBAL_GET("physics/jolt_physics_3d/simulation/continuous_cd_movement_threshold");
95+
ccd_max_penetration = GLOBAL_GET("physics/jolt_physics_3d/simulation/continuous_cd_max_penetration");
96+
body_pair_contact_cache_enabled = GLOBAL_GET("physics/jolt_physics_3d/simulation/body_pair_contact_cache_enabled");
97+
float body_pair_cache_distance = GLOBAL_GET("physics/jolt_physics_3d/simulation/body_pair_contact_cache_distance_threshold");
98+
body_pair_cache_distance_sq = body_pair_cache_distance * body_pair_cache_distance;
99+
float body_pair_cache_angle = GLOBAL_GET("physics/jolt_physics_3d/simulation/body_pair_contact_cache_angle_threshold");
100+
body_pair_cache_angle_cos_div2 = Math::cos(body_pair_cache_angle / 2.0f);
101+
102+
use_enhanced_internal_edge_removal_for_queries = GLOBAL_GET("physics/jolt_physics_3d/queries/use_enhanced_internal_edge_removal");
103+
enable_ray_cast_face_index = GLOBAL_GET("physics/jolt_physics_3d/queries/enable_ray_cast_face_index");
104+
105+
use_enhanced_internal_edge_removal_for_motion_queries = GLOBAL_GET("physics/jolt_physics_3d/motion_queries/use_enhanced_internal_edge_removal");
106+
motion_query_recovery_iterations = GLOBAL_GET("physics/jolt_physics_3d/motion_queries/recovery_iterations");
107+
motion_query_recovery_amount = GLOBAL_GET("physics/jolt_physics_3d/motion_queries/recovery_amount");
108+
109+
collision_margin_fraction = GLOBAL_GET("physics/jolt_physics_3d/collisions/collision_margin_fraction");
110+
float active_edge_threshold = GLOBAL_GET("physics/jolt_physics_3d/collisions/active_edge_threshold");
111+
active_edge_threshold_cos = Math::cos(active_edge_threshold);
112+
113+
joint_world_node = (JoltJointWorldNode)(int)GLOBAL_GET("physics/jolt_physics_3d/joints/world_node");
114+
115+
temp_memory_mib = GLOBAL_GET("physics/jolt_physics_3d/limits/temporary_memory_buffer_size");
116+
temp_memory_b = temp_memory_mib * 1024 * 1024;
117+
world_boundary_shape_size = GLOBAL_GET("physics/jolt_physics_3d/limits/world_boundary_shape_size");
118+
max_linear_velocity = GLOBAL_GET("physics/jolt_physics_3d/limits/max_linear_velocity");
119+
max_angular_velocity = GLOBAL_GET("physics/jolt_physics_3d/limits/max_angular_velocity");
120+
max_bodies = GLOBAL_GET("physics/jolt_physics_3d/limits/max_bodies");
121+
max_body_pairs = GLOBAL_GET("physics/jolt_physics_3d/limits/max_body_pairs");
122+
max_contact_constraints = GLOBAL_GET("physics/jolt_physics_3d/limits/max_contact_constraints");
228123
}

0 commit comments

Comments
 (0)