From a559a1c6d8d6f328d42fbe6c7926238ea1be53be Mon Sep 17 00:00:00 2001 From: Mikael Hermansson Date: Tue, 23 Jul 2024 13:11:34 +0200 Subject: [PATCH] Bind `PhysicsServer*D::body_set_state_sync_callback` --- doc/classes/PhysicsServer2D.xml | 11 +++++++++++ doc/classes/PhysicsServer2DExtension.xml | 2 +- doc/classes/PhysicsServer3D.xml | 11 +++++++++++ servers/physics_server_2d.cpp | 2 ++ servers/physics_server_3d.cpp | 2 ++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml index c0672cc5035..bd960e3da51 100644 --- a/doc/classes/PhysicsServer2D.xml +++ b/doc/classes/PhysicsServer2D.xml @@ -694,6 +694,17 @@ [b]Note:[/b] The state change doesn't take effect immediately. The state will change on the next physics frame. + + + + + + Sets the body's state synchronization callback function to [param callable]. Use an empty [Callable] ([code skip-lint]Callable()[/code]) to clear the callback. + The function [param callable] will be called every physics frame, assuming that the body was active during the previous physics tick, and can be used to fetch the latest state from the physics server. + The function [param callable] must take the following parameters: + 1. [code]state[/code]: a [PhysicsDirectBodyState2D], used to retrieve the body's state. + + diff --git a/doc/classes/PhysicsServer2DExtension.xml b/doc/classes/PhysicsServer2DExtension.xml index 41826ea7c2a..07c65915c6f 100644 --- a/doc/classes/PhysicsServer2DExtension.xml +++ b/doc/classes/PhysicsServer2DExtension.xml @@ -713,7 +713,7 @@ Assigns the [param body] to call the given [param callable] during the synchronization phase of the loop, before [method _step] is called. See also [method _sync]. - Overridable version of [PhysicsServer2D]'s internal [code]body_set_state_sync_callback[/code] method. + Overridable version of [method PhysicsServer2D.body_set_state_sync_callback]. diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml index a7b55387a49..f87d6342c79 100644 --- a/doc/classes/PhysicsServer3D.xml +++ b/doc/classes/PhysicsServer3D.xml @@ -678,6 +678,17 @@ Sets a body state (see [enum BodyState] constants). + + + + + + Sets the body's state synchronization callback function to [param callable]. Use an empty [Callable] ([code skip-lint]Callable()[/code]) to clear the callback. + The function [param callable] will be called every physics frame, assuming that the body was active during the previous physics tick, and can be used to fetch the latest state from the physics server. + The function [param callable] must take the following parameters: + 1. [code]state[/code]: a [PhysicsDirectBodyState3D], used to retrieve the body's state. + + diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index aea0c52a630..da25621ba50 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -754,6 +754,8 @@ void PhysicsServer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("body_set_omit_force_integration", "body", "enable"), &PhysicsServer2D::body_set_omit_force_integration); ClassDB::bind_method(D_METHOD("body_is_omitting_force_integration", "body"), &PhysicsServer2D::body_is_omitting_force_integration); + ClassDB::bind_method(D_METHOD("body_set_state_sync_callback", "body", "callable"), &PhysicsServer2D::body_set_state_sync_callback); + ClassDB::bind_method(D_METHOD("body_set_force_integration_callback", "body", "callable", "userdata"), &PhysicsServer2D::body_set_force_integration_callback, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("body_test_motion", "body", "parameters", "result"), &PhysicsServer2D::_body_test_motion, DEFVAL(Variant())); diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp index cda04e0aae7..698805bbddb 100644 --- a/servers/physics_server_3d.cpp +++ b/servers/physics_server_3d.cpp @@ -829,6 +829,8 @@ void PhysicsServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("body_set_omit_force_integration", "body", "enable"), &PhysicsServer3D::body_set_omit_force_integration); ClassDB::bind_method(D_METHOD("body_is_omitting_force_integration", "body"), &PhysicsServer3D::body_is_omitting_force_integration); + ClassDB::bind_method(D_METHOD("body_set_state_sync_callback", "body", "callable"), &PhysicsServer3D::body_set_state_sync_callback); + ClassDB::bind_method(D_METHOD("body_set_force_integration_callback", "body", "callable", "userdata"), &PhysicsServer3D::body_set_force_integration_callback, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer3D::body_set_ray_pickable);