summaryrefslogtreecommitdiff
path: root/servers/physics_2d
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-05-14 16:41:43 +0200
committerRémi Verschelde <rverschelde@gmail.com>2020-05-14 21:57:34 +0200
commit0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (patch)
tree198d4ff7665d89307f6ca2469fa38620a9eb1672 /servers/physics_2d
parent07bc4e2f96f8f47991339654ff4ab16acc19d44f (diff)
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
Diffstat (limited to 'servers/physics_2d')
-rw-r--r--servers/physics_2d/area_2d_sw.cpp39
-rw-r--r--servers/physics_2d/area_2d_sw.h18
-rw-r--r--servers/physics_2d/area_pair_2d_sw.cpp39
-rw-r--r--servers/physics_2d/body_2d_sw.cpp90
-rw-r--r--servers/physics_2d/body_2d_sw.h15
-rw-r--r--servers/physics_2d/body_pair_2d_sw.cpp45
-rw-r--r--servers/physics_2d/broad_phase_2d_basic.cpp15
-rw-r--r--servers/physics_2d/broad_phase_2d_hash_grid.cpp124
-rw-r--r--servers/physics_2d/collision_object_2d_sw.cpp27
-rw-r--r--servers/physics_2d/collision_solver_2d_sat.cpp354
-rw-r--r--servers/physics_2d/collision_solver_2d_sw.cpp36
-rw-r--r--servers/physics_2d/joints_2d_sw.cpp36
-rw-r--r--servers/physics_2d/physics_server_2d_sw.cpp38
-rw-r--r--servers/physics_2d/physics_server_2d_wrap_mt.cpp5
-rw-r--r--servers/physics_2d/physics_server_2d_wrap_mt.h7
-rw-r--r--servers/physics_2d/shape_2d_sw.cpp65
-rw-r--r--servers/physics_2d/shape_2d_sw.h15
-rw-r--r--servers/physics_2d/space_2d_sw.cpp146
-rw-r--r--servers/physics_2d/space_2d_sw.h3
-rw-r--r--servers/physics_2d/step_2d_sw.cpp18
20 files changed, 747 insertions, 388 deletions
diff --git a/servers/physics_2d/area_2d_sw.cpp b/servers/physics_2d/area_2d_sw.cpp
index db2ae36067..acbbb7e1e8 100644
--- a/servers/physics_2d/area_2d_sw.cpp
+++ b/servers/physics_2d/area_2d_sw.cpp
@@ -47,13 +47,15 @@ Area2DSW::BodyKey::BodyKey(Area2DSW *p_body, uint32_t p_body_shape, uint32_t p_a
}
void Area2DSW::_shapes_changed() {
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
}
void Area2DSW::set_transform(const Transform2D &p_transform) {
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
_set_transform(p_transform);
_set_inv_transform(p_transform.affine_inverse());
@@ -61,10 +63,12 @@ void Area2DSW::set_transform(const Transform2D &p_transform) {
void Area2DSW::set_space(Space2DSW *p_space) {
if (get_space()) {
- if (monitor_query_list.in_list())
+ if (monitor_query_list.in_list()) {
get_space()->area_remove_from_monitor_query_list(&monitor_query_list);
- if (moved_list.in_list())
+ }
+ if (moved_list.in_list()) {
get_space()->area_remove_from_moved_list(&moved_list);
+ }
}
monitored_bodies.clear();
@@ -89,8 +93,9 @@ void Area2DSW::set_monitor_callback(ObjectID p_id, const StringName &p_method) {
_shape_changed();
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
}
void Area2DSW::set_area_monitor_callback(ObjectID p_id, const StringName &p_method) {
@@ -109,14 +114,16 @@ void Area2DSW::set_area_monitor_callback(ObjectID p_id, const StringName &p_meth
_shape_changed();
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
}
void Area2DSW::set_space_override_mode(PhysicsServer2D::AreaSpaceOverrideMode p_mode) {
bool do_override = p_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED;
- if (do_override == (space_override_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED))
+ if (do_override == (space_override_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)) {
return;
+ }
_unregister_shapes();
space_override_mode = p_mode;
_shape_changed();
@@ -177,13 +184,15 @@ Variant Area2DSW::get_param(PhysicsServer2D::AreaParameter p_param) const {
void Area2DSW::_queue_monitor_update() {
ERR_FAIL_COND(!get_space());
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
get_space()->area_add_to_monitor_query_list(&monitor_query_list);
+ }
}
void Area2DSW::set_monitorable(bool p_monitorable) {
- if (monitorable == p_monitorable)
+ if (monitorable == p_monitorable) {
return;
+ }
monitorable = p_monitorable;
_set_static(!monitorable);
@@ -193,8 +202,9 @@ void Area2DSW::call_queries() {
if (monitor_callback_id.is_valid() && !monitored_bodies.empty()) {
Variant res[5];
Variant *resptr[5];
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < 5; i++) {
resptr[i] = &res[i];
+ }
Object *obj = ObjectDB::get_instance(monitor_callback_id);
if (!obj) {
@@ -204,8 +214,9 @@ void Area2DSW::call_queries() {
}
for (Map<BodyKey, BodyState>::Element *E = monitored_bodies.front(); E; E = E->next()) {
- if (E->get().state == 0)
+ if (E->get().state == 0) {
continue; //nothing happened
+ }
res[0] = E->get().state > 0 ? PhysicsServer2D::AREA_BODY_ADDED : PhysicsServer2D::AREA_BODY_REMOVED;
res[1] = E->key().rid;
@@ -223,8 +234,9 @@ void Area2DSW::call_queries() {
if (area_monitor_callback_id.is_valid() && !monitored_areas.empty()) {
Variant res[5];
Variant *resptr[5];
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < 5; i++) {
resptr[i] = &res[i];
+ }
Object *obj = ObjectDB::get_instance(area_monitor_callback_id);
if (!obj) {
@@ -234,8 +246,9 @@ void Area2DSW::call_queries() {
}
for (Map<BodyKey, BodyState>::Element *E = monitored_areas.front(); E; E = E->next()) {
- if (E->get().state == 0)
+ if (E->get().state == 0) {
continue; //nothing happened
+ }
res[0] = E->get().state > 0 ? PhysicsServer2D::AREA_BODY_ADDED : PhysicsServer2D::AREA_BODY_REMOVED;
res[1] = E->key().rid;
diff --git a/servers/physics_2d/area_2d_sw.h b/servers/physics_2d/area_2d_sw.h
index 8deeb82174..f14466f582 100644
--- a/servers/physics_2d/area_2d_sw.h
+++ b/servers/physics_2d/area_2d_sw.h
@@ -71,10 +71,12 @@ class Area2DSW : public CollisionObject2DSW {
if (rid == p_key.rid) {
if (body_shape == p_key.body_shape) {
return area_shape < p_key.area_shape;
- } else
+ } else {
return body_shape < p_key.body_shape;
- } else
+ }
+ } else {
return rid < p_key.rid;
+ }
}
_FORCE_INLINE_ BodyKey() {}
@@ -166,29 +168,33 @@ public:
void Area2DSW::add_body_to_query(Body2DSW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
BodyKey bk(p_body, p_body_shape, p_area_shape);
monitored_bodies[bk].inc();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
void Area2DSW::remove_body_from_query(Body2DSW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
BodyKey bk(p_body, p_body_shape, p_area_shape);
monitored_bodies[bk].dec();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
void Area2DSW::add_area_to_query(Area2DSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
BodyKey bk(p_area, p_area_shape, p_self_shape);
monitored_areas[bk].inc();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
void Area2DSW::remove_area_from_query(Area2DSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
BodyKey bk(p_area, p_area_shape, p_self_shape);
monitored_areas[bk].dec();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
#endif // AREA_2D_SW_H
diff --git a/servers/physics_2d/area_pair_2d_sw.cpp b/servers/physics_2d/area_pair_2d_sw.cpp
index a3d5e403c1..d7bceb9f02 100644
--- a/servers/physics_2d/area_pair_2d_sw.cpp
+++ b/servers/physics_2d/area_pair_2d_sw.cpp
@@ -42,16 +42,20 @@ bool AreaPair2DSW::setup(real_t p_step) {
if (result != colliding) {
if (result) {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)
+ if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
body->add_area(area);
- if (area->has_monitor_callback())
+ }
+ if (area->has_monitor_callback()) {
area->add_body_to_query(body, body_shape, area_shape);
+ }
} else {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)
+ if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
body->remove_area(area);
- if (area->has_monitor_callback())
+ }
+ if (area->has_monitor_callback()) {
area->remove_body_from_query(body, body_shape, area_shape);
+ }
}
colliding = result;
@@ -71,16 +75,19 @@ AreaPair2DSW::AreaPair2DSW(Body2DSW *p_body, int p_body_shape, Area2DSW *p_area,
colliding = false;
body->add_constraint(this, 0);
area->add_constraint(this);
- if (p_body->get_mode() == PhysicsServer2D::BODY_MODE_KINEMATIC) //need to be active to process pair
+ if (p_body->get_mode() == PhysicsServer2D::BODY_MODE_KINEMATIC) { //need to be active to process pair
p_body->set_active(true);
+ }
}
AreaPair2DSW::~AreaPair2DSW() {
if (colliding) {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)
+ if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
body->remove_area(area);
- if (area->has_monitor_callback())
+ }
+ if (area->has_monitor_callback()) {
area->remove_body_from_query(body, body_shape, area_shape);
+ }
}
body->remove_constraint(this);
area->remove_constraint(this);
@@ -98,18 +105,22 @@ bool Area2Pair2DSW::setup(real_t p_step) {
if (result != colliding) {
if (result) {
- if (area_b->has_area_monitor_callback() && area_a->is_monitorable())
+ if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
area_b->add_area_to_query(area_a, shape_a, shape_b);
+ }
- if (area_a->has_area_monitor_callback() && area_b->is_monitorable())
+ if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
area_a->add_area_to_query(area_b, shape_b, shape_a);
+ }
} else {
- if (area_b->has_area_monitor_callback() && area_a->is_monitorable())
+ if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
area_b->remove_area_from_query(area_a, shape_a, shape_b);
+ }
- if (area_a->has_area_monitor_callback() && area_b->is_monitorable())
+ if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
area_a->remove_area_from_query(area_b, shape_b, shape_a);
+ }
}
colliding = result;
@@ -133,11 +144,13 @@ Area2Pair2DSW::Area2Pair2DSW(Area2DSW *p_area_a, int p_shape_a, Area2DSW *p_area
Area2Pair2DSW::~Area2Pair2DSW() {
if (colliding) {
- if (area_b->has_area_monitor_callback())
+ if (area_b->has_area_monitor_callback()) {
area_b->remove_area_from_query(area_a, shape_a, shape_b);
+ }
- if (area_a->has_area_monitor_callback())
+ if (area_a->has_area_monitor_callback()) {
area_a->remove_area_from_query(area_b, shape_b, shape_a);
+ }
}
area_a->remove_constraint(this);
diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp
index 498972f538..856bba78f7 100644
--- a/servers/physics_2d/body_2d_sw.cpp
+++ b/servers/physics_2d/body_2d_sw.cpp
@@ -34,8 +34,9 @@
#include "space_2d_sw.h"
void Body2DSW::_update_inertia() {
- if (!user_inertia && get_space() && !inertia_update_list.in_list())
+ if (!user_inertia && get_space() && !inertia_update_list.in_list()) {
get_space()->body_add_to_inertia_update_list(&inertia_update_list);
+ }
}
void Body2DSW::update_inertias() {
@@ -74,10 +75,11 @@ void Body2DSW::update_inertias() {
_inv_inertia = inertia > 0 ? (1.0 / inertia) : 0;
- if (mass)
+ if (mass) {
_inv_mass = 1.0 / mass;
- else
+ } else {
_inv_mass = 0;
+ }
} break;
case PhysicsServer2D::BODY_MODE_KINEMATIC:
@@ -97,18 +99,22 @@ void Body2DSW::update_inertias() {
}
void Body2DSW::set_active(bool p_active) {
- if (active == p_active)
+ if (active == p_active) {
return;
+ }
active = p_active;
if (!p_active) {
- if (get_space())
+ if (get_space()) {
get_space()->body_remove_from_active_list(&active_list);
+ }
} else {
- if (mode == PhysicsServer2D::BODY_MODE_STATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC) {
return; //static bodies can't become active
- if (get_space())
+ }
+ if (get_space()) {
get_space()->body_add_to_active_list(&active_list);
+ }
//still_time=0;
}
@@ -265,8 +271,9 @@ void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_va
Transform2D t = p_variant;
t.orthonormalize();
new_transform = get_transform(); //used as old to compute motion
- if (t == new_transform)
+ if (t == new_transform) {
break;
+ }
_set_transform(t);
_set_inv_transform(get_transform().inverse());
}
@@ -293,8 +300,9 @@ void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_va
} break;
case PhysicsServer2D::BODY_STATE_SLEEPING: {
//?
- if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
break;
+ }
bool do_sleep = p_variant;
if (do_sleep) {
linear_velocity = Vector2();
@@ -303,14 +311,16 @@ void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_va
//biased_angular_velocity=Vector3();
set_active(false);
} else {
- if (mode != PhysicsServer2D::BODY_MODE_STATIC)
+ if (mode != PhysicsServer2D::BODY_MODE_STATIC) {
set_active(true);
+ }
}
} break;
case PhysicsServer2D::BODY_STATE_CAN_SLEEP: {
can_sleep = p_variant;
- if (mode == PhysicsServer2D::BODY_MODE_RIGID && !active && !can_sleep)
+ if (mode == PhysicsServer2D::BODY_MODE_RIGID && !active && !can_sleep) {
set_active(true);
+ }
} break;
}
@@ -342,20 +352,24 @@ void Body2DSW::set_space(Space2DSW *p_space) {
if (get_space()) {
wakeup_neighbours();
- if (inertia_update_list.in_list())
+ if (inertia_update_list.in_list()) {
get_space()->body_remove_from_inertia_update_list(&inertia_update_list);
- if (active_list.in_list())
+ }
+ if (active_list.in_list()) {
get_space()->body_remove_from_active_list(&active_list);
- if (direct_state_query_list.in_list())
+ }
+ if (direct_state_query_list.in_list()) {
get_space()->body_remove_from_state_query_list(&direct_state_query_list);
+ }
}
_set_space(p_space);
if (get_space()) {
_update_inertia();
- if (active)
+ if (active) {
get_space()->body_add_to_active_list(&active_list);
+ }
/*
_update_queries();
if (is_active()) {
@@ -385,8 +399,9 @@ void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) {
}
void Body2DSW::integrate_forces(real_t p_step) {
- if (mode == PhysicsServer2D::BODY_MODE_STATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC) {
return;
+ }
Area2DSW *def_area = get_space()->get_default_area();
// Area2DSW *damp_area = def_area;
@@ -428,15 +443,17 @@ void Body2DSW::integrate_forces(real_t p_step) {
gravity *= gravity_scale;
// If less than 0, override dampenings with that of the Body2D
- if (angular_damp >= 0)
+ if (angular_damp >= 0) {
area_angular_damp = angular_damp;
+ }
/*
else
area_angular_damp=damp_area->get_angular_damp();
*/
- if (linear_damp >= 0)
+ if (linear_damp >= 0) {
area_linear_damp = linear_damp;
+ }
/*
else
area_linear_damp=damp_area->get_linear_damp();
@@ -472,13 +489,15 @@ void Body2DSW::integrate_forces(real_t p_step) {
real_t damp = 1.0 - p_step * area_linear_damp;
- if (damp < 0) // reached zero in the given time
+ if (damp < 0) { // reached zero in the given time
damp = 0;
+ }
real_t angular_damp = 1.0 - p_step * area_angular_damp;
- if (angular_damp < 0) // reached zero in the given time
+ if (angular_damp < 0) { // reached zero in the given time
angular_damp = 0;
+ }
linear_velocity *= damp;
angular_velocity *= angular_damp;
@@ -509,17 +528,20 @@ void Body2DSW::integrate_forces(real_t p_step) {
}
void Body2DSW::integrate_velocities(real_t p_step) {
- if (mode == PhysicsServer2D::BODY_MODE_STATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC) {
return;
+ }
- if (fi_callback)
+ if (fi_callback) {
get_space()->body_add_to_state_query_list(&direct_state_query_list);
+ }
if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
_set_transform(new_transform, false);
_set_inv_transform(new_transform.affine_inverse());
- if (contacts.size() == 0 && linear_velocity == Vector2() && angular_velocity == 0)
+ if (contacts.size() == 0 && linear_velocity == Vector2() && angular_velocity == 0) {
set_active(false); //stopped moving, deactivate
+ }
return;
}
@@ -532,8 +554,9 @@ void Body2DSW::integrate_velocities(real_t p_step) {
_set_transform(Transform2D(angle, pos), continuous_cd_mode == PhysicsServer2D::CCD_MODE_DISABLED);
_set_inv_transform(get_transform().inverse());
- if (continuous_cd_mode != PhysicsServer2D::CCD_MODE_DISABLED)
+ if (continuous_cd_mode != PhysicsServer2D::CCD_MODE_DISABLED) {
new_transform = get_transform();
+ }
//_update_inertia_tensor();
}
@@ -545,14 +568,17 @@ void Body2DSW::wakeup_neighbours() {
int bc = c->get_body_count();
for (int i = 0; i < bc; i++) {
- if (i == E->get())
+ if (i == E->get()) {
continue;
+ }
Body2DSW *b = n[i];
- if (b->mode != PhysicsServer2D::BODY_MODE_RIGID)
+ if (b->mode != PhysicsServer2D::BODY_MODE_RIGID) {
continue;
+ }
- if (!b->is_active())
+ if (!b->is_active()) {
b->set_active(true);
+ }
}
}
}
@@ -581,12 +607,13 @@ void Body2DSW::call_queries() {
}
bool Body2DSW::sleep_test(real_t p_step) {
- if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
return true; //
- else if (mode == PhysicsServer2D::BODY_MODE_CHARACTER)
+ } else if (mode == PhysicsServer2D::BODY_MODE_CHARACTER) {
return !active; // characters and kinematic bodies don't sleep unless asked to sleep
- else if (!can_sleep)
+ } else if (!can_sleep) {
return false;
+ }
if (Math::abs(angular_velocity) < get_space()->get_body_angular_velocity_sleep_threshold() && Math::abs(linear_velocity.length_squared()) < get_space()->get_body_linear_velocity_sleep_threshold() * get_space()->get_body_linear_velocity_sleep_threshold()) {
still_time += p_step;
@@ -650,8 +677,9 @@ Body2DSW::Body2DSW() :
}
Body2DSW::~Body2DSW() {
- if (fi_callback)
+ if (fi_callback) {
memdelete(fi_callback);
+ }
}
PhysicsDirectBodyState2DSW *PhysicsDirectBodyState2DSW::singleton = nullptr;
diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h
index c1fc4e2bb5..2300c9cdee 100644
--- a/servers/physics_2d/body_2d_sw.h
+++ b/servers/physics_2d/body_2d_sw.h
@@ -146,16 +146,18 @@ public:
int index = areas.find(AreaCMP(p_area));
if (index > -1) {
areas.write[index].refCount -= 1;
- if (areas[index].refCount < 1)
+ if (areas[index].refCount < 1) {
areas.remove(index);
+ }
}
}
_FORCE_INLINE_ void set_max_contacts_reported(int p_size) {
contacts.resize(p_size);
contact_count = 0;
- if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC && p_size)
+ if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC && p_size) {
set_active(true);
+ }
}
_FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); }
@@ -219,8 +221,9 @@ public:
_FORCE_INLINE_ bool is_active() const { return active; }
_FORCE_INLINE_ void wakeup() {
- if ((!get_space()) || mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC)
+ if ((!get_space()) || mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
return;
+ }
set_active(true);
}
@@ -293,8 +296,9 @@ public:
void Body2DSW::add_contact(const Vector2 &p_local_pos, const Vector2 &p_local_normal, real_t p_depth, int p_local_shape, const Vector2 &p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID &p_collider, const Vector2 &p_collider_velocity_at_pos) {
int c_max = contacts.size();
- if (c_max == 0)
+ if (c_max == 0) {
return;
+ }
Contact *c = contacts.ptrw();
@@ -315,8 +319,9 @@ void Body2DSW::add_contact(const Vector2 &p_local_pos, const Vector2 &p_local_no
if (least_deep >= 0 && least_depth < p_depth) {
idx = least_deep;
}
- if (idx == -1)
+ if (idx == -1) {
return; //none least deepe than this
+ }
}
c[idx].local_pos = p_local_pos;
diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp
index 32a3dd2504..e483ddf1cc 100644
--- a/servers/physics_2d/body_pair_2d_sw.cpp
+++ b/servers/physics_2d/body_pair_2d_sw.cpp
@@ -161,8 +161,9 @@ void BodyPair2DSW::_validate_contacts() {
bool BodyPair2DSW::_test_ccd(real_t p_step, Body2DSW *p_A, int p_shape_A, const Transform2D &p_xform_A, Body2DSW *p_B, int p_shape_B, const Transform2D &p_xform_B, bool p_swap_result) {
Vector2 motion = p_A->get_linear_velocity() * p_step;
real_t mlen = motion.length();
- if (mlen < CMP_EPSILON)
+ if (mlen < CMP_EPSILON) {
return false;
+ }
Vector2 mnormal = motion / mlen;
@@ -188,8 +189,9 @@ bool BodyPair2DSW::_test_ccd(real_t p_step, Body2DSW *p_A, int p_shape_A, const
Vector2 local_to = from_inv.xform(to);
Vector2 rpos, rnorm;
- if (!p_B->get_shape(p_shape_B)->intersect_segment(local_from, local_to, rpos, rnorm))
+ if (!p_B->get_shape(p_shape_B)->intersect_segment(local_from, local_to, rpos, rnorm)) {
return false;
+ }
//ray hit something
@@ -200,10 +202,11 @@ bool BodyPair2DSW::_test_ccd(real_t p_step, Body2DSW *p_A, int p_shape_A, const
//create a contact
- if (p_swap_result)
+ if (p_swap_result) {
_contact_added_callback(contact_B, contact_A);
- else
+ } else {
_contact_added_callback(contact_A, contact_B);
+ }
return true;
}
@@ -261,13 +264,15 @@ bool BodyPair2DSW::setup(real_t p_step) {
//test ccd (currently just a raycast)
if (A->get_continuous_collision_detection_mode() == PhysicsServer2D::CCD_MODE_CAST_RAY && A->get_mode() > PhysicsServer2D::BODY_MODE_KINEMATIC) {
- if (_test_ccd(p_step, A, shape_A, xform_A, B, shape_B, xform_B))
+ if (_test_ccd(p_step, A, shape_A, xform_A, B, shape_B, xform_B)) {
collided = true;
+ }
}
if (B->get_continuous_collision_detection_mode() == PhysicsServer2D::CCD_MODE_CAST_RAY && B->get_mode() > PhysicsServer2D::BODY_MODE_KINEMATIC) {
- if (_test_ccd(p_step, B, shape_B, xform_B, A, shape_A, xform_A, true))
+ if (_test_ccd(p_step, B, shape_B, xform_B, A, shape_A, xform_A, true)) {
collided = true;
+ }
}
if (!collided) {
@@ -276,8 +281,9 @@ bool BodyPair2DSW::setup(real_t p_step) {
}
}
- if (oneway_disabled)
+ if (oneway_disabled) {
return false;
+ }
//if (!prev_collided) {
{
@@ -287,10 +293,12 @@ bool BodyPair2DSW::setup(real_t p_step) {
if (B->get_linear_velocity().dot(direction) >= 0) {
for (int i = 0; i < contact_count; i++) {
Contact &c = contacts[i];
- if (!c.reused)
+ if (!c.reused) {
continue;
- if (c.normal.dot(direction) > 0) //greater (normal inverted)
+ }
+ if (c.normal.dot(direction) > 0) { //greater (normal inverted)
continue;
+ }
valid = true;
break;
@@ -310,10 +318,12 @@ bool BodyPair2DSW::setup(real_t p_step) {
if (A->get_linear_velocity().dot(direction) >= 0) {
for (int i = 0; i < contact_count; i++) {
Contact &c = contacts[i];
- if (!c.reused)
+ if (!c.reused) {
continue;
- if (c.normal.dot(direction) < 0) //less (normal ok)
+ }
+ if (c.normal.dot(direction) < 0) { //less (normal ok)
continue;
+ }
valid = true;
break;
@@ -331,12 +341,13 @@ bool BodyPair2DSW::setup(real_t p_step) {
real_t bias = 0.3;
if (shape_A_ptr->get_custom_bias() || shape_B_ptr->get_custom_bias()) {
- if (shape_A_ptr->get_custom_bias() == 0)
+ if (shape_A_ptr->get_custom_bias() == 0) {
bias = shape_B_ptr->get_custom_bias();
- else if (shape_B_ptr->get_custom_bias() == 0)
+ } else if (shape_B_ptr->get_custom_bias() == 0) {
bias = shape_A_ptr->get_custom_bias();
- else
+ } else {
bias = (shape_B_ptr->get_custom_bias() + shape_A_ptr->get_custom_bias()) * 0.5;
+ }
}
cc = 0;
@@ -437,15 +448,17 @@ bool BodyPair2DSW::setup(real_t p_step) {
}
void BodyPair2DSW::solve(real_t p_step) {
- if (!collided)
+ if (!collided) {
return;
+ }
for (int i = 0; i < contact_count; ++i) {
Contact &c = contacts[i];
cc++;
- if (!c.active)
+ if (!c.active) {
continue;
+ }
// Relative velocity at contact
diff --git a/servers/physics_2d/broad_phase_2d_basic.cpp b/servers/physics_2d/broad_phase_2d_basic.cpp
index a6bcae11e9..8c7e715a09 100644
--- a/servers/physics_2d/broad_phase_2d_basic.cpp
+++ b/servers/physics_2d/broad_phase_2d_basic.cpp
@@ -87,8 +87,9 @@ int BroadPhase2DBasic::cull_segment(const Vector2 &p_from, const Vector2 &p_to,
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
- if (rc >= p_max_results)
+ if (rc >= p_max_results) {
break;
+ }
}
}
@@ -104,8 +105,9 @@ int BroadPhase2DBasic::cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p_re
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
- if (rc >= p_max_results)
+ if (rc >= p_max_results) {
break;
+ }
}
}
@@ -129,8 +131,9 @@ void BroadPhase2DBasic::update() {
Element *elem_A = &I->get();
Element *elem_B = &J->get();
- if (elem_A->owner == elem_B->owner)
+ if (elem_A->owner == elem_B->owner) {
continue;
+ }
bool pair_ok = elem_A->aabb.intersects(elem_B->aabb) && (!elem_A->_static || !elem_B->_static);
@@ -139,15 +142,17 @@ void BroadPhase2DBasic::update() {
Map<PairKey, void *>::Element *E = pair_map.find(key);
if (!pair_ok && E) {
- if (unpair_callback)
+ if (unpair_callback) {
unpair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, E->get(), unpair_userdata);
+ }
pair_map.erase(key);
}
if (pair_ok && !E) {
void *data = nullptr;
- if (pair_callback)
+ if (pair_callback) {
data = pair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, unpair_userdata);
+ }
pair_map.insert(key, data);
}
}
diff --git a/servers/physics_2d/broad_phase_2d_hash_grid.cpp b/servers/physics_2d/broad_phase_2d_hash_grid.cpp
index e3a841366e..ae549ed2e4 100644
--- a/servers/physics_2d/broad_phase_2d_hash_grid.cpp
+++ b/servers/physics_2d/broad_phase_2d_hash_grid.cpp
@@ -93,12 +93,15 @@ void BroadPhase2DHashGrid::_enter_grid(Element *p_elem, const Rect2 &p_rect, boo
if (sz.width * sz.height > large_object_min_surface) {
//large object, do not use grid, must check against all elements
for (Map<ID, Element>::Element *E = element_map.front(); E; E = E->next()) {
- if (E->key() == p_elem->self)
+ if (E->key() == p_elem->self) {
continue; // do not pair against itself
- if (E->get().owner == p_elem->owner)
+ }
+ if (E->get().owner == p_elem->owner) {
continue;
- if (E->get()._static && p_static)
+ }
+ if (E->get()._static && p_static) {
continue;
+ }
_pair_attempt(p_elem, &E->get());
}
@@ -149,15 +152,17 @@ void BroadPhase2DHashGrid::_enter_grid(Element *p_elem, const Rect2 &p_rect, boo
if (entered) {
for (Map<Element *, RC>::Element *E = pb->object_set.front(); E; E = E->next()) {
- if (E->key()->owner == p_elem->owner)
+ if (E->key()->owner == p_elem->owner) {
continue;
+ }
_pair_attempt(p_elem, E->key());
}
if (!p_static) {
for (Map<Element *, RC>::Element *E = pb->static_object_set.front(); E; E = E->next()) {
- if (E->key()->owner == p_elem->owner)
+ if (E->key()->owner == p_elem->owner) {
continue;
+ }
_pair_attempt(p_elem, E->key());
}
}
@@ -168,12 +173,15 @@ void BroadPhase2DHashGrid::_enter_grid(Element *p_elem, const Rect2 &p_rect, boo
//pair separatedly with large elements
for (Map<Element *, RC>::Element *E = large_elements.front(); E; E = E->next()) {
- if (E->key() == p_elem)
+ if (E->key() == p_elem) {
continue; // do not pair against itself
- if (E->key()->owner == p_elem->owner)
+ }
+ if (E->key()->owner == p_elem->owner) {
continue;
- if (E->key()->_static && p_static)
+ }
+ if (E->key()->_static && p_static) {
continue;
+ }
_pair_attempt(E->key(), p_elem);
}
@@ -234,15 +242,17 @@ void BroadPhase2DHashGrid::_exit_grid(Element *p_elem, const Rect2 &p_rect, bool
if (exited) {
for (Map<Element *, RC>::Element *E = pb->object_set.front(); E; E = E->next()) {
- if (E->key()->owner == p_elem->owner)
+ if (E->key()->owner == p_elem->owner) {
continue;
+ }
_unpair_attempt(p_elem, E->key());
}
if (!p_static) {
for (Map<Element *, RC>::Element *E = pb->static_object_set.front(); E; E = E->next()) {
- if (E->key()->owner == p_elem->owner)
+ if (E->key()->owner == p_elem->owner) {
continue;
+ }
_unpair_attempt(p_elem, E->key());
}
}
@@ -272,12 +282,15 @@ void BroadPhase2DHashGrid::_exit_grid(Element *p_elem, const Rect2 &p_rect, bool
}
for (Map<Element *, RC>::Element *E = large_elements.front(); E; E = E->next()) {
- if (E->key() == p_elem)
+ if (E->key() == p_elem) {
continue; // do not pair against itself
- if (E->key()->owner == p_elem->owner)
+ }
+ if (E->key()->owner == p_elem->owner) {
continue;
- if (E->key()->_static && p_static)
+ }
+ if (E->key()->_static && p_static) {
continue;
+ }
//unpair from large elements
_unpair_attempt(p_elem, E->key());
@@ -304,8 +317,9 @@ void BroadPhase2DHashGrid::move(ID p_id, const Rect2 &p_aabb) {
Element &e = E->get();
- if (p_aabb == e.aabb)
+ if (p_aabb == e.aabb) {
return;
+ }
if (p_aabb != Rect2()) {
_enter_grid(&e, p_aabb, e._static);
@@ -328,11 +342,13 @@ void BroadPhase2DHashGrid::set_static(ID p_id, bool p_static) {
Element &e = E->get();
- if (e._static == p_static)
+ if (e._static == p_static) {
return;
+ }
- if (e.aabb != Rect2())
+ if (e.aabb != Rect2()) {
_exit_grid(&e, e.aabb, e._static);
+ }
e._static = p_static;
@@ -348,8 +364,9 @@ void BroadPhase2DHashGrid::remove(ID p_id) {
Element &e = E->get();
- if (e.aabb != Rect2())
+ if (e.aabb != Rect2()) {
_exit_grid(&e, e.aabb, e._static);
+ }
element_map.erase(p_id);
}
@@ -389,22 +406,27 @@ void BroadPhase2DHashGrid::_cull(const Point2i p_cell, const Rect2 &p_aabb, cons
pb = pb->next;
}
- if (!pb)
+ if (!pb) {
return;
+ }
for (Map<Element *, RC>::Element *E = pb->object_set.front(); E; E = E->next()) {
- if (index >= p_max_results)
+ if (index >= p_max_results) {
break;
- if (E->key()->pass == pass)
+ }
+ if (E->key()->pass == pass) {
continue;
+ }
E->key()->pass = pass;
- if (use_aabb && !p_aabb.intersects(E->key()->aabb))
+ if (use_aabb && !p_aabb.intersects(E->key()->aabb)) {
continue;
+ }
- if (use_segment && !E->key()->aabb.intersects_segment(p_from, p_to))
+ if (use_segment && !E->key()->aabb.intersects_segment(p_from, p_to)) {
continue;
+ }
p_results[index] = E->key()->owner;
p_result_indices[index] = E->key()->subindex;
@@ -412,17 +434,20 @@ void BroadPhase2DHashGrid::_cull(const Point2i p_cell, const Rect2 &p_aabb, cons
}
for (Map<Element *, RC>::Element *E = pb->static_object_set.front(); E; E = E->next()) {
- if (index >= p_max_results)
+ if (index >= p_max_results) {
break;
- if (E->key()->pass == pass)
+ }
+ if (E->key()->pass == pass) {
continue;
+ }
if (use_aabb && !p_aabb.intersects(E->key()->aabb)) {
continue;
}
- if (use_segment && !E->key()->aabb.intersects_segment(p_from, p_to))
+ if (use_segment && !E->key()->aabb.intersects_segment(p_from, p_to)) {
continue;
+ }
E->key()->pass = pass;
p_results[index] = E->key()->owner;
@@ -435,14 +460,17 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2 &p_from, const Vector2 &p_t
pass++;
Vector2 dir = (p_to - p_from);
- if (dir == Vector2())
+ if (dir == Vector2()) {
return 0;
+ }
//avoid divisions by zero
dir.normalize();
- if (dir.x == 0.0)
+ if (dir.x == 0.0) {
dir.x = 0.000001;
- if (dir.y == 0.0)
+ }
+ if (dir.y == 0.0) {
dir.y = 0.000001;
+ }
Vector2 delta = dir.abs();
delta.x = cell_size / delta.x;
@@ -455,15 +483,17 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2 &p_from, const Vector2 &p_t
Vector2 max;
- if (dir.x < 0)
+ if (dir.x < 0) {
max.x = (Math::floor((double)pos.x) * cell_size - p_from.x) / dir.x;
- else
+ } else {
max.x = (Math::floor((double)pos.x + 1) * cell_size - p_from.x) / dir.x;
+ }
- if (dir.y < 0)
+ if (dir.y < 0) {
max.y = (Math::floor((double)pos.y) * cell_size - p_from.y) / dir.y;
- else
+ } else {
max.y = (Math::floor((double)pos.y + 1) * cell_size - p_from.y) / dir.y;
+ }
int cullcount = 0;
_cull<false, true>(pos, Rect2(), p_from, p_to, p_results, p_max_results, p_result_indices, cullcount);
@@ -481,30 +511,35 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2 &p_from, const Vector2 &p_t
}
if (step.x > 0) {
- if (pos.x >= end.x)
+ if (pos.x >= end.x) {
reached_x = true;
+ }
} else if (pos.x <= end.x) {
reached_x = true;
}
if (step.y > 0) {
- if (pos.y >= end.y)
+ if (pos.y >= end.y) {
reached_y = true;
+ }
} else if (pos.y <= end.y) {
reached_y = true;
}
_cull<false, true>(pos, Rect2(), p_from, p_to, p_results, p_max_results, p_result_indices, cullcount);
- if (reached_x && reached_y)
+ if (reached_x && reached_y) {
break;
+ }
}
for (Map<Element *, RC>::Element *E = large_elements.front(); E; E = E->next()) {
- if (cullcount >= p_max_results)
+ if (cullcount >= p_max_results) {
break;
- if (E->key()->pass == pass)
+ }
+ if (E->key()->pass == pass) {
continue;
+ }
E->key()->pass = pass;
@@ -513,8 +548,9 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2 &p_from, const Vector2 &p_t
continue;
*/
- if (!E->key()->aabb.intersects_segment(p_from, p_to))
+ if (!E->key()->aabb.intersects_segment(p_from, p_to)) {
continue;
+ }
p_results[cullcount] = E->key()->owner;
p_result_indices[cullcount] = E->key()->subindex;
@@ -538,15 +574,18 @@ int BroadPhase2DHashGrid::cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p
}
for (Map<Element *, RC>::Element *E = large_elements.front(); E; E = E->next()) {
- if (cullcount >= p_max_results)
+ if (cullcount >= p_max_results) {
break;
- if (E->key()->pass == pass)
+ }
+ if (E->key()->pass == pass) {
continue;
+ }
E->key()->pass = pass;
- if (!p_aabb.intersects(E->key()->aabb))
+ if (!p_aabb.intersects(E->key()->aabb)) {
continue;
+ }
/*
if (!E->key()->aabb.intersects_segment(p_from,p_to))
@@ -589,8 +628,9 @@ BroadPhase2DHashGrid::BroadPhase2DHashGrid() {
large_object_min_surface = GLOBAL_DEF("physics/2d/large_object_surface_threshold_in_cells", 512);
ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/large_object_surface_threshold_in_cells", PropertyInfo(Variant::INT, "physics/2d/large_object_surface_threshold_in_cells", PROPERTY_HINT_RANGE, "0,1024,1,or_greater"));
- for (uint32_t i = 0; i < hash_table_size; i++)
+ for (uint32_t i = 0; i < hash_table_size; i++) {
hash_table[i] = nullptr;
+ }
pass = 1;
current = 0;
diff --git a/servers/physics_2d/collision_object_2d_sw.cpp b/servers/physics_2d/collision_object_2d_sw.cpp
index 696100ccc3..6931d96fe4 100644
--- a/servers/physics_2d/collision_object_2d_sw.cpp
+++ b/servers/physics_2d/collision_object_2d_sw.cpp
@@ -87,13 +87,15 @@ void CollisionObject2DSW::set_shape_as_disabled(int p_idx, bool p_disabled) {
ERR_FAIL_INDEX(p_idx, shapes.size());
CollisionObject2DSW::Shape &shape = shapes.write[p_idx];
- if (shape.disabled == p_disabled)
+ if (shape.disabled == p_disabled) {
return;
+ }
shape.disabled = p_disabled;
- if (!space)
+ if (!space) {
return;
+ }
if (p_disabled && shape.bpid != 0) {
space->get_broadphase()->remove(shape.bpid);
@@ -124,8 +126,9 @@ void CollisionObject2DSW::remove_shape(int p_index) {
//remove anything from shape to be erased to end, so subindices don't change
ERR_FAIL_INDEX(p_index, shapes.size());
for (int i = p_index; i < shapes.size(); i++) {
- if (shapes[i].bpid == 0)
+ if (shapes[i].bpid == 0) {
continue;
+ }
//should never get here with a null owner
space->get_broadphase()->remove(shapes[i].bpid);
shapes.write[i].bpid = 0;
@@ -141,12 +144,14 @@ void CollisionObject2DSW::remove_shape(int p_index) {
}
void CollisionObject2DSW::_set_static(bool p_static) {
- if (_static == p_static)
+ if (_static == p_static) {
return;
+ }
_static = p_static;
- if (!space)
+ if (!space) {
return;
+ }
for (int i = 0; i < get_shape_count(); i++) {
const Shape &s = shapes[i];
if (s.bpid > 0) {
@@ -166,14 +171,16 @@ void CollisionObject2DSW::_unregister_shapes() {
}
void CollisionObject2DSW::_update_shapes() {
- if (!space)
+ if (!space) {
return;
+ }
for (int i = 0; i < shapes.size(); i++) {
Shape &s = shapes.write[i];
- if (s.disabled)
+ if (s.disabled) {
continue;
+ }
if (s.bpid == 0) {
s.bpid = space->get_broadphase()->create(this, i);
@@ -192,13 +199,15 @@ void CollisionObject2DSW::_update_shapes() {
}
void CollisionObject2DSW::_update_shapes_with_motion(const Vector2 &p_motion) {
- if (!space)
+ if (!space) {
return;
+ }
for (int i = 0; i < shapes.size(); i++) {
Shape &s = shapes.write[i];
- if (s.disabled)
+ if (s.disabled) {
continue;
+ }
if (s.bpid == 0) {
s.bpid = space->get_broadphase()->create(this, i);
diff --git a/servers/physics_2d/collision_solver_2d_sat.cpp b/servers/physics_2d/collision_solver_2d_sat.cpp
index 58cba28fe1..2cada2bf50 100644
--- a/servers/physics_2d/collision_solver_2d_sat.cpp
+++ b/servers/physics_2d/collision_solver_2d_sat.cpp
@@ -45,10 +45,11 @@ struct _CollectorCallback2D {
if (normal.dot(p_point_A) >= normal.dot(p_point_B))
return;
*/
- if (swap)
+ if (swap) {
callback(p_point_B, p_point_A, userdata);
- else
+ } else {
callback(p_point_A, p_point_B, userdata);
+ }
}
};
@@ -113,14 +114,16 @@ _FORCE_INLINE_ static void _generate_contacts_edge_edge(const Vector2 *p_points_
if (dvec[i].a) {
Vector2 a = p_points_A[dvec[i].idx];
Vector2 b = n.plane_project(dB, a);
- if (n.dot(a) > n.dot(b) - CMP_EPSILON)
+ if (n.dot(a) > n.dot(b) - CMP_EPSILON) {
continue;
+ }
p_collector->call(a, b);
} else {
Vector2 b = p_points_B[dvec[i].idx];
Vector2 a = n.plane_project(dA, b);
- if (n.dot(a) > n.dot(b) - CMP_EPSILON)
+ if (n.dot(a) > n.dot(b) - CMP_EPSILON) {
continue;
+ }
p_collector->call(a, b);
}
}
@@ -203,18 +206,22 @@ public:
_FORCE_INLINE_ bool test_cast() {
if (castA) {
Vector2 na = motion_A.normalized();
- if (!test_axis(na))
+ if (!test_axis(na)) {
return false;
- if (!test_axis(na.tangent()))
+ }
+ if (!test_axis(na.tangent())) {
return false;
+ }
}
if (castB) {
Vector2 nb = motion_B.normalized();
- if (!test_axis(nb))
+ if (!test_axis(nb)) {
return false;
- if (!test_axis(nb.tangent()))
+ }
+ if (!test_axis(nb.tangent())) {
return false;
+ }
}
return true;
@@ -231,15 +238,17 @@ public:
real_t min_A, max_A, min_B, max_B;
- if (castA)
+ if (castA) {
shape_A->project_range_cast(motion_A, axis, *transform_A, min_A, max_A);
- else
+ } else {
shape_A->project_range(axis, *transform_A, min_A, max_A);
+ }
- if (castB)
+ if (castB) {
shape_B->project_range_cast(motion_B, axis, *transform_B, min_B, max_B);
- else
+ } else {
shape_B->project_range(axis, *transform_B, min_B, max_B);
+ }
if (withMargin) {
min_A -= margin_A;
@@ -255,8 +264,9 @@ public:
real_t dmax = max_B - (min_A + max_A) * 0.5;
if (dmin > 0.0 || dmax < 0.0) {
- if (callback && callback->sep_axis)
+ if (callback && callback->sep_axis) {
*callback->sep_axis = axis;
+ }
#ifdef DEBUG_ENABLED
best_axis_count++;
#endif
@@ -295,14 +305,16 @@ public:
_FORCE_INLINE_ void generate_contacts() {
// nothing to do, don't generate
- if (best_axis == Vector2(0.0, 0.0))
+ if (best_axis == Vector2(0.0, 0.0)) {
return;
+ }
if (callback) {
callback->collided = true;
- if (!callback->callback)
+ if (!callback->callback) {
return; //only collide, no callback
+ }
}
static const int max_supports = 2;
@@ -343,8 +355,9 @@ public:
callback->normal = best_axis;
_generate_contacts_from_supports(supports_A, support_count_A, supports_B, support_count_B, callback);
- if (callback->sep_axis && *callback->sep_axis != Vector2())
+ if (callback->sep_axis && *callback->sep_axis != Vector2()) {
*callback->sep_axis = Vector2(); //invalidate previous axis (no test)
+ }
}
}
@@ -384,29 +397,37 @@ static void _collision_segment_segment(const Shape2DSW *p_a, const Transform2D &
SeparatorAxisTest2D<SegmentShape2DSW, SegmentShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, segment_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
//this collision is kind of pointless
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a)))
+ if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a))) {
return;
- if (!separator.test_axis(segment_B->get_xformed_normal(p_transform_b)))
+ }
+ if (!separator.test_axis(segment_B->get_xformed_normal(p_transform_b))) {
return;
+ }
if (withMargin) {
//points grow to circles
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(segment_B->get_a())))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(segment_B->get_a()))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(segment_B->get_b())))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(segment_B->get_b()))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(segment_B->get_a())))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(segment_B->get_a()))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(segment_B->get_b())))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(segment_B->get_b()))) {
return;
+ }
}
separator.generate_contacts();
@@ -419,23 +440,28 @@ static void _collision_segment_circle(const Shape2DSW *p_a, const Transform2D &p
SeparatorAxisTest2D<SegmentShape2DSW, CircleShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, circle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//segment normal
if (!separator.test_axis(
- (p_transform_a.xform(segment_A->get_b()) - p_transform_a.xform(segment_A->get_a())).normalized().tangent()))
+ (p_transform_a.xform(segment_A->get_b()) - p_transform_a.xform(segment_A->get_a())).normalized().tangent())) {
return;
+ }
//endpoint a vs circle
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.get_origin()))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.get_origin())) {
return;
+ }
//endpoint b vs circle
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.get_origin()))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.get_origin())) {
return;
+ }
separator.generate_contacts();
}
@@ -447,20 +473,25 @@ static void _collision_segment_rectangle(const Shape2DSW *p_a, const Transform2D
SeparatorAxisTest2D<SegmentShape2DSW, RectangleShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, rectangle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a)))
+ if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a))) {
return;
+ }
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_b.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[1].normalized())) {
return;
+ }
if (withMargin) {
Transform2D inv = p_transform_b.affine_inverse();
@@ -468,30 +499,38 @@ static void _collision_segment_rectangle(const Shape2DSW *p_a, const Transform2D
Vector2 a = p_transform_a.xform(segment_A->get_a());
Vector2 b = p_transform_a.xform(segment_A->get_b());
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a))) {
return;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b)))
+ }
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b))) {
return;
+ }
if (castA) {
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a + p_motion_a)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a + p_motion_a))) {
return;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b + p_motion_a)))
+ }
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b + p_motion_a))) {
return;
+ }
}
if (castB) {
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a - p_motion_b)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a - p_motion_b))) {
return;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b - p_motion_b)))
+ }
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b - p_motion_b))) {
return;
+ }
}
if (castA && castB) {
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a - p_motion_b + p_motion_a)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a - p_motion_b + p_motion_a))) {
return;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b - p_motion_b + p_motion_a)))
+ }
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b - p_motion_b + p_motion_a))) {
return;
+ }
}
}
@@ -505,26 +544,34 @@ static void _collision_segment_capsule(const Shape2DSW *p_a, const Transform2D &
SeparatorAxisTest2D<SegmentShape2DSW, CapsuleShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a)))
+ if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a))) {
return;
+ }
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5)))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5)))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5)))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5)))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5))) {
return;
+ }
separator.generate_contacts();
}
@@ -536,24 +583,30 @@ static void _collision_segment_convex_polygon(const Shape2DSW *p_a, const Transf
SeparatorAxisTest2D<SegmentShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a)))
+ if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a))) {
return;
+ }
for (int i = 0; i < convex_B->get_point_count(); i++) {
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
if (withMargin) {
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(convex_B->get_point(i))))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(convex_B->get_point(i)))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(convex_B->get_point(i))))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(convex_B->get_point(i)))) {
return;
+ }
}
}
@@ -569,14 +622,17 @@ static void _collision_circle_circle(const Shape2DSW *p_a, const Transform2D &p_
SeparatorAxisTest2D<CircleShape2DSW, CircleShape2DSW, castA, castB, withMargin> separator(circle_A, p_transform_a, circle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (TEST_POINT(p_transform_a.get_origin(), p_transform_b.get_origin()))
+ if (TEST_POINT(p_transform_a.get_origin(), p_transform_b.get_origin())) {
return;
+ }
separator.generate_contacts();
}
@@ -588,44 +644,52 @@ static void _collision_circle_rectangle(const Shape2DSW *p_a, const Transform2D
SeparatorAxisTest2D<CircleShape2DSW, RectangleShape2DSW, castA, castB, withMargin> separator(circle_A, p_transform_a, rectangle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
const Vector2 &sphere = p_transform_a.elements[2];
const Vector2 *axis = &p_transform_b.elements[0];
//const Vector2& half_extents = rectangle_B->get_half_extents();
- if (!separator.test_axis(axis[0].normalized()))
+ if (!separator.test_axis(axis[0].normalized())) {
return;
+ }
- if (!separator.test_axis(axis[1].normalized()))
+ if (!separator.test_axis(axis[1].normalized())) {
return;
+ }
Transform2D binv = p_transform_b.affine_inverse();
{
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphere)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphere))) {
return;
+ }
}
if (castA) {
Vector2 sphereofs = sphere + p_motion_a;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs))) {
return;
+ }
}
if (castB) {
Vector2 sphereofs = sphere - p_motion_b;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs))) {
return;
+ }
}
if (castA && castB) {
Vector2 sphereofs = sphere - p_motion_b + p_motion_a;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs))) {
return;
+ }
}
separator.generate_contacts();
@@ -638,21 +702,26 @@ static void _collision_circle_capsule(const Shape2DSW *p_a, const Transform2D &p
SeparatorAxisTest2D<CircleShape2DSW, CapsuleShape2DSW, castA, castB, withMargin> separator(circle_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//capsule axis
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
//capsule endpoints
- if (TEST_POINT(p_transform_a.get_origin(), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5)))
+ if (TEST_POINT(p_transform_a.get_origin(), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5))) {
return;
- if (TEST_POINT(p_transform_a.get_origin(), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5)))
+ }
+ if (TEST_POINT(p_transform_a.get_origin(), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5))) {
return;
+ }
separator.generate_contacts();
}
@@ -664,19 +733,23 @@ static void _collision_circle_convex_polygon(const Shape2DSW *p_a, const Transfo
SeparatorAxisTest2D<CircleShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(circle_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//poly faces and poly points vs circle
for (int i = 0; i < convex_B->get_point_count(); i++) {
- if (TEST_POINT(p_transform_a.get_origin(), p_transform_b.xform(convex_B->get_point(i))))
+ if (TEST_POINT(p_transform_a.get_origin(), p_transform_b.xform(convex_B->get_point(i)))) {
return;
+ }
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
}
separator.generate_contacts();
@@ -691,32 +764,39 @@ static void _collision_rectangle_rectangle(const Shape2DSW *p_a, const Transform
SeparatorAxisTest2D<RectangleShape2DSW, RectangleShape2DSW, castA, castB, withMargin> separator(rectangle_A, p_transform_a, rectangle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//box faces A
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_a.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[1].normalized())) {
return;
+ }
//box faces B
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_b.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[1].normalized())) {
return;
+ }
if (withMargin) {
Transform2D invA = p_transform_a.affine_inverse();
Transform2D invB = p_transform_b.affine_inverse();
- if (!separator.test_axis(rectangle_A->get_box_axis(p_transform_a, invA, rectangle_B, p_transform_b, invB)))
+ if (!separator.test_axis(rectangle_A->get_box_axis(p_transform_a, invA, rectangle_B, p_transform_b, invB))) {
return;
+ }
if (castA || castB) {
Transform2D aofs = p_transform_a;
@@ -729,18 +809,21 @@ static void _collision_rectangle_rectangle(const Shape2DSW *p_a, const Transform
Transform2D bofsinv = bofs.affine_inverse();
if (castA) {
- if (!separator.test_axis(rectangle_A->get_box_axis(aofs, aofsinv, rectangle_B, p_transform_b, invB)))
+ if (!separator.test_axis(rectangle_A->get_box_axis(aofs, aofsinv, rectangle_B, p_transform_b, invB))) {
return;
+ }
}
if (castB) {
- if (!separator.test_axis(rectangle_A->get_box_axis(p_transform_a, invA, rectangle_B, bofs, bofsinv)))
+ if (!separator.test_axis(rectangle_A->get_box_axis(p_transform_a, invA, rectangle_B, bofs, bofsinv))) {
return;
+ }
}
if (castA && castB) {
- if (!separator.test_axis(rectangle_A->get_box_axis(aofs, aofsinv, rectangle_B, bofs, bofsinv)))
+ if (!separator.test_axis(rectangle_A->get_box_axis(aofs, aofsinv, rectangle_B, bofs, bofsinv))) {
return;
+ }
}
}
}
@@ -755,22 +838,27 @@ static void _collision_rectangle_capsule(const Shape2DSW *p_a, const Transform2D
SeparatorAxisTest2D<RectangleShape2DSW, CapsuleShape2DSW, castA, castB, withMargin> separator(rectangle_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//box faces
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_a.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[1].normalized())) {
return;
+ }
//capsule axis
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
//box endpoints to capsule circles
@@ -780,24 +868,27 @@ static void _collision_rectangle_capsule(const Shape2DSW *p_a, const Transform2D
{
Vector2 capsule_endpoint = p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * (i == 0 ? 0.5 : -0.5);
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint))) {
return;
+ }
}
if (castA) {
Vector2 capsule_endpoint = p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * (i == 0 ? 0.5 : -0.5);
capsule_endpoint -= p_motion_a;
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint))) {
return;
+ }
}
if (castB) {
Vector2 capsule_endpoint = p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * (i == 0 ? 0.5 : -0.5);
capsule_endpoint += p_motion_b;
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint))) {
return;
+ }
}
if (castA && castB) {
@@ -805,8 +896,9 @@ static void _collision_rectangle_capsule(const Shape2DSW *p_a, const Transform2D
capsule_endpoint -= p_motion_a;
capsule_endpoint += p_motion_b;
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint))) {
return;
+ }
}
}
@@ -820,18 +912,22 @@ static void _collision_rectangle_convex_polygon(const Shape2DSW *p_a, const Tran
SeparatorAxisTest2D<RectangleShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(rectangle_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//box faces
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_a.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[1].normalized())) {
return;
+ }
//convex faces
Transform2D boxinv;
@@ -839,24 +935,29 @@ static void _collision_rectangle_convex_polygon(const Shape2DSW *p_a, const Tran
boxinv = p_transform_a.affine_inverse();
}
for (int i = 0; i < convex_B->get_point_count(); i++) {
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
if (withMargin) {
//all points vs all points need to be tested if margin exist
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)))))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i))))) {
return;
+ }
if (castA) {
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) - p_motion_a)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) - p_motion_a))) {
return;
+ }
}
if (castB) {
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) + p_motion_b)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) + p_motion_b))) {
return;
+ }
}
if (castA && castB) {
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) + p_motion_b - p_motion_a)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) + p_motion_b - p_motion_a))) {
return;
+ }
}
}
}
@@ -873,19 +974,23 @@ static void _collision_capsule_capsule(const Shape2DSW *p_a, const Transform2D &
SeparatorAxisTest2D<CapsuleShape2DSW, CapsuleShape2DSW, castA, castB, withMargin> separator(capsule_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//capsule axis
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
//capsule endpoints
@@ -895,8 +1000,9 @@ static void _collision_capsule_capsule(const Shape2DSW *p_a, const Transform2D &
for (int j = 0; j < 2; j++) {
Vector2 capsule_endpoint_B = p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * (j == 0 ? 0.5 : -0.5);
- if (TEST_POINT(capsule_endpoint_A, capsule_endpoint_B))
+ if (TEST_POINT(capsule_endpoint_A, capsule_endpoint_B)) {
return;
+ }
}
}
@@ -910,16 +1016,19 @@ static void _collision_capsule_convex_polygon(const Shape2DSW *p_a, const Transf
SeparatorAxisTest2D<CapsuleShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(capsule_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//capsule axis
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
//poly vs capsule
for (int i = 0; i < convex_B->get_point_count(); i++) {
@@ -928,12 +1037,14 @@ static void _collision_capsule_convex_polygon(const Shape2DSW *p_a, const Transf
for (int j = 0; j < 2; j++) {
Vector2 capsule_endpoint_A = p_transform_a.get_origin() + p_transform_a.elements[1] * capsule_A->get_height() * (j == 0 ? 0.5 : -0.5);
- if (TEST_POINT(capsule_endpoint_A, cpoint))
+ if (TEST_POINT(capsule_endpoint_A, cpoint)) {
return;
+ }
}
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
}
separator.generate_contacts();
@@ -948,27 +1059,32 @@ static void _collision_convex_polygon_convex_polygon(const Shape2DSW *p_a, const
SeparatorAxisTest2D<ConvexPolygonShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(convex_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
for (int i = 0; i < convex_A->get_point_count(); i++) {
- if (!separator.test_axis(convex_A->get_xformed_segment_normal(p_transform_a, i)))
+ if (!separator.test_axis(convex_A->get_xformed_segment_normal(p_transform_a, i))) {
return;
+ }
}
for (int i = 0; i < convex_B->get_point_count(); i++) {
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
}
if (withMargin) {
for (int i = 0; i < convex_A->get_point_count(); i++) {
for (int j = 0; j < convex_B->get_point_count(); j++) {
- if (TEST_POINT(p_transform_a.xform(convex_A->get_point(i)), p_transform_b.xform(convex_B->get_point(j))))
+ if (TEST_POINT(p_transform_a.xform(convex_A->get_point(i)), p_transform_b.xform(convex_B->get_point(j)))) {
return;
+ }
}
}
}
diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp
index 636b288358..beba709807 100644
--- a/servers/physics_2d/collision_solver_2d_sw.cpp
+++ b/servers/physics_2d/collision_solver_2d_sw.cpp
@@ -36,8 +36,9 @@
bool CollisionSolver2DSW::solve_static_line(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) {
const LineShape2DSW *line = static_cast<const LineShape2DSW *>(p_shape_A);
- if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_LINE)
+ if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_LINE) {
return false;
+ }
Vector2 n = p_transform_A.basis_xform(line->get_normal()).normalized();
Vector2 p = p_transform_A.xform(line->get_normal() * line->get_d());
@@ -53,17 +54,19 @@ bool CollisionSolver2DSW::solve_static_line(const Shape2DSW *p_shape_A, const Tr
for (int i = 0; i < support_count; i++) {
supports[i] = p_transform_B.xform(supports[i]);
real_t pd = n.dot(supports[i]);
- if (pd >= d)
+ if (pd >= d) {
continue;
+ }
found = true;
Vector2 support_A = supports[i] - n * (pd - d);
if (p_result_callback) {
- if (p_swap_result)
+ if (p_swap_result) {
p_result_callback(supports[i], support_A, p_userdata);
- else
+ } else {
p_result_callback(support_A, supports[i], p_userdata);
+ }
}
}
@@ -72,8 +75,9 @@ bool CollisionSolver2DSW::solve_static_line(const Shape2DSW *p_shape_A, const Tr
bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Vector2 &p_motion_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis) {
const RayShape2DSW *ray = static_cast<const RayShape2DSW *>(p_shape_A);
- if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_RAY)
+ if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_RAY) {
return false;
+ }
Vector2 from = p_transform_A.get_origin();
Vector2 to = from + p_transform_A[1] * ray->get_length();
@@ -90,8 +94,9 @@ bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Vector
Vector2 p, n;
if (!p_shape_B->intersect_segment(from, to, p, n)) {
- if (sep_axis)
+ if (sep_axis) {
*sep_axis = p_transform_A[1].normalized();
+ }
return false;
}
@@ -102,10 +107,11 @@ bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Vector
}
if (p_result_callback) {
- if (p_swap_result)
+ if (p_swap_result) {
p_result_callback(support_B, support_A, p_userdata);
- else
+ } else {
p_result_callback(support_A, support_B, p_userdata);
+ }
}
return true;
}
@@ -130,12 +136,14 @@ struct _ConcaveCollisionInfo2D {
void CollisionSolver2DSW::concave_callback(void *p_userdata, Shape2DSW *p_convex) {
_ConcaveCollisionInfo2D &cinfo = *(_ConcaveCollisionInfo2D *)(p_userdata);
cinfo.aabb_tests++;
- if (!cinfo.result_callback && cinfo.collided)
+ if (!cinfo.result_callback && cinfo.collided) {
return; //already collided and no contacts requested, don't test anymore
+ }
bool collided = collision_solver(cinfo.shape_A, *cinfo.transform_A, cinfo.motion_A, p_convex, *cinfo.transform_B, cinfo.motion_B, cinfo.result_callback, cinfo.userdata, cinfo.swap_result, cinfo.sep_axis, cinfo.margin_A, cinfo.margin_B);
- if (!collided)
+ if (!collided) {
return;
+ }
cinfo.collided = true;
cinfo.collisions++;
@@ -224,13 +232,15 @@ bool CollisionSolver2DSW::solve(const Shape2DSW *p_shape_A, const Transform2D &p
}
} else if (concave_B) {
- if (concave_A)
+ if (concave_A) {
return false;
+ }
- if (!swap)
+ if (!swap) {
return solve_concave(p_shape_A, p_transform_A, p_motion_A, p_shape_B, p_transform_B, p_motion_B, p_result_callback, p_userdata, false, sep_axis, margin_A, margin_B);
- else
+ } else {
return solve_concave(p_shape_B, p_transform_B, p_motion_B, p_shape_A, p_transform_A, p_motion_A, p_result_callback, p_userdata, true, sep_axis, margin_A, margin_B);
+ }
} else {
return collision_solver(p_shape_A, p_transform_A, p_motion_A, p_shape_B, p_transform_B, p_motion_B, p_result_callback, p_userdata, false, sep_axis, margin_A, margin_B);
diff --git a/servers/physics_2d/joints_2d_sw.cpp b/servers/physics_2d/joints_2d_sw.cpp
index 73d916138b..eda0b923a2 100644
--- a/servers/physics_2d/joints_2d_sw.cpp
+++ b/servers/physics_2d/joints_2d_sw.cpp
@@ -76,10 +76,11 @@ static inline real_t k_scalar(Body2DSW *a, Body2DSW *b, const Vector2 &rA, const
static inline Vector2
relative_velocity(Body2DSW *a, Body2DSW *b, Vector2 rA, Vector2 rB) {
Vector2 sum = a->get_linear_velocity() - rA.tangent() * a->get_angular_velocity();
- if (b)
+ if (b) {
return (b->get_linear_velocity() - rB.tangent() * b->get_angular_velocity()) - sum;
- else
+ } else {
return -sum;
+ }
}
static inline real_t
@@ -136,8 +137,9 @@ bool PinJoint2DSW::setup(real_t p_step) {
// apply accumulated impulse
A->apply_impulse(rA, -P);
- if (B)
+ if (B) {
B->apply_impulse(rB, P);
+ }
return true;
}
@@ -151,28 +153,32 @@ void PinJoint2DSW::solve(real_t p_step) {
Vector2 vA = A->get_linear_velocity() - custom_cross(rA, A->get_angular_velocity());
Vector2 rel_vel;
- if (B)
+ if (B) {
rel_vel = B->get_linear_velocity() - custom_cross(rB, B->get_angular_velocity()) - vA;
- else
+ } else {
rel_vel = -vA;
+ }
Vector2 impulse = M.basis_xform(bias - rel_vel - Vector2(softness, softness) * P);
A->apply_impulse(rA, -impulse);
- if (B)
+ if (B) {
B->apply_impulse(rB, impulse);
+ }
P += impulse;
}
void PinJoint2DSW::set_param(PhysicsServer2D::PinJointParam p_param, real_t p_value) {
- if (p_param == PhysicsServer2D::PIN_JOINT_SOFTNESS)
+ if (p_param == PhysicsServer2D::PIN_JOINT_SOFTNESS) {
softness = p_value;
+ }
}
real_t PinJoint2DSW::get_param(PhysicsServer2D::PinJointParam p_param) const {
- if (p_param == PhysicsServer2D::PIN_JOINT_SOFTNESS)
+ if (p_param == PhysicsServer2D::PIN_JOINT_SOFTNESS) {
return softness;
+ }
ERR_FAIL_V(0);
}
@@ -186,15 +192,18 @@ PinJoint2DSW::PinJoint2DSW(const Vector2 &p_pos, Body2DSW *p_body_a, Body2DSW *p
softness = 0;
p_body_a->add_constraint(this, 0);
- if (p_body_b)
+ if (p_body_b) {
p_body_b->add_constraint(this, 1);
+ }
}
PinJoint2DSW::~PinJoint2DSW() {
- if (A)
+ if (A) {
A->remove_constraint(this);
- if (B)
+ }
+ if (B) {
B->remove_constraint(this);
+ }
}
//////////////////////////////////////////////
@@ -345,10 +354,11 @@ bool DampedSpringJoint2DSW::setup(real_t p_step) {
Vector2 delta = (B->get_transform().get_origin() + rB) - (A->get_transform().get_origin() + rA);
real_t dist = delta.length();
- if (dist)
+ if (dist) {
n = delta / dist;
- else
+ } else {
n = Vector2();
+ }
real_t k = k_scalar(A, B, rA, rB, n);
n_mass = 1.0f / k;
diff --git a/servers/physics_2d/physics_server_2d_sw.cpp b/servers/physics_2d/physics_server_2d_sw.cpp
index a35283d76d..e9b2ac6875 100644
--- a/servers/physics_2d/physics_server_2d_sw.cpp
+++ b/servers/physics_2d/physics_server_2d_sw.cpp
@@ -145,8 +145,9 @@ real_t PhysicsServer2DSW::shape_get_custom_solver_bias(RID p_shape) const {
void PhysicsServer2DSW::_shape_col_cbk(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_userdata) {
CollCbkData *cbk = (CollCbkData *)p_userdata;
- if (cbk->max == 0)
+ if (cbk->max == 0) {
return;
+ }
if (cbk->valid_dir != Vector2()) {
if (p_point_A.distance_squared_to(p_point_B) > cbk->valid_depth * cbk->valid_depth) {
@@ -182,8 +183,9 @@ void PhysicsServer2DSW::_shape_col_cbk(const Vector2 &p_point_A, const Vector2 &
}
real_t d = p_point_A.distance_squared_to(p_point_B);
- if (d < min_depth)
+ if (d < min_depth) {
return;
+ }
cbk->ptr[min_depth_idx * 2 + 0] = p_point_A;
cbk->ptr[min_depth_idx * 2 + 1] = p_point_B;
cbk->passed++;
@@ -234,10 +236,11 @@ RID PhysicsServer2DSW::space_create() {
void PhysicsServer2DSW::space_set_active(RID p_space, bool p_active) {
Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND(!space);
- if (p_active)
+ if (p_active) {
active_spaces.insert(space);
- else
+ } else {
active_spaces.erase(space);
+ }
}
bool PhysicsServer2DSW::space_is_active(RID p_space) const {
@@ -303,8 +306,9 @@ void PhysicsServer2DSW::area_set_space(RID p_area, RID p_space) {
ERR_FAIL_COND(!space);
}
- if (area->get_space() == space)
+ if (area->get_space() == space) {
return; //pointless
+ }
area->clear_constraints();
area->set_space(space);
@@ -315,8 +319,9 @@ RID PhysicsServer2DSW::area_get_space(RID p_area) const {
ERR_FAIL_COND_V(!area, RID());
Space2DSW *space = area->get_space();
- if (!space)
+ if (!space) {
return RID();
+ }
return space->get_self();
};
@@ -406,8 +411,9 @@ void PhysicsServer2DSW::area_clear_shapes(RID p_area) {
Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
- while (area->get_shape_count())
+ while (area->get_shape_count()) {
area->remove_shape(0);
+ }
}
void PhysicsServer2DSW::area_attach_object_instance_id(RID p_area, ObjectID p_id) {
@@ -544,8 +550,9 @@ void PhysicsServer2DSW::body_set_space(RID p_body, RID p_space) {
ERR_FAIL_COND(!space);
}
- if (body->get_space() == space)
+ if (body->get_space() == space) {
return; //pointless
+ }
body->clear_constraint_map();
body->set_space(space);
@@ -556,8 +563,9 @@ RID PhysicsServer2DSW::body_get_space(RID p_body) const {
ERR_FAIL_COND_V(!body, RID());
Space2DSW *space = body->get_space();
- if (!space)
+ if (!space) {
return RID();
+ }
return space->get_self();
};
@@ -651,8 +659,9 @@ void PhysicsServer2DSW::body_clear_shapes(RID p_body) {
Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
- while (body->get_shape_count())
+ while (body->get_shape_count()) {
body->remove_shape(0);
+ }
}
void PhysicsServer2DSW::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {
@@ -966,8 +975,9 @@ int PhysicsServer2DSW::body_test_ray_separation(RID p_body, const Transform2D &p
PhysicsDirectBodyState2D *PhysicsServer2DSW::body_get_direct_state(RID p_body) {
ERR_FAIL_COND_V_MSG((using_threads && !doing_sync), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");
- if (!body_owner.owns(p_body))
+ if (!body_owner.owns(p_body)) {
return nullptr;
+ }
Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, nullptr);
@@ -1213,8 +1223,9 @@ void PhysicsServer2DSW::init() {
};
void PhysicsServer2DSW::step(real_t p_step) {
- if (!active)
+ if (!active) {
return;
+ }
_update_shapes();
@@ -1238,8 +1249,9 @@ void PhysicsServer2DSW::sync() {
};
void PhysicsServer2DSW::flush_queries() {
- if (!active)
+ if (!active) {
return;
+ }
flushing_queries = true;
diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.cpp b/servers/physics_2d/physics_server_2d_wrap_mt.cpp
index 86d5755ec5..49c38c6ce0 100644
--- a/servers/physics_2d/physics_server_2d_wrap_mt.cpp
+++ b/servers/physics_2d/physics_server_2d_wrap_mt.cpp
@@ -77,10 +77,11 @@ void PhysicsServer2DWrapMT::step(real_t p_step) {
void PhysicsServer2DWrapMT::sync() {
if (thread) {
- if (first_frame)
+ if (first_frame) {
first_frame = false;
- else
+ } else {
step_sem.wait(); //must not wait if a step was not issued
+ }
}
physics_2d_server->sync();
}
diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.h b/servers/physics_2d/physics_server_2d_wrap_mt.h
index dbfdb077ab..c2ae288f95 100644
--- a/servers/physics_2d/physics_server_2d_wrap_mt.h
+++ b/servers/physics_2d/physics_server_2d_wrap_mt.h
@@ -318,12 +318,13 @@ public:
template <class T>
static PhysicsServer2D *init_server() {
int tm = GLOBAL_DEF("physics/2d/thread_model", 1);
- if (tm == 0) // single unsafe
+ if (tm == 0) { // single unsafe
return memnew(T);
- else if (tm == 1) // single safe
+ } else if (tm == 1) { // single safe
return memnew(PhysicsServer2DWrapMT(memnew(T), false));
- else // multi threaded
+ } else { // multi threaded
return memnew(PhysicsServer2DWrapMT(memnew(T), true));
+ }
}
#undef ServerNameWrapMT
diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp
index 1fb53cf065..c0589b9804 100644
--- a/servers/physics_2d/shape_2d_sw.cpp
+++ b/servers/physics_2d/shape_2d_sw.cpp
@@ -146,10 +146,11 @@ Variant LineShape2DSW::get_data() const {
void RayShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_supports, int &r_amount) const {
r_amount = 1;
- if (p_normal.y > 0)
+ if (p_normal.y > 0) {
*r_supports = Vector2(0, length);
- else
+ } else {
*r_supports = Vector2();
+ }
}
bool RayShape2DSW::contains_point(const Vector2 &p_point) const {
@@ -191,10 +192,11 @@ void SegmentShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_supports
}
real_t dp = p_normal.dot(b - a);
- if (dp > 0)
+ if (dp > 0) {
*r_supports = b;
- else
+ } else {
*r_supports = a;
+ }
r_amount = 1;
}
@@ -203,8 +205,9 @@ bool SegmentShape2DSW::contains_point(const Vector2 &p_point) const {
}
bool SegmentShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p_end, Vector2 &r_point, Vector2 &r_normal) const {
- if (!Geometry::segment_intersects_segment_2d(p_begin, p_end, a, b, &r_point))
+ if (!Geometry::segment_intersects_segment_2d(p_begin, p_end, a, b, &r_point)) {
return false;
+ }
if (n.dot(p_begin) > n.dot(a)) {
r_normal = n;
@@ -230,10 +233,12 @@ void SegmentShape2DSW::set_data(const Variant &p_data) {
Rect2 aabb;
aabb.position = a;
aabb.expand_to(b);
- if (aabb.size.x == 0)
+ if (aabb.size.x == 0) {
aabb.size.x = 0.001;
- if (aabb.size.y == 0)
+ }
+ if (aabb.size.y == 0) {
aabb.size.y = 0.001;
+ }
configure(aabb);
}
@@ -268,8 +273,9 @@ bool CircleShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p
real_t sqrtterm = b * b - 4 * a * c;
- if (sqrtterm < 0)
+ if (sqrtterm < 0) {
return false;
+ }
sqrtterm = Math::sqrt(sqrtterm);
real_t res = (-b - sqrtterm) / (2 * a);
@@ -307,8 +313,9 @@ void RectangleShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_suppor
Vector2 ag;
ag[i] = 1.0;
real_t dp = ag.dot(p_normal);
- if (Math::abs(dp) < _SEGMENT_IS_VALID_SUPPORT_THRESHOLD)
+ if (Math::abs(dp) < _SEGMENT_IS_VALID_SUPPORT_THRESHOLD) {
continue;
+ }
real_t sgn = dp > 0 ? 1.0 : -1.0;
@@ -394,8 +401,9 @@ bool CapsuleShape2DSW::contains_point(const Vector2 &p_point) const {
Vector2 p = p_point;
p.y = Math::abs(p.y);
p.y -= height * 0.5;
- if (p.y < 0)
+ if (p.y < 0) {
p.y = 0;
+ }
return p.length_squared() < radius * radius;
}
@@ -423,8 +431,9 @@ bool CapsuleShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &
real_t sqrtterm = b * b - 4 * a * c;
- if (sqrtterm < 0)
+ if (sqrtterm < 0) {
continue;
+ }
sqrtterm = Math::sqrt(sqrtterm);
real_t res = (-b - sqrtterm) / (2 * a);
@@ -523,10 +532,11 @@ bool ConvexPolygonShape2DSW::contains_point(const Vector2 &p_point) const {
for (int i = 0; i < point_count; i++) {
real_t d = points[i].normal.dot(p_point) - points[i].normal.dot(points[i].pos);
- if (d > 0)
+ if (d > 0) {
out = true;
- else
+ } else {
in = true;
+ }
}
return in != out;
@@ -546,8 +556,9 @@ bool ConvexPolygonShape2DSW::intersect_segment(const Vector2 &p_begin, const Vec
Vector2 res;
- if (!Geometry::segment_intersects_segment_2d(p_begin, p_end, points[i].pos, points[(i + 1) % point_count].pos, &res))
+ if (!Geometry::segment_intersects_segment_2d(p_begin, p_end, points[i].pos, points[(i + 1) % point_count].pos, &res)) {
continue;
+ }
real_t nd = n.dot(res);
if (nd < d) {
@@ -559,8 +570,9 @@ bool ConvexPolygonShape2DSW::intersect_segment(const Vector2 &p_begin, const Vec
}
if (inters) {
- if (n.dot(r_normal) > 0)
+ if (n.dot(r_normal) > 0) {
r_normal = -r_normal;
+ }
}
//return get_aabb().intersects_segment(p_begin,p_end,&r_point,&r_normal);
@@ -580,8 +592,9 @@ real_t ConvexPolygonShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2
void ConvexPolygonShape2DSW::set_data(const Variant &p_data) {
ERR_FAIL_COND(p_data.get_type() != Variant::PACKED_VECTOR2_ARRAY && p_data.get_type() != Variant::PACKED_FLOAT32_ARRAY);
- if (points)
+ if (points) {
memdelete_arr(points);
+ }
points = nullptr;
point_count = 0;
@@ -621,8 +634,9 @@ void ConvexPolygonShape2DSW::set_data(const Variant &p_data) {
ERR_FAIL_COND(point_count == 0);
Rect2 aabb;
aabb.position = points[0].pos;
- for (int i = 1; i < point_count; i++)
+ for (int i = 1; i < point_count; i++) {
aabb.expand_to(points[i].pos);
+ }
configure(aabb);
}
@@ -645,8 +659,9 @@ ConvexPolygonShape2DSW::ConvexPolygonShape2DSW() {
}
ConvexPolygonShape2DSW::~ConvexPolygonShape2DSW() {
- if (points)
+ if (points) {
memdelete_arr(points);
+ }
}
//////////////////////////////////////////////////
@@ -754,19 +769,22 @@ bool ConcavePolygonShape2DSW::intersect_segment(const Vector2 &p_begin, const Ve
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
}
continue;
}
- if (done)
+ if (done) {
break;
+ }
}
if (inters) {
- if (n.dot(r_normal) > 0)
+ if (n.dot(r_normal) > 0) {
r_normal = -r_normal;
+ }
}
return inters;
@@ -966,10 +984,11 @@ void ConcavePolygonShape2DSW::cull(const Rect2 &p_local_aabb, Callback p_callbac
}
continue;
case VISIT_DONE_BIT: {
- if (level == 0)
+ if (level == 0) {
return;
- else
+ } else {
level--;
+ }
}
continue;
}
diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h
index 97a051ca65..eca284f7a4 100644
--- a/servers/physics_2d/shape_2d_sw.h
+++ b/servers/physics_2d/shape_2d_sw.h
@@ -100,8 +100,9 @@ public:
_FORCE_INLINE_ void get_supports_transformed_cast(const Vector2 &p_cast, const Vector2 &p_normal, const Transform2D &p_xform, Vector2 *r_supports, int &r_amount) const {
get_supports(p_xform.basis_xform_inv(p_normal).normalized(), r_supports, r_amount);
- for (int i = 0; i < r_amount; i++)
+ for (int i = 0; i < r_amount; i++) {
r_supports[i] = p_xform.xform(r_supports[i]);
+ }
if (r_amount == 1) {
if (Math::abs(p_normal.dot(p_cast.normalized())) < (1.0 - _SEGMENT_IS_VALID_SUPPORT_THRESHOLD)) {
@@ -325,10 +326,12 @@ public:
for (int i = 0; i < 4; i++) {
real_t d = p_normal.dot(p_transform.xform(Vector2(((i & 1) * 2 - 1) * half_extents.x, ((i >> 1) * 2 - 1) * half_extents.y)));
- if (d > r_max)
+ if (d > r_max) {
r_max = d;
- if (d < r_min)
+ }
+ if (d < r_min) {
r_min = d;
+ }
}
}
@@ -452,10 +455,12 @@ public:
r_min = r_max = p_normal.dot(p_transform.xform(points[0].pos));
for (int i = 1; i < point_count; i++) {
real_t d = p_normal.dot(p_transform.xform(points[i].pos));
- if (d > r_max)
+ if (d > r_max) {
r_max = d;
- if (d < r_min)
+ }
+ if (d < r_min) {
r_min = d;
+ }
}
}
diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp
index 97bbc0f8f2..f4a21da254 100644
--- a/servers/physics_2d/space_2d_sw.cpp
+++ b/servers/physics_2d/space_2d_sw.cpp
@@ -39,18 +39,21 @@ _FORCE_INLINE_ static bool _can_collide_with(CollisionObject2DSW *p_object, uint
return false;
}
- if (p_object->get_type() == CollisionObject2DSW::TYPE_AREA && !p_collide_with_areas)
+ if (p_object->get_type() == CollisionObject2DSW::TYPE_AREA && !p_collide_with_areas) {
return false;
+ }
- if (p_object->get_type() == CollisionObject2DSW::TYPE_BODY && !p_collide_with_bodies)
+ if (p_object->get_type() == CollisionObject2DSW::TYPE_BODY && !p_collide_with_bodies) {
return false;
+ }
return true;
}
int PhysicsDirectSpaceState2DSW::_intersect_point_impl(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_pick_point, bool p_filter_by_canvas, ObjectID p_canvas_instance_id) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return 0;
+ }
Rect2 aabb;
aabb.position = p_point - Vector2(0.00001, 0.00001);
@@ -61,19 +64,23 @@ int PhysicsDirectSpaceState2DSW::_intersect_point_impl(const Vector2 &p_point, S
int cc = 0;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
- if (p_pick_point && !col_obj->is_pickable())
+ if (p_pick_point && !col_obj->is_pickable()) {
continue;
+ }
- if (p_filter_by_canvas && col_obj->get_canvas_instance_id() != p_canvas_instance_id)
+ if (p_filter_by_canvas && col_obj->get_canvas_instance_id() != p_canvas_instance_id) {
continue;
+ }
int shape_idx = space->intersection_query_subindex_results[i];
@@ -81,15 +88,18 @@ int PhysicsDirectSpaceState2DSW::_intersect_point_impl(const Vector2 &p_point, S
Vector2 local_point = (col_obj->get_transform() * col_obj->get_shape_transform(shape_idx)).affine_inverse().xform(p_point);
- if (!shape->contains_point(local_point))
+ if (!shape->contains_point(local_point)) {
continue;
+ }
- if (cc >= p_result_max)
+ if (cc >= p_result_max) {
continue;
+ }
r_results[cc].collider_id = col_obj->get_instance_id();
- if (r_results[cc].collider_id.is_valid())
+ if (r_results[cc].collider_id.is_valid()) {
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
+ }
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
r_results[cc].metadata = col_obj->get_shape_metadata(shape_idx);
@@ -128,11 +138,13 @@ bool PhysicsDirectSpaceState2DSW::intersect_ray(const Vector2 &p_from, const Vec
real_t min_d = 1e10;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
@@ -169,12 +181,14 @@ bool PhysicsDirectSpaceState2DSW::intersect_ray(const Vector2 &p_from, const Vec
}
}
- if (!collided)
+ if (!collided) {
return false;
+ }
r_result.collider_id = res_obj->get_instance_id();
- if (r_result.collider_id.is_valid())
+ if (r_result.collider_id.is_valid()) {
r_result.collider = ObjectDB::get_instance(r_result.collider_id);
+ }
r_result.normal = res_normal;
r_result.metadata = res_obj->get_shape_metadata(res_shape);
r_result.position = res_point;
@@ -185,8 +199,9 @@ bool PhysicsDirectSpaceState2DSW::intersect_ray(const Vector2 &p_from, const Vec
}
int PhysicsDirectSpaceState2DSW::intersect_shape(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return 0;
+ }
Shape2DSW *shape = PhysicsServer2DSW::singletonsw->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
@@ -199,24 +214,29 @@ int PhysicsDirectSpaceState2DSW::intersect_shape(const RID &p_shape, const Trans
int cc = 0;
for (int i = 0; i < amount; i++) {
- if (cc >= p_result_max)
+ if (cc >= p_result_max) {
break;
+ }
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
- if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), nullptr, nullptr, nullptr, p_margin))
+ if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), nullptr, nullptr, nullptr, p_margin)) {
continue;
+ }
r_results[cc].collider_id = col_obj->get_instance_id();
- if (r_results[cc].collider_id.is_valid())
+ if (r_results[cc].collider_id.is_valid()) {
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
+ }
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
r_results[cc].metadata = col_obj->get_shape_metadata(shape_idx);
@@ -241,11 +261,13 @@ bool PhysicsDirectSpaceState2DSW::cast_motion(const RID &p_shape, const Transfor
real_t best_unsafe = 1;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue; //ignore excluded
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
@@ -293,8 +315,9 @@ bool PhysicsDirectSpaceState2DSW::cast_motion(const RID &p_shape, const Transfor
}
bool PhysicsDirectSpaceState2DSW::collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return false;
+ }
Shape2DSW *shape = PhysicsServer2DSW::singletonsw->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
@@ -318,14 +341,16 @@ bool PhysicsDirectSpaceState2DSW::collide_shape(RID p_shape, const Transform2D &
PhysicsServer2DSW::CollCbkData *cbkptr = &cbk;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
- if (p_exclude.has(col_obj->get_self()))
+ if (p_exclude.has(col_obj->get_self())) {
continue;
+ }
cbk.valid_dir = Vector2();
cbk.valid_depth = 0;
@@ -359,20 +384,24 @@ static void _rest_cbk_result(const Vector2 &p_point_A, const Vector2 &p_point_B,
_RestCallbackData2D *rd = (_RestCallbackData2D *)p_userdata;
if (rd->valid_dir != Vector2()) {
- if (p_point_A.distance_squared_to(p_point_B) > rd->valid_depth * rd->valid_depth)
+ if (p_point_A.distance_squared_to(p_point_B) > rd->valid_depth * rd->valid_depth) {
return;
- if (rd->valid_dir.dot((p_point_A - p_point_B).normalized()) < Math_PI * 0.25)
+ }
+ if (rd->valid_dir.dot((p_point_A - p_point_B).normalized()) < Math_PI * 0.25) {
return;
+ }
}
Vector2 contact_rel = p_point_B - p_point_A;
real_t len = contact_rel.length();
- if (len < rd->min_allowed_depth)
+ if (len < rd->min_allowed_depth) {
return;
+ }
- if (len <= rd->best_len)
+ if (len <= rd->best_len) {
return;
+ }
rd->best_len = len;
rd->best_contact = p_point_B;
@@ -399,14 +428,16 @@ bool PhysicsDirectSpaceState2DSW::rest_info(RID p_shape, const Transform2D &p_sh
rcd.min_allowed_depth = space->test_motion_min_contact_depth;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
- if (p_exclude.has(col_obj->get_self()))
+ if (p_exclude.has(col_obj->get_self())) {
continue;
+ }
rcd.valid_dir = Vector2();
rcd.valid_depth = 0;
@@ -414,12 +445,14 @@ bool PhysicsDirectSpaceState2DSW::rest_info(RID p_shape, const Transform2D &p_sh
rcd.shape = shape_idx;
rcd.local_shape = 0;
bool sc = CollisionSolver2DSW::solve(shape, p_shape_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), _rest_cbk_result, &rcd, nullptr, p_margin);
- if (!sc)
+ if (!sc) {
continue;
+ }
}
- if (rcd.best_len == 0 || !rcd.best_object)
+ if (rcd.best_len == 0 || !rcd.best_object) {
return false;
+ }
r_info->collider_id = rcd.best_object->get_instance_id();
r_info->shape = rcd.best_shape;
@@ -451,16 +484,17 @@ int Space2DSW::_cull_aabb_for_body(Body2DSW *p_body, const Rect2 &p_aabb) {
for (int i = 0; i < amount; i++) {
bool keep = true;
- if (intersection_query_results[i] == p_body)
+ if (intersection_query_results[i] == p_body) {
keep = false;
- else if (intersection_query_results[i]->get_type() == CollisionObject2DSW::TYPE_AREA)
+ } else if (intersection_query_results[i]->get_type() == CollisionObject2DSW::TYPE_AREA) {
keep = false;
- else if ((static_cast<Body2DSW *>(intersection_query_results[i])->test_collision_mask(p_body)) == 0)
+ } else if ((static_cast<Body2DSW *>(intersection_query_results[i])->test_collision_mask(p_body)) == 0) {
keep = false;
- else if (static_cast<Body2DSW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self()))
+ } else if (static_cast<Body2DSW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self())) {
keep = false;
- else if (static_cast<Body2DSW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i]))
+ } else if (static_cast<Body2DSW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i])) {
keep = false;
+ }
if (!keep) {
if (i < amount - 1) {
@@ -482,11 +516,13 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t
bool shapes_found = false;
for (int i = 0; i < p_body->get_shape_count(); i++) {
- if (p_body->is_shape_set_as_disabled(i))
+ if (p_body->is_shape_set_as_disabled(i)) {
continue;
+ }
- if (p_body->get_shape(i)->get_type() != PhysicsServer2D::SHAPE_RAY)
+ if (p_body->get_shape(i)->get_type() != PhysicsServer2D::SHAPE_RAY) {
continue;
+ }
if (!shapes_found) {
body_aabb = p_body->get_shape_aabb(i);
@@ -532,13 +568,15 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t
int amount = _cull_aabb_for_body(p_body, body_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
- if (p_body->is_shape_set_as_disabled(j))
+ if (p_body->is_shape_set_as_disabled(j)) {
continue;
+ }
Shape2DSW *body_shape = p_body->get_shape(j);
- if (body_shape->get_type() != PhysicsServer2D::SHAPE_RAY)
+ if (body_shape->get_type() != PhysicsServer2D::SHAPE_RAY) {
continue;
+ }
Transform2D body_shape_xform = body_transform * p_body->get_shape_transform(j);
@@ -671,11 +709,13 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
bool shapes_found = false;
for (int i = 0; i < p_body->get_shape_count(); i++) {
- if (p_body->is_shape_set_as_disabled(i))
+ if (p_body->is_shape_set_as_disabled(i)) {
continue;
+ }
- if (p_exclude_raycast_shapes && p_body->get_shape(i)->get_type() == PhysicsServer2D::SHAPE_RAY)
+ if (p_exclude_raycast_shapes && p_body->get_shape(i)->get_type() == PhysicsServer2D::SHAPE_RAY) {
continue;
+ }
if (!shapes_found) {
body_aabb = p_body->get_shape_aabb(i);
@@ -729,8 +769,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
int amount = _cull_aabb_for_body(p_body, body_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
- if (p_body->is_shape_set_as_disabled(j))
+ if (p_body->is_shape_set_as_disabled(j)) {
continue;
+ }
Shape2DSW *body_shape = p_body->get_shape(j);
if (p_exclude_raycast_shapes && body_shape->get_type() == PhysicsServer2D::SHAPE_RAY) {
@@ -840,8 +881,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
int amount = _cull_aabb_for_body(p_body, motion_aabb);
for (int body_shape_idx = 0; body_shape_idx < p_body->get_shape_count(); body_shape_idx++) {
- if (p_body->is_shape_set_as_disabled(body_shape_idx))
+ if (p_body->is_shape_set_as_disabled(body_shape_idx)) {
continue;
+ }
Shape2DSW *body_shape = p_body->get_shape(body_shape_idx);
if (p_exclude_raycast_shapes && body_shape->get_type() == PhysicsServer2D::SHAPE_RAY) {
@@ -977,8 +1019,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
int to_shape = best_shape != -1 ? best_shape + 1 : p_body->get_shape_count();
for (int j = from_shape; j < to_shape; j++) {
- if (p_body->is_shape_set_as_disabled(j))
+ if (p_body->is_shape_set_as_disabled(j)) {
continue;
+ }
Transform2D body_shape_xform = ugt * p_body->get_shape_transform(j);
Shape2DSW *body_shape = p_body->get_shape(j);
@@ -1011,8 +1054,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
break;
}
}
- if (excluded)
+ if (excluded) {
continue;
+ }
Transform2D col_obj_shape_xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx);
@@ -1028,8 +1072,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
rcd.shape = shape_idx;
rcd.local_shape = j;
bool sc = CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), _rest_cbk_result, &rcd, nullptr, p_margin);
- if (!sc)
+ if (!sc) {
continue;
+ }
}
}
@@ -1291,8 +1336,9 @@ Space2DSW::Space2DSW() {
direct_access = memnew(PhysicsDirectSpaceState2DSW);
direct_access->space = this;
- for (int i = 0; i < ELAPSED_TIME_MAX; i++)
+ for (int i = 0; i < ELAPSED_TIME_MAX; i++) {
elapsed_time[i] = 0;
+ }
}
Space2DSW::~Space2DSW() {
diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h
index 79c38fd638..0a96f2f495 100644
--- a/servers/physics_2d/space_2d_sw.h
+++ b/servers/physics_2d/space_2d_sw.h
@@ -190,8 +190,9 @@ public:
void set_debug_contacts(int p_amount) { contact_debug.resize(p_amount); }
_FORCE_INLINE_ bool is_debugging_contacts() const { return !contact_debug.empty(); }
_FORCE_INLINE_ void add_debug_contact(const Vector2 &p_contact) {
- if (contact_debug_count < contact_debug.size())
+ if (contact_debug_count < contact_debug.size()) {
contact_debug.write[contact_debug_count++] = p_contact;
+ }
}
_FORCE_INLINE_ Vector<Vector2> get_debug_contacts() { return contact_debug; }
_FORCE_INLINE_ int get_debug_contact_count() { return contact_debug_count; }
diff --git a/servers/physics_2d/step_2d_sw.cpp b/servers/physics_2d/step_2d_sw.cpp
index b184e652c7..c7711bcd1d 100644
--- a/servers/physics_2d/step_2d_sw.cpp
+++ b/servers/physics_2d/step_2d_sw.cpp
@@ -38,18 +38,21 @@ void Step2DSW::_populate_island(Body2DSW *p_body, Body2DSW **p_island, Constrain
for (Map<Constraint2DSW *, int>::Element *E = p_body->get_constraint_map().front(); E; E = E->next()) {
Constraint2DSW *c = (Constraint2DSW *)E->key();
- if (c->get_island_step() == _step)
+ if (c->get_island_step() == _step) {
continue; //already processed
+ }
c->set_island_step(_step);
c->set_island_next(*p_constraint_island);
*p_constraint_island = c;
for (int i = 0; i < c->get_body_count(); i++) {
- if (i == E->get())
+ if (i == E->get()) {
continue;
+ }
Body2DSW *b = c->get_body_ptr()[i];
- if (b->get_island_step() == _step || b->get_mode() == PhysicsServer2D::BODY_MODE_STATIC || b->get_mode() == PhysicsServer2D::BODY_MODE_KINEMATIC)
+ if (b->get_island_step() == _step || b->get_mode() == PhysicsServer2D::BODY_MODE_STATIC || b->get_mode() == PhysicsServer2D::BODY_MODE_KINEMATIC) {
continue; //no go
+ }
_populate_island(c->get_body_ptr()[i], p_island, p_constraint_island);
}
}
@@ -99,8 +102,9 @@ void Step2DSW::_check_suspend(Body2DSW *p_island, real_t p_delta) {
continue; //ignore for static
}
- if (!b->sleep_test(p_delta))
+ if (!b->sleep_test(p_delta)) {
can_sleep = false;
+ }
b = b->get_island_next();
}
@@ -116,8 +120,9 @@ void Step2DSW::_check_suspend(Body2DSW *p_island, real_t p_delta) {
bool active = b->is_active();
- if (active == can_sleep)
+ if (active == can_sleep) {
b->set_active(!can_sleep);
+ }
b = b->get_island_next();
}
@@ -187,8 +192,9 @@ void Step2DSW::step(Space2DSW *p_space, real_t p_delta, int p_iterations) {
while (aml.first()) {
for (const Set<Constraint2DSW *>::Element *E = aml.first()->self()->get_constraints().front(); E; E = E->next()) {
Constraint2DSW *c = E->get();
- if (c->get_island_step() == _step)
+ if (c->get_island_step() == _step) {
continue;
+ }
c->set_island_step(_step);
c->set_island_next(nullptr);
c->set_island_list_next(constraint_island_list);