diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/physics/body_sw.cpp | 30 | ||||
-rw-r--r-- | servers/physics_2d/body_2d_sw.cpp | 33 | ||||
-rw-r--r-- | servers/physics_2d_server.cpp | 4 | ||||
-rw-r--r-- | servers/physics_2d_server.h | 2 | ||||
-rw-r--r-- | servers/physics_server.cpp | 4 | ||||
-rw-r--r-- | servers/physics_server.h | 2 |
6 files changed, 54 insertions, 21 deletions
diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index c66e73b430..79d08b1e75 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -406,29 +406,41 @@ void BodySW::integrate_forces(real_t p_step) { return; AreaSW *def_area = get_space()->get_default_area(); - AreaSW *damp_area = def_area; + // AreaSW *damp_area = def_area; ERR_FAIL_COND(!def_area); int ac = areas.size(); - bool replace = false; + bool stopped = false; gravity = Vector3(0,0,0); area_linear_damp = 0; area_angular_damp = 0; if (ac) { areas.sort(); const AreaCMP *aa = &areas[0]; - damp_area = aa[ac-1].area; - for(int i=ac-1;i>=0;i--) { - _compute_area_gravity_and_dampenings(aa[i].area); - if (aa[i].area->get_space_override_mode() == PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE) { - replace = true; - break; + // damp_area = aa[ac-1].area; + for(int i=ac-1;i>=0 && !stopped;i--) { + PhysicsServer::AreaSpaceOverrideMode mode=aa[i].area->get_space_override_mode(); + switch (mode) { + case PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE: + case PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: { + _compute_area_gravity_and_dampenings(aa[i].area); + stopped = mode==PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE; + } break; + case PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE: + case PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: { + gravity = Vector3(0,0,0); + area_angular_damp = 0; + area_linear_damp = 0; + _compute_area_gravity_and_dampenings(aa[i].area); + stopped = mode==PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE; + } break; + default: {} } } } - if( !replace ) { + if( !stopped ) { _compute_area_gravity_and_dampenings(def_area); } diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index d0c5cbc77b..8d82d4a920 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -395,6 +395,7 @@ void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) { area_linear_damp += p_area->get_linear_damp(); area_angular_damp += p_area->get_angular_damp(); + printf("%f\n",gravity.y); } void Body2DSW::integrate_forces(real_t p_step) { @@ -403,27 +404,39 @@ void Body2DSW::integrate_forces(real_t p_step) { return; Area2DSW *def_area = get_space()->get_default_area(); - Area2DSW *damp_area = def_area; + // Area2DSW *damp_area = def_area; ERR_FAIL_COND(!def_area); int ac = areas.size(); - bool replace = false; + bool stopped = false; gravity = Vector2(0,0); area_angular_damp = 0; area_linear_damp = 0; if (ac) { areas.sort(); const AreaCMP *aa = &areas[0]; - damp_area = aa[ac-1].area; - for(int i=ac-1;i>=0;i--) { - _compute_area_gravity_and_dampenings(aa[i].area); - if (aa[i].area->get_space_override_mode() == Physics2DServer::AREA_SPACE_OVERRIDE_REPLACE) { - replace = true; - break; + // damp_area = aa[ac-1].area; + for(int i=ac-1;i>=0 && !stopped;i--) { + Physics2DServer::AreaSpaceOverrideMode mode=aa[i].area->get_space_override_mode(); + switch (mode) { + case Physics2DServer::AREA_SPACE_OVERRIDE_COMBINE: + case Physics2DServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: { + _compute_area_gravity_and_dampenings(aa[i].area); + stopped = mode==Physics2DServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE; + } break; + case Physics2DServer::AREA_SPACE_OVERRIDE_REPLACE: + case Physics2DServer::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: { + gravity = Vector2(0,0); + area_angular_damp = 0; + area_linear_damp = 0; + _compute_area_gravity_and_dampenings(aa[i].area); + stopped = mode==Physics2DServer::AREA_SPACE_OVERRIDE_REPLACE; + } break; + default: {} } } } - if( !replace ) { + if( !stopped ) { _compute_area_gravity_and_dampenings(def_area); } gravity*=gravity_scale; @@ -501,7 +514,7 @@ void Body2DSW::integrate_forces(real_t p_step) { _update_shapes_with_motion(motion); } - damp_area=NULL; // clear the area, so it is set in the next frame + // damp_area=NULL; // clear the area, so it is set in the next frame def_area=NULL; // clear the area, so it is set in the next frame contact_count=0; diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp index 5d8446ed38..c18b32468a 100644 --- a/servers/physics_2d_server.cpp +++ b/servers/physics_2d_server.cpp @@ -663,9 +663,11 @@ void Physics2DServer::_bind_methods() { BIND_CONSTANT( AREA_PARAM_ANGULAR_DAMP); BIND_CONSTANT( AREA_PARAM_PRIORITY ); - BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE ); BIND_CONSTANT( AREA_SPACE_OVERRIDE_DISABLED ); + BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE ); + BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE_REPLACE ); BIND_CONSTANT( AREA_SPACE_OVERRIDE_REPLACE ); + BIND_CONSTANT( AREA_SPACE_OVERRIDE_REPLACE_COMBINE ); BIND_CONSTANT( BODY_MODE_STATIC ); BIND_CONSTANT( BODY_MODE_KINEMATIC ); diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 6845c7dfe1..a53cfae752 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -325,7 +325,9 @@ public: enum AreaSpaceOverrideMode { AREA_SPACE_OVERRIDE_DISABLED, AREA_SPACE_OVERRIDE_COMBINE, + AREA_SPACE_OVERRIDE_COMBINE_REPLACE, // Combines, then discards all subsequent calculations AREA_SPACE_OVERRIDE_REPLACE, + AREA_SPACE_OVERRIDE_REPLACE_COMBINE // Discards all previous calculations, then keeps combining }; virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode)=0; diff --git a/servers/physics_server.cpp b/servers/physics_server.cpp index 53409acdfb..bc2b37d92c 100644 --- a/servers/physics_server.cpp +++ b/servers/physics_server.cpp @@ -693,9 +693,11 @@ void PhysicsServer::_bind_methods() { BIND_CONSTANT( AREA_PARAM_ANGULAR_DAMP ); BIND_CONSTANT( AREA_PARAM_PRIORITY ); - BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE ); BIND_CONSTANT( AREA_SPACE_OVERRIDE_DISABLED ); + BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE ); + BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE_REPLACE ); BIND_CONSTANT( AREA_SPACE_OVERRIDE_REPLACE ); + BIND_CONSTANT( AREA_SPACE_OVERRIDE_REPLACE_COMBINE ); BIND_CONSTANT( BODY_MODE_STATIC ); BIND_CONSTANT( BODY_MODE_KINEMATIC ); diff --git a/servers/physics_server.h b/servers/physics_server.h index 75584966bb..66296fa15d 100644 --- a/servers/physics_server.h +++ b/servers/physics_server.h @@ -318,7 +318,9 @@ public: enum AreaSpaceOverrideMode { AREA_SPACE_OVERRIDE_DISABLED, AREA_SPACE_OVERRIDE_COMBINE, + AREA_SPACE_OVERRIDE_COMBINE_REPLACE, AREA_SPACE_OVERRIDE_REPLACE, + AREA_SPACE_OVERRIDE_REPLACE_COMBINE }; virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode)=0; |