Skip to content

Commit 4f8f6a6

Browse files
committed
set guards to prevent redundant calls, cached lookup to only happen once.
1 parent d1fd9a3 commit 4f8f6a6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

modules/godot_physics_3d/godot_physics_server_3d.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,9 @@ ObjectID GodotPhysicsServer3D::area_get_object_instance_id(RID p_area) const {
349349
}
350350

351351
void GodotPhysicsServer3D::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {
352-
if (space_owner.owns(p_area)) {
353-
GodotSpace3D *space = space_owner.get_or_null(p_area);
352+
// caching prevents multiple lookups.
353+
GodotSpace3D *space = space_owner.get_or_null(p_area);
354+
if (space) {
354355
p_area = space->get_default_area()->get_self();
355356
}
356357
GodotArea3D *area = area_owner.get_or_null(p_area);

scene/3d/physics/area_3d.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "servers/audio_server.h"
3636

3737
void Area3D::set_gravity_space_override_mode(SpaceOverride p_mode) {
38+
if (gravity_space_override == p_mode) return;
3839
gravity_space_override = p_mode;
3940
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_OVERRIDE_MODE, p_mode);
4041
}
@@ -44,6 +45,7 @@ Area3D::SpaceOverride Area3D::get_gravity_space_override_mode() const {
4445
}
4546

4647
void Area3D::set_gravity_is_point(bool p_enabled) {
48+
if (gravity_is_point == p_enabled) return;
4749
gravity_is_point = p_enabled;
4850
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_IS_POINT, p_enabled);
4951
}
@@ -53,6 +55,7 @@ bool Area3D::is_gravity_a_point() const {
5355
}
5456

5557
void Area3D::set_gravity_point_unit_distance(real_t p_scale) {
58+
if (gravity_point_unit_distance == p_scale) return;
5659
gravity_point_unit_distance = p_scale;
5760
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE, p_scale);
5861
}
@@ -62,6 +65,7 @@ real_t Area3D::get_gravity_point_unit_distance() const {
6265
}
6366

6467
void Area3D::set_gravity_point_center(const Vector3 &p_center) {
68+
if (gravity_vec == p_center) return;
6569
gravity_vec = p_center;
6670
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, p_center);
6771
}
@@ -71,6 +75,7 @@ const Vector3 &Area3D::get_gravity_point_center() const {
7175
}
7276

7377
void Area3D::set_gravity_direction(const Vector3 &p_direction) {
78+
if (gravity_vec == p_direction) return;
7479
gravity_vec = p_direction;
7580
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, p_direction);
7681
}
@@ -80,6 +85,7 @@ const Vector3 &Area3D::get_gravity_direction() const {
8085
}
8186

8287
void Area3D::set_gravity(real_t p_gravity) {
88+
if (gravity == p_gravity) return;
8389
gravity = p_gravity;
8490
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY, p_gravity);
8591
}
@@ -89,6 +95,7 @@ real_t Area3D::get_gravity() const {
8995
}
9096

9197
void Area3D::set_linear_damp_space_override_mode(SpaceOverride p_mode) {
98+
if (linear_damp_space_override == p_mode) return;
9299
linear_damp_space_override = p_mode;
93100
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE, p_mode);
94101
}
@@ -98,6 +105,7 @@ Area3D::SpaceOverride Area3D::get_linear_damp_space_override_mode() const {
98105
}
99106

100107
void Area3D::set_angular_damp_space_override_mode(SpaceOverride p_mode) {
108+
if (angular_damp_space_override == p_mode) return;
101109
angular_damp_space_override = p_mode;
102110
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE, p_mode);
103111
}
@@ -107,6 +115,7 @@ Area3D::SpaceOverride Area3D::get_angular_damp_space_override_mode() const {
107115
}
108116

109117
void Area3D::set_linear_damp(real_t p_linear_damp) {
118+
if (linear_damp == p_linear_damp) return;
110119
linear_damp = p_linear_damp;
111120
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, p_linear_damp);
112121
}
@@ -116,6 +125,7 @@ real_t Area3D::get_linear_damp() const {
116125
}
117126

118127
void Area3D::set_angular_damp(real_t p_angular_damp) {
128+
if (angular_damp == p_angular_damp) return;
119129
angular_damp = p_angular_damp;
120130
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, p_angular_damp);
121131
}
@@ -125,6 +135,7 @@ real_t Area3D::get_angular_damp() const {
125135
}
126136

127137
void Area3D::set_priority(int p_priority) {
138+
if (priority == p_priority) return;
128139
priority = p_priority;
129140
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_PRIORITY, p_priority);
130141
}
@@ -134,6 +145,7 @@ int Area3D::get_priority() const {
134145
}
135146

136147
void Area3D::set_wind_force_magnitude(real_t p_wind_force_magnitude) {
148+
if (wind_force_magnitude == p_wind_force_magnitude) return;
137149
wind_force_magnitude = p_wind_force_magnitude;
138150
if (is_inside_tree()) {
139151
_initialize_wind();
@@ -145,6 +157,7 @@ real_t Area3D::get_wind_force_magnitude() const {
145157
}
146158

147159
void Area3D::set_wind_attenuation_factor(real_t p_wind_force_attenuation_factor) {
160+
if (wind_attenuation_factor == p_wind_force_attenuation_factor) return;
148161
wind_attenuation_factor = p_wind_force_attenuation_factor;
149162
if (is_inside_tree()) {
150163
_initialize_wind();
@@ -156,6 +169,7 @@ real_t Area3D::get_wind_attenuation_factor() const {
156169
}
157170

158171
void Area3D::set_wind_source_path(const NodePath &p_wind_source_path) {
172+
if (wind_source_path == p_wind_source_path) return;
159173
wind_source_path = p_wind_source_path;
160174
if (is_inside_tree()) {
161175
_initialize_wind();

0 commit comments

Comments
 (0)