Skip to content

Commit a90a5a5

Browse files
miheSpartan322
authored andcommitted
Refactor Jolt-related project settings to only be loaded as needed
(cherry picked from commit 3b78ff5)
1 parent ed434eb commit a90a5a5

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
@@ -2338,13 +2338,11 @@
23382338
[b]Note:[/b] Setting this too high can result in objects not depenetrating properly.
23392339
[b]Note:[/b] This applies to all shape queries, as well as physics bodies within the simulation.
23402340
[b]Note:[/b] This does not apply when enabling Jolt's enhanced internal edge removal, which supersedes this.
2341-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
23422341
</member>
23432342
<member name="physics/jolt_physics_3d/collisions/collision_margin_fraction" type="float" setter="" getter="" default="0.08">
23442343
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.
23452344
[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.
23462345
[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.
2347-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
23482346
</member>
23492347
<member name="physics/jolt_physics_3d/joints/world_node" type="int" setter="" getter="" default="0">
23502348
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.
@@ -2379,28 +2377,23 @@
23792377
<member name="physics/jolt_physics_3d/motion_queries/recovery_amount" type="float" setter="" getter="" default="0.4">
23802378
Fraction of the total penetration to depenetrate per iteration during motion queries.
23812379
[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].
2382-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
23832380
</member>
23842381
<member name="physics/jolt_physics_3d/motion_queries/recovery_iterations" type="int" setter="" getter="" default="4">
23852382
The number of iterations to run when depenetrating during motion queries.
23862383
[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].
2387-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
23882384
</member>
23892385
<member name="physics/jolt_physics_3d/motion_queries/use_enhanced_internal_edge_removal" type="bool" setter="" getter="" default="true">
23902386
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.
23912387
[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].
2392-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
23932388
</member>
23942389
<member name="physics/jolt_physics_3d/queries/enable_ray_cast_face_index" type="bool" setter="" getter="" default="false">
23952390
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].
23962391
[b]Note:[/b] Enabling this setting will increase Jolt's memory usage for [ConcavePolygonShape3D] by around 25%.
2397-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
23982392
</member>
23992393
<member name="physics/jolt_physics_3d/queries/use_enhanced_internal_edge_removal" type="bool" setter="" getter="" default="false">
24002394
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.
24012395
[b]Note:[/b] This affects methods [method PhysicsDirectSpaceState3D.cast_motion], [method PhysicsDirectSpaceState3D.collide_shape], [method PhysicsDirectSpaceState3D.get_rest_info] and [method PhysicsDirectSpaceState3D.intersect_shape].
24022396
[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.
2403-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24042397
</member>
24052398
<member name="physics/jolt_physics_3d/simulation/allow_sleep" type="bool" setter="" getter="" default="true">
24062399
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.
@@ -2426,7 +2419,6 @@
24262419
</member>
24272420
<member name="physics/jolt_physics_3d/simulation/bounce_velocity_threshold" type="float" setter="" getter="" default="1.0">
24282421
The minimum velocity needed before a collision can be bouncy, in meters per second.
2429-
[b]Note:[/b] This setting will only be read once during the lifetime of the application.
24302422
</member>
24312423
<member name="physics/jolt_physics_3d/simulation/continuous_cd_max_penetration" type="float" setter="" getter="" default="0.25">
24322424
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
@@ -120,7 +120,7 @@ JoltJoint3D::JoltJoint3D(const JoltJoint3D &p_old_joint, JoltBody3D *p_body_a, J
120120
body_b->add_joint(this);
121121
}
122122

123-
if (body_b == nullptr && JoltProjectSettings::use_joint_world_node_a()) {
123+
if (body_b == nullptr && JoltProjectSettings::joint_world_node == JOLT_JOINT_WORLD_NODE_A) {
124124
// The joint scene nodes will, when omitting one of the two body nodes, always pass in a
125125
// null `body_b` to indicate it being the "world node", regardless of which body node you
126126
// 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
@@ -34,15 +34,6 @@
3434

3535
#include "core/config/project_settings.h"
3636

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

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

0 commit comments

Comments
 (0)