diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-09-05 12:44:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-05 12:44:58 +0200 |
commit | 6c818da55ef1f45eaed06e1413220af1d23a9c41 (patch) | |
tree | 2a5f85948dd22a7c38f67a70ba5e56a66b824a65 | |
parent | 26c073aa1d9bb0db7a908decef68c0bb9ed6b21b (diff) | |
parent | d22ff48b3d34c805a6328fa5b615f1ac586d3090 (diff) |
Merge pull request #65321 from rburing/physics_server_2d_extension
Create GDExtension classes for PhysicsServer2D
-rw-r--r-- | doc/classes/PhysicsDirectBodyState2DExtension.xml | 249 | ||||
-rw-r--r-- | doc/classes/PhysicsDirectSpaceState2DExtension.xml | 91 | ||||
-rw-r--r-- | doc/classes/PhysicsServer2D.xml | 2 | ||||
-rw-r--r-- | doc/classes/PhysicsServer2DExtension.xml | 777 | ||||
-rw-r--r-- | modules/mono/editor/bindings_generator.cpp | 2 | ||||
-rw-r--r-- | servers/extensions/physics_server_2d_extension.cpp | 294 | ||||
-rw-r--r-- | servers/extensions/physics_server_2d_extension.h | 462 | ||||
-rw-r--r-- | servers/physics_server_2d.cpp | 2 | ||||
-rw-r--r-- | servers/physics_server_2d.h | 1 | ||||
-rw-r--r-- | servers/register_server_types.cpp | 11 |
10 files changed, 1890 insertions, 1 deletions
diff --git a/doc/classes/PhysicsDirectBodyState2DExtension.xml b/doc/classes/PhysicsDirectBodyState2DExtension.xml new file mode 100644 index 0000000000..8fd34c1243 --- /dev/null +++ b/doc/classes/PhysicsDirectBodyState2DExtension.xml @@ -0,0 +1,249 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="PhysicsDirectBodyState2DExtension" inherits="PhysicsDirectBodyState2D" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="_add_constant_central_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="force" type="Vector2" /> + <description> + </description> + </method> + <method name="_add_constant_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="force" type="Vector2" /> + <param index="1" name="position" type="Vector2" /> + <description> + </description> + </method> + <method name="_add_constant_torque" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="torque" type="float" /> + <description> + </description> + </method> + <method name="_apply_central_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="force" type="Vector2" /> + <description> + </description> + </method> + <method name="_apply_central_impulse" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="impulse" type="Vector2" /> + <description> + </description> + </method> + <method name="_apply_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="force" type="Vector2" /> + <param index="1" name="position" type="Vector2" /> + <description> + </description> + </method> + <method name="_apply_impulse" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="impulse" type="Vector2" /> + <param index="1" name="position" type="Vector2" /> + <description> + </description> + </method> + <method name="_apply_torque" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="torque" type="float" /> + <description> + </description> + </method> + <method name="_apply_torque_impulse" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="impulse" type="float" /> + <description> + </description> + </method> + <method name="_get_angular_velocity" qualifiers="virtual const"> + <return type="float" /> + <description> + </description> + </method> + <method name="_get_center_of_mass" qualifiers="virtual const"> + <return type="Vector2" /> + <description> + </description> + </method> + <method name="_get_center_of_mass_local" qualifiers="virtual const"> + <return type="Vector2" /> + <description> + </description> + </method> + <method name="_get_constant_force" qualifiers="virtual const"> + <return type="Vector2" /> + <description> + </description> + </method> + <method name="_get_constant_torque" qualifiers="virtual const"> + <return type="float" /> + <description> + </description> + </method> + <method name="_get_contact_collider" qualifiers="virtual const"> + <return type="RID" /> + <param index="0" name="contact_idx" type="int" /> + <description> + </description> + </method> + <method name="_get_contact_collider_id" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="contact_idx" type="int" /> + <description> + </description> + </method> + <method name="_get_contact_collider_object" qualifiers="virtual const"> + <return type="Object" /> + <param index="0" name="contact_idx" type="int" /> + <description> + </description> + </method> + <method name="_get_contact_collider_position" qualifiers="virtual const"> + <return type="Vector2" /> + <param index="0" name="contact_idx" type="int" /> + <description> + </description> + </method> + <method name="_get_contact_collider_shape" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="contact_idx" type="int" /> + <description> + </description> + </method> + <method name="_get_contact_collider_velocity_at_position" qualifiers="virtual const"> + <return type="Vector2" /> + <param index="0" name="contact_idx" type="int" /> + <description> + </description> + </method> + <method name="_get_contact_count" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_contact_local_normal" qualifiers="virtual const"> + <return type="Vector2" /> + <param index="0" name="contact_idx" type="int" /> + <description> + </description> + </method> + <method name="_get_contact_local_position" qualifiers="virtual const"> + <return type="Vector2" /> + <param index="0" name="contact_idx" type="int" /> + <description> + </description> + </method> + <method name="_get_contact_local_shape" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="contact_idx" type="int" /> + <description> + </description> + </method> + <method name="_get_inverse_inertia" qualifiers="virtual const"> + <return type="float" /> + <description> + </description> + </method> + <method name="_get_inverse_mass" qualifiers="virtual const"> + <return type="float" /> + <description> + </description> + </method> + <method name="_get_linear_velocity" qualifiers="virtual const"> + <return type="Vector2" /> + <description> + </description> + </method> + <method name="_get_space_state" qualifiers="virtual"> + <return type="PhysicsDirectSpaceState2D" /> + <description> + </description> + </method> + <method name="_get_step" qualifiers="virtual const"> + <return type="float" /> + <description> + </description> + </method> + <method name="_get_total_angular_damp" qualifiers="virtual const"> + <return type="float" /> + <description> + </description> + </method> + <method name="_get_total_gravity" qualifiers="virtual const"> + <return type="Vector2" /> + <description> + </description> + </method> + <method name="_get_total_linear_damp" qualifiers="virtual const"> + <return type="float" /> + <description> + </description> + </method> + <method name="_get_transform" qualifiers="virtual const"> + <return type="Transform2D" /> + <description> + </description> + </method> + <method name="_get_velocity_at_local_position" qualifiers="virtual const"> + <return type="Vector2" /> + <param index="0" name="local_position" type="Vector2" /> + <description> + </description> + </method> + <method name="_integrate_forces" qualifiers="virtual"> + <return type="void" /> + <description> + </description> + </method> + <method name="_is_sleeping" qualifiers="virtual const"> + <return type="bool" /> + <description> + </description> + </method> + <method name="_set_angular_velocity" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="velocity" type="float" /> + <description> + </description> + </method> + <method name="_set_constant_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="force" type="Vector2" /> + <description> + </description> + </method> + <method name="_set_constant_torque" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="torque" type="float" /> + <description> + </description> + </method> + <method name="_set_linear_velocity" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="velocity" type="Vector2" /> + <description> + </description> + </method> + <method name="_set_sleep_state" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="enabled" type="bool" /> + <description> + </description> + </method> + <method name="_set_transform" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="transform" type="Transform2D" /> + <description> + </description> + </method> + </methods> +</class> diff --git a/doc/classes/PhysicsDirectSpaceState2DExtension.xml b/doc/classes/PhysicsDirectSpaceState2DExtension.xml new file mode 100644 index 0000000000..3235793853 --- /dev/null +++ b/doc/classes/PhysicsDirectSpaceState2DExtension.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="PhysicsDirectSpaceState2DExtension" inherits="PhysicsDirectSpaceState2D" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="_cast_motion" qualifiers="virtual"> + <return type="bool" /> + <param index="0" name="shape_rid" type="RID" /> + <param index="1" name="transform" type="Transform2D" /> + <param index="2" name="motion" type="Vector2" /> + <param index="3" name="margin" type="float" /> + <param index="4" name="collision_mask" type="int" /> + <param index="5" name="collide_with_bodies" type="bool" /> + <param index="6" name="collide_with_areas" type="bool" /> + <param index="7" name="closest_safe" type="float*" /> + <param index="8" name="closest_unsafe" type="float*" /> + <description> + </description> + </method> + <method name="_collide_shape" qualifiers="virtual"> + <return type="bool" /> + <param index="0" name="shape_rid" type="RID" /> + <param index="1" name="transform" type="Transform2D" /> + <param index="2" name="motion" type="Vector2" /> + <param index="3" name="margin" type="float" /> + <param index="4" name="collision_mask" type="int" /> + <param index="5" name="collide_with_bodies" type="bool" /> + <param index="6" name="collide_with_areas" type="bool" /> + <param index="7" name="results" type="void*" /> + <param index="8" name="max_results" type="int" /> + <param index="9" name="result_count" type="int32_t*" /> + <description> + </description> + </method> + <method name="_intersect_point" qualifiers="virtual"> + <return type="int" /> + <param index="0" name="position" type="Vector2" /> + <param index="1" name="canvas_instance_id" type="int" /> + <param index="2" name="collision_mask" type="int" /> + <param index="3" name="collide_with_bodies" type="bool" /> + <param index="4" name="collide_with_areas" type="bool" /> + <param index="5" name="results" type="PhysicsServer2DExtensionShapeResult*" /> + <param index="6" name="max_results" type="int" /> + <description> + </description> + </method> + <method name="_intersect_ray" qualifiers="virtual"> + <return type="bool" /> + <param index="0" name="from" type="Vector2" /> + <param index="1" name="to" type="Vector2" /> + <param index="2" name="collision_mask" type="int" /> + <param index="3" name="collide_with_bodies" type="bool" /> + <param index="4" name="collide_with_areas" type="bool" /> + <param index="5" name="hit_from_inside" type="bool" /> + <param index="6" name="result" type="PhysicsServer2DExtensionRayResult*" /> + <description> + </description> + </method> + <method name="_intersect_shape" qualifiers="virtual"> + <return type="int" /> + <param index="0" name="shape_rid" type="RID" /> + <param index="1" name="transform" type="Transform2D" /> + <param index="2" name="motion" type="Vector2" /> + <param index="3" name="margin" type="float" /> + <param index="4" name="collision_mask" type="int" /> + <param index="5" name="collide_with_bodies" type="bool" /> + <param index="6" name="collide_with_areas" type="bool" /> + <param index="7" name="result" type="PhysicsServer2DExtensionShapeResult*" /> + <param index="8" name="max_results" type="int" /> + <description> + </description> + </method> + <method name="_rest_info" qualifiers="virtual"> + <return type="bool" /> + <param index="0" name="shape_rid" type="RID" /> + <param index="1" name="transform" type="Transform2D" /> + <param index="2" name="motion" type="Vector2" /> + <param index="3" name="margin" type="float" /> + <param index="4" name="collision_mask" type="int" /> + <param index="5" name="collide_with_bodies" type="bool" /> + <param index="6" name="collide_with_areas" type="bool" /> + <param index="7" name="rest_info" type="PhysicsServer2DExtensionShapeRestInfo*" /> + <description> + </description> + </method> + </methods> +</class> diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml index 5ae7423a71..4b588033c0 100644 --- a/doc/classes/PhysicsServer2D.xml +++ b/doc/classes/PhysicsServer2D.xml @@ -1058,6 +1058,8 @@ </constant> <constant name="JOINT_PARAM_MAX_FORCE" value="2" enum="JointParam"> </constant> + <constant name="PIN_JOINT_SOFTNESS" value="0" enum="PinJointParam"> + </constant> <constant name="DAMPED_SPRING_REST_LENGTH" value="0" enum="DampedSpringParam"> Sets the resting length of the spring joint. The joint will always try to go to back this length when pulled apart. </constant> diff --git a/doc/classes/PhysicsServer2DExtension.xml b/doc/classes/PhysicsServer2DExtension.xml new file mode 100644 index 0000000000..2659d3221f --- /dev/null +++ b/doc/classes/PhysicsServer2DExtension.xml @@ -0,0 +1,777 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="PhysicsServer2DExtension" inherits="PhysicsServer2D" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="_area_add_shape" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="shape" type="RID" /> + <param index="2" name="transform" type="Transform2D" /> + <param index="3" name="disabled" type="bool" /> + <description> + </description> + </method> + <method name="_area_attach_canvas_instance_id" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="id" type="int" /> + <description> + </description> + </method> + <method name="_area_attach_object_instance_id" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="id" type="int" /> + <description> + </description> + </method> + <method name="_area_clear_shapes" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> + <method name="_area_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_area_get_canvas_instance_id" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> + <method name="_area_get_object_instance_id" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> + <method name="_area_get_param" qualifiers="virtual const"> + <return type="Variant" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.AreaParameter" /> + <description> + </description> + </method> + <method name="_area_get_shape" qualifiers="virtual const"> + <return type="RID" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <description> + </description> + </method> + <method name="_area_get_shape_count" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> + <method name="_area_get_shape_transform" qualifiers="virtual const"> + <return type="Transform2D" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <description> + </description> + </method> + <method name="_area_get_space" qualifiers="virtual const"> + <return type="RID" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> + <method name="_area_get_transform" qualifiers="virtual const"> + <return type="Transform2D" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> + <method name="_area_remove_shape" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <description> + </description> + </method> + <method name="_area_set_area_monitor_callback" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="callback" type="Callable" /> + <description> + </description> + </method> + <method name="_area_set_collision_layer" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="layer" type="int" /> + <description> + </description> + </method> + <method name="_area_set_collision_mask" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="mask" type="int" /> + <description> + </description> + </method> + <method name="_area_set_monitor_callback" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="callback" type="Callable" /> + <description> + </description> + </method> + <method name="_area_set_monitorable" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="monitorable" type="bool" /> + <description> + </description> + </method> + <method name="_area_set_param" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.AreaParameter" /> + <param index="2" name="value" type="Variant" /> + <description> + </description> + </method> + <method name="_area_set_shape" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <param index="2" name="shape" type="RID" /> + <description> + </description> + </method> + <method name="_area_set_shape_disabled" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <param index="2" name="disabled" type="bool" /> + <description> + </description> + </method> + <method name="_area_set_shape_transform" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <param index="2" name="transform" type="Transform2D" /> + <description> + </description> + </method> + <method name="_area_set_space" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="space" type="RID" /> + <description> + </description> + </method> + <method name="_area_set_transform" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="area" type="RID" /> + <param index="1" name="transform" type="Transform2D" /> + <description> + </description> + </method> + <method name="_body_add_collision_exception" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="excepted_body" type="RID" /> + <description> + </description> + </method> + <method name="_body_add_constant_central_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="force" type="Vector2" /> + <description> + </description> + </method> + <method name="_body_add_constant_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="force" type="Vector2" /> + <param index="2" name="position" type="Vector2" /> + <description> + </description> + </method> + <method name="_body_add_constant_torque" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="torque" type="float" /> + <description> + </description> + </method> + <method name="_body_add_shape" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="shape" type="RID" /> + <param index="2" name="transform" type="Transform2D" /> + <param index="3" name="disabled" type="bool" /> + <description> + </description> + </method> + <method name="_body_apply_central_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="force" type="Vector2" /> + <description> + </description> + </method> + <method name="_body_apply_central_impulse" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="impulse" type="Vector2" /> + <description> + </description> + </method> + <method name="_body_apply_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="force" type="Vector2" /> + <param index="2" name="position" type="Vector2" /> + <description> + </description> + </method> + <method name="_body_apply_impulse" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="impulse" type="Vector2" /> + <param index="2" name="position" type="Vector2" /> + <description> + </description> + </method> + <method name="_body_apply_torque" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="torque" type="float" /> + <description> + </description> + </method> + <method name="_body_apply_torque_impulse" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="impulse" type="float" /> + <description> + </description> + </method> + <method name="_body_attach_canvas_instance_id" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="id" type="int" /> + <description> + </description> + </method> + <method name="_body_attach_object_instance_id" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="id" type="int" /> + <description> + </description> + </method> + <method name="_body_clear_shapes" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_body_get_canvas_instance_id" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_collision_layer" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_collision_mask" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_collision_priority" qualifiers="virtual const"> + <return type="float" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_constant_force" qualifiers="virtual const"> + <return type="Vector2" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_constant_torque" qualifiers="virtual const"> + <return type="float" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_continuous_collision_detection_mode" qualifiers="virtual const"> + <return type="int" enum="PhysicsServer2D.CCDMode" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_direct_state" qualifiers="virtual"> + <return type="PhysicsDirectBodyState2D" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_max_contacts_reported" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_mode" qualifiers="virtual const"> + <return type="int" enum="PhysicsServer2D.BodyMode" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_object_instance_id" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_param" qualifiers="virtual const"> + <return type="Variant" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.BodyParameter" /> + <description> + </description> + </method> + <method name="_body_get_shape" qualifiers="virtual const"> + <return type="RID" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <description> + </description> + </method> + <method name="_body_get_shape_count" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_shape_transform" qualifiers="virtual const"> + <return type="Transform2D" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <description> + </description> + </method> + <method name="_body_get_space" qualifiers="virtual const"> + <return type="RID" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_get_state" qualifiers="virtual const"> + <return type="Variant" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="state" type="int" enum="PhysicsServer2D.BodyState" /> + <description> + </description> + </method> + <method name="_body_is_omitting_force_integration" qualifiers="virtual const"> + <return type="bool" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_remove_collision_exception" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="excepted_body" type="RID" /> + <description> + </description> + </method> + <method name="_body_remove_shape" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <description> + </description> + </method> + <method name="_body_reset_mass_properties" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <description> + </description> + </method> + <method name="_body_set_axis_velocity" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="axis_velocity" type="Vector2" /> + <description> + </description> + </method> + <method name="_body_set_collision_layer" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="layer" type="int" /> + <description> + </description> + </method> + <method name="_body_set_collision_mask" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="mask" type="int" /> + <description> + </description> + </method> + <method name="_body_set_collision_priority" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="priority" type="float" /> + <description> + </description> + </method> + <method name="_body_set_constant_force" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="force" type="Vector2" /> + <description> + </description> + </method> + <method name="_body_set_constant_torque" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="torque" type="float" /> + <description> + </description> + </method> + <method name="_body_set_continuous_collision_detection_mode" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="mode" type="int" enum="PhysicsServer2D.CCDMode" /> + <description> + </description> + </method> + <method name="_body_set_force_integration_callback" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="callable" type="Callable" /> + <param index="2" name="userdata" type="Variant" /> + <description> + </description> + </method> + <method name="_body_set_max_contacts_reported" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="amount" type="int" /> + <description> + </description> + </method> + <method name="_body_set_mode" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="mode" type="int" enum="PhysicsServer2D.BodyMode" /> + <description> + </description> + </method> + <method name="_body_set_omit_force_integration" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="enable" type="bool" /> + <description> + </description> + </method> + <method name="_body_set_param" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.BodyParameter" /> + <param index="2" name="value" type="Variant" /> + <description> + </description> + </method> + <method name="_body_set_shape" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <param index="2" name="shape" type="RID" /> + <description> + </description> + </method> + <method name="_body_set_shape_as_one_way_collision" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <param index="2" name="enable" type="bool" /> + <param index="3" name="margin" type="float" /> + <description> + </description> + </method> + <method name="_body_set_shape_disabled" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <param index="2" name="disabled" type="bool" /> + <description> + </description> + </method> + <method name="_body_set_shape_transform" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="shape_idx" type="int" /> + <param index="2" name="transform" type="Transform2D" /> + <description> + </description> + </method> + <method name="_body_set_space" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="space" type="RID" /> + <description> + </description> + </method> + <method name="_body_set_state" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="state" type="int" enum="PhysicsServer2D.BodyState" /> + <param index="2" name="value" type="Variant" /> + <description> + </description> + </method> + <method name="_body_test_motion" qualifiers="virtual const"> + <return type="bool" /> + <param index="0" name="body" type="RID" /> + <param index="1" name="from" type="Transform2D" /> + <param index="2" name="motion" type="Vector2" /> + <param index="3" name="margin" type="float" /> + <param index="4" name="collide_separation_ray" type="bool" /> + <param index="5" name="recovery_as_collision" type="bool" /> + <param index="6" name="result" type="PhysicsServer2DExtensionMotionResult*" /> + <description> + </description> + </method> + <method name="_capsule_shape_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_circle_shape_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_concave_polygon_shape_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_convex_polygon_shape_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_damped_spring_joint_get_param" qualifiers="virtual const"> + <return type="float" /> + <param index="0" name="joint" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.DampedSpringParam" /> + <description> + </description> + </method> + <method name="_damped_spring_joint_set_param" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="joint" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.DampedSpringParam" /> + <param index="2" name="value" type="float" /> + <description> + </description> + </method> + <method name="_free_rid" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="rid" type="RID" /> + <description> + </description> + </method> + <method name="_get_process_info" qualifiers="virtual"> + <return type="int" /> + <param index="0" name="process_info" type="int" enum="PhysicsServer2D.ProcessInfo" /> + <description> + </description> + </method> + <method name="_joint_clear" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="joint" type="RID" /> + <description> + </description> + </method> + <method name="_joint_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_joint_get_param" qualifiers="virtual const"> + <return type="float" /> + <param index="0" name="joint" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.JointParam" /> + <description> + </description> + </method> + <method name="_joint_get_type" qualifiers="virtual const"> + <return type="int" enum="PhysicsServer2D.JointType" /> + <param index="0" name="joint" type="RID" /> + <description> + </description> + </method> + <method name="_joint_make_damped_spring" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="joint" type="RID" /> + <param index="1" name="anchor_a" type="Vector2" /> + <param index="2" name="anchor_b" type="Vector2" /> + <param index="3" name="body_a" type="RID" /> + <param index="4" name="body_b" type="RID" /> + <description> + </description> + </method> + <method name="_joint_make_groove" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="joint" type="RID" /> + <param index="1" name="a_groove1" type="Vector2" /> + <param index="2" name="a_groove2" type="Vector2" /> + <param index="3" name="b_anchor" type="Vector2" /> + <param index="4" name="body_a" type="RID" /> + <param index="5" name="body_b" type="RID" /> + <description> + </description> + </method> + <method name="_joint_make_pin" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="joint" type="RID" /> + <param index="1" name="anchor" type="Vector2" /> + <param index="2" name="body_a" type="RID" /> + <param index="3" name="body_b" type="RID" /> + <description> + </description> + </method> + <method name="_joint_set_param" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="joint" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.JointParam" /> + <param index="2" name="value" type="float" /> + <description> + </description> + </method> + <method name="_pin_joint_get_param" qualifiers="virtual const"> + <return type="float" /> + <param index="0" name="joint" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.PinJointParam" /> + <description> + </description> + </method> + <method name="_pin_joint_set_param" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="joint" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.PinJointParam" /> + <param index="2" name="value" type="float" /> + <description> + </description> + </method> + <method name="_rectangle_shape_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_segment_shape_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_separation_ray_shape_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_set_active" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="active" type="bool" /> + <description> + </description> + </method> + <method name="_shape_get_data" qualifiers="virtual const"> + <return type="Variant" /> + <param index="0" name="shape" type="RID" /> + <description> + </description> + </method> + <method name="_shape_get_type" qualifiers="virtual const"> + <return type="int" enum="PhysicsServer2D.ShapeType" /> + <param index="0" name="shape" type="RID" /> + <description> + </description> + </method> + <method name="_shape_set_data" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="shape" type="RID" /> + <param index="1" name="data" type="Variant" /> + <description> + </description> + </method> + <method name="_space_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + <method name="_space_get_direct_state" qualifiers="virtual"> + <return type="PhysicsDirectSpaceState2D" /> + <param index="0" name="space" type="RID" /> + <description> + </description> + </method> + <method name="_space_get_param" qualifiers="virtual const"> + <return type="float" /> + <param index="0" name="space" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.SpaceParameter" /> + <description> + </description> + </method> + <method name="_space_is_active" qualifiers="virtual const"> + <return type="bool" /> + <param index="0" name="space" type="RID" /> + <description> + </description> + </method> + <method name="_space_set_active" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="space" type="RID" /> + <param index="1" name="active" type="bool" /> + <description> + </description> + </method> + <method name="_space_set_param" qualifiers="virtual"> + <return type="void" /> + <param index="0" name="space" type="RID" /> + <param index="1" name="param" type="int" enum="PhysicsServer2D.SpaceParameter" /> + <param index="2" name="value" type="float" /> + <description> + </description> + </method> + <method name="_world_boundary_shape_create" qualifiers="virtual"> + <return type="RID" /> + <description> + </description> + </method> + </methods> +</class> diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 15a40c8ca5..c27bb959fe 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -113,7 +113,7 @@ StringBuilder &operator<<(StringBuilder &r_sb, const char *p_cstring) { #define C_METHOD_MANAGED_FROM_SIGNAL C_NS_MONOMARSHAL ".ConvertSignalToManaged" // Types that will be ignored by the generator and won't be available in C#. -const Vector<String> ignored_types = { "PhysicsServer3DExtension" }; +const Vector<String> ignored_types = { "PhysicsServer2DExtension", "PhysicsServer3DExtension" }; void BindingsGenerator::TypeInterface::postsetup_enum_type(BindingsGenerator::TypeInterface &r_enum_itype) { // C interface for enums is the same as that of 'uint32_t'. Remember to apply diff --git a/servers/extensions/physics_server_2d_extension.cpp b/servers/extensions/physics_server_2d_extension.cpp new file mode 100644 index 0000000000..2ef4cd3352 --- /dev/null +++ b/servers/extensions/physics_server_2d_extension.cpp @@ -0,0 +1,294 @@ +/*************************************************************************/ +/* physics_server_2d_extension.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "physics_server_2d_extension.h" + +bool PhysicsDirectSpaceState2DExtension::is_body_excluded_from_query(const RID &p_body) const { + return exclude && exclude->has(p_body); +} + +thread_local const HashSet<RID> *PhysicsDirectSpaceState2DExtension::exclude = nullptr; + +void PhysicsDirectSpaceState2DExtension::_bind_methods() { + GDVIRTUAL_BIND(_intersect_ray, "from", "to", "collision_mask", "collide_with_bodies", "collide_with_areas", "hit_from_inside", "result"); + GDVIRTUAL_BIND(_intersect_point, "position", "canvas_instance_id", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results"); + GDVIRTUAL_BIND(_intersect_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "result", "max_results"); + GDVIRTUAL_BIND(_cast_motion, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "closest_safe", "closest_unsafe"); + GDVIRTUAL_BIND(_collide_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results", "result_count"); + GDVIRTUAL_BIND(_rest_info, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "rest_info"); +} + +PhysicsDirectSpaceState2DExtension::PhysicsDirectSpaceState2DExtension() { +} + +void PhysicsDirectBodyState2DExtension::_bind_methods() { + GDVIRTUAL_BIND(_get_total_gravity); + GDVIRTUAL_BIND(_get_total_linear_damp); + GDVIRTUAL_BIND(_get_total_angular_damp); + + GDVIRTUAL_BIND(_get_center_of_mass); + GDVIRTUAL_BIND(_get_center_of_mass_local); + GDVIRTUAL_BIND(_get_inverse_mass); + GDVIRTUAL_BIND(_get_inverse_inertia); + + GDVIRTUAL_BIND(_set_linear_velocity, "velocity"); + GDVIRTUAL_BIND(_get_linear_velocity); + + GDVIRTUAL_BIND(_set_angular_velocity, "velocity"); + GDVIRTUAL_BIND(_get_angular_velocity); + + GDVIRTUAL_BIND(_set_transform, "transform"); + GDVIRTUAL_BIND(_get_transform); + + GDVIRTUAL_BIND(_get_velocity_at_local_position, "local_position"); + + GDVIRTUAL_BIND(_apply_central_impulse, "impulse"); + GDVIRTUAL_BIND(_apply_impulse, "impulse", "position"); + GDVIRTUAL_BIND(_apply_torque_impulse, "impulse"); + + GDVIRTUAL_BIND(_apply_central_force, "force"); + GDVIRTUAL_BIND(_apply_force, "force", "position"); + GDVIRTUAL_BIND(_apply_torque, "torque"); + + GDVIRTUAL_BIND(_add_constant_central_force, "force"); + GDVIRTUAL_BIND(_add_constant_force, "force", "position"); + GDVIRTUAL_BIND(_add_constant_torque, "torque"); + + GDVIRTUAL_BIND(_set_constant_force, "force"); + GDVIRTUAL_BIND(_get_constant_force); + + GDVIRTUAL_BIND(_set_constant_torque, "torque"); + GDVIRTUAL_BIND(_get_constant_torque); + + GDVIRTUAL_BIND(_set_sleep_state, "enabled"); + GDVIRTUAL_BIND(_is_sleeping); + + GDVIRTUAL_BIND(_get_contact_count); + + GDVIRTUAL_BIND(_get_contact_local_position, "contact_idx"); + GDVIRTUAL_BIND(_get_contact_local_normal, "contact_idx"); + GDVIRTUAL_BIND(_get_contact_local_shape, "contact_idx"); + GDVIRTUAL_BIND(_get_contact_collider, "contact_idx"); + GDVIRTUAL_BIND(_get_contact_collider_position, "contact_idx"); + GDVIRTUAL_BIND(_get_contact_collider_id, "contact_idx"); + GDVIRTUAL_BIND(_get_contact_collider_object, "contact_idx"); + GDVIRTUAL_BIND(_get_contact_collider_shape, "contact_idx"); + GDVIRTUAL_BIND(_get_contact_collider_velocity_at_position, "contact_idx"); + + GDVIRTUAL_BIND(_get_step); + GDVIRTUAL_BIND(_integrate_forces); + + GDVIRTUAL_BIND(_get_space_state); +} + +PhysicsDirectBodyState2DExtension::PhysicsDirectBodyState2DExtension() { +} + +thread_local const HashSet<RID> *PhysicsServer2DExtension::exclude_bodies = nullptr; +thread_local const HashSet<ObjectID> *PhysicsServer2DExtension::exclude_objects = nullptr; + +bool PhysicsServer2DExtension::body_test_motion_is_excluding_body(RID p_body) const { + return exclude_bodies && exclude_bodies->has(p_body); +} + +bool PhysicsServer2DExtension::body_test_motion_is_excluding_object(ObjectID p_object) const { + return exclude_objects && exclude_objects->has(p_object); +} + +void PhysicsServer2DExtension::_bind_methods() { + GDVIRTUAL_BIND(_world_boundary_shape_create); + GDVIRTUAL_BIND(_separation_ray_shape_create); + GDVIRTUAL_BIND(_segment_shape_create); + GDVIRTUAL_BIND(_circle_shape_create); + GDVIRTUAL_BIND(_rectangle_shape_create); + GDVIRTUAL_BIND(_capsule_shape_create); + GDVIRTUAL_BIND(_convex_polygon_shape_create); + GDVIRTUAL_BIND(_concave_polygon_shape_create); + + GDVIRTUAL_BIND(_shape_set_data, "shape", "data"); + + GDVIRTUAL_BIND(_shape_get_type, "shape"); + GDVIRTUAL_BIND(_shape_get_data, "shape"); + + GDVIRTUAL_BIND(_space_create); + GDVIRTUAL_BIND(_space_set_active, "space", "active"); + GDVIRTUAL_BIND(_space_is_active, "space"); + GDVIRTUAL_BIND(_space_set_param, "space", "param", "value"); + GDVIRTUAL_BIND(_space_get_param, "space", "param"); + GDVIRTUAL_BIND(_space_get_direct_state, "space"); + + GDVIRTUAL_BIND(_area_create); + GDVIRTUAL_BIND(_area_set_space, "area", "space"); + GDVIRTUAL_BIND(_area_get_space, "area"); + + GDVIRTUAL_BIND(_area_add_shape, "area", "shape", "transform", "disabled"); + GDVIRTUAL_BIND(_area_set_shape, "area", "shape_idx", "shape"); + GDVIRTUAL_BIND(_area_set_shape_transform, "area", "shape_idx", "transform"); + GDVIRTUAL_BIND(_area_set_shape_disabled, "area", "shape_idx", "disabled"); + + GDVIRTUAL_BIND(_area_get_shape_count, "area"); + GDVIRTUAL_BIND(_area_get_shape, "area", "shape_idx"); + GDVIRTUAL_BIND(_area_get_shape_transform, "area", "shape_idx"); + + GDVIRTUAL_BIND(_area_remove_shape, "area", "shape_idx"); + GDVIRTUAL_BIND(_area_clear_shapes, "area"); + + GDVIRTUAL_BIND(_area_set_collision_layer, "area", "layer"); + GDVIRTUAL_BIND(_area_set_collision_mask, "area", "mask"); + + GDVIRTUAL_BIND(_area_set_param, "area", "param", "value"); + GDVIRTUAL_BIND(_area_set_transform, "area", "transform"); + + GDVIRTUAL_BIND(_area_get_param, "area", "param"); + GDVIRTUAL_BIND(_area_get_transform, "area"); + + GDVIRTUAL_BIND(_area_attach_object_instance_id, "area", "id"); + GDVIRTUAL_BIND(_area_get_object_instance_id, "area"); + + GDVIRTUAL_BIND(_area_attach_canvas_instance_id, "area", "id"); + GDVIRTUAL_BIND(_area_get_canvas_instance_id, "area"); + + GDVIRTUAL_BIND(_area_set_monitor_callback, "area", "callback"); + GDVIRTUAL_BIND(_area_set_area_monitor_callback, "area", "callback"); + GDVIRTUAL_BIND(_area_set_monitorable, "area", "monitorable"); + + GDVIRTUAL_BIND(_body_create); + + GDVIRTUAL_BIND(_body_set_space, "body", "space"); + GDVIRTUAL_BIND(_body_get_space, "body"); + + GDVIRTUAL_BIND(_body_set_mode, "body", "mode"); + GDVIRTUAL_BIND(_body_get_mode, "body"); + + GDVIRTUAL_BIND(_body_add_shape, "body", "shape", "transform", "disabled"); + GDVIRTUAL_BIND(_body_set_shape, "body", "shape_idx", "shape"); + GDVIRTUAL_BIND(_body_set_shape_transform, "body", "shape_idx", "transform"); + + GDVIRTUAL_BIND(_body_get_shape_count, "body"); + GDVIRTUAL_BIND(_body_get_shape, "body", "shape_idx"); + GDVIRTUAL_BIND(_body_get_shape_transform, "body", "shape_idx"); + + GDVIRTUAL_BIND(_body_remove_shape, "body", "shape_idx"); + GDVIRTUAL_BIND(_body_clear_shapes, "body"); + + GDVIRTUAL_BIND(_body_set_shape_disabled, "body", "shape_idx", "disabled"); + GDVIRTUAL_BIND(_body_set_shape_as_one_way_collision, "body", "shape_idx", "enable", "margin"); + + GDVIRTUAL_BIND(_body_attach_object_instance_id, "body", "id"); + GDVIRTUAL_BIND(_body_get_object_instance_id, "body"); + + GDVIRTUAL_BIND(_body_attach_canvas_instance_id, "body", "id"); + GDVIRTUAL_BIND(_body_get_canvas_instance_id, "body"); + + GDVIRTUAL_BIND(_body_set_continuous_collision_detection_mode, "body", "mode"); + GDVIRTUAL_BIND(_body_get_continuous_collision_detection_mode, "body"); + + GDVIRTUAL_BIND(_body_set_collision_layer, "body", "layer"); + GDVIRTUAL_BIND(_body_get_collision_layer, "body"); + + GDVIRTUAL_BIND(_body_set_collision_mask, "body", "mask"); + GDVIRTUAL_BIND(_body_get_collision_mask, "body"); + + GDVIRTUAL_BIND(_body_set_collision_priority, "body", "priority"); + GDVIRTUAL_BIND(_body_get_collision_priority, "body"); + + GDVIRTUAL_BIND(_body_set_param, "body", "param", "value"); + GDVIRTUAL_BIND(_body_get_param, "body", "param"); + + GDVIRTUAL_BIND(_body_reset_mass_properties, "body"); + + GDVIRTUAL_BIND(_body_set_state, "body", "state", "value"); + GDVIRTUAL_BIND(_body_get_state, "body", "state"); + + GDVIRTUAL_BIND(_body_apply_central_impulse, "body", "impulse"); + GDVIRTUAL_BIND(_body_apply_torque_impulse, "body", "impulse"); + GDVIRTUAL_BIND(_body_apply_impulse, "body", "impulse", "position"); + + GDVIRTUAL_BIND(_body_apply_central_force, "body", "force"); + GDVIRTUAL_BIND(_body_apply_force, "body", "force", "position"); + GDVIRTUAL_BIND(_body_apply_torque, "body", "torque"); + + GDVIRTUAL_BIND(_body_add_constant_central_force, "body", "force"); + GDVIRTUAL_BIND(_body_add_constant_force, "body", "force", "position"); + GDVIRTUAL_BIND(_body_add_constant_torque, "body", "torque"); + + GDVIRTUAL_BIND(_body_set_constant_force, "body", "force"); + GDVIRTUAL_BIND(_body_get_constant_force, "body"); + + GDVIRTUAL_BIND(_body_set_constant_torque, "body", "torque"); + GDVIRTUAL_BIND(_body_get_constant_torque, "body"); + + GDVIRTUAL_BIND(_body_set_axis_velocity, "body", "axis_velocity"); + + GDVIRTUAL_BIND(_body_add_collision_exception, "body", "excepted_body"); + GDVIRTUAL_BIND(_body_remove_collision_exception, "body", "excepted_body"); + + GDVIRTUAL_BIND(_body_set_max_contacts_reported, "body", "amount"); + GDVIRTUAL_BIND(_body_get_max_contacts_reported, "body"); + + GDVIRTUAL_BIND(_body_set_omit_force_integration, "body", "enable"); + GDVIRTUAL_BIND(_body_is_omitting_force_integration, "body"); + + GDVIRTUAL_BIND(_body_set_force_integration_callback, "body", "callable", "userdata"); + + GDVIRTUAL_BIND(_body_test_motion, "body", "from", "motion", "margin", "collide_separation_ray", "recovery_as_collision", "result"); + + GDVIRTUAL_BIND(_body_get_direct_state, "body"); + + GDVIRTUAL_BIND(_joint_create); + GDVIRTUAL_BIND(_joint_clear, "joint"); + + GDVIRTUAL_BIND(_joint_set_param, "joint", "param", "value"); + GDVIRTUAL_BIND(_joint_get_param, "joint", "param"); + + GDVIRTUAL_BIND(_joint_make_pin, "joint", "anchor", "body_a", "body_b"); + GDVIRTUAL_BIND(_joint_make_groove, "joint", "a_groove1", "a_groove2", "b_anchor", "body_a", "body_b"); + GDVIRTUAL_BIND(_joint_make_damped_spring, "joint", "anchor_a", "anchor_b", "body_a", "body_b"); + + GDVIRTUAL_BIND(_pin_joint_set_param, "joint", "param", "value"); + GDVIRTUAL_BIND(_pin_joint_get_param, "joint", "param"); + + GDVIRTUAL_BIND(_damped_spring_joint_set_param, "joint", "param", "value"); + GDVIRTUAL_BIND(_damped_spring_joint_get_param, "joint", "param"); + + GDVIRTUAL_BIND(_joint_get_type, "joint"); + + GDVIRTUAL_BIND(_free_rid, "rid"); + + GDVIRTUAL_BIND(_set_active, "active"); + + GDVIRTUAL_BIND(_get_process_info, "process_info"); +} + +PhysicsServer2DExtension::PhysicsServer2DExtension() { +} + +PhysicsServer2DExtension::~PhysicsServer2DExtension() { +} diff --git a/servers/extensions/physics_server_2d_extension.h b/servers/extensions/physics_server_2d_extension.h new file mode 100644 index 0000000000..4c83664b14 --- /dev/null +++ b/servers/extensions/physics_server_2d_extension.h @@ -0,0 +1,462 @@ +/*************************************************************************/ +/* physics_server_2d_extension.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef PHYSICS_SERVER_2D_EXTENSION_H +#define PHYSICS_SERVER_2D_EXTENSION_H + +#include "core/extension/ext_wrappers.gen.inc" +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" +#include "core/variant/native_ptr.h" +#include "core/variant/type_info.h" +#include "core/variant/typed_array.h" +#include "servers/physics_server_2d.h" + +class PhysicsDirectBodyState2DExtension : public PhysicsDirectBodyState2D { + GDCLASS(PhysicsDirectBodyState2DExtension, PhysicsDirectBodyState2D); + +protected: + static void _bind_methods(); + +public: + // The warning is valid, but unavoidable. If the function is not overridden it will error anyway. + + EXBIND0RC(Vector2, get_total_gravity) + EXBIND0RC(real_t, get_total_angular_damp) + EXBIND0RC(real_t, get_total_linear_damp) + + EXBIND0RC(Vector2, get_center_of_mass) + EXBIND0RC(Vector2, get_center_of_mass_local) + EXBIND0RC(real_t, get_inverse_mass) + EXBIND0RC(real_t, get_inverse_inertia) + + EXBIND1(set_linear_velocity, const Vector2 &) + EXBIND0RC(Vector2, get_linear_velocity) + + EXBIND1(set_angular_velocity, real_t) + EXBIND0RC(real_t, get_angular_velocity) + + EXBIND1(set_transform, const Transform2D &) + EXBIND0RC(Transform2D, get_transform) + + EXBIND1RC(Vector2, get_velocity_at_local_position, const Vector2 &) + + EXBIND1(apply_central_impulse, const Vector2 &) + EXBIND1(apply_torque_impulse, real_t) + EXBIND2(apply_impulse, const Vector2 &, const Vector2 &) + + EXBIND1(apply_central_force, const Vector2 &) + EXBIND2(apply_force, const Vector2 &, const Vector2 &) + EXBIND1(apply_torque, real_t) + + EXBIND1(add_constant_central_force, const Vector2 &) + EXBIND2(add_constant_force, const Vector2 &, const Vector2 &) + EXBIND1(add_constant_torque, real_t) + + EXBIND1(set_constant_force, const Vector2 &) + EXBIND0RC(Vector2, get_constant_force) + + EXBIND1(set_constant_torque, real_t) + EXBIND0RC(real_t, get_constant_torque) + + EXBIND1(set_sleep_state, bool) + EXBIND0RC(bool, is_sleeping) + + EXBIND0RC(int, get_contact_count) + + EXBIND1RC(Vector2, get_contact_local_position, int) + EXBIND1RC(Vector2, get_contact_local_normal, int) + EXBIND1RC(int, get_contact_local_shape, int) + + EXBIND1RC(RID, get_contact_collider, int) + EXBIND1RC(Vector2, get_contact_collider_position, int) + EXBIND1RC(ObjectID, get_contact_collider_id, int) + EXBIND1RC(Object *, get_contact_collider_object, int) + EXBIND1RC(int, get_contact_collider_shape, int) + EXBIND1RC(Vector2, get_contact_collider_velocity_at_position, int) + + EXBIND0RC(real_t, get_step) + EXBIND0(integrate_forces) + + EXBIND0R(PhysicsDirectSpaceState2D *, get_space_state) + + PhysicsDirectBodyState2DExtension(); +}; + +typedef PhysicsDirectSpaceState2D::RayResult PhysicsServer2DExtensionRayResult; +typedef PhysicsDirectSpaceState2D::ShapeResult PhysicsServer2DExtensionShapeResult; +typedef PhysicsDirectSpaceState2D::ShapeRestInfo PhysicsServer2DExtensionShapeRestInfo; + +GDVIRTUAL_NATIVE_PTR(PhysicsServer2DExtensionRayResult) +GDVIRTUAL_NATIVE_PTR(PhysicsServer2DExtensionShapeResult) +GDVIRTUAL_NATIVE_PTR(PhysicsServer2DExtensionShapeRestInfo) + +class PhysicsDirectSpaceState2DExtension : public PhysicsDirectSpaceState2D { + GDCLASS(PhysicsDirectSpaceState2DExtension, PhysicsDirectSpaceState2D); + + thread_local static const HashSet<RID> *exclude; + +protected: + static void _bind_methods(); + bool is_body_excluded_from_query(const RID &p_body) const; + + GDVIRTUAL7R(bool, _intersect_ray, const Vector2 &, const Vector2 &, uint32_t, bool, bool, bool, GDNativePtr<PhysicsServer2DExtensionRayResult>) + GDVIRTUAL7R(int, _intersect_point, const Vector2 &, ObjectID, uint32_t, bool, bool, GDNativePtr<PhysicsServer2DExtensionShapeResult>, int) + GDVIRTUAL9R(int, _intersect_shape, RID, const Transform2D &, const Vector2 &, real_t, uint32_t, bool, bool, GDNativePtr<PhysicsServer2DExtensionShapeResult>, int) + GDVIRTUAL9R(bool, _cast_motion, RID, const Transform2D &, const Vector2 &, real_t, uint32_t, bool, bool, GDNativePtr<real_t>, GDNativePtr<real_t>) + GDVIRTUAL10R(bool, _collide_shape, RID, const Transform2D &, const Vector2 &, real_t, uint32_t, bool, bool, GDNativePtr<Vector2>, int, GDNativePtr<int>) + GDVIRTUAL8R(bool, _rest_info, RID, const Transform2D &, const Vector2 &, real_t, uint32_t, bool, bool, GDNativePtr<PhysicsServer2DExtensionShapeRestInfo>) + +public: + virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) override { + exclude = &p_parameters.exclude; + bool ret = false; + GDVIRTUAL_REQUIRED_CALL(_intersect_ray, p_parameters.from, p_parameters.to, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, p_parameters.hit_from_inside, &r_result, ret); + exclude = nullptr; + return ret; + } + virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { + exclude = &p_parameters.exclude; + int ret = false; + GDVIRTUAL_REQUIRED_CALL(_intersect_point, p_parameters.position, p_parameters.canvas_instance_id, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, r_results, p_result_max, ret); + exclude = nullptr; + return ret; + } + virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { + exclude = &p_parameters.exclude; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_intersect_shape, p_parameters.shape_rid, p_parameters.transform, p_parameters.motion, p_parameters.margin, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, r_results, p_result_max, ret); + exclude = nullptr; + return ret; + } + virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe) override { + exclude = &p_parameters.exclude; + bool ret = false; + GDVIRTUAL_REQUIRED_CALL(_cast_motion, p_parameters.shape_rid, p_parameters.transform, p_parameters.motion, p_parameters.margin, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, &p_closest_safe, &p_closest_unsafe, ret); + exclude = nullptr; + return ret; + } + virtual bool collide_shape(const ShapeParameters &p_parameters, Vector2 *r_results, int p_result_max, int &r_result_count) override { + exclude = &p_parameters.exclude; + bool ret = false; + GDVIRTUAL_REQUIRED_CALL(_collide_shape, p_parameters.shape_rid, p_parameters.transform, p_parameters.motion, p_parameters.margin, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, r_results, p_result_max, &r_result_count, ret); + exclude = nullptr; + return ret; + } + virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) override { + exclude = &p_parameters.exclude; + bool ret = false; + GDVIRTUAL_REQUIRED_CALL(_rest_info, p_parameters.shape_rid, p_parameters.transform, p_parameters.motion, p_parameters.margin, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, r_info, ret); + exclude = nullptr; + return ret; + } + + PhysicsDirectSpaceState2DExtension(); +}; + +typedef PhysicsServer2D::MotionResult PhysicsServer2DExtensionMotionResult; + +struct PhysicsServer2DExtensionStateCallback { + void *instance = nullptr; + void (*callback)(void *p_instance, PhysicsDirectBodyState2D *p_state); +}; + +GDVIRTUAL_NATIVE_PTR(PhysicsServer2DExtensionMotionResult) +GDVIRTUAL_NATIVE_PTR(PhysicsServer2DExtensionStateCallback) + +class PhysicsServer2DExtension : public PhysicsServer2D { + GDCLASS(PhysicsServer2DExtension, PhysicsServer2D); + +protected: + static void _bind_methods(); + + GDVIRTUAL9R(bool, _shape_collide, RID, const Transform2D &, const Vector2 &, RID, const Transform2D &, const Vector2 &, GDNativePtr<Vector2>, int, GDNativePtr<int>) + + GDVIRTUAL8R(bool, _body_collide_shape, RID, int, RID, const Transform2D &, const Vector2 &, GDNativePtr<Vector2>, int, GDNativePtr<int>) + +public: + // The warning is valid, but unavoidable. If the function is not overridden it will error anyway. + + EXBIND0R(RID, world_boundary_shape_create) + EXBIND0R(RID, separation_ray_shape_create) + EXBIND0R(RID, segment_shape_create) + EXBIND0R(RID, circle_shape_create) + EXBIND0R(RID, rectangle_shape_create) + EXBIND0R(RID, capsule_shape_create) + EXBIND0R(RID, convex_polygon_shape_create) + EXBIND0R(RID, concave_polygon_shape_create) + + EXBIND2(shape_set_data, RID, const Variant &) + EXBIND2(shape_set_custom_solver_bias, RID, real_t) + + EXBIND1RC(ShapeType, shape_get_type, RID) + EXBIND1RC(Variant, shape_get_data, RID) + EXBIND1RC(real_t, shape_get_custom_solver_bias, RID) + + virtual bool shape_collide(RID p_shape_A, const Transform2D &p_xform_A, const Vector2 &p_motion_A, RID p_shape_B, const Transform2D &p_xform_B, const Vector2 &p_motion_B, Vector2 *r_results, int p_result_max, int &r_result_count) override { + bool ret = false; + GDVIRTUAL_REQUIRED_CALL(_shape_collide, p_shape_A, p_xform_A, p_motion_A, p_shape_B, p_xform_B, p_motion_B, r_results, p_result_max, &r_result_count, ret); + return ret; + } + + /* SPACE API */ + + EXBIND0R(RID, space_create) + EXBIND2(space_set_active, RID, bool) + EXBIND1RC(bool, space_is_active, RID) + + EXBIND3(space_set_param, RID, SpaceParameter, real_t) + EXBIND2RC(real_t, space_get_param, RID, SpaceParameter) + + EXBIND1R(PhysicsDirectSpaceState2D *, space_get_direct_state, RID) + + EXBIND2(space_set_debug_contacts, RID, int) + EXBIND1RC(Vector<Vector2>, space_get_contacts, RID) + EXBIND1RC(int, space_get_contact_count, RID) + + /* AREA API */ + + //EXBIND0RID(area); + EXBIND0R(RID, area_create) + + EXBIND2(area_set_space, RID, RID) + EXBIND1RC(RID, area_get_space, RID) + + EXBIND4(area_add_shape, RID, RID, const Transform2D &, bool) + EXBIND3(area_set_shape, RID, int, RID) + EXBIND3(area_set_shape_transform, RID, int, const Transform2D &) + + EXBIND1RC(int, area_get_shape_count, RID) + EXBIND2RC(RID, area_get_shape, RID, int) + EXBIND2RC(Transform2D, area_get_shape_transform, RID, int) + + EXBIND2(area_remove_shape, RID, int) + EXBIND1(area_clear_shapes, RID) + + EXBIND3(area_set_shape_disabled, RID, int, bool) + + EXBIND2(area_attach_object_instance_id, RID, ObjectID) + EXBIND1RC(ObjectID, area_get_object_instance_id, RID) + + EXBIND2(area_attach_canvas_instance_id, RID, ObjectID) + EXBIND1RC(ObjectID, area_get_canvas_instance_id, RID) + + EXBIND3(area_set_param, RID, AreaParameter, const Variant &) + EXBIND2(area_set_transform, RID, const Transform2D &) + + EXBIND2RC(Variant, area_get_param, RID, AreaParameter) + EXBIND1RC(Transform2D, area_get_transform, RID) + + EXBIND2(area_set_collision_mask, RID, uint32_t) + EXBIND2(area_set_collision_layer, RID, uint32_t) + + EXBIND2(area_set_monitorable, RID, bool) + EXBIND2(area_set_pickable, RID, bool) + + EXBIND2(area_set_monitor_callback, RID, const Callable &) + EXBIND2(area_set_area_monitor_callback, RID, const Callable &) + + /* BODY API */ + + //EXBIND2RID(body,BodyMode,bool); + EXBIND0R(RID, body_create) + + EXBIND2(body_set_space, RID, RID) + EXBIND1RC(RID, body_get_space, RID) + + EXBIND2(body_set_mode, RID, BodyMode) + EXBIND1RC(BodyMode, body_get_mode, RID) + + EXBIND4(body_add_shape, RID, RID, const Transform2D &, bool) + EXBIND3(body_set_shape, RID, int, RID) + EXBIND3(body_set_shape_transform, RID, int, const Transform2D &) + + EXBIND1RC(int, body_get_shape_count, RID) + EXBIND2RC(RID, body_get_shape, RID, int) + EXBIND2RC(Transform2D, body_get_shape_transform, RID, int) + + EXBIND3(body_set_shape_disabled, RID, int, bool) + EXBIND4(body_set_shape_as_one_way_collision, RID, int, bool, real_t) + + EXBIND2(body_remove_shape, RID, int) + EXBIND1(body_clear_shapes, RID) + + EXBIND2(body_attach_object_instance_id, RID, ObjectID) + EXBIND1RC(ObjectID, body_get_object_instance_id, RID) + + EXBIND2(body_attach_canvas_instance_id, RID, ObjectID) + EXBIND1RC(ObjectID, body_get_canvas_instance_id, RID) + + EXBIND2(body_set_continuous_collision_detection_mode, RID, CCDMode) + EXBIND1RC(CCDMode, body_get_continuous_collision_detection_mode, RID) + + EXBIND2(body_set_collision_layer, RID, uint32_t) + EXBIND1RC(uint32_t, body_get_collision_layer, RID) + + EXBIND2(body_set_collision_mask, RID, uint32_t) + EXBIND1RC(uint32_t, body_get_collision_mask, RID) + + EXBIND2(body_set_collision_priority, RID, real_t) + EXBIND1RC(real_t, body_get_collision_priority, RID) + + EXBIND3(body_set_param, RID, BodyParameter, const Variant &) + EXBIND2RC(Variant, body_get_param, RID, BodyParameter) + + EXBIND1(body_reset_mass_properties, RID) + + EXBIND3(body_set_state, RID, BodyState, const Variant &) + EXBIND2RC(Variant, body_get_state, RID, BodyState) + + EXBIND2(body_apply_central_impulse, RID, const Vector2 &) + EXBIND2(body_apply_torque_impulse, RID, real_t) + EXBIND3(body_apply_impulse, RID, const Vector2 &, const Vector2 &) + + EXBIND2(body_apply_central_force, RID, const Vector2 &) + EXBIND3(body_apply_force, RID, const Vector2 &, const Vector2 &) + EXBIND2(body_apply_torque, RID, real_t) + + EXBIND2(body_add_constant_central_force, RID, const Vector2 &) + EXBIND3(body_add_constant_force, RID, const Vector2 &, const Vector2 &) + EXBIND2(body_add_constant_torque, RID, real_t) + + EXBIND2(body_set_constant_force, RID, const Vector2 &) + EXBIND1RC(Vector2, body_get_constant_force, RID) + + EXBIND2(body_set_constant_torque, RID, real_t) + EXBIND1RC(real_t, body_get_constant_torque, RID) + + EXBIND2(body_set_axis_velocity, RID, const Vector2 &) + + EXBIND2(body_add_collision_exception, RID, RID) + EXBIND2(body_remove_collision_exception, RID, RID) + GDVIRTUAL1RC(TypedArray<RID>, _body_get_collision_exceptions, RID) + + void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override { + TypedArray<RID> ret; + GDVIRTUAL_REQUIRED_CALL(_body_get_collision_exceptions, p_body, ret); + for (int i = 0; i < ret.size(); i++) { + p_exceptions->push_back(ret[i]); + } + } + + EXBIND2(body_set_max_contacts_reported, RID, int) + EXBIND1RC(int, body_get_max_contacts_reported, RID) + + EXBIND2(body_set_contacts_reported_depth_threshold, RID, real_t) + EXBIND1RC(real_t, body_get_contacts_reported_depth_threshold, RID) + + EXBIND2(body_set_omit_force_integration, RID, bool) + EXBIND1RC(bool, body_is_omitting_force_integration, RID) + + GDVIRTUAL2(_body_set_state_sync_callback, RID, GDNativePtr<PhysicsServer2DExtensionStateCallback>) + void body_set_state_sync_callback(RID p_body, void *p_instance, BodyStateCallback p_callback) override { + PhysicsServer2DExtensionStateCallback callback; + callback.callback = p_callback; + callback.instance = p_instance; + GDVIRTUAL_REQUIRED_CALL(_body_set_state_sync_callback, p_body, &callback); + } + EXBIND3(body_set_force_integration_callback, RID, const Callable &, const Variant &) + + 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 { + bool ret = false; + GDVIRTUAL_REQUIRED_CALL(_body_collide_shape, p_body, p_body_shape, p_shape, p_shape_xform, p_motion, r_results, p_result_max, &r_result_count, ret); + return ret; + } + + EXBIND2(body_set_pickable, RID, bool) + + EXBIND1R(PhysicsDirectBodyState2D *, body_get_direct_state, RID) + + GDVIRTUAL7RC(bool, _body_test_motion, RID, const Transform2D &, const Vector2 &, real_t, bool, bool, GDNativePtr<PhysicsServer2DExtensionMotionResult>) + + thread_local static const HashSet<RID> *exclude_bodies; + thread_local static const HashSet<ObjectID> *exclude_objects; + + bool body_test_motion_is_excluding_body(RID p_body) const; + bool body_test_motion_is_excluding_object(ObjectID p_object) const; + + bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) override { + bool ret = false; + exclude_bodies = &p_parameters.exclude_bodies; + exclude_objects = &p_parameters.exclude_objects; + GDVIRTUAL_REQUIRED_CALL(_body_test_motion, p_body, p_parameters.from, p_parameters.motion, p_parameters.margin, p_parameters.collide_separation_ray, p_parameters.recovery_as_collision, r_result, ret); + exclude_bodies = nullptr; + exclude_objects = nullptr; + return ret; + } + + /* JOINT API */ + + EXBIND0R(RID, joint_create) + + EXBIND1(joint_clear, RID) + + EXBIND3(joint_set_param, RID, JointParam, real_t) + EXBIND2RC(real_t, joint_get_param, RID, JointParam) + + EXBIND2(joint_disable_collisions_between_bodies, RID, bool) + EXBIND1RC(bool, joint_is_disabled_collisions_between_bodies, RID) + + EXBIND4(joint_make_pin, RID, const Vector2 &, RID, RID) + EXBIND6(joint_make_groove, RID, const Vector2 &, const Vector2 &, const Vector2 &, RID, RID) + EXBIND5(joint_make_damped_spring, RID, const Vector2 &, const Vector2 &, RID, RID) + + EXBIND3(pin_joint_set_param, RID, PinJointParam, real_t) + EXBIND2RC(real_t, pin_joint_get_param, RID, PinJointParam) + + EXBIND3(damped_spring_joint_set_param, RID, DampedSpringParam, real_t) + EXBIND2RC(real_t, damped_spring_joint_get_param, RID, DampedSpringParam) + + EXBIND1RC(JointType, joint_get_type, RID) + + /* MISC */ + + GDVIRTUAL1(_free_rid, RID) + virtual void free(RID p_rid) override { + GDVIRTUAL_REQUIRED_CALL(_free_rid, p_rid); + } + + EXBIND1(set_active, bool) + + EXBIND0(init) + EXBIND1(step, real_t) + EXBIND0(sync) + EXBIND0(flush_queries) + EXBIND0(end_sync) + EXBIND0(finish) + + EXBIND0RC(bool, is_flushing_queries) + EXBIND1R(int, get_process_info, ProcessInfo) + + PhysicsServer2DExtension(); + ~PhysicsServer2DExtension(); +}; + +#endif // PHYSICS_SERVER_2D_EXTENSION_H diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index 6424915b58..528ac18f88 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -850,6 +850,8 @@ void PhysicsServer2D::_bind_methods() { BIND_ENUM_CONSTANT(JOINT_PARAM_MAX_BIAS); BIND_ENUM_CONSTANT(JOINT_PARAM_MAX_FORCE); + BIND_ENUM_CONSTANT(PIN_JOINT_SOFTNESS); + BIND_ENUM_CONSTANT(DAMPED_SPRING_REST_LENGTH); BIND_ENUM_CONSTANT(DAMPED_SPRING_STIFFNESS); BIND_ENUM_CONSTANT(DAMPED_SPRING_DAMPING); diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index f7c44533bf..f1e05e7a46 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -820,6 +820,7 @@ VARIANT_ENUM_CAST(PhysicsServer2D::BodyState); VARIANT_ENUM_CAST(PhysicsServer2D::CCDMode); VARIANT_ENUM_CAST(PhysicsServer2D::JointParam); VARIANT_ENUM_CAST(PhysicsServer2D::JointType); +VARIANT_ENUM_CAST(PhysicsServer2D::PinJointParam); VARIANT_ENUM_CAST(PhysicsServer2D::DampedSpringParam); VARIANT_ENUM_CAST(PhysicsServer2D::AreaBodyStatus); VARIANT_ENUM_CAST(PhysicsServer2D::ProcessInfo); diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index db473f6296..2e794683b9 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -72,6 +72,7 @@ #include "rendering/rendering_device.h" #include "rendering/rendering_device_binds.h" #include "rendering_server.h" +#include "servers/extensions/physics_server_2d_extension.h" #include "servers/extensions/physics_server_3d_extension.h" #include "servers/rendering/shader_types.h" #include "text/text_server_dummy.h" @@ -133,6 +134,16 @@ void register_server_types() { GDREGISTER_CLASS(AudioServer); GDREGISTER_ABSTRACT_CLASS(PhysicsServer2D); + GDREGISTER_VIRTUAL_CLASS(PhysicsServer2DExtension); + GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState2DExtension); + GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState2DExtension); + + GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionRayResult, "Vector2 position;Vector2 normal;RID rid;ObjectID collider_id;Object *collider;int shape"); + GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeResult, "RID rid;ObjectID collider_id;Object *collider;int shape"); + GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeRestInfo, "Vector2 point;Vector2 normal;RID rid;ObjectID collider_id;int shape;Vector2 linear_velocity"); + GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionMotionResult, "Vector2 travel;Vector2 remainder;Vector2 collision_point;Vector2 collision_normal;Vector2 collider_velocity;real_t collision_depth;real_t collision_safe_fraction;real_t collision_unsafe_fraction;int collision_local_shape;ObjectID collider_id;RID collider;int collider_shape"); + GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionStateCallback, "void *instance;void (*callback)(void *p_instance, PhysicsDirectBodyState2D *p_state)"); + GDREGISTER_ABSTRACT_CLASS(PhysicsServer3D); GDREGISTER_VIRTUAL_CLASS(PhysicsServer3DExtension); GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState3DExtension); |