diff options
| author | Rémi Verschelde | 2017-10-09 11:01:36 +0200 |
|---|---|---|
| committer | GitHub | 2017-10-09 11:01:36 +0200 |
| commit | 8e9b99fe59a360c0c9822e8e3e8f53afd1a72b5c (patch) | |
| tree | 63645c75c3ab6ea2b8052e32870a21a8194fda83 /servers/physics_2d | |
| parent | 30a4882cf808f04a80bf0b6a3c879c8e9a74f673 (diff) | |
| parent | c56c67db39b619d37c503e41e718f9cda39c3f0e (diff) | |
| download | godot-8e9b99fe59a360c0c9822e8e3e8f53afd1a72b5c.tar.gz godot-8e9b99fe59a360c0c9822e8e3e8f53afd1a72b5c.tar.zst godot-8e9b99fe59a360c0c9822e8e3e8f53afd1a72b5c.zip | |
Merge pull request #11702 from AndreaCatania/bodyDS
Added new API to get body direct state
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 2b7505169..df3bf72a3 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 0ebd43be5..c40cf0e3e 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 5bec2f7cb..50e9ab100 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); |
