diff options
Diffstat (limited to 'servers/physics_2d')
-rw-r--r-- | servers/physics_2d/physics_2d_server_sw.cpp | 15 | ||||
-rw-r--r-- | servers/physics_2d/physics_2d_server_sw.h | 3 | ||||
-rw-r--r-- | servers/physics_2d/physics_2d_server_wrap_mt.h | 7 |
3 files changed, 25 insertions, 0 deletions
diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index 2b7505169a..df3bf72a31 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -954,6 +954,21 @@ bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from, return body->get_space()->test_body_motion(body, p_from, p_motion, p_margin, r_result); } +Physics2DDirectBodyState *Physics2DServerSW::body_get_direct_state(RID p_body) { + + Body2DSW *body = body_owner.get(p_body); + ERR_FAIL_COND_V(!body, NULL); + + if ((using_threads && !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); + } + + direct_state->body = body; + return direct_state; +} + /* JOINT API */ void Physics2DServerSW::joint_set_param(RID p_joint, JointParam p_param, real_t p_value) { diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index 0ebd43be53..c40cf0e3e0 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -222,6 +222,9 @@ public: virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, real_t p_margin = 0.001, MotionResult *r_result = NULL); + // this function only works on physics process, errors and returns null otherwise + virtual Physics2DDirectBodyState *body_get_direct_state(RID p_body); + /* JOINT API */ virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value); diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h index 5bec2f7cbd..50e9ab1005 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.h +++ b/servers/physics_2d/physics_2d_server_wrap_mt.h @@ -253,6 +253,13 @@ public: return physics_2d_server->body_test_motion(p_body, p_from, p_motion, p_margin, r_result); } + // this function only works on physics process, errors and returns null otherwise + Physics2DDirectBodyState *body_get_direct_state(RID p_body) { + + ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), NULL); + return physics_2d_server->body_get_direct_state(p_body); + } + /* JOINT API */ FUNC3(joint_set_param, RID, JointParam, real_t); |