diff options
author | Ricardo Buring <ricardo.buring@gmail.com> | 2022-09-15 14:15:39 +0200 |
---|---|---|
committer | Ricardo Buring <ricardo.buring@gmail.com> | 2022-09-15 15:09:23 +0200 |
commit | ff4e72a0bcf8ee1b8db2cb492397866559d17a73 (patch) | |
tree | 93f66050a4a2dac4a20943fdf94db068a63b433d /servers/physics_2d | |
parent | 4ba934bf3d1e697d8f332b5e8cfd694cdf49a7ba (diff) |
PhysicsServer2D and PhysicsServer3D: make body_set_state_sync_callback take a Callable
Prefer Callable to a C-style callback. This is helpful for GDExtension.
Diffstat (limited to 'servers/physics_2d')
-rw-r--r-- | servers/physics_2d/godot_body_2d.cpp | 17 | ||||
-rw-r--r-- | servers/physics_2d/godot_body_2d.h | 5 | ||||
-rw-r--r-- | servers/physics_2d/godot_physics_server_2d.cpp | 4 | ||||
-rw-r--r-- | servers/physics_2d/godot_physics_server_2d.h | 2 |
4 files changed, 15 insertions, 13 deletions
diff --git a/servers/physics_2d/godot_body_2d.cpp b/servers/physics_2d/godot_body_2d.cpp index ef6a6b1ae2..90124cd991 100644 --- a/servers/physics_2d/godot_body_2d.cpp +++ b/servers/physics_2d/godot_body_2d.cpp @@ -615,7 +615,7 @@ void GodotBody2D::integrate_velocities(real_t p_step) { return; } - if (fi_callback_data || body_state_callback) { + if (fi_callback_data || body_state_callback.get_object()) { get_space()->body_add_to_state_query_list(&direct_state_query_list); } @@ -673,11 +673,12 @@ void GodotBody2D::wakeup_neighbours() { } void GodotBody2D::call_queries() { + Variant direct_state_variant = get_direct_state(); + if (fi_callback_data) { if (!fi_callback_data->callable.get_object()) { set_force_integration_callback(Callable()); } else { - Variant direct_state_variant = get_direct_state(); const Variant *vp[2] = { &direct_state_variant, &fi_callback_data->udata }; Callable::CallError ce; @@ -691,8 +692,11 @@ void GodotBody2D::call_queries() { } } - if (body_state_callback) { - (body_state_callback)(body_state_callback_instance, get_direct_state()); + if (body_state_callback.get_object()) { + const Variant *vp[1] = { &direct_state_variant }; + Callable::CallError ce; + Variant rv; + body_state_callback.callp(vp, 1, rv, ce); } } @@ -713,9 +717,8 @@ bool GodotBody2D::sleep_test(real_t p_step) { } } -void GodotBody2D::set_state_sync_callback(void *p_instance, PhysicsServer2D::BodyStateCallback p_callback) { - body_state_callback_instance = p_instance; - body_state_callback = p_callback; +void GodotBody2D::set_state_sync_callback(const Callable &p_callable) { + body_state_callback = p_callable; } void GodotBody2D::set_force_integration_callback(const Callable &p_callable, const Variant &p_udata) { diff --git a/servers/physics_2d/godot_body_2d.h b/servers/physics_2d/godot_body_2d.h index 409940d4f8..86d42ae7f8 100644 --- a/servers/physics_2d/godot_body_2d.h +++ b/servers/physics_2d/godot_body_2d.h @@ -137,8 +137,7 @@ class GodotBody2D : public GodotCollisionObject2D { Vector<Contact> contacts; //no contacts by default int contact_count = 0; - void *body_state_callback_instance = nullptr; - PhysicsServer2D::BodyStateCallback body_state_callback = nullptr; + Callable body_state_callback; struct ForceIntegrationCallbackData { Callable callable; @@ -156,7 +155,7 @@ class GodotBody2D : public GodotCollisionObject2D { friend class GodotPhysicsDirectBodyState2D; // i give up, too many functions to expose public: - void set_state_sync_callback(void *p_instance, PhysicsServer2D::BodyStateCallback p_callback); + void set_state_sync_callback(const Callable &p_callable); void set_force_integration_callback(const Callable &p_callable, const Variant &p_udata = Variant()); GodotPhysicsDirectBodyState2D *get_direct_state(); diff --git a/servers/physics_2d/godot_physics_server_2d.cpp b/servers/physics_2d/godot_physics_server_2d.cpp index cec31bdc31..11f6bd9c1e 100644 --- a/servers/physics_2d/godot_physics_server_2d.cpp +++ b/servers/physics_2d/godot_physics_server_2d.cpp @@ -951,10 +951,10 @@ int GodotPhysicsServer2D::body_get_max_contacts_reported(RID p_body) const { return body->get_max_contacts_reported(); } -void GodotPhysicsServer2D::body_set_state_sync_callback(RID p_body, void *p_instance, BodyStateCallback p_callback) { +void GodotPhysicsServer2D::body_set_state_sync_callback(RID p_body, const Callable &p_callable) { GodotBody2D *body = body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); - body->set_state_sync_callback(p_instance, p_callback); + body->set_state_sync_callback(p_callable); } void GodotPhysicsServer2D::body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata) { diff --git a/servers/physics_2d/godot_physics_server_2d.h b/servers/physics_2d/godot_physics_server_2d.h index 20e492d87a..c780ef3b66 100644 --- a/servers/physics_2d/godot_physics_server_2d.h +++ b/servers/physics_2d/godot_physics_server_2d.h @@ -243,7 +243,7 @@ public: virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) override; virtual int body_get_max_contacts_reported(RID p_body) const override; - virtual void body_set_state_sync_callback(RID p_body, void *p_instance, BodyStateCallback p_callback) override; + virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) override; virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) override; virtual bool body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) override; |