summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-07-23 15:55:46 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-07-23 15:55:46 +0200
commit29e1bdee2b48247d858f6985fc4e8f2c509de037 (patch)
treed5e8f708a68f2f4aef76f4e4bf9291f61f2a1d3f
parent432d15e3f10aa556d357cbd5b1d5a10026cd2821 (diff)
parenta559a1c6d8d6f328d42fbe6c7926238ea1be53be (diff)
downloadredot-engine-29e1bdee2b48247d858f6985fc4e8f2c509de037.tar.gz
Merge pull request #94653 from mihe/bind-physics-state-sync
Bind `PhysicsServer*D::body_set_state_sync_callback`
-rw-r--r--doc/classes/PhysicsServer2D.xml11
-rw-r--r--doc/classes/PhysicsServer2DExtension.xml2
-rw-r--r--doc/classes/PhysicsServer3D.xml11
-rw-r--r--servers/physics_server_2d.cpp2
-rw-r--r--servers/physics_server_3d.cpp2
5 files changed, 27 insertions, 1 deletions
diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml
index c0672cc503..bd960e3da5 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.
</description>
</method>
+ <method name="body_set_state_sync_callback">
+ <return type="void" />
+ <param index="0" name="body" type="RID" />
+ <param index="1" name="callable" type="Callable" />
+ <description>
+ 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.
+ </description>
+ </method>
<method name="body_test_motion">
<return type="bool" />
<param index="0" name="body" type="RID" />
diff --git a/doc/classes/PhysicsServer2DExtension.xml b/doc/classes/PhysicsServer2DExtension.xml
index 41826ea7c2..07c65915c6 100644
--- a/doc/classes/PhysicsServer2DExtension.xml
+++ b/doc/classes/PhysicsServer2DExtension.xml
@@ -713,7 +713,7 @@
<param index="1" name="callable" type="Callable" />
<description>
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].
</description>
</method>
<method name="_body_test_motion" qualifiers="virtual const">
diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml
index a7b55387a4..f87d6342c7 100644
--- a/doc/classes/PhysicsServer3D.xml
+++ b/doc/classes/PhysicsServer3D.xml
@@ -678,6 +678,17 @@
Sets a body state (see [enum BodyState] constants).
</description>
</method>
+ <method name="body_set_state_sync_callback">
+ <return type="void" />
+ <param index="0" name="body" type="RID" />
+ <param index="1" name="callable" type="Callable" />
+ <description>
+ 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.
+ </description>
+ </method>
<method name="body_test_motion">
<return type="bool" />
<param index="0" name="body" type="RID" />
diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp
index aea0c52a63..da25621ba5 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 cda04e0aae..698805bbdd 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);