summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2016-07-18 16:37:50 +0200
committerGitHub <noreply@github.com>2016-07-18 16:37:50 +0200
commit3725114a1658337d6de21bb7a5b6fde5f8a74d1f (patch)
tree1f8b1e38ecc1bab5782df21dba22087bcfc9cf1c
parent254d79a560781e9f86debcc63ef6726cfd81ac80 (diff)
parentb09b449615956f795bee7a0d3a64bc1e65f2cab5 (diff)
Merge pull request #5383 from Ovnuniarchos/OptimizeOneWay
Optimized one-way collision loops.
-rw-r--r--servers/physics_2d/body_pair_2d_sw.cpp45
1 files changed, 20 insertions, 25 deletions
diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp
index 35f19605df..ba0358a1f2 100644
--- a/servers/physics_2d/body_pair_2d_sw.cpp
+++ b/servers/physics_2d/body_pair_2d_sw.cpp
@@ -298,19 +298,17 @@ bool BodyPair2DSW::setup(float p_step) {
if (A->is_using_one_way_collision()) {
Vector2 direction = A->get_one_way_collision_direction();
bool valid=false;
- for(int i=0;i<contact_count;i++) {
- Contact& c = contacts[i];
-
- if (c.normal.dot(direction)<0)
- continue;
- if (B->get_linear_velocity().dot(direction)<0)
- continue;
-
- if (!c.reused) {
- continue;
+ if (B->get_linear_velocity().dot(direction)>=0){
+ for(int i=0;i<contact_count;i++) {
+ Contact& c = contacts[i];
+ if (!c.reused)
+ continue;
+ if (c.normal.dot(direction)<0)
+ continue;
+
+ valid=true;
+ break;
}
-
- valid=true;
}
if (!valid) {
@@ -323,20 +321,17 @@ bool BodyPair2DSW::setup(float p_step) {
if (B->is_using_one_way_collision()) {
Vector2 direction = B->get_one_way_collision_direction();
bool valid=false;
- for(int i=0;i<contact_count;i++) {
-
- Contact& c = contacts[i];
-
- if (c.normal.dot(direction)<0)
- continue;
- if (A->get_linear_velocity().dot(direction)<0)
- continue;
-
- if (!c.reused) {
- continue;
+ if (A->get_linear_velocity().dot(direction)>=0){
+ for(int i=0;i<contact_count;i++) {
+ Contact& c = contacts[i];
+ if (!c.reused)
+ continue;
+ if (c.normal.dot(direction)<0)
+ continue;
+
+ valid=true;
+ break;
}
-
- valid=true;
}
if (!valid) {
collided=false;