diff options
Diffstat (limited to 'servers/physics')
-rw-r--r-- | servers/physics/area_sw.cpp | 2 | ||||
-rw-r--r-- | servers/physics/body_sw.cpp | 8 | ||||
-rw-r--r-- | servers/physics/broad_phase_octree.cpp | 2 | ||||
-rw-r--r-- | servers/physics/collision_object_sw.cpp | 7 | ||||
-rw-r--r-- | servers/physics/collision_object_sw.h | 13 | ||||
-rw-r--r-- | servers/physics/collision_solver_sat.cpp | 12 | ||||
-rw-r--r-- | servers/physics/collision_solver_sw.cpp | 4 | ||||
-rw-r--r-- | servers/physics/gjk_epa.cpp | 5 | ||||
-rw-r--r-- | servers/physics/gjk_epa.h | 5 | ||||
-rw-r--r-- | servers/physics/joints/generic_6dof_joint_sw.cpp | 1 | ||||
-rw-r--r-- | servers/physics/joints/hinge_joint_sw.cpp | 1 | ||||
-rw-r--r-- | servers/physics/physics_server_sw.cpp | 26 | ||||
-rw-r--r-- | servers/physics/shape_sw.cpp | 14 | ||||
-rw-r--r-- | servers/physics/space_sw.cpp | 10 |
14 files changed, 37 insertions, 73 deletions
diff --git a/servers/physics/area_sw.cpp b/servers/physics/area_sw.cpp index 9d68869bc2..ad3e40916d 100644 --- a/servers/physics/area_sw.cpp +++ b/servers/physics/area_sw.cpp @@ -250,7 +250,7 @@ AreaSW::AreaSW() : gravity_is_point = false; gravity_distance_scale = 0; point_attenuation = 1; - angular_damp = 1.0; + angular_damp = 0.1; linear_damp = 0.1; priority = 0; set_ray_pickable(false); diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index b4c3670a7b..ba98e14d2e 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -260,12 +260,15 @@ void BodySW::set_mode(PhysicsServer::BodyMode p_mode) { _inv_mass = mass > 0 ? (1.0 / mass) : 0; _set_static(false); + set_active(true); } break; case PhysicsServer::BODY_MODE_CHARACTER: { _inv_mass = mass > 0 ? (1.0 / mass) : 0; _set_static(false); + set_active(true); + angular_velocity = Vector3(); } break; } @@ -346,8 +349,7 @@ void BodySW::set_state(PhysicsServer::BodyState p_state, const Variant &p_varian //biased_angular_velocity=Vector3(); set_active(false); } else { - if (mode != PhysicsServer::BODY_MODE_STATIC) - set_active(true); + set_active(true); } } break; case PhysicsServer::BODY_STATE_CAN_SLEEP: { @@ -794,7 +796,7 @@ BodySW::BodySW() : still_time = 0; continuous_cd = false; - can_sleep = false; + can_sleep = true; fi_callback = NULL; } diff --git a/servers/physics/broad_phase_octree.cpp b/servers/physics/broad_phase_octree.cpp index 94bf274f9c..1b59779bd6 100644 --- a/servers/physics/broad_phase_octree.cpp +++ b/servers/physics/broad_phase_octree.cpp @@ -45,7 +45,7 @@ void BroadPhaseOctree::move(ID p_id, const AABB &p_aabb) { void BroadPhaseOctree::set_static(ID p_id, bool p_static) { CollisionObjectSW *it = octree.get(p_id); - octree.set_pairable(p_id, p_static ? false : true, 1 << it->get_type(), p_static ? 0 : 0xFFFFF); //pair everything, don't care 1? + octree.set_pairable(p_id, !p_static, 1 << it->get_type(), p_static ? 0 : 0xFFFFF); //pair everything, don't care 1? } void BroadPhaseOctree::remove(ID p_id) { diff --git a/servers/physics/collision_object_sw.cpp b/servers/physics/collision_object_sw.cpp index b1c21290ab..39de440da2 100644 --- a/servers/physics/collision_object_sw.cpp +++ b/servers/physics/collision_object_sw.cpp @@ -76,6 +76,13 @@ void CollisionObjectSW::set_shape_transform(int p_index, const Transform &p_tran //_shapes_changed(); } +void CollisionObjectSW::set_shape_as_disabled(int p_idx, bool p_enable) { + shapes.write[p_idx].disabled = p_enable; + if (!pending_shape_update_list.in_list()) { + PhysicsServerSW::singleton->pending_shape_update_list.add(&pending_shape_update_list); + } +} + void CollisionObjectSW::remove_shape(ShapeSW *p_shape) { //remove a shape, all the times it appears diff --git a/servers/physics/collision_object_sw.h b/servers/physics/collision_object_sw.h index c2c3fe0e5a..08708e2f60 100644 --- a/servers/physics/collision_object_sw.h +++ b/servers/physics/collision_object_sw.h @@ -86,13 +86,9 @@ protected: void _unregister_shapes(); _FORCE_INLINE_ void _set_transform(const Transform &p_transform, bool p_update_shapes = true) { - #ifdef DEBUG_ENABLED - if (p_transform.origin.length_squared() > MAX_OBJECT_DISTANCE_X2) { - ERR_EXPLAIN("Object went too far away (more than " + itos(MAX_OBJECT_DISTANCE) + "mts from origin)."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(p_transform.origin.length_squared() > MAX_OBJECT_DISTANCE_X2, "Object went too far away (more than '" + itos(MAX_OBJECT_DISTANCE) + "' units from origin)."); #endif transform = p_transform; @@ -139,8 +135,11 @@ public: _FORCE_INLINE_ void set_ray_pickable(bool p_enable) { ray_pickable = p_enable; } _FORCE_INLINE_ bool is_ray_pickable() const { return ray_pickable; } - _FORCE_INLINE_ void set_shape_as_disabled(int p_idx, bool p_enable) { shapes.write[p_idx].disabled = p_enable; } - _FORCE_INLINE_ bool is_shape_set_as_disabled(int p_idx) const { return shapes[p_idx].disabled; } + void set_shape_as_disabled(int p_idx, bool p_enable); + _FORCE_INLINE_ bool is_shape_set_as_disabled(int p_idx) const { + CRASH_BAD_INDEX(p_idx, shapes.size()); + return shapes[p_idx].disabled; + } _FORCE_INLINE_ void set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; } _FORCE_INLINE_ uint32_t get_collision_layer() const { return collision_layer; } diff --git a/servers/physics/collision_solver_sat.cpp b/servers/physics/collision_solver_sat.cpp index 3073cc8b11..a13fa65009 100644 --- a/servers/physics/collision_solver_sat.cpp +++ b/servers/physics/collision_solver_sat.cpp @@ -538,8 +538,6 @@ static void _collision_sphere_capsule(const ShapeSW *p_a, const Transform &p_tra template <bool withMargin> static void _collision_sphere_cylinder(const ShapeSW *p_a, const Transform &p_transform_a, const ShapeSW *p_b, const Transform &p_transform_b, _CollectorCallback *p_collector, real_t p_margin_a, real_t p_margin_b) { - - return; } template <bool withMargin> @@ -835,8 +833,6 @@ static void _collision_box_capsule(const ShapeSW *p_a, const Transform &p_transf template <bool withMargin> static void _collision_box_cylinder(const ShapeSW *p_a, const Transform &p_transform_a, const ShapeSW *p_b, const Transform &p_transform_b, _CollectorCallback *p_collector, real_t p_margin_a, real_t p_margin_b) { - - return; } template <bool withMargin> @@ -1117,8 +1113,6 @@ static void _collision_capsule_capsule(const ShapeSW *p_a, const Transform &p_tr template <bool withMargin> static void _collision_capsule_cylinder(const ShapeSW *p_a, const Transform &p_transform_a, const ShapeSW *p_b, const Transform &p_transform_b, _CollectorCallback *p_collector, real_t p_margin_a, real_t p_margin_b) { - - return; } template <bool withMargin> @@ -1243,20 +1237,14 @@ static void _collision_capsule_face(const ShapeSW *p_a, const Transform &p_trans template <bool withMargin> static void _collision_cylinder_cylinder(const ShapeSW *p_a, const Transform &p_transform_a, const ShapeSW *p_b, const Transform &p_transform_b, _CollectorCallback *p_collector, real_t p_margin_a, real_t p_margin_b) { - - return; } template <bool withMargin> static void _collision_cylinder_convex_polygon(const ShapeSW *p_a, const Transform &p_transform_a, const ShapeSW *p_b, const Transform &p_transform_b, _CollectorCallback *p_collector, real_t p_margin_a, real_t p_margin_b) { - - return; } template <bool withMargin> static void _collision_cylinder_face(const ShapeSW *p_a, const Transform &p_transform_a, const ShapeSW *p_b, const Transform &p_transform_b, _CollectorCallback *p_collector, real_t p_margin_a, real_t p_margin_b) { - - return; } template <bool withMargin> diff --git a/servers/physics/collision_solver_sw.cpp b/servers/physics/collision_solver_sw.cpp index 0d10dae8cc..d970dd39fb 100644 --- a/servers/physics/collision_solver_sw.cpp +++ b/servers/physics/collision_solver_sw.cpp @@ -233,8 +233,6 @@ bool CollisionSolverSW::solve_static(const ShapeSW *p_shape_A, const Transform & return collision_solver(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false, r_sep_axis, p_margin_A, p_margin_B); } - - return false; } void CollisionSolverSW::concave_distance_callback(void *p_userdata, ShapeSW *p_convex) { @@ -371,6 +369,4 @@ bool CollisionSolverSW::solve_distance(const ShapeSW *p_shape_A, const Transform return gjk_epa_calculate_distance(p_shape_A, p_transform_A, p_shape_B, p_transform_B, r_point_A, r_point_B); //should pass sepaxis.. } - - return false; } diff --git a/servers/physics/gjk_epa.cpp b/servers/physics/gjk_epa.cpp index ae512183fd..1d5ca42838 100644 --- a/servers/physics/gjk_epa.cpp +++ b/servers/physics/gjk_epa.cpp @@ -722,7 +722,10 @@ struct GJK append(m_stock,face); return(0); } - m_status=m_stock.root?eStatus::OutOfVertices:eStatus::OutOfFaces; + // -- GODOT start -- + //m_status=m_stock.root?eStatus::OutOfVertices:eStatus::OutOfFaces; + m_status=eStatus::OutOfFaces; + // -- GODOT end -- return(0); } sFace* findbest() diff --git a/servers/physics/gjk_epa.h b/servers/physics/gjk_epa.h index 0b7885c9a5..d3fa192804 100644 --- a/servers/physics/gjk_epa.h +++ b/servers/physics/gjk_epa.h @@ -31,11 +31,8 @@ #ifndef GJK_EPA_H #define GJK_EPA_H -#include "shape_sw.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ #include "collision_solver_sw.h" +#include "shape_sw.h" bool gjk_epa_calculate_penetration(const ShapeSW *p_shape_A, const Transform &p_transform_A, const ShapeSW *p_shape_B, const Transform &p_transform_B, CollisionSolverSW::CallbackResult p_result_callback, void *p_userdata, bool p_swap = false); bool gjk_epa_calculate_distance(const ShapeSW *p_shape_A, const Transform &p_transform_A, const ShapeSW *p_shape_B, const Transform &p_transform_B, Vector3 &r_result_A, Vector3 &r_result_B); diff --git a/servers/physics/joints/generic_6dof_joint_sw.cpp b/servers/physics/joints/generic_6dof_joint_sw.cpp index 813d9b7704..a9fe045856 100644 --- a/servers/physics/joints/generic_6dof_joint_sw.cpp +++ b/servers/physics/joints/generic_6dof_joint_sw.cpp @@ -421,7 +421,6 @@ void Generic6DOFJointSW::calcAnchorPos(void) { const Vector3 &pA = m_calculatedTransformA.origin; const Vector3 &pB = m_calculatedTransformB.origin; m_AnchorPos = pA * weight + pB * (real_t(1.0) - weight); - return; } // Generic6DOFJointSW::calcAnchorPos() void Generic6DOFJointSW::set_param(Vector3::Axis p_axis, PhysicsServer::G6DOFJointAxisParam p_param, real_t p_value) { diff --git a/servers/physics/joints/hinge_joint_sw.cpp b/servers/physics/joints/hinge_joint_sw.cpp index 1d1b30286e..209cddda5e 100644 --- a/servers/physics/joints/hinge_joint_sw.cpp +++ b/servers/physics/joints/hinge_joint_sw.cpp @@ -198,7 +198,6 @@ bool HingeJointSW::setup(real_t p_step) { plane_space(m_rbAFrame.basis.get_axis(2), jointAxis0local, jointAxis1local); - A->get_transform().basis.xform(m_rbAFrame.basis.get_axis(2)); Vector3 jointAxis0 = A->get_transform().basis.xform(jointAxis0local); Vector3 jointAxis1 = A->get_transform().basis.xform(jointAxis1local); Vector3 hingeAxisWorld = A->get_transform().basis.xform(m_rbAFrame.basis.get_axis(2)); diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 7b982e7015..09872977b6 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -40,11 +40,8 @@ #include "joints/pin_joint_sw.h" #include "joints/slider_joint_sw.h" -#define FLUSH_QUERY_CHECK(m_object) \ - if (m_object->get_space() && flushing_queries) { \ - ERR_EXPLAIN("Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead"); \ - ERR_FAIL(); \ - } +#define FLUSH_QUERY_CHECK(m_object) \ + ERR_FAIL_COND_MSG(m_object->get_space() && flushing_queries, "Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead."); RID PhysicsServerSW::shape_create(ShapeType p_shape) { @@ -73,8 +70,7 @@ RID PhysicsServerSW::shape_create(ShapeType p_shape) { } break; case SHAPE_CYLINDER: { - ERR_EXPLAIN("CylinderShape is not supported in GodotPhysics. Please switch to Bullet in the Project Settings."); - ERR_FAIL_V(RID()); + ERR_FAIL_V_MSG(RID(), "CylinderShape is not supported in GodotPhysics. Please switch to Bullet in the Project Settings."); } break; case SHAPE_CONVEX_POLYGON: { @@ -200,11 +196,7 @@ PhysicsDirectSpaceState *PhysicsServerSW::space_get_direct_state(RID p_space) { SpaceSW *space = space_owner.get(p_space); ERR_FAIL_COND_V(!space, NULL); - if (!doing_sync || space->is_locked()) { - - ERR_EXPLAIN("Space state is inaccessible right now, wait for iteration or physics process notification."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!doing_sync || space->is_locked(), NULL, "Space state is inaccessible right now, wait for iteration or physics process notification."); return space->get_direct_state(); } @@ -987,12 +979,7 @@ PhysicsDirectBodyState *PhysicsServerSW::body_get_direct_state(RID p_body) { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body, NULL); - - if (!doing_sync || body->get_space()->is_locked()) { - - ERR_EXPLAIN("Body state is inaccessible right now, wait for iteration or physics process notification."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!doing_sync || body->get_space()->is_locked(), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification."); direct_state->body = body; return direct_state; @@ -1410,8 +1397,7 @@ void PhysicsServerSW::free(RID p_rid) { } else { - ERR_EXPLAIN("Invalid ID"); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid ID."); } }; diff --git a/servers/physics/shape_sw.cpp b/servers/physics/shape_sw.cpp index d40de669fd..f01caefdce 100644 --- a/servers/physics/shape_sw.cpp +++ b/servers/physics/shape_sw.cpp @@ -543,16 +543,6 @@ void CapsuleShapeSW::project_range(const Vector3 &p_normal, const Transform &p_t r_max = p_normal.dot(p_transform.xform(n)); r_min = p_normal.dot(p_transform.xform(-n)); - return; - - n = p_transform.basis.xform(n); - - real_t distance = p_normal.dot(p_transform.origin); - real_t length = Math::abs(p_normal.dot(n)); - r_min = distance - length; - r_max = distance + length; - - ERR_FAIL_COND(r_max < r_min); } Vector3 CapsuleShapeSW::get_support(const Vector3 &p_normal) const { @@ -1524,8 +1514,8 @@ void ConcavePolygonShapeSW::_setup(PoolVector<Vector3> p_faces) { _aabb.merge_with(bvh_arrayw[i].aabb); } - w = PoolVector<Face>::Write(); - vw = PoolVector<Vector3>::Write(); + w.release(); + vw.release(); int count = 0; _VolumeSW_BVH *bvh_tree = _volume_sw_build_bvh(bvh_arrayw, src_face_count, count); diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index 8b9f210850..410b6e59a0 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -118,7 +118,7 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vecto if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; - if (p_pick_ray && !(static_cast<CollisionObjectSW *>(space->intersection_query_results[i])->is_ray_pickable())) + if (p_pick_ray && !(space->intersection_query_results[i]->is_ray_pickable())) continue; if (p_exclude.has(space->intersection_query_results[i]->get_self())) @@ -348,11 +348,9 @@ bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform &p_sh cbk.max = p_result_max; cbk.amount = 0; cbk.ptr = r_results; - CollisionSolverSW::CallbackResult cbkres = NULL; + CollisionSolverSW::CallbackResult cbkres = PhysicsServerSW::_shape_col_cbk; - PhysicsServerSW::CollCbkData *cbkptr = NULL; - cbkptr = &cbk; - cbkres = PhysicsServerSW::_shape_col_cbk; + PhysicsServerSW::CollCbkData *cbkptr = &cbk; for (int i = 0; i < amount; i++) { @@ -439,7 +437,7 @@ bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform &p_shape_ continue; } - if (rcd.best_len == 0) + if (rcd.best_len == 0 || !rcd.best_object) return false; r_info->collider_id = rcd.best_object->get_instance_id(); |