diff options
Diffstat (limited to 'servers/physics/physics_server_sw.cpp')
-rw-r--r-- | servers/physics/physics_server_sw.cpp | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index a06942cb2a..fddb531a4f 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -32,13 +32,19 @@ #include "broad_phase_basic.h" #include "broad_phase_octree.h" +#include "core/os/os.h" +#include "core/script_language.h" #include "joints/cone_twist_joint_sw.h" #include "joints/generic_6dof_joint_sw.h" #include "joints/hinge_joint_sw.h" #include "joints/pin_joint_sw.h" #include "joints/slider_joint_sw.h" -#include "os/os.h" -#include "script_language.h" + +#define FLUSH_QUERY_CHECK \ + if (flushing_queries) { \ + ERR_EXPLAIN("Can't change this state while flushing queries. Use call_deferred()/set_deferred() to change monitoring state instead"); \ + ERR_FAIL(); \ + } RID PhysicsServerSW::shape_create(ShapeType p_shape) { @@ -124,6 +130,13 @@ Variant PhysicsServerSW::shape_get_data(RID p_shape) const { return shape->get_data(); }; +void PhysicsServerSW::shape_set_margin(RID p_shape, real_t p_margin) { +} + +real_t PhysicsServerSW::shape_get_margin(RID p_shape) const { + return 0.0; +} + real_t PhysicsServerSW::shape_get_custom_solver_bias(RID p_shape) const { const ShapeSW *shape = shape_owner.get(p_shape); @@ -292,6 +305,7 @@ void PhysicsServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) { area->set_shape(p_shape_idx, shape); } + void PhysicsServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) { AreaSW *area = area_owner.get(p_area); @@ -344,6 +358,8 @@ void PhysicsServerSW::area_clear_shapes(RID p_area) { void PhysicsServerSW::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) { + FLUSH_QUERY_CHECK + AreaSW *area = area_owner.get(p_area); ERR_FAIL_COND(!area); ERR_FAIL_INDEX(p_shape_idx, area->get_shape_count()); @@ -427,6 +443,8 @@ void PhysicsServerSW::area_set_collision_mask(RID p_area, uint32_t p_mask) { void PhysicsServerSW::area_set_monitorable(RID p_area, bool p_monitorable) { + FLUSH_QUERY_CHECK + AreaSW *area = area_owner.get(p_area); ERR_FAIL_COND(!area); @@ -574,6 +592,8 @@ RID PhysicsServerSW::body_get_shape(RID p_body, int p_shape_idx) const { void PhysicsServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) { + FLUSH_QUERY_CHECK + BodySW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); @@ -701,20 +721,6 @@ real_t PhysicsServerSW::body_get_param(RID p_body, BodyParameter p_param) const return body->get_param(p_param); }; -void PhysicsServerSW::body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) { - BodySW *body = body_owner.get(p_body); - ERR_FAIL_COND(!body); - - body->set_combine_mode(p_param, p_mode); -} - -PhysicsServer::CombineMode PhysicsServerSW::body_get_combine_mode(RID p_body, BodyParameter p_param) const { - BodySW *body = body_owner.get(p_body); - ERR_FAIL_COND_V(!body, COMBINE_MODE_INHERIT); - - return body->get_combine_mode(p_param); -} - void PhysicsServerSW::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); @@ -955,7 +961,7 @@ bool PhysicsServerSW::body_is_ray_pickable(RID p_body) const { return body->is_ray_pickable(); } -bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result) { +bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes) { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body, false); @@ -964,7 +970,19 @@ bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, cons _update_shapes(); - return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, body->get_kinematic_margin(), r_result); + return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, body->get_kinematic_margin(), r_result, p_exclude_raycast_shapes); +} + +int PhysicsServerSW::body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) { + + BodySW *body = body_owner.get(p_body); + ERR_FAIL_COND_V(!body, false); + ERR_FAIL_COND_V(!body->get_space(), false); + ERR_FAIL_COND_V(body->get_space()->is_locked(), false); + + _update_shapes(); + + return body->get_space()->test_body_ray_separation(body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin); } PhysicsDirectBodyState *PhysicsServerSW::body_get_direct_state(RID p_body) { @@ -1453,6 +1471,8 @@ void PhysicsServerSW::flush_queries() { doing_sync = true; + flushing_queries = true; + uint64_t time_beg = OS::get_singleton()->get_ticks_usec(); for (Set<const SpaceSW *>::Element *E = active_spaces.front(); E; E = E->next()) { @@ -1461,6 +1481,8 @@ void PhysicsServerSW::flush_queries() { space->call_queries(); } + flushing_queries = false; + if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) { uint64_t total_time[SpaceSW::ELAPSED_TIME_MAX]; @@ -1574,6 +1596,7 @@ PhysicsServerSW::PhysicsServerSW() { collision_pairs = 0; active = true; + flushing_queries = false; }; PhysicsServerSW::~PhysicsServerSW(){ |