Merge pull request #11702 from AndreaCatania/bodyDS

Added new API to get body direct state
This commit is contained in:
Rémi Verschelde 2017-10-09 11:01:36 +02:00 committed by GitHub
commit 8e9b99fe59
9 changed files with 53 additions and 0 deletions

View file

@ -914,6 +914,21 @@ bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, cons
return body->get_space()->test_body_motion(body, p_from, p_motion, p_margin, r_result); return body->get_space()->test_body_motion(body, p_from, p_motion, p_margin, r_result);
} }
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);
}
direct_state->body = body;
return direct_state;
}
/* JOINT API */ /* JOINT API */
RID PhysicsServerSW::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) { RID PhysicsServerSW::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) {

View file

@ -223,6 +223,9 @@ public:
virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, float p_margin = 0.001, MotionResult *r_result = NULL); virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, float p_margin = 0.001, MotionResult *r_result = NULL);
// this function only works on physics process, errors and returns null otherwise
virtual PhysicsDirectBodyState *body_get_direct_state(RID p_body);
/* JOINT API */ /* JOINT API */
virtual RID joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B); virtual RID joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B);

View file

@ -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); 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 */ /* JOINT API */
void Physics2DServerSW::joint_set_param(RID p_joint, JointParam p_param, real_t p_value) { void Physics2DServerSW::joint_set_param(RID p_joint, JointParam p_param, real_t p_value) {

View file

@ -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); 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 */ /* JOINT API */
virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value); virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value);

View file

@ -253,6 +253,13 @@ public:
return physics_2d_server->body_test_motion(p_body, p_from, p_motion, p_margin, r_result); 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 */ /* JOINT API */
FUNC3(joint_set_param, RID, JointParam, real_t); FUNC3(joint_set_param, RID, JointParam, real_t);

View file

@ -579,6 +579,8 @@ void Physics2DServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("body_test_motion", "body", "from", "motion", "margin", "result"), &Physics2DServer::_body_test_motion, DEFVAL(0.08), DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("body_test_motion", "body", "from", "motion", "margin", "result"), &Physics2DServer::_body_test_motion, DEFVAL(0.08), DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &Physics2DServer::body_get_direct_state);
/* JOINT API */ /* JOINT API */
ClassDB::bind_method(D_METHOD("joint_set_param", "joint", "param", "value"), &Physics2DServer::joint_set_param); ClassDB::bind_method(D_METHOD("joint_set_param", "joint", "param", "value"), &Physics2DServer::joint_set_param);

View file

@ -468,6 +468,9 @@ public:
virtual void body_set_pickable(RID p_body, bool p_pickable) = 0; virtual void body_set_pickable(RID p_body, bool p_pickable) = 0;
// this function only works on physics process, errors and returns null otherwise
virtual Physics2DDirectBodyState *body_get_direct_state(RID p_body) = 0;
struct MotionResult { struct MotionResult {
Vector2 motion; Vector2 motion;

View file

@ -504,6 +504,8 @@ void PhysicsServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer::body_set_ray_pickable); ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer::body_set_ray_pickable);
ClassDB::bind_method(D_METHOD("body_is_ray_pickable", "body"), &PhysicsServer::body_is_ray_pickable); ClassDB::bind_method(D_METHOD("body_is_ray_pickable", "body"), &PhysicsServer::body_is_ray_pickable);
ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &PhysicsServer::body_get_direct_state);
/* JOINT API */ /* JOINT API */
BIND_ENUM_CONSTANT(JOINT_PIN); BIND_ENUM_CONSTANT(JOINT_PIN);

View file

@ -464,6 +464,9 @@ public:
virtual void body_set_ray_pickable(RID p_body, bool p_enable) = 0; virtual void body_set_ray_pickable(RID p_body, bool p_enable) = 0;
virtual bool body_is_ray_pickable(RID p_body) const = 0; virtual bool body_is_ray_pickable(RID p_body) const = 0;
// this function only works on physics process, errors and returns null otherwise
virtual PhysicsDirectBodyState *body_get_direct_state(RID p_body) = 0;
struct MotionResult { struct MotionResult {
Vector3 motion; Vector3 motion;