diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-12-22 10:57:39 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-12-22 10:57:39 -0300 |
commit | acc9db1695ebabe61e6dc68bf9d63478a81c0827 (patch) | |
tree | d67bdb5c707db95e1685581e4d4c9dd2488c7cf3 | |
parent | 02d6669a3849c55e415f37b23b36b49f23319957 (diff) | |
parent | 89efebbf561fa19d29533acdd3716f8d1385595a (diff) |
Merge pull request #3071 from Ovnuniarchos/NewAreaCombiners
New and corrected area override modes.
-rw-r--r-- | scene/2d/area_2d.cpp | 2 | ||||
-rw-r--r-- | scene/2d/area_2d.h | 4 | ||||
-rw-r--r-- | scene/3d/area.cpp | 2 | ||||
-rw-r--r-- | scene/3d/area.h | 4 | ||||
-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 |
10 files changed, 62 insertions, 25 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index c44b46adbf..5038752b22 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -652,7 +652,7 @@ void Area2D::_bind_methods() { ADD_SIGNAL( MethodInfo("area_exit",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"))); - ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); + ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Combine-Replace,Replace,Replace-Combine"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); ADD_PROPERTYNZ( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector")); diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index f5a88390e7..2b74655109 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -40,7 +40,9 @@ public: enum SpaceOverride { SPACE_OVERRIDE_DISABLED, SPACE_OVERRIDE_COMBINE, - SPACE_OVERRIDE_REPLACE + SPACE_OVERRIDE_COMBINE_REPLACE, + SPACE_OVERRIDE_REPLACE, + SPACE_OVERRIDE_REPLACE_COMBINE }; private: diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index ff35837bc0..47cebd25a2 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -579,7 +579,7 @@ void Area::_bind_methods() { ADD_SIGNAL( MethodInfo("area_enter",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"))); ADD_SIGNAL( MethodInfo("area_exit",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"))); - ADD_PROPERTY( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Combine-Replace,Replace,Replace-Combine"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector")); diff --git a/scene/3d/area.h b/scene/3d/area.h index f03955d1e7..529a116937 100644 --- a/scene/3d/area.h +++ b/scene/3d/area.h @@ -40,7 +40,9 @@ public: enum SpaceOverride { SPACE_OVERRIDE_DISABLED, SPACE_OVERRIDE_COMBINE, - SPACE_OVERRIDE_REPLACE + SPACE_OVERRIDE_COMBINE_REPLACE, + SPACE_OVERRIDE_REPLACE, + SPACE_OVERRIDE_REPLACE_COMBINE }; private: 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; |